Merge pull request #18640 from taosdata/fix/TS-2189-xx
fix(tsdb/cache): use lru erase to invalidate cache entries
This commit is contained in:
commit
14a384e93f
|
@ -228,8 +228,7 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST
|
||||||
invalidate = true;
|
invalidate = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
} else { // new inserting key is greater than cached, update cached entry
|
||||||
} else {
|
|
||||||
SLastCol lastCol = {.ts = keyTs, .colVal = colVal};
|
SLastCol lastCol = {.ts = keyTs, .colVal = colVal};
|
||||||
if (IS_VAR_DATA_TYPE(colVal.type) && colVal.value.nData > 0) {
|
if (IS_VAR_DATA_TYPE(colVal.type) && colVal.value.nData > 0) {
|
||||||
SLastCol *pLastCol = (SLastCol *)taosArrayGet(pLast, iCol);
|
SLastCol *pLastCol = (SLastCol *)taosArrayGet(pLast, iCol);
|
||||||
|
@ -248,71 +247,17 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_invalidate:
|
_invalidate:
|
||||||
taosMemoryFreeClear(pTSchema);
|
taosMemoryFreeClear(pTSchema);
|
||||||
|
|
||||||
taosLRUCacheRelease(pCache, h, invalidate);
|
taosLRUCacheRelease(pCache, h, invalidate);
|
||||||
/*
|
if (invalidate) {
|
||||||
cacheRow = (STSRow *)taosLRUCacheValue(pCache, h);
|
taosLRUCacheErase(pCache, key, keyLen);
|
||||||
if (row->ts >= cacheRow->ts) {
|
|
||||||
if (row->ts == cacheRow->ts) {
|
|
||||||
STSRow *mergedRow = NULL;
|
|
||||||
SRowMerger merger = {0};
|
|
||||||
STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1, 1);
|
|
||||||
|
|
||||||
tRowMergerInit(&merger, &tsdbRowFromTSRow(0, cacheRow), pTSchema);
|
|
||||||
|
|
||||||
tRowMerge(&merger, &tsdbRowFromTSRow(1, row));
|
|
||||||
|
|
||||||
tRowMergerGetRow(&merger, &mergedRow);
|
|
||||||
tRowMergerClear(&merger);
|
|
||||||
|
|
||||||
taosMemoryFreeClear(pTSchema);
|
|
||||||
|
|
||||||
row = mergedRow;
|
|
||||||
dup = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TD_ROW_LEN(row) <= TD_ROW_LEN(cacheRow)) {
|
|
||||||
tdRowCpy(cacheRow, row);
|
|
||||||
if (!dup) {
|
|
||||||
taosMemoryFree(row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taosLRUCacheRelease(pCache, h, false);
|
|
||||||
} else {
|
|
||||||
taosLRUCacheRelease(pCache, h, true);
|
|
||||||
// tsdbCacheDeleteLastrow(pCache, uid, TSKEY_MAX);
|
|
||||||
if (dup) {
|
|
||||||
cacheRow = tdRowDup(row);
|
|
||||||
} else {
|
|
||||||
cacheRow = row;
|
|
||||||
}
|
|
||||||
_taos_lru_deleter_t deleter = deleteTableCacheLastrow;
|
|
||||||
LRUStatus status = taosLRUCacheInsert(pCache, key, keyLen, cacheRow, TD_ROW_LEN(cacheRow), deleter, NULL,
|
|
||||||
TAOS_LRU_PRIORITY_LOW);
|
|
||||||
if (status != TAOS_LRU_STATUS_OK) {
|
|
||||||
code = -1;
|
|
||||||
}
|
|
||||||
// tsdbCacheInsertLastrow(pCache, uid, row, dup);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
} /*else {
|
|
||||||
if (dup) {
|
|
||||||
cacheRow = tdRowDup(row);
|
|
||||||
} else {
|
|
||||||
cacheRow = row;
|
|
||||||
}
|
|
||||||
|
|
||||||
_taos_lru_deleter_t deleter = deleteTableCacheLastrow;
|
|
||||||
LRUStatus status =
|
|
||||||
taosLRUCacheInsert(pCache, key, keyLen, cacheRow, TD_ROW_LEN(cacheRow), deleter, NULL, TAOS_LRU_PRIORITY_LOW);
|
|
||||||
if (status != TAOS_LRU_STATUS_OK) {
|
|
||||||
code = -1;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,12 +294,11 @@ int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb
|
||||||
|
|
||||||
SColVal colVal = {0};
|
SColVal colVal = {0};
|
||||||
tTSRowGetVal(row, pTSchema, iCol, &colVal);
|
tTSRowGetVal(row, pTSchema, iCol, &colVal);
|
||||||
if (!COL_VAL_IS_VALUE(&colVal)) {
|
if (COL_VAL_IS_VALUE(&colVal)) {
|
||||||
if (keyTs == tTsVal1->ts && COL_VAL_IS_VALUE(tColVal)) {
|
if (keyTs == tTsVal1->ts && COL_VAL_IS_VALUE(tColVal)) {
|
||||||
invalidate = true;
|
invalidate = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
SLastCol lastCol = {.ts = keyTs, .colVal = colVal};
|
SLastCol lastCol = {.ts = keyTs, .colVal = colVal};
|
||||||
if (IS_VAR_DATA_TYPE(colVal.type) && colVal.value.nData > 0) {
|
if (IS_VAR_DATA_TYPE(colVal.type) && colVal.value.nData > 0) {
|
||||||
|
@ -374,14 +318,15 @@ int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_invalidate:
|
_invalidate:
|
||||||
taosMemoryFreeClear(pTSchema);
|
taosMemoryFreeClear(pTSchema);
|
||||||
|
|
||||||
taosLRUCacheRelease(pCache, h, invalidate);
|
taosLRUCacheRelease(pCache, h, invalidate);
|
||||||
|
if (invalidate) {
|
||||||
// clear last cache anyway, lazy load when get last lookup
|
taosLRUCacheErase(pCache, key, keyLen);
|
||||||
// taosLRUCacheRelease(pCache, h, true);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
Loading…
Reference in New Issue