Skip to content

Commit

Permalink
Merge pull request #20905 from taosdata/fix/TD-22941
Browse files Browse the repository at this point in the history
fix(tsdb/cache): fix block index ref releasing
  • Loading branch information
xiao-yu-wang committed Apr 13, 2023
2 parents 1eae60c + 589ed9d commit 3d962cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion source/dnode/vnode/src/tsdb/tsdbCache.c
Expand Up @@ -35,7 +35,11 @@ static int32_t tsdbOpenBICache(STsdb *pTsdb) {
static void tsdbCloseBICache(STsdb *pTsdb) {
SLRUCache *pCache = pTsdb->biCache;
if (pCache) {
int32_t elems = taosLRUCacheGetElems(pCache);
tsdbTrace("vgId:%d, elems: %d", TD_VID(pTsdb->pVnode), elems);
taosLRUCacheEraseUnrefEntries(pCache);
elems = taosLRUCacheGetElems(pCache);
tsdbTrace("vgId:%d, elems: %d", TD_VID(pTsdb->pVnode), elems);

taosLRUCacheCleanup(pCache);

Expand Down Expand Up @@ -819,7 +823,12 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie
* &state->blockIdx);
*/
state->pBlockIdx = taosArraySearch(state->aBlockIdx, state->pBlockIdxExp, tCmprBlockIdx, TD_EQ);
if (!state->pBlockIdx) { /*
if (!state->pBlockIdx) {
tsdbBICacheRelease(state->pTsdb->biCache, state->aBlockIdxHandle);

state->aBlockIdxHandle = NULL;
state->aBlockIdx = NULL;
/*
tsdbDataFReaderClose(state->pDataFReader);
*state->pDataFReader = NULL;
resetLastBlockLoadInfo(state->pLoadInfo);*/
Expand Down Expand Up @@ -1936,6 +1945,7 @@ int32_t tsdbCacheGetBlockIdx(SLRUCache *pCache, SDataFReader *pFileReader, LRUHa
taosThreadMutexUnlock(&pTsdb->biMutex);
}

tsdbTrace("bi cache:%p, ref", pCache);
*handle = h;

return code;
Expand All @@ -1945,6 +1955,7 @@ int32_t tsdbBICacheRelease(SLRUCache *pCache, LRUHandle *h) {
int32_t code = 0;

taosLRUCacheRelease(pCache, h, false);
tsdbTrace("bi cache:%p, release", pCache);

return code;
}
2 changes: 1 addition & 1 deletion tests/script/tsim/parser/last_cache.sim
Expand Up @@ -53,7 +53,7 @@ sql insert into tbc values ("2021-05-11 10:12:29",36, 37, NULL, -4005)
sql insert into tbd values ("2021-05-11 10:12:29",NULL,NULL,NULL,NULL )

run tsim/parser/last_cache_query.sim

sql flush database $db
system sh/exec.sh -n dnode1 -s stop -x SIGINT

system sh/exec.sh -n dnode1 -s start
Expand Down

0 comments on commit 3d962cd

Please sign in to comment.