From 28c358c33992ca1238f95a0a1a41bff2672dd2e7 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 22 Dec 2021 23:29:54 +0800 Subject: [PATCH] update tindex reader --- source/libs/index/inc/index_tfile.h | 1 + source/libs/index/src/index_tfile.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/source/libs/index/inc/index_tfile.h b/source/libs/index/inc/index_tfile.h index cf6341ce9c..b19b887e9f 100644 --- a/source/libs/index/inc/index_tfile.h +++ b/source/libs/index/inc/index_tfile.h @@ -66,6 +66,7 @@ typedef struct TFileWriter { uint32_t offset; } TFileWriter; +// multi reader and single write typedef struct TFileReader { T_REF_DECLARE() Fst* fst; diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index 9acd9f6870..1cd5673faa 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -134,8 +134,15 @@ TFileReader* tfileCacheGet(TFileCache* tcache, TFileCacheKey* key) { void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader* reader) { char buf[128] = {0}; tfileSerialCacheKey(key, buf); - tfileReadRef(reader); + // remove last version index reader + TFileReader** p = taosHashGet(tcache->tableCache, buf, strlen(buf)); + if (*p != NULL) { + TFileReader* oldReader = *p; + taosHashRemove(tcache->tableCache, buf, strlen(buf)); + tfileReadUnRef(oldReader); + } + tfileReadRef(reader); taosHashPut(tcache->tableCache, buf, strlen(buf), &reader, sizeof(void*)); return; } -- GitLab