From fb6d7c4676423c715247dcb1d9c32e3ffbf0144e Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Mon, 14 Jul 2025 16:48:24 +0300 Subject: [PATCH] Fix merge conflict --- pgxn/neon/relkind_cache.c | 54 +++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/pgxn/neon/relkind_cache.c b/pgxn/neon/relkind_cache.c index 14dd160825..c3cb6386c1 100644 --- a/pgxn/neon/relkind_cache.c +++ b/pgxn/neon/relkind_cache.c @@ -54,7 +54,6 @@ typedef struct } RelKindHashControl; static HTAB *relkind_hash; -static LWLockId finish_unlogged_build_lock; static int relkind_hash_size; static RelKindHashControl* relkind_ctl; static shmem_startup_hook_type prev_shmem_startup_hook = NULL; @@ -63,6 +62,8 @@ static shmem_request_hook_type prev_shmem_request_hook = NULL; static void relkind_shmem_request(void); #endif +LWLockId finish_unlogged_build_lock; + /* * Size of a cache entry is 32 bytes. So this default will take about 2 MB, * which seems reasonable. @@ -116,17 +117,29 @@ static RelKindEntry* get_pinned_entry(NRelFileInfo rinfo) { bool found; - RelKindEntry* entry; + RelKindEntry* entry = hash_search(relkind_hash, &rinfo, HASH_ENTER_NULL, &found); - while ((entry = hash_search(relkind_hash, &rinfo, HASH_ENTER_NULL, &found)) == NULL) + if (entry == NULL) { - /* - * Remove least recently used element from the hash. - */ - RelKindEntry *victim = dlist_container(RelKindEntry, lru_node, dlist_pop_head_node(&relkind_ctl->lru)); - hash_search(relkind_hash, &victim->rel, HASH_REMOVE, NULL); - Assert(relkind_ctl->size > 0); - relkind_ctl->size -= 1; + if (&dlist_is_empty(relkind_ctl->lru)) + { + neon_log(PANIC, "Not unpinned relkind entries"); + } + else + { + bool found; + /* + * Remove least recently used element from the hash. + */ + RelKindEntry *victim = dlist_container(RelKindEntry, lru_node, dlist_pop_head_node(&relkind_ctl->lru)); + Assert(victim->access_count == 0); + hash_search(relkind_hash, &victim->rel, HASH_REMOVE, &found); + Assert(found); + Assert(relkind_ctl->size > 0); + relkind_ctl->size -= 1; + } + entry = hash_search(relkind_hash, &rinfo, HASH_ENTER_NULL, &found); + Assert(!found); } if (!found) { @@ -193,6 +206,7 @@ get_cached_relkind(NRelFileInfo rinfo) entry = hash_search(relkind_hash, &rinfo, HASH_FIND, NULL); if (entry != NULL) { + /* Do pin+unpin entry to move it to the end of LRU list */ if (entry->access_count++ == 0) { dlist_delete(&entry->lru_node); @@ -215,6 +229,7 @@ set_cached_relkind(NRelFileInfo rinfo, RelKind relkind) RelKindEntry *entry; SpinLockAcquire(&relkind_ctl->mutex); + /* Do pin+unpin entry to move it to the end of LRU list */ entry = get_pinned_entry(rinfo); Assert(entry->relkind == RELKIND_UNKNOWN || entry->relkind == relkind); entry->relkind = relkind; @@ -222,24 +237,6 @@ set_cached_relkind(NRelFileInfo rinfo, RelKind relkind) SpinLockRelease(&relkind_ctl->mutex); } -void -fs_exclusive_lock(void) -{ - LWLockAcquire(finish_unlogged_build_lock, LW_EXCLUSIVE); -} - -void -fs_shared_lock(void) -{ - LWLockAcquire(finish_unlogged_build_lock, LW_SHARED); -} - -void -fs_unlock(void) -{ - LWLockRelease(finish_unlogged_build_lock); -} - void unpin_cached_relkind(RelKindEntry* entry) { @@ -259,6 +256,7 @@ forget_cached_relkind(NRelFileInfo rinfo) entry = hash_search(relkind_hash, &rinfo, HASH_REMOVE, NULL); if (entry) { + Assert(entry->access_count == 0); dlist_delete(&entry->lru_node); relkind_ctl->size -= 1; }