PostgreSQL Source Code git master
Loading...
Searching...
No Matches
dshash.h File Reference
#include "utils/dsa.h"
Include dependency graph for dshash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dshash_parameters
 
struct  dshash_seq_status
 

Macros

#define DSHASH_HANDLE_INVALID   ((dshash_table_handle) InvalidDsaPointer)
 
#define DSHASH_INSERT_NO_OOM   0x01 /* no failure if out-of-memory */
 
#define dshash_find_or_insert(hash_table, key, found)    dshash_find_or_insert_extended(hash_table, key, found, 0)
 

Typedefs

typedef struct dshash_table dshash_table
 
typedef dsa_pointer dshash_table_handle
 
typedef uint32 dshash_hash
 
typedef int(* dshash_compare_function) (const void *a, const void *b, size_t size, void *arg)
 
typedef dshash_hash(* dshash_hash_function) (const void *v, size_t size, void *arg)
 
typedef void(* dshash_copy_function) (void *dest, const void *src, size_t size, void *arg)
 
typedef struct dshash_parameters dshash_parameters
 
typedef struct dshash_table_item dshash_table_item
 
typedef struct dshash_seq_status dshash_seq_status
 

Functions

dshash_tabledshash_create (dsa_area *area, const dshash_parameters *params, void *arg)
 
dshash_tabledshash_attach (dsa_area *area, const dshash_parameters *params, dshash_table_handle handle, void *arg)
 
void dshash_detach (dshash_table *hash_table)
 
dshash_table_handle dshash_get_hash_table_handle (dshash_table *hash_table)
 
void dshash_destroy (dshash_table *hash_table)
 
voiddshash_find (dshash_table *hash_table, const void *key, bool exclusive)
 
voiddshash_find_or_insert_extended (dshash_table *hash_table, const void *key, bool *found, int flags)
 
bool dshash_delete_key (dshash_table *hash_table, const void *key)
 
void dshash_delete_entry (dshash_table *hash_table, void *entry)
 
void dshash_release_lock (dshash_table *hash_table, void *entry)
 
void dshash_seq_init (dshash_seq_status *status, dshash_table *hash_table, bool exclusive)
 
voiddshash_seq_next (dshash_seq_status *status)
 
void dshash_seq_term (dshash_seq_status *status)
 
void dshash_delete_current (dshash_seq_status *status)
 
int dshash_memcmp (const void *a, const void *b, size_t size, void *arg)
 
dshash_hash dshash_memhash (const void *v, size_t size, void *arg)
 
void dshash_memcpy (void *dest, const void *src, size_t size, void *arg)
 
int dshash_strcmp (const void *a, const void *b, size_t size, void *arg)
 
dshash_hash dshash_strhash (const void *v, size_t size, void *arg)
 
void dshash_strcpy (void *dest, const void *src, size_t size, void *arg)
 
void dshash_dump (dshash_table *hash_table)
 

Macro Definition Documentation

◆ dshash_find_or_insert

#define dshash_find_or_insert (   hash_table,
  key,
  found 
)     dshash_find_or_insert_extended(hash_table, key, found, 0)

Definition at line 109 of file dshash.h.

◆ DSHASH_HANDLE_INVALID

#define DSHASH_HANDLE_INVALID   ((dshash_table_handle) InvalidDsaPointer)

Definition at line 27 of file dshash.h.

◆ DSHASH_INSERT_NO_OOM

#define DSHASH_INSERT_NO_OOM   0x01 /* no failure if out-of-memory */

Definition at line 96 of file dshash.h.

Typedef Documentation

◆ dshash_compare_function

typedef int(* dshash_compare_function) (const void *a, const void *b, size_t size, void *arg)

Definition at line 33 of file dshash.h.

◆ dshash_copy_function

typedef void(* dshash_copy_function) (void *dest, const void *src, size_t size, void *arg)

Definition at line 41 of file dshash.h.

◆ dshash_hash

Definition at line 30 of file dshash.h.

◆ dshash_hash_function

typedef dshash_hash(* dshash_hash_function) (const void *v, size_t size, void *arg)

Definition at line 37 of file dshash.h.

◆ dshash_parameters

◆ dshash_seq_status

◆ dshash_table

Definition at line 21 of file dshash.h.

◆ dshash_table_handle

Definition at line 24 of file dshash.h.

◆ dshash_table_item

Definition at line 66 of file dshash.h.

Function Documentation

◆ dshash_attach()

dshash_table * dshash_attach ( dsa_area area,
const dshash_parameters params,
dshash_table_handle  handle,
void arg 
)
extern

Definition at line 274 of file dshash.c.

276{
277 dshash_table *hash_table;
278 dsa_pointer control;
279
280 /* Allocate the backend-local object representing the hash table. */
281 hash_table = palloc_object(dshash_table);
282
283 /* Find the control object in shared memory. */
284 control = handle;
285
286 /* Set up the local hash table struct. */
287 hash_table->area = area;
288 hash_table->params = *params;
289 hash_table->arg = arg;
290 hash_table->control = dsa_get_address(area, control);
291 Assert(hash_table->control->magic == DSHASH_MAGIC);
292
293 /*
294 * These will later be set to the correct values by
295 * ensure_valid_bucket_pointers(), at which time we'll be holding a
296 * partition lock for interlocking against concurrent resizing.
297 */
298 hash_table->buckets = NULL;
299 hash_table->size_log2 = 0;
300
301 return hash_table;
302}
#define Assert(condition)
Definition c.h:943
void * dsa_get_address(dsa_area *area, dsa_pointer dp)
Definition dsa.c:957
uint64 dsa_pointer
Definition dsa.h:62
#define DSHASH_MAGIC
Definition dshash.c:65
Datum arg
Definition elog.c:1322
#define palloc_object(type)
Definition fe_memutils.h:74
static int fb(int x)
dshash_parameters params
Definition dshash.c:108
dsa_pointer * buckets
Definition dshash.c:111
dsa_area * area
Definition dshash.c:107
void * arg
Definition dshash.c:109
size_t size_log2
Definition dshash.c:112
dshash_table_control * control
Definition dshash.c:110

References dshash_table::area, dshash_table::arg, arg, Assert, dshash_table::buckets, dshash_table::control, dsa_get_address(), DSHASH_MAGIC, fb(), dshash_table_control::magic, palloc_object, dshash_table::params, and dshash_table::size_log2.

Referenced by GetNamedDSHash(), init_dsm_registry(), initGlobalChannelTable(), logicalrep_launcher_attach_dshmem(), pgsa_attach(), pgstat_attach_shmem(), and SharedRecordTypmodRegistryAttach().

◆ dshash_create()

dshash_table * dshash_create ( dsa_area area,
const dshash_parameters params,
void arg 
)
extern

Definition at line 210 of file dshash.c.

211{
212 dshash_table *hash_table;
213 dsa_pointer control;
214
215 /* Allocate the backend-local object representing the hash table. */
216 hash_table = palloc_object(dshash_table);
217
218 /* Allocate the control object in shared memory. */
219 control = dsa_allocate(area, sizeof(dshash_table_control));
220
221 /* Set up the local and shared hash table structs. */
222 hash_table->area = area;
223 hash_table->params = *params;
224 hash_table->arg = arg;
225 hash_table->control = dsa_get_address(area, control);
226 hash_table->control->handle = control;
227 hash_table->control->magic = DSHASH_MAGIC;
228 hash_table->control->lwlock_tranche_id = params->tranche_id;
229
230 /* Set up the array of lock partitions. */
231 {
233 int tranche_id = hash_table->control->lwlock_tranche_id;
234 int i;
235
236 for (i = 0; i < DSHASH_NUM_PARTITIONS; ++i)
237 {
238 LWLockInitialize(&partitions[i].lock, tranche_id);
239 partitions[i].count = 0;
240 }
241 }
242
243 /*
244 * Set up the initial array of buckets. Our initial size is the same as
245 * the number of partitions.
246 */
248 hash_table->control->buckets =
252 if (!DsaPointerIsValid(hash_table->control->buckets))
253 {
254 dsa_free(area, control);
257 errmsg("out of memory"),
258 errdetail("Failed on DSA request of size %zu.",
260 }
261 hash_table->buckets = dsa_get_address(area,
262 hash_table->control->buckets);
263 hash_table->size_log2 = hash_table->control->size_log2;
264
265 return hash_table;
266}
dsa_pointer dsa_allocate_extended(dsa_area *area, size_t size, int flags)
Definition dsa.c:686
void dsa_free(dsa_area *area, dsa_pointer dp)
Definition dsa.c:841
#define dsa_allocate(area, size)
Definition dsa.h:109
#define DSA_ALLOC_NO_OOM
Definition dsa.h:74
#define DsaPointerIsValid(x)
Definition dsa.h:106
#define DSA_ALLOC_ZERO
Definition dsa.h:75
#define DSHASH_NUM_PARTITIONS
Definition dshash.c:62
#define DSHASH_NUM_PARTITIONS_LOG2
Definition dshash.c:61
int errcode(int sqlerrcode)
Definition elog.c:874
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:151
int i
Definition isn.c:77
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition lwlock.c:670
static char * errmsg
static int partitions
Definition pgbench.c:224
dshash_partition partitions[DSHASH_NUM_PARTITIONS]
Definition dshash.c:89
dshash_table_handle handle
Definition dshash.c:87
dsa_pointer buckets
Definition dshash.c:99

References dshash_table::area, dshash_table::arg, arg, dshash_table_control::buckets, dshash_table::buckets, dshash_table::control, DSA_ALLOC_NO_OOM, DSA_ALLOC_ZERO, dsa_allocate, dsa_allocate_extended(), dsa_free(), dsa_get_address(), DsaPointerIsValid, DSHASH_MAGIC, DSHASH_NUM_PARTITIONS, DSHASH_NUM_PARTITIONS_LOG2, ereport, errcode(), errdetail(), errmsg, ERROR, fb(), dshash_table_control::handle, i, dshash_table_control::lwlock_tranche_id, LWLockInitialize(), dshash_table_control::magic, palloc_object, dshash_table::params, dshash_table_control::partitions, partitions, dshash_table_control::size_log2, dshash_table::size_log2, and dshash_parameters::tranche_id.

Referenced by GetNamedDSHash(), init_dsm_registry(), initGlobalChannelTable(), logicalrep_launcher_attach_dshmem(), pgsa_attach(), SharedRecordTypmodRegistryInit(), and StatsShmemInit().

◆ dshash_delete_current()

void dshash_delete_current ( dshash_seq_status status)
extern

Definition at line 778 of file dshash.c.

779{
780 dshash_table *hash_table = status->hash_table;
781 dshash_table_item *item = status->curitem;
783
785
786 Assert(status->exclusive);
787 Assert(hash_table->control->magic == DSHASH_MAGIC);
789 LW_EXCLUSIVE));
790
791 delete_item(hash_table, item);
792}
#define PG_USED_FOR_ASSERTS_ONLY
Definition c.h:249
#define PARTITION_LOCK(hash_table, i)
Definition dshash.c:196
static void delete_item(dshash_table *hash_table, dshash_table_item *item)
Definition dshash.c:853
#define PARTITION_FOR_HASH(hash)
Definition dshash.c:142
bool LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1929
@ LW_EXCLUSIVE
Definition lwlock.h:104
dshash_table_item * curitem
Definition dshash.h:77
dshash_table * hash_table
Definition dshash.h:74
dshash_hash hash
Definition dshash.c:51

References Assert, dshash_table::control, dshash_seq_status::curitem, delete_item(), DSHASH_MAGIC, dshash_seq_status::exclusive, fb(), dshash_table_item::hash, dshash_seq_status::hash_table, LW_EXCLUSIVE, LWLockHeldByMeInMode(), dshash_table_control::magic, PARTITION_FOR_HASH, PARTITION_LOCK, and PG_USED_FOR_ASSERTS_ONLY.

Referenced by CleanupListenersOnExit(), pgsa_drop_stash(), and pgstat_free_entry().

◆ dshash_delete_entry()

void dshash_delete_entry ( dshash_table hash_table,
void entry 
)
extern

◆ dshash_delete_key()

bool dshash_delete_key ( dshash_table hash_table,
const void key 
)
extern

Definition at line 524 of file dshash.c.

525{
527 size_t partition;
528 bool found;
529
530 Assert(hash_table->control->magic == DSHASH_MAGIC);
532
533 hash = hash_key(hash_table, key);
535
538
539 if (delete_key_from_bucket(hash_table, key,
540 &BUCKET_FOR_HASH(hash_table, hash)))
541 {
542 Assert(hash_table->control->partitions[partition].count > 0);
543 found = true;
544 --hash_table->control->partitions[partition].count;
545 }
546 else
547 found = false;
548
550
551 return found;
552}
static bool delete_key_from_bucket(dshash_table *hash_table, const void *key, dsa_pointer *bucket_head)
Definition dshash.c:1052
static dshash_hash hash_key(dshash_table *hash_table, const void *key)
Definition dshash.c:1109
#define ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME(hash_table)
Definition dshash.c:199
static void ensure_valid_bucket_pointers(dshash_table *hash_table)
Definition dshash.c:976
#define BUCKET_FOR_HASH(hash_table, hash)
Definition dshash.c:163
uint32 dshash_hash
Definition dshash.h:30
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
static unsigned hash(unsigned *uv, int n)
Definition rege_dfa.c:715
size_t count
Definition dshash.c:78

References Assert, ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, BUCKET_FOR_HASH, dshash_table::control, dshash_partition::count, delete_key_from_bucket(), DSHASH_MAGIC, ensure_valid_bucket_pointers(), fb(), hash(), hash_key(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), dshash_table_control::magic, PARTITION_FOR_HASH, PARTITION_LOCK, and dshash_table_control::partitions.

Referenced by ApplyLauncherForgetWorkerStartTime(), and find_or_make_matching_shared_tupledesc().

◆ dshash_destroy()

void dshash_destroy ( dshash_table hash_table)
extern

Definition at line 327 of file dshash.c.

328{
329 size_t size;
330 size_t i;
331
332 Assert(hash_table->control->magic == DSHASH_MAGIC);
334
335 /* Free all the entries. */
336 size = NUM_BUCKETS(hash_table->size_log2);
337 for (i = 0; i < size; ++i)
338 {
339 dsa_pointer item_pointer = hash_table->buckets[i];
340
342 {
343 dshash_table_item *item;
345
346 item = dsa_get_address(hash_table->area, item_pointer);
347 next_item_pointer = item->next;
348 dsa_free(hash_table->area, item_pointer);
350 }
351 }
352
353 /*
354 * Vandalize the control block to help catch programming errors where
355 * other backends access the memory formerly occupied by this hash table.
356 */
357 hash_table->control->magic = 0;
358
359 /* Free the active table and control object. */
360 dsa_free(hash_table->area, hash_table->control->buckets);
361 dsa_free(hash_table->area, hash_table->control->handle);
362
363 pfree(hash_table);
364}
#define NUM_BUCKETS(size_log2)
Definition dshash.c:129
void pfree(void *pointer)
Definition mcxt.c:1616
dsa_pointer next
Definition dshash.c:49

References dshash_table::area, Assert, dshash_table_control::buckets, dshash_table::buckets, dshash_table::control, dsa_free(), dsa_get_address(), DsaPointerIsValid, DSHASH_MAGIC, ensure_valid_bucket_pointers(), fb(), dshash_table_control::handle, i, dshash_table_control::magic, dshash_table_item::next, NUM_BUCKETS, pfree(), and dshash_table::size_log2.

◆ dshash_detach()

void dshash_detach ( dshash_table hash_table)
extern

Definition at line 311 of file dshash.c.

312{
314
315 /* The hash table may have been destroyed. Just free local memory. */
316 pfree(hash_table);
317}

References ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, and pfree().

Referenced by pgstat_detach_shmem(), shared_record_typmod_registry_detach(), and StatsShmemInit().

◆ dshash_dump()

void dshash_dump ( dshash_table hash_table)
extern

Definition at line 799 of file dshash.c.

800{
801 size_t i;
802 size_t j;
803
804 Assert(hash_table->control->magic == DSHASH_MAGIC);
806
807 for (i = 0; i < DSHASH_NUM_PARTITIONS; ++i)
808 {
809 Assert(!LWLockHeldByMe(PARTITION_LOCK(hash_table, i)));
811 }
812
814
816 "hash table size = %zu\n", (size_t) 1 << hash_table->size_log2);
817 for (i = 0; i < DSHASH_NUM_PARTITIONS; ++i)
818 {
820 size_t begin = BUCKET_INDEX_FOR_PARTITION(i, hash_table->size_log2);
821 size_t end = BUCKET_INDEX_FOR_PARTITION(i + 1, hash_table->size_log2);
822
823 fprintf(stderr, " partition %zu\n", i);
825 " active buckets (key count = %zu)\n", partition->count);
826
827 for (j = begin; j < end; ++j)
828 {
829 size_t count = 0;
830 dsa_pointer bucket = hash_table->buckets[j];
831
833 {
834 dshash_table_item *item;
835
836 item = dsa_get_address(hash_table->area, bucket);
837
838 bucket = item->next;
839 ++count;
840 }
841 fprintf(stderr, " bucket %zu (key count = %zu)\n", j, count);
842 }
843 }
844
845 for (i = 0; i < DSHASH_NUM_PARTITIONS; ++i)
846 LWLockRelease(PARTITION_LOCK(hash_table, i));
847}
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
#define BUCKET_INDEX_FOR_PARTITION(partition, size_log2)
Definition dshash.c:155
int j
Definition isn.c:78
bool LWLockHeldByMe(LWLock *lock)
Definition lwlock.c:1885
@ LW_SHARED
Definition lwlock.h:105

References dshash_table::area, Assert, ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, BUCKET_INDEX_FOR_PARTITION, dshash_table::buckets, dshash_table::control, dsa_get_address(), DsaPointerIsValid, DSHASH_MAGIC, DSHASH_NUM_PARTITIONS, ensure_valid_bucket_pointers(), fb(), fprintf, i, j, LW_SHARED, LWLockAcquire(), LWLockHeldByMe(), LWLockRelease(), dshash_table_control::magic, dshash_table_item::next, PARTITION_LOCK, dshash_table_control::partitions, and dshash_table::size_log2.

◆ dshash_find()

void * dshash_find ( dshash_table hash_table,
const void key,
bool  exclusive 
)
extern

Definition at line 394 of file dshash.c.

395{
397 size_t partition;
398 dshash_table_item *item;
399
400 hash = hash_key(hash_table, key);
402
403 Assert(hash_table->control->magic == DSHASH_MAGIC);
405
407 exclusive ? LW_EXCLUSIVE : LW_SHARED);
409
410 /* Search the active bucket. */
411 item = find_in_bucket(hash_table, key, BUCKET_FOR_HASH(hash_table, hash));
412
413 if (!item)
414 {
415 /* Not found. */
417 return NULL;
418 }
419 else
420 {
421 /* The caller will free the lock by calling dshash_release_lock. */
422 return ENTRY_FROM_ITEM(item);
423 }
424}
#define ENTRY_FROM_ITEM(item)
Definition dshash.c:116
static dshash_table_item * find_in_bucket(dshash_table *hash_table, const void *key, dsa_pointer item_pointer)
Definition dshash.c:990

References Assert, ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, BUCKET_FOR_HASH, dshash_table::control, DSHASH_MAGIC, ensure_valid_bucket_pointers(), ENTRY_FROM_ITEM, fb(), find_in_bucket(), hash(), hash_key(), LW_EXCLUSIVE, LW_SHARED, LWLockAcquire(), LWLockRelease(), dshash_table_control::magic, PARTITION_FOR_HASH, and PARTITION_LOCK.

Referenced by ApplyLauncherGetWorkerStartTime(), ApplyPendingListenActions(), find_or_make_matching_shared_tupledesc(), get_val_in_hash(), lookup_rowtype_tupdesc_internal(), pgsa_advisor(), pgsa_clear_advice_string(), pgsa_drop_stash(), pgsa_lookup_stash_id(), pgstat_drop_entry(), pgstat_get_entry_ref(), pgstat_release_entry_ref(), and SignalBackends().

◆ dshash_find_or_insert_extended()

void * dshash_find_or_insert_extended ( dshash_table hash_table,
const void key,
bool found,
int  flags 
)
extern

Definition at line 442 of file dshash.c.

446{
448 size_t partition_index;
450 dshash_table_item *item;
451
452 hash = hash_key(hash_table, key);
455
456 Assert(hash_table->control->magic == DSHASH_MAGIC);
458
459restart:
463
464 /* Search the active bucket. */
465 item = find_in_bucket(hash_table, key, BUCKET_FOR_HASH(hash_table, hash));
466
467 if (item)
468 *found = true;
469 else
470 {
471 *found = false;
472
473 /* Check if we are getting too full. */
474 if (partition->count > MAX_COUNT_PER_PARTITION(hash_table))
475 {
476 /*
477 * The load factor (= keys / buckets) for all buckets protected by
478 * this partition is > 0.75. Presumably the same applies
479 * generally across the whole hash table (though we don't attempt
480 * to track that directly to avoid contention on some kind of
481 * central counter; we just assume that this partition is
482 * representative). This is a good time to resize.
483 *
484 * Give up our existing lock first, because resizing needs to
485 * reacquire all the locks in the right order to avoid deadlocks.
486 */
488 if (!resize(hash_table, hash_table->size_log2 + 1, flags))
489 {
490 Assert((flags & DSHASH_INSERT_NO_OOM) != 0);
491 return NULL;
492 }
493
494 goto restart;
495 }
496
497 /* Finally we can try to insert the new item. */
498 item = insert_into_bucket(hash_table, key,
499 &BUCKET_FOR_HASH(hash_table, hash),
500 flags);
501 if (item == NULL)
502 {
503 Assert((flags & DSHASH_INSERT_NO_OOM) != 0);
505 return NULL;
506 }
507 item->hash = hash;
508 /* Adjust per-lock-partition counter for load factor knowledge. */
509 ++partition->count;
510 }
511
512 /* The caller must release the lock with dshash_release_lock. */
513 return ENTRY_FROM_ITEM(item);
514}
static dshash_table_item * insert_into_bucket(dshash_table *hash_table, const void *key, dsa_pointer *bucket, int flags)
Definition dshash.c:1026
#define MAX_COUNT_PER_PARTITION(hash_table)
Definition dshash.c:137
static bool resize(dshash_table *hash_table, size_t new_size_log2, int flags)
Definition dshash.c:883
#define DSHASH_INSERT_NO_OOM
Definition dshash.h:96

References Assert, ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, BUCKET_FOR_HASH, dshash_table::control, DSHASH_INSERT_NO_OOM, DSHASH_MAGIC, ensure_valid_bucket_pointers(), ENTRY_FROM_ITEM, fb(), find_in_bucket(), dshash_table_item::hash, hash(), hash_key(), insert_into_bucket(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), dshash_table_control::magic, MAX_COUNT_PER_PARTITION, PARTITION_FOR_HASH, PARTITION_LOCK, dshash_table_control::partitions, resize(), and dshash_table::size_log2.

Referenced by pgsa_set_advice_string().

◆ dshash_get_hash_table_handle()

◆ dshash_memcmp()

int dshash_memcmp ( const void a,
const void b,
size_t  size,
void arg 
)
extern

Definition at line 593 of file dshash.c.

594{
595 return memcmp(a, b, size);
596}
int b
Definition isn.c:74
int a
Definition isn.c:73

References a, b, and fb().

◆ dshash_memcpy()

void dshash_memcpy ( void dest,
const void src,
size_t  size,
void arg 
)
extern

Definition at line 611 of file dshash.c.

612{
613 (void) memcpy(dest, src, size);
614}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))

References fb(), and memcpy().

◆ dshash_memhash()

dshash_hash dshash_memhash ( const void v,
size_t  size,
void arg 
)
extern

Definition at line 602 of file dshash.c.

603{
604 return tag_hash(v, size);
605}
uint32 tag_hash(const void *key, Size keysize)
Definition hashfn.c:677

References tag_hash().

◆ dshash_release_lock()

◆ dshash_seq_init()

◆ dshash_seq_next()

void * dshash_seq_next ( dshash_seq_status status)
extern

Definition at line 678 of file dshash.c.

679{
681
682 /*
683 * Not yet holding any partition locks. Need to determine the size of the
684 * hash table, it could have been resized since we were looking last.
685 * Since we iterate in partition order, we can start by unconditionally
686 * lock partition 0.
687 *
688 * Once we hold the lock, no resizing can happen until the scan ends. So
689 * we don't need to repeatedly call ensure_valid_bucket_pointers().
690 */
691 if (status->curpartition == -1)
692 {
693 Assert(status->curbucket == 0);
695
696 status->curpartition = 0;
697
699 status->curpartition),
700 status->exclusive ? LW_EXCLUSIVE : LW_SHARED);
701
703
704 status->nbuckets =
706 next_item_pointer = status->hash_table->buckets[status->curbucket];
707 }
708 else
710
712 status->curpartition),
713 status->exclusive ? LW_EXCLUSIVE : LW_SHARED));
714
715 /* Move to the next bucket if we finished the current bucket */
717 {
718 int next_partition;
719
720 if (++status->curbucket >= status->nbuckets)
721 {
722 /* all buckets have been scanned. finish. */
723 return NULL;
724 }
725
726 /* Check if move to the next partition */
727 next_partition =
729 status->hash_table->size_log2);
730
731 if (status->curpartition != next_partition)
732 {
733 /*
734 * Move to the next partition. Lock the next partition then
735 * release the current, not in the reverse order to avoid
736 * concurrent resizing. Avoid dead lock by taking lock in the
737 * same order with resize().
738 */
740 next_partition),
741 status->exclusive ? LW_EXCLUSIVE : LW_SHARED);
743 status->curpartition));
744 status->curpartition = next_partition;
745 }
746
747 next_item_pointer = status->hash_table->buckets[status->curbucket];
748 }
749
750 status->curitem =
752
753 /*
754 * The caller may delete the item. Store the next item in case of
755 * deletion.
756 */
757 status->pnextitem = status->curitem->next;
758
759 return ENTRY_FROM_ITEM(status->curitem);
760}
#define PARTITION_FOR_BUCKET_INDEX(bucket_idx, size_log2)
Definition dshash.c:159

References dshash_table::area, Assert, ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, dshash_table::buckets, dshash_table::control, dshash_seq_status::curbucket, dshash_seq_status::curitem, dshash_seq_status::curpartition, dsa_get_address(), DsaPointerIsValid, ensure_valid_bucket_pointers(), ENTRY_FROM_ITEM, dshash_seq_status::exclusive, fb(), dshash_seq_status::hash_table, LW_EXCLUSIVE, LW_SHARED, LWLockAcquire(), LWLockHeldByMeInMode(), LWLockRelease(), dshash_seq_status::nbuckets, dshash_table_item::next, NUM_BUCKETS, PARTITION_FOR_BUCKET_INDEX, PARTITION_LOCK, dshash_seq_status::pnextitem, dshash_table_control::size_log2, and dshash_table::size_log2.

Referenced by CleanupListenersOnExit(), pg_get_advice_stash_contents(), pg_get_advice_stashes(), pg_get_dsm_registry_allocations(), pgsa_drop_stash(), pgstat_build_snapshot(), pgstat_drop_database_and_contents(), pgstat_drop_matching_entries(), pgstat_reset_matching_entries(), and pgstat_write_statsfile().

◆ dshash_seq_term()

◆ dshash_strcmp()

int dshash_strcmp ( const void a,
const void b,
size_t  size,
void arg 
)
extern

Definition at line 620 of file dshash.c.

621{
622 Assert(strlen((const char *) a) < size);
623 Assert(strlen((const char *) b) < size);
624
625 return strcmp((const char *) a, (const char *) b);
626}

References a, Assert, b, and fb().

◆ dshash_strcpy()

void dshash_strcpy ( void dest,
const void src,
size_t  size,
void arg 
)
extern

Definition at line 643 of file dshash.c.

644{
645 Assert(strlen((const char *) src) < size);
646
647 (void) strcpy((char *) dest, (const char *) src);
648}

References Assert, and fb().

◆ dshash_strhash()

dshash_hash dshash_strhash ( const void v,
size_t  size,
void arg 
)
extern

Definition at line 632 of file dshash.c.

633{
634 Assert(strlen((const char *) v) < size);
635
636 return string_hash((const char *) v, size);
637}
uint32 string_hash(const void *key, Size keysize)
Definition hashfn.c:660

References Assert, fb(), and string_hash().