Re: DSM segment handle generation in background workers
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2018-10-11T04:51:12Z
Lists: pgsql-hackers
Thomas Munro <thomas.munro@enterprisedb.com> writes: >> Ok, here is a sketch patch with a new function InitRandomSeeds() to do >> that. It is called from PostmasterMain(), InitPostmasterChild() and >> InitStandaloneProcess() for consistency. > Here's a version I propose to push to master and 11 tomorrow, if there > are no objections. The comment adjacent to the change in InitStandaloneProcess bothers me. In particular, it points out that what BackendRun() is currently doing creates more entropy in the process's random seed than what you have here: MyStartTime is only good to the nearest second, whereas the code you removed from BackendRun() factors in fractional seconds to whatever the precision of GetCurrentTimestamp is. This does not seem like an improvement. I'm inclined to think we should refactor a bit more aggressively so that, rather than dumbing backends down to the standard of other processes, we make them all use the better method. A reasonable way to approach this would be to invent a global variable MyStartTimestamp beside MyStartTime, and initialize both of them in the places that currently initialize the latter, using code like that in BackendInitialize: /* save process start time */ port->SessionStartTime = GetCurrentTimestamp(); MyStartTime = timestamptz_to_time_t(port->SessionStartTime); and then this new InitRandomSeeds function could adopt BackendRun's seed initialization method instead of the stupider way. Possibly it'd be sane to merge the MyStartTime* initializations and the srandom resets into one function, not sure. regards, tom lane
Commits
-
Increase the number of possible random seeds per time period.
- 5b0ce3ec334b 12.0 landed
-
Refactor pid, random seed and start time initialization.
- 197e4af9d5da 12.0 landed
-
Increase the number of different values used when seeding random().
- 98c50656cac2 9.4.0 cited