pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Increase the number of possible random seeds per time period.
4+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2018-11-15 ab8984f52d  Further adjustment to random() seed initialization.
* pgsql: Increase the number of possible random seeds per time period.
@ 2018-11-15 03:28 Thomas Munro <tmunro@postgresql.org>
  2018-11-15 03:38 ` Re: pgsql: Increase the number of possible random seeds per time period. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Thomas Munro @ 2018-11-15 03:28 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Increase the number of possible random seeds per time period.

Commit 197e4af9 refactored the initialization of the libc random()
seed, but reduced the number of possible seeds values that could be
chosen in a given time period.  This negation of the effects of
commit 98c50656c was unintentional.  Replace with code that
shifts the fast moving timestamp bits left, similar to the original
algorithm (though not the previous float-tolerating coding, which
is no longer necessary).

Author: Thomas Munro
Reported-by: Noah Misch
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/20181112083358.GA1073796%40rfd.leadboat.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5b0ce3ec334bb65bbab4aba78f204f986c356e80

Modified Files
--------------
src/backend/postmaster/postmaster.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: pgsql: Increase the number of possible random seeds per time period.
  2018-11-15 03:28 pgsql: Increase the number of possible random seeds per time period. Thomas Munro <tmunro@postgresql.org>
@ 2018-11-15 03:38 ` Tom Lane <tgl@sss.pgh.pa.us>
  2018-11-15 03:59   ` Re: pgsql: Increase the number of possible random seeds per time period. Thomas Munro <thomas.munro@enterprisedb.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2018-11-15 03:38 UTC (permalink / raw)
  To: Thomas Munro <tmunro@postgresql.org>; +Cc: pgsql-committers@lists.postgresql.org

Thomas Munro <tmunro@postgresql.org> writes:
> Increase the number of possible random seeds per time period.

Um, this bit is *not* right:

+           ((unsigned int) MyStartTimestamp >> 20));

You're cutting it down to 32 bits and then right shifting, which
means you are shifting in a lot of zeroes when you could be shifting
in something that's not quite as predetermined.  I had in mind to do
the shifts in uint64 arithmetic and then narrow the final XOR result
to int (maybe let the compiler do that implicitly).

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: pgsql: Increase the number of possible random seeds per time period.
  2018-11-15 03:28 pgsql: Increase the number of possible random seeds per time period. Thomas Munro <tmunro@postgresql.org>
  2018-11-15 03:38 ` Re: pgsql: Increase the number of possible random seeds per time period. Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-11-15 03:59   ` Thomas Munro <thomas.munro@enterprisedb.com>
  2018-11-15 04:21     ` Re: pgsql: Increase the number of possible random seeds per time period. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Thomas Munro @ 2018-11-15 03:59 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Thomas Munro <tmunro@postgresql.org>; pgsql-committers@lists.postgresql.org

On Thu, Nov 15, 2018 at 4:38 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Thomas Munro <tmunro@postgresql.org> writes:
> > Increase the number of possible random seeds per time period.
>
> Um, this bit is *not* right:
>
> +           ((unsigned int) MyStartTimestamp >> 20));
>
> You're cutting it down to 32 bits and then right shifting, which
> means you are shifting in a lot of zeroes when you could be shifting
> in something that's not quite as predetermined.  I had in mind to do
> the shifts in uint64 arithmetic and then narrow the final XOR result
> to int (maybe let the compiler do that implicitly).

Will this close the case?

-       srandom(((unsigned int) MyProcPid) ^
-                       ((unsigned int) MyStartTimestamp << 12) ^
-                       ((unsigned int) MyStartTimestamp >> 20));
+       srandom(((uint64) MyProcPid) ^
+                       ((uint64) MyStartTimestamp << 12) ^
+                       ((uint64) MyStartTimestamp >> 20));


--
Thomas Munro
http://www.enterprisedb.com




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: pgsql: Increase the number of possible random seeds per time period.
  2018-11-15 03:28 pgsql: Increase the number of possible random seeds per time period. Thomas Munro <tmunro@postgresql.org>
  2018-11-15 03:38 ` Re: pgsql: Increase the number of possible random seeds per time period. Tom Lane <tgl@sss.pgh.pa.us>
  2018-11-15 03:59   ` Re: pgsql: Increase the number of possible random seeds per time period. Thomas Munro <thomas.munro@enterprisedb.com>
@ 2018-11-15 04:21     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2018-11-15 04:21 UTC (permalink / raw)
  To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: Thomas Munro <tmunro@postgresql.org>; pgsql-committers@lists.postgresql.org

Thomas Munro <thomas.munro@enterprisedb.com> writes:
> On Thu, Nov 15, 2018 at 4:38 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Um, this bit is *not* right:

> Will this close the case?

> -       srandom(((unsigned int) MyProcPid) ^
> -                       ((unsigned int) MyStartTimestamp << 12) ^
> -                       ((unsigned int) MyStartTimestamp >> 20));
> +       srandom(((uint64) MyProcPid) ^
> +                       ((uint64) MyStartTimestamp << 12) ^
> +                       ((uint64) MyStartTimestamp >> 20));

WFM.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2018-11-15 04:21 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-11-15 03:28 pgsql: Increase the number of possible random seeds per time period. Thomas Munro <tmunro@postgresql.org>
2018-11-15 03:38 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-11-15 03:59   ` Thomas Munro <thomas.munro@enterprisedb.com>
2018-11-15 04:21     ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox