From a37337751f53eae137344993c22ee22cc7f30e92 Mon Sep 17 00:00:00 2001 From: SudeepRed Date: Mon, 6 Nov 2023 00:30:10 +0530 Subject: [PATCH] [WORKING]: switched to local memory segment --- src/include/pgagroal.h | 2 +- src/libpgagroal/pipeline_session.c | 2 ++ src/libpgagroal/query_cache.c | 23 ++--------------------- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/include/pgagroal.h b/src/include/pgagroal.h index 4271d0cc..28fa5e89 100644 --- a/src/include/pgagroal.h +++ b/src/include/pgagroal.h @@ -456,7 +456,7 @@ struct hashEntry { void* value; size_t length; - char key[]; + char key[1024]; } __attribute__ ((aligned (64))); /** @struct diff --git a/src/libpgagroal/pipeline_session.c b/src/libpgagroal/pipeline_session.c index 08c23ecc..f7c0d2c7 100644 --- a/src/libpgagroal/pipeline_session.c +++ b/src/libpgagroal/pipeline_session.c @@ -369,6 +369,8 @@ session_client(struct ev_loop* loop, struct ev_io* watcher, int revents) if (s != NULL && s->value != NULL) { + // log cache hit + pgagroal_log_info("Cache hit"); struct message* result = NULL; diff --git a/src/libpgagroal/query_cache.c b/src/libpgagroal/query_cache.c index 65f117bf..48ee9a75 100644 --- a/src/libpgagroal/query_cache.c +++ b/src/libpgagroal/query_cache.c @@ -65,7 +65,8 @@ pgagroal_query_cache_init(size_t* p_size, void** p_shmem) pgagroal_log_info("Query cache initialised"); - if (pgagroal_create_shared_memory(cache_size, config->hugepage, (void*) &cache)) + cache = (struct query_cache*)malloc(cache_size); + if (cache == NULL) { goto error; } @@ -101,19 +102,14 @@ pgagroal_query_cache_get(struct query_cache* cache, struct hashTable** Table, st if (atomic_compare_exchange_strong(&cache->lock, &cache_is_free, STATE_IN_USE)) { - pgagroal_log_fatal("NUMBER OF ELEMENTS %d", cache->max_elements); - for (int i = 0; i < cache->max_elements; i++) { int x = strncmp(cache->cache[i].key->key, key->key, key->length); - pgagroal_log_warn("from cache GET to comapre %d, %s, %s, %d", x, key->key, cache->cache[i].key->key, i); if (x == 0) { - // Key found, return the corresponding data - atomic_store(&cache->lock, STATE_FREE); return cache->cache[i].data; @@ -201,25 +197,10 @@ pgagroal_query_cache_add(struct query_cache* cache, struct hashTable** Table, st memcpy(copy_data->value, data->value, data->length); copy_data->length = data->length; int idx = cache->max_elements; - pgagroal_log_info("Adding to cache %d", idx); cache->cache[idx].key = copy_key; cache->cache[idx].data = copy_data; cache->max_elements = idx + 1; - pgagroal_log_info("fromcache to cache %s", cache->cache[idx].key->key); - pgagroal_log_info("fromcache to parameter %s", key->key); - for (int i = 0; i < cache->max_elements; i++) - { - if (cache->cache[i].key == NULL) - { - pgagroal_log_info("from cache GET to comapre %s", "NULL"); - continue; - } - char t[cache->cache[i].key->length]; - strcpy(t, cache->cache[i].key->key); - pgagroal_log_info("from cache GET to comapre %s", cache->cache[i].key->key); - - } atomic_store(&cache->lock, STATE_FREE); return 1;