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

fix: index memory error

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