Skip to content

Commit

Permalink
[WORKING]: switched to local memory segment
Browse files Browse the repository at this point in the history
  • Loading branch information
SudeepRed committed Nov 5, 2023
1 parent e4c8dc3 commit a373377
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/include/pgagroal.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ struct hashEntry
{
void* value;
size_t length;
char key[];
char key[1024];
} __attribute__ ((aligned (64)));

/** @struct
Expand Down
2 changes: 2 additions & 0 deletions src/libpgagroal/pipeline_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
23 changes: 2 additions & 21 deletions src/libpgagroal/query_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a373377

Please sign in to comment.