update index cache

This commit is contained in:
yihaoDeng 2021-12-17 21:35:05 +08:00
parent 10a7547b61
commit 653665641d
4 changed files with 18 additions and 1 deletions

View File

@ -9,6 +9,7 @@ target_link_libraries(
index index
PUBLIC os PUBLIC os
PUBLIC util PUBLIC util
PUBLIC common
) )
if (${BUILD_WITH_LUCENE}) if (${BUILD_WITH_LUCENE})

View File

@ -17,6 +17,7 @@
#include "index.h" #include "index.h"
#include "tlockfree.h" #include "tlockfree.h"
#include "tskiplist.h"
// ----------------- row structure in skiplist --------------------- // ----------------- row structure in skiplist ---------------------
/* A data row, the format is like below: /* A data row, the format is like below:
@ -30,6 +31,7 @@ extern "C" {
typedef struct IndexCache { typedef struct IndexCache {
T_REF_DECLARE() T_REF_DECLARE()
SSkipList *skiplist;
} IndexCache; } IndexCache;

View File

@ -315,7 +315,6 @@ typedef struct StreamWithStateResult {
FstSlice data; FstSlice data;
FstOutput out; FstOutput out;
void *state; void *state;
} StreamWithStateResult; } StreamWithStateResult;
StreamWithStateResult *swsResultCreate(FstSlice *data, FstOutput fOut, void *state); StreamWithStateResult *swsResultCreate(FstSlice *data, FstOutput fOut, void *state);

View File

@ -14,7 +14,13 @@
*/ */
#include "index_cache.h" #include "index_cache.h"
#include "tcompare.h"
#define MAX_INDEX_KEY_LEN 128 // test only, change later
static char* getIndexKey(const void *pData) {
return NULL;
}
static int32_t compareKey(const void *l, const void *r) { static int32_t compareKey(const void *l, const void *r) {
char *lp = (char *)l; char *lp = (char *)l;
char *rp = (char *)r; char *rp = (char *)r;
@ -85,10 +91,14 @@ static int32_t compareKey(const void *l, const void *r) {
} }
IndexCache *indexCacheCreate() { IndexCache *indexCacheCreate() {
IndexCache *cache = calloc(1, sizeof(IndexCache)); IndexCache *cache = calloc(1, sizeof(IndexCache));
cache->skiplist = tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_INDEX_KEY_LEN, compareKey, SL_ALLOW_DUP_KEY, getIndexKey);
return cache; return cache;
} }
void indexCacheDestroy(IndexCache *cache) { void indexCacheDestroy(IndexCache *cache) {
if (cache == NULL) { return; }
tSkipListDestroy(cache->skiplist);
free(cache); free(cache);
} }
@ -96,6 +106,7 @@ int indexCachePut(IndexCache *cache, int16_t fieldId, int16_t fieldType, const c
uint32_t version, uint64_t uid, int8_t operType) { uint32_t version, uint64_t uid, int8_t operType) {
if (cache == NULL) { return -1;} if (cache == NULL) { return -1;}
// encode data
int32_t total = sizeof(int32_t) + sizeof(fieldId) + sizeof(fieldType) + sizeof(fvLen) + fvLen + sizeof(version) + sizeof(uid) + sizeof(operType); int32_t total = sizeof(int32_t) + sizeof(fieldId) + sizeof(fieldType) + sizeof(fvLen) + fvLen + sizeof(version) + sizeof(uid) + sizeof(operType);
char *buf = calloc(1, total); char *buf = calloc(1, total);
@ -123,6 +134,10 @@ int indexCachePut(IndexCache *cache, int16_t fieldId, int16_t fieldType, const c
memcpy(p, &operType, sizeof(operType)); memcpy(p, &operType, sizeof(operType));
p += sizeof(operType); p += sizeof(operType);
tSkipListPut(cache->skiplist, (void *)buf);
// encode end
} }
int indexCacheDel(IndexCache *cache, int32_t fieldId, const char *fieldValue, int32_t fvlen, uint64_t uid, int8_t operType) { int indexCacheDel(IndexCache *cache, int32_t fieldId, const char *fieldValue, int32_t fvlen, uint64_t uid, int8_t operType) {