diff --git a/source/libs/index/CMakeLists.txt b/source/libs/index/CMakeLists.txt index 3da2c93b39..f68fc5e61e 100644 --- a/source/libs/index/CMakeLists.txt +++ b/source/libs/index/CMakeLists.txt @@ -9,6 +9,7 @@ target_link_libraries( index PUBLIC os PUBLIC util + PUBLIC common ) if (${BUILD_WITH_LUCENE}) diff --git a/source/libs/index/inc/index_cache.h b/source/libs/index/inc/index_cache.h index ff915a3930..39107a78ac 100644 --- a/source/libs/index/inc/index_cache.h +++ b/source/libs/index/inc/index_cache.h @@ -17,6 +17,7 @@ #include "index.h" #include "tlockfree.h" +#include "tskiplist.h" // ----------------- row structure in skiplist --------------------- /* A data row, the format is like below: @@ -30,6 +31,7 @@ extern "C" { typedef struct IndexCache { T_REF_DECLARE() + SSkipList *skiplist; } IndexCache; diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 20037f829a..0dcc25831c 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -315,7 +315,6 @@ typedef struct StreamWithStateResult { FstSlice data; FstOutput out; void *state; - } StreamWithStateResult; StreamWithStateResult *swsResultCreate(FstSlice *data, FstOutput fOut, void *state); diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index 2ecc823ef9..acb8e32157 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -14,7 +14,13 @@ */ #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) { char *lp = (char *)l; char *rp = (char *)r; @@ -85,10 +91,14 @@ static int32_t compareKey(const void *l, const void *r) { } IndexCache *indexCacheCreate() { 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; + } void indexCacheDestroy(IndexCache *cache) { + if (cache == NULL) { return; } + tSkipListDestroy(cache->skiplist); 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) { 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); 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)); 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) {