diff options
author | Robert Haas <rhaas@postgresql.org> | 2019-12-17 14:11:14 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2019-12-17 14:14:32 -0500 |
commit | da41d71070d14ecd9e2f4bbe275c98a136826d4b (patch) | |
tree | f353351aa720e3af715caae71fa0d066cd081a8c | |
parent | 48995040d5e7b1e9bac35d72aff326cae002219d (diff) | |
download | postgresql-da41d71070d14ecd9e2f4bbe275c98a136826d4b.tar.gz postgresql-da41d71070d14ecd9e2f4bbe275c98a136826d4b.zip |
simplehash: Allow for use in frontend code.
Commit 48995040d5e7b1e9bac35d72aff326cae002219d removed the largest
barrier to use of simplehash in frontend code, but there's one more
problem: it uses elog(ERROR, ...) or elog(LOG, ...) in a couple of
places. Work around that by changing those to pg_log_error() and
pg_log_info() when FRONTEND is defined.
Patch by me, reviewed by Andres Freund.
Discussion: http://postgr.es/m/CA+Tgmob8oyh02NrZW=xCScB+5GyJ-jVowE3+TWTUmPF=FsGWTA@mail.gmail.com
-rw-r--r-- | src/include/lib/simplehash.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/include/lib/simplehash.h b/src/include/lib/simplehash.h index 403837a4072..5a6783f6532 100644 --- a/src/include/lib/simplehash.h +++ b/src/include/lib/simplehash.h @@ -236,6 +236,14 @@ sh_pow2(uint64 num) return ((uint64) 1) << sh_log2(num); } +#ifdef FRONTEND +#define sh_error(...) pg_log_error(__VA_ARGS__) +#define sh_log(...) pg_log_info(__VA_ARGS__) +#else +#define sh_error(...) elog(ERROR, __VA_ARGS__) +#define sh_log(...) elog(LOG, __VA_ARGS__) +#endif + #endif /* @@ -258,8 +266,8 @@ SH_COMPUTE_PARAMETERS(SH_TYPE * tb, uint32 newsize) * Verify that allocation of ->data is possible on this platform, without * overflowing Size. */ - if ((((uint64) sizeof(SH_ELEMENT_TYPE)) * size) >= MaxAllocHugeSize) - elog(ERROR, "hash table too large"); + if ((((uint64) sizeof(SH_ELEMENT_TYPE)) * size) >= SIZE_MAX / 2) + sh_error("hash table too large"); /* now set size */ tb->size = size; @@ -549,7 +557,7 @@ restart: { if (tb->size == SH_MAX_SIZE) { - elog(ERROR, "hash table size exceeded"); + sh_error("hash table size exceeded"); } /* @@ -1001,7 +1009,7 @@ SH_STAT(SH_TYPE * tb) avg_collisions = 0; } - elog(LOG, "size: " UINT64_FORMAT ", members: %u, filled: %f, total chain: %u, max chain: %u, avg chain: %f, total_collisions: %u, max_collisions: %i, avg_collisions: %f", + sh_log("size: " UINT64_FORMAT ", members: %u, filled: %f, total chain: %u, max chain: %u, avg chain: %f, total_collisions: %u, max_collisions: %i, avg_collisions: %f", tb->size, tb->members, fillfactor, total_chain_length, max_chain_length, avg_chain_length, total_collisions, max_collisions, avg_collisions); } |