From d731fc0dbf3dd487a7dec16e3a733dbb687e9629 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Mon, 18 Nov 2019 21:36:53 +0800 Subject: [PATCH 1/3] fix #742 --- src/system/detail/src/vnodeImport.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/system/detail/src/vnodeImport.c b/src/system/detail/src/vnodeImport.c index 260d531200..0d3cd2b338 100644 --- a/src/system/detail/src/vnodeImport.c +++ b/src/system/detail/src/vnodeImport.c @@ -479,7 +479,7 @@ int vnodeImportToFile(SImportInfo *pImport) { slot = (slot + 1 + pInfo->maxBlocks) % pInfo->maxBlocks; } - // last slot, the uncommitted slots shall be shifted + // last slot, the uncommitted slots shall be shifted, a cache block may have empty rows SCacheBlock *pCacheBlock = pInfo->cacheBlocks[slot]; int points = pCacheBlock->numOfPoints - pInfo->commitPoint; if (points > 0) { @@ -568,7 +568,7 @@ int vnodeImportToCache(SImportInfo *pImport, char *payload, int rows) { } } - // copy the overwritten data into buffer + // copy the overwritten data into buffer, merge cache blocks tpoints = rows; pos = pImport->pos; slot = pImport->slot; @@ -603,6 +603,19 @@ int vnodeImportToCache(SImportInfo *pImport, char *payload, int rows) { pos = 0; tpoints -= points; + if (tpoints == 0) { + // free the rest of cache blocks, since cache blocks are merged + int currentSlot = slot; + while (slot != pInfo->currentSlot) { + slot = (slot + 1) % pInfo->maxBlocks; + pCacheBlock = pInfo->cacheBlocks[slot]; + vnodeFreeCacheBlock(pCacheBlock); + } + + pInfo->currentSlot = currentSlot; + slot = currentSlot; // make sure to exit from the while loop + } + if (slot == pInfo->currentSlot) break; slot = (slot + 1) % pInfo->maxBlocks; } From 78158e32a5160c924b5426db841ce4ca16bc5d5d Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Tue, 19 Nov 2019 10:31:53 +0800 Subject: [PATCH 2/3] fix #742 --- src/system/detail/src/vnodeCache.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/system/detail/src/vnodeCache.c b/src/system/detail/src/vnodeCache.c index 94ac006060..d4a654de95 100644 --- a/src/system/detail/src/vnodeCache.c +++ b/src/system/detail/src/vnodeCache.c @@ -172,6 +172,7 @@ int vnodeFreeCacheBlock(SCacheBlock *pCacheBlock) { SCachePool *pPool = (SCachePool *)vnodeList[pObj->vnode].pCachePool; if (pCacheBlock->notFree) { pPool->notFreeSlots--; + pPool->unCommittedBlocks--; dTrace("vid:%d sid:%d id:%s, cache block is not free, slot:%d, index:%d notFreeSlots:%d", pObj->vnode, pObj->sid, pObj->meterId, pCacheBlock->slot, pCacheBlock->index, pPool->notFreeSlots); } From 1f953a0f63b1b2fb0fc027c7a33c418d313964ac Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Tue, 19 Nov 2019 10:36:39 +0800 Subject: [PATCH 3/3] fix #742 unCommittedBlocks shall be decreased by one --- src/system/detail/src/vnodeCache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system/detail/src/vnodeCache.c b/src/system/detail/src/vnodeCache.c index d4a654de95..45596ff553 100644 --- a/src/system/detail/src/vnodeCache.c +++ b/src/system/detail/src/vnodeCache.c @@ -172,7 +172,7 @@ int vnodeFreeCacheBlock(SCacheBlock *pCacheBlock) { SCachePool *pPool = (SCachePool *)vnodeList[pObj->vnode].pCachePool; if (pCacheBlock->notFree) { pPool->notFreeSlots--; - pPool->unCommittedBlocks--; + pInfo->unCommittedBlocks--; dTrace("vid:%d sid:%d id:%s, cache block is not free, slot:%d, index:%d notFreeSlots:%d", pObj->vnode, pObj->sid, pObj->meterId, pCacheBlock->slot, pCacheBlock->index, pPool->notFreeSlots); }