mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Refactor pid, random seed and start time initialization.
Background workers, including parallel workers, were generating the same sequence of numbers in random(). This showed up as DSM handle collisions when Parallel Hash created multiple segments, but any code that calls random() in background workers could be affected if it cares about different backends generating different numbers. Repair by making sure that all new processes initialize the seed at the same time as they set MyProcPid and MyStartTime in a new function InitProcessGlobals(), called by the postmaster, its children and also standalone processes. Also add a new high resolution MyStartTimestamp as a potentially useful by-product, and remove SessionStartTime from struct Port as it is now redundant. No back-patch for now, as the known consequences so far are just a bunch of harmless shm_open(O_EXCL) collisions. Author: Thomas Munro Reviewed-by: Tom Lane Discussion: https://postgr.es/m/CAEepm%3D2eJj_6%3DB%2B2tEpGu2nf1BjthCf9nXXUouYvJJ4C5WSwhg%40mail.gmail.com
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include "datatype/timestamp.h" /* for TimestampTZ */
|
||||
#include "pgtime.h" /* for pg_time_t */
|
||||
|
||||
|
||||
@ -163,6 +164,7 @@ extern PGDLLIMPORT int max_parallel_workers;
|
||||
|
||||
extern PGDLLIMPORT int MyProcPid;
|
||||
extern PGDLLIMPORT pg_time_t MyStartTime;
|
||||
extern PGDLLIMPORT TimestampTz MyStartTimestamp;
|
||||
extern PGDLLIMPORT struct Port *MyProcPort;
|
||||
extern PGDLLIMPORT struct Latch *MyLatch;
|
||||
extern int32 MyCancelKey;
|
||||
|
Reference in New Issue
Block a user