Merge pull request #9630 from taosdata/feature/index_complete
refactor code
This commit is contained in:
commit
70bd0cdcbc
|
@ -27,9 +27,9 @@
|
||||||
static void indexMemRef(MemTable* tbl);
|
static void indexMemRef(MemTable* tbl);
|
||||||
static void indexMemUnRef(MemTable* tbl);
|
static void indexMemUnRef(MemTable* tbl);
|
||||||
|
|
||||||
static void cacheTermDestroy(CacheTerm* ct);
|
static void indexCacheTermDestroy(CacheTerm* ct);
|
||||||
static char* getIndexKey(const void* pData);
|
static int32_t indexCacheTermCompare(const void* l, const void* r);
|
||||||
static int32_t compareKey(const void* l, const void* r);
|
static char* indexCacheTermGet(const void* pData);
|
||||||
|
|
||||||
static MemTable* indexInternalCacheCreate(int8_t type);
|
static MemTable* indexInternalCacheCreate(int8_t type);
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ int indexCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t u
|
||||||
|
|
||||||
static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SArray* result, STermValueType* s) {
|
static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SArray* result, STermValueType* s) {
|
||||||
if (mem == NULL) { return 0; }
|
if (mem == NULL) { return 0; }
|
||||||
char* key = getIndexKey(ct);
|
char* key = indexCacheTermGet(ct);
|
||||||
|
|
||||||
SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
|
SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
|
||||||
while (tSkipListIterNext(iter)) {
|
while (tSkipListIterNext(iter)) {
|
||||||
|
@ -321,17 +321,16 @@ void indexMemUnRef(MemTable* tbl) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cacheTermDestroy(CacheTerm* ct) {
|
static void indexCacheTermDestroy(CacheTerm* ct) {
|
||||||
if (ct == NULL) { return; }
|
if (ct == NULL) { return; }
|
||||||
free(ct->colVal);
|
free(ct->colVal);
|
||||||
free(ct);
|
free(ct);
|
||||||
}
|
}
|
||||||
static char* getIndexKey(const void* pData) {
|
static char* indexCacheTermGet(const void* pData) {
|
||||||
CacheTerm* p = (CacheTerm*)pData;
|
CacheTerm* p = (CacheTerm*)pData;
|
||||||
return (char*)p;
|
return (char*)p;
|
||||||
}
|
}
|
||||||
|
static int32_t indexCacheTermCompare(const void* l, const void* r) {
|
||||||
static int32_t compareKey(const void* l, const void* r) {
|
|
||||||
CacheTerm* lt = (CacheTerm*)l;
|
CacheTerm* lt = (CacheTerm*)l;
|
||||||
CacheTerm* rt = (CacheTerm*)r;
|
CacheTerm* rt = (CacheTerm*)r;
|
||||||
|
|
||||||
|
@ -345,7 +344,8 @@ static MemTable* indexInternalCacheCreate(int8_t type) {
|
||||||
MemTable* tbl = calloc(1, sizeof(MemTable));
|
MemTable* tbl = calloc(1, sizeof(MemTable));
|
||||||
indexMemRef(tbl);
|
indexMemRef(tbl);
|
||||||
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
|
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
tbl->mem = tSkipListCreate(MAX_SKIP_LIST_LEVEL, type, MAX_INDEX_KEY_LEN, compareKey, SL_ALLOW_DUP_KEY, getIndexKey);
|
tbl->mem = tSkipListCreate(MAX_SKIP_LIST_LEVEL, type, MAX_INDEX_KEY_LEN, indexCacheTermCompare, SL_ALLOW_DUP_KEY,
|
||||||
|
indexCacheTermGet);
|
||||||
}
|
}
|
||||||
return tbl;
|
return tbl;
|
||||||
}
|
}
|
||||||
|
@ -375,4 +375,7 @@ static bool indexCacheIteratorNext(Iterate* itera) {
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
static IterateValue* indexCacheIteratorGetValue(Iterate* iter) { return &iter->val; }
|
static IterateValue* indexCacheIteratorGetValue(Iterate* iter) {
|
||||||
|
// opt later
|
||||||
|
return &iter->val;
|
||||||
|
}
|
||||||
|
|
|
@ -125,6 +125,7 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) {
|
||||||
if (ctx->type == TMemory) {
|
if (ctx->type == TMemory) {
|
||||||
free(ctx->mem.buf);
|
free(ctx->mem.buf);
|
||||||
} else {
|
} else {
|
||||||
|
ctx->flush(ctx);
|
||||||
tfClose(ctx->file.fd);
|
tfClose(ctx->file.fd);
|
||||||
if (ctx->file.readOnly) {
|
if (ctx->file.readOnly) {
|
||||||
#ifdef USE_MMAP
|
#ifdef USE_MMAP
|
||||||
|
|
|
@ -48,7 +48,7 @@ class FstWriter {
|
||||||
|
|
||||||
class FstReadMemory {
|
class FstReadMemory {
|
||||||
public:
|
public:
|
||||||
FstReadMemory(size_t size, const std::string& fileName = fileName) {
|
FstReadMemory(size_t size, const std::string& fileName = "/tmp/tindex.tindex") {
|
||||||
tfInit();
|
tfInit();
|
||||||
_wc = writerCtxCreate(TFile, fileName.c_str(), true, 64 * 1024);
|
_wc = writerCtxCreate(TFile, fileName.c_str(), true, 64 * 1024);
|
||||||
_w = fstCountingWriterCreate(_wc);
|
_w = fstCountingWriterCreate(_wc);
|
||||||
|
@ -307,7 +307,7 @@ void validateTFile(char* arg) {
|
||||||
tfCleanup();
|
tfCleanup();
|
||||||
}
|
}
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
// tool to check all kind of fst test
|
// tool to check all kind of fst test
|
||||||
// if (argc > 1) { validateTFile(argv[1]); }
|
// if (argc > 1) { validateTFile(argv[1]); }
|
||||||
// checkFstCheckIterator();
|
// checkFstCheckIterator();
|
||||||
// checkFstLongTerm();
|
// checkFstLongTerm();
|
||||||
|
|
Loading…
Reference in New Issue