[pgpool-committers: 10507] pgpool: Replace random() with pg_prng random function.
Tatsuo Ishii
ishii at postgresql.org
Tue May 27 19:18:04 JST 2025
Replace random() with pg_prng random function.
Previously we used random() for choosing load balancing node. However
PostgreSQL has better random number generator: pg_prng.c. This commit
imports the file and use pg_prng_double() to generate random number in
range [0.0, 1.0).
Other notes regarding the port:
- pg_prng needs to be initialized using pg_prng_strong_seed() per
process. Currently the only caller is child.c (per session
process). If other process needs to use pg_prng, it needs the same
initialization as child.c.
- Some of functions in the file were not ported because they require
additional library: pg_bitutils.c. In the future we may revisit and
import pg_bitutils.c.
- likely/unlikely are ignored. In the future we may revisit import
them.
- All conditional compiling regarding "sun" or "_sun" are removed. It
seems the platform is not used for running pgpool anymore.
- Since srandom() is not necessary any more, related code are removed
from pgpool_main.c, child.c and pcp_worker.c.
Discussion: [pgpool-hackers: 4588] Shuffle random functions and use better random numbers
https://www.pgpool.net/pipermail/pgpool-hackers/2025-May/004589.html
Branch
------
master
Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=66fcd561d74c8f00326bad94300053bd7ea13566
Modified Files
--------------
src/Makefile.am | 3 +-
src/include/pool_type.h | 8 +-
src/main/pgpool_main.c | 5 -
src/pcp_con/pcp_worker.c | 6 +-
src/protocol/child.c | 75 ++++++++--
src/protocol/pool_pg_utils.c | 30 ++--
src/utils/pg_prng.c | 333 +++++++++++++++++++++++++++++++++++++++++++
7 files changed, 417 insertions(+), 43 deletions(-)
More information about the pgpool-committers
mailing list