Re: Use pg_nextpower2_* in a few more places - Mailing list pgsql-hackers

From David Rowley
Subject Re: Use pg_nextpower2_* in a few more places
Date
Msg-id CAApHDvqtgDjzs4TdEednVewaFd9N8N7C+SpwVHfE0KJidpiDVQ@mail.gmail.com
Whole thread Raw
In response to Re: Use pg_nextpower2_* in a few more places  (Zhihong Yu <zyu@yugabyte.com>)
Responses Re: Use pg_nextpower2_* in a few more places
List pgsql-hackers
On Sun, 13 Jun 2021 at 02:08, Zhihong Yu <zyu@yugabyte.com> wrote:
> Maybe add an assertion after the assignment, that newalloc >=  LWLockTrancheNamesAllocated.

I don't quite see how it would be possible for that to ever fail.  I
could understand adding an Assert() if some logic was outside the
function and we wanted to catch something outside of the function's
control, but that's not the case here.  All the logic is within a few
lines.

Maybe it would help if we look at the if condition that this code
executes under:

/* If necessary, create or enlarge array. */
if (tranche_id >= LWLockTrancheNamesAllocated)

So since we're doing:

+       newalloc = pg_nextpower2_32(Max(8, tranche_id + 1));

assuming pg_nextpower2_32 does not give us something incorrect, then I
don't quite see why Assert(newalloc >=  LWLockTrancheNamesAllocated)
could ever fail.

Can you explain why you think it might?

David



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Race condition in recovery?
Next
From: Zhihong Yu
Date:
Subject: Re: Use pg_nextpower2_* in a few more places