提交 d067104e 编写于 作者: dengyihao's avatar dengyihao

fix: index memory error

上级 c8ba20ac
......@@ -558,17 +558,17 @@ static int64_t indexGetAvaialbleVer(SIndex* sIdx, IndexCache* cache) {
ICacheKey key = {.suid = cache->suid, .colName = cache->colName, .nColName = strlen(cache->colName)};
int64_t ver = CACHE_VERSION(cache);
TFileReader* rd = tfileCacheGet(((IndexTFile*)sIdx->tindex)->cache, &key);
IndexTFile* tf = (IndexTFile*)(sIdx->tindex);
taosThreadMutexLock(&tf->mtx);
tfileCacheGet(tf->cache, &key);
TFileReader* rd = tfileCacheGet(tf->cache, &key);
taosThreadMutexUnlock(&tf->mtx);
if (rd != NULL) {
ver += MAX(ver, rd->header.version) + 1;
indexInfo("header: %" PRId64 ", ver: %" PRId64 "", rd->header.version, ver);
}
tfileReaderUnRef(rd);
return ver;
}
static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) {
......
......@@ -165,11 +165,11 @@ void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* reader) {
// remove last version index reader
TFileReader** p = taosHashGet(tcache->tableCache, buf, sz);
if (p != NULL && *p != NULL) {
TFileReader* oldReader = *p;
TFileReader* oldRdr = *p;
taosHashRemove(tcache->tableCache, buf, sz);
indexInfo("found %s, remove file %s", buf, oldReader->ctx->file.buf);
oldReader->remove = true;
tfileReaderUnRef(oldReader);
indexInfo("found %s, should remove file %s", buf, oldRdr->ctx->file.buf);
oldRdr->remove = true;
tfileReaderUnRef(oldRdr);
}
taosHashPut(tcache->tableCache, buf, sz, &reader, sizeof(void*));
tfileReaderRef(reader);
......@@ -212,6 +212,12 @@ void tfileReaderDestroy(TFileReader* reader) {
// T_REF_INC(reader);
fstDestroy(reader->fst);
writerCtxDestroy(reader->ctx, reader->remove);
if (reader->remove) {
indexInfo("%s is removed", reader->ctx->file.buf);
} else {
indexInfo("%s is not removed", reader->ctx->file.buf);
}
taosMemoryFree(reader);
}
static int32_t tfSearchTerm(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
......
......@@ -953,8 +953,8 @@ TEST_F(IndexEnv2, testIndex_TrigeFlush) {
}
static void single_write_and_search(IndexObj* idx) {
int target = idx->SearchOne("tag1", "Hello");
target = idx->SearchOne("tag2", "Test");
// int target = idx->SearchOne("tag1", "Hello");
// target = idx->SearchOne("tag2", "Test");
}
static void multi_write_and_search(IndexObj* idx) {
idx->PutOne("tag1", "Hello");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册