Re: Use pg_nextpower2_* in a few more places

Поиск
Список
Период
Сортировка
От Zhihong Yu
Тема Re: Use pg_nextpower2_* in a few more places
Дата
Msg-id CALNJ-vQfeHXHEXO=pmOOPcFba5DoO-tkQ8sZnxcRwzt_Q9=NyQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Use pg_nextpower2_* in a few more places  (David Rowley <dgrowleyml@gmail.com>)
Ответы Re: Use pg_nextpower2_* in a few more places  (David Rowley <dgrowleyml@gmail.com>)
Список pgsql-hackers


On Sat, Jun 12, 2021 at 6:40 AM David Rowley <dgrowleyml@gmail.com> wrote:
Thanks for having a look.

On Sun, 13 Jun 2021 at 00:50, Zhihong Yu <zyu@yugabyte.com> wrote:
> -       newalloc = Max(LWLockTrancheNamesAllocated, 8);
> -       while (newalloc <= tranche_id)
> -           newalloc *= 2;
> +       newalloc = pg_nextpower2_32(Max(8, tranche_id + 1));
>
> Should LWLockTrancheNamesAllocated be included in the Max() expression (in case it gets to a high value) ?

I think the new code will produce the same result as the old code in all cases.

All the old code did was finding the next power of 2 that's >= 8 and
larger than tranche_id.  LWLockTrancheNamesAllocated is just a hint at
where the old code should start searching from.  The new code does not
need that hint. All it seems to do is save the old code from having to
start the loop at 8 each time we need more space.

David
Hi,
Maybe add an assertion after the assignment, that newalloc >=  LWLockTrancheNamesAllocated.

Cheers

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Ranier Vilela
Дата:
Сообщение: Signed vs Unsigned (take 2) (src/backend/storage/ipc/procarray.c)
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Race condition in recovery?