Hi hackers,
Recently, while working with hash tables in dynahash.c, I noticed
something weird.
When a hash table is already created in shared memory, and the another
process
calls hash_create attempting to attach to it, it seems like the
HASH_FIXED_SIZE
flag gets lost.
For example, if you start the server compiled with the EXEC_BACKEND
option, and a
hash table with a fixed size is created at the beginning in shared
memory, any
other process started by the postmaster then tries to initialize its
hash table
pointer by calling hash_create with HASH_ATTACH flag. But the table
structure it
points to has 'isfixed' flag set to false, even though the original
table was
created with a HASH_FIXED_SIZE provided.
This could lead to the situation where, when the table's capacity limit
is reached
(which was specified when the table was created), the process will
silently occupy
more of the shared memory (up to a certain point?). Then, another insert
could
trigger an out of shared memory error.
Any thoughts?
Regards,
Aidar Imamov
diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index 1ad155d446e..f0efb4fd3b6 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -496,6 +496,9 @@ hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
hashp->ssize = hctl->ssize;
hashp->sshift = hctl->sshift;
+ if (flags & HASH_FIXED_SIZE)
+ hashp->isfixed = true;
+
return hashp;
}
}