-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace fa_cache with htable cache (#160)
* Make htab cache generic * Remove cache lookup on ldb_wal_index_node_retriever_mut * Create MemoryContext inside cache_create
- Loading branch information
Showing
9 changed files
with
117 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ | |
#else | ||
#define LanternBench(name, code) (code) | ||
#endif | ||
#endif // LDB_BENCH_H | ||
#endif // LDB_BENCH_H |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "htab_cache.h" | ||
|
||
#include "utils.h" | ||
|
||
HTABCache cache_create(const char *name) | ||
{ | ||
HTABCache cache; | ||
HASHCTL hctl; | ||
|
||
hctl.keysize = sizeof(HTABCacheKey); | ||
hctl.entrysize = sizeof(HTABCacheEntry); | ||
hctl.hcxt = AllocSetContextCreate(CacheMemoryContext, "HTABCache", ALLOCSET_DEFAULT_SIZES); | ||
HTAB *htab = hash_create(name, 1, &hctl, HASH_ELEM | HASH_CONTEXT | HASH_BLOBS); | ||
cache.hctl = hctl; | ||
cache.htab = htab; | ||
return cache; | ||
} | ||
|
||
bool cache_remove(HTABCache *cache, HTABCacheKey *key) | ||
{ | ||
bool status; | ||
|
||
hash_search(cache->htab, key, HASH_REMOVE, &status); | ||
|
||
return status; | ||
} | ||
|
||
void *cache_get_item(HTABCache *cache, HTABCacheKey *key) | ||
{ | ||
bool status; | ||
|
||
HTABCacheEntry *item = (HTABCacheEntry *)hash_search(cache->htab, key, HASH_FIND, &status); | ||
|
||
if(!status) { | ||
return NULL; | ||
} | ||
|
||
return item->value; | ||
} | ||
|
||
void cache_set_item(HTABCache *cache, HTABCacheKey *key, void *value) | ||
{ | ||
HTABCacheEntry *entry; | ||
|
||
entry = (HTABCacheEntry *)hash_search(cache->htab, key, HASH_ENTER, NULL); | ||
entry->value = value; | ||
} | ||
|
||
void cache_destroy(HTABCache *cache) | ||
{ | ||
MemoryContext old_context = MemoryContextSwitchTo(cache->hctl.hcxt); | ||
hash_destroy(cache->htab); | ||
MemoryContextSwitchTo(old_context); | ||
MemoryContextDelete(cache->hctl.hcxt); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef LDB_HNSW_HTAB_CACHE_H | ||
#define LDB_HNSW_HTAB_CACHE_H | ||
|
||
#include <postgres.h> | ||
|
||
#include <utils/hsearch.h> | ||
#include <utils/memutils.h> | ||
|
||
/* | ||
* An abstract hash table (HTAB) cache that stores void pointers. | ||
* Casting of pointers should be done externally when retrieving items. | ||
* | ||
* Note: | ||
* - This cache stores void pointers, so type casting should be performed externally | ||
* when retrieving items from the cache. | ||
* - The key and value pointers supplied for cache operations should have lifetimes | ||
* that outlive the cache itself. | ||
* - If an item is not found in the cache, a NULL value will be returned. | ||
* - A new memory context will be created in CacheMemoryContext when calling | ||
* cache_create, and it will be destroyed when calling cache_destroy. | ||
*/ | ||
|
||
typedef int32 HTABCacheKey; | ||
typedef struct HTABCacheEntry | ||
{ | ||
HTABCacheKey key; | ||
void *value; | ||
} HTABCacheEntry; | ||
|
||
typedef struct HTABCache | ||
{ | ||
HTAB *htab; | ||
HASHCTL hctl; | ||
} HTABCache; | ||
|
||
HTABCache cache_create(const char *name); | ||
bool cache_remove(HTABCache *cache, HTABCacheKey *key); | ||
void *cache_get_item(HTABCache *cache, HTABCacheKey *key); | ||
void cache_set_item(HTABCache *cache, HTABCacheKey *key, void *entry); | ||
void cache_destroy(HTABCache *cache); | ||
|
||
#endif // LDB_HNSW_HTAB_CACHE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters