]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add dshash_get_dsa_area(), able to retrieve the DSA area of a dshash table
authorMichael Paquier <michael@paquier.xyz>
Mon, 3 Aug 2026 11:05:23 +0000 (20:05 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 3 Aug 2026 11:05:23 +0000 (20:05 +0900)
Code using GetNamedDSHash() to retrieve a dshash table may also want to
limit its size, but there is actually no easy way to do so because the
dsa_area of a hash table is hidden within dshash.c.

This commit adds dshash_get_dsa_area() to close the gap, which returns
the dsa_area for a given dshash_table.  The DSA area retrieved can then
be passed to dsa_set_size_limit(), to limit its size.  This accessor
routine also opens the door for allocating additional objects in the
same DSA area as a hash table, which may be useful for some.

Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0tKfCVqFnMZtavM42H63ha2Haf_C4mbJNWqkaW30cPW1w@mail.gmail.com

src/backend/lib/dshash.c
src/include/lib/dshash.h

index 1999989c14f717f5836077282c164dd972c71b9e..62ac68d4add7b15f76c57a43caac79f0ea290359 100644 (file)
@@ -363,6 +363,17 @@ dshash_destroy(dshash_table *hash_table)
        pfree(hash_table);
 }
 
+/*
+ * Get the DSA area used by this hash table.
+ */
+dsa_area *
+dshash_get_dsa_area(dshash_table *hash_table)
+{
+       Assert(hash_table->control->magic == DSHASH_MAGIC);
+
+       return hash_table->area;
+}
+
 /*
  * Get a handle that can be used by other processes to attach to this hash
  * table.
index 64b758b381b34764b65525718b241a8efafb7451..b868084df04426b22bfe94d527b14532b184b431 100644 (file)
@@ -89,6 +89,7 @@ extern dshash_table *dshash_attach(dsa_area *area,
                                                                   dshash_table_handle handle,
                                                                   void *arg);
 extern void dshash_detach(dshash_table *hash_table);
+extern dsa_area *dshash_get_dsa_area(dshash_table *hash_table);
 extern dshash_table_handle dshash_get_hash_table_handle(dshash_table *hash_table);
 extern void dshash_destroy(dshash_table *hash_table);