pgpool2.git / summary / log / commit / refs
commit d6c447df5d292b9fe6456051fe48502956fdf193
Author: Tatsuo Ishii <ishii@postgresql.org>
Date: Sat Oct 19 03:58:20 2013 +0000
Avoid to run out free query cache hash index entry.
If hash index entries are run out, pgpool-II cannot reuse old cache
entry because pgpool-II always expects there's at least one empty hash
index entry. To mitigate the problem, if free hash index entries are run
out, look for victim cache block to reuse the hash index entry.
Per bug #70.
src/query_cache/pool_memqcache.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/src/query_cache/pool_memqcache.c b/src/query_cache/pool_memqcache.c
index e65b01f0c..a0eabcf8d 100644
--- a/src/query_cache/pool_memqcache.c
+++ b/src/query_cache/pool_memqcache.c
@@ -115,6 +115,7 @@ static int pool_hash_insert(POOL_QUERY_HASH *key, POOL_CACHEID *cacheid, bool up
static uint32 create_hash_key(POOL_QUERY_HASH *key);
static volatile POOL_HASH_ELEMENT *get_new_hash_element(void);
static void put_back_hash_element(volatile POOL_HASH_ELEMENT *element);
+static bool is_free_hash_element(void);
static char *get_relation_without_alias(RangeVar *relation);
/*
@@ -2002,6 +2003,16 @@ static POOL_CACHEID *pool_add_item_shmem_cache(POOL_QUERY_HASH *query_hash, char
*/
pool_init_cache_block(blockid);
+ /*
+ * Make sure that we have at least one free hash element.
+ */
+ while (!is_free_hash_element())
+ {
+ /* If not, reuse next victim block */
+ blockid = pool_reuse_block();
+ pool_init_cache_block(blockid);
+ }
+
/* Get block address on shmem */
p = block_address(blockid);
bh = (POOL_CACHE_BLOCK_HEADER *)p;
@@ -3708,6 +3719,14 @@ static void put_back_hash_element(volatile POOL_HASH_ELEMENT *element)
element->next = elm;
}
+/*
+ * Return true if there's a free hash element.
+ */
+static bool is_free_hash_element(void)
+{
+ return hash_free->next != NULL;
+}
+
/*
* Returns shared memory cache stats.
* Subsequent call to this function will break return value
[parent: fa4bb56004e9]