Merge pull request #27584 from taosdata/fix/TD-31728-new

fix: (last) use insert to update LRU entry
This commit is contained in:
Hongze Cheng 2024-09-03 13:15:30 +08:00 committed by GitHub
commit 9147ad6074
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 22 deletions

View File

@ -757,24 +757,12 @@ static int32_t tsdbCacheDropTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid,
rocksdb_free(values_list[0]); rocksdb_free(values_list[0]);
rocksdb_free(values_list[1]); rocksdb_free(values_list[1]);
bool erase = false; for (int i = 0; i < 2; i++) {
LRUHandle *h = taosLRUCacheLookup(pTsdb->lruCache, keys_list[0], klen); LRUHandle *h = taosLRUCacheLookup(pTsdb->lruCache, keys_list[i], klen);
if (h) { if (h) {
erase = true; (void)taosLRUCacheRelease(pTsdb->lruCache, h, true);
(void)taosLRUCacheRelease(pTsdb->lruCache, h, erase); taosLRUCacheErase(pTsdb->lruCache, keys_list[i], klen);
} }
if (erase) {
taosLRUCacheErase(pTsdb->lruCache, keys_list[0], klen);
}
erase = false;
h = taosLRUCacheLookup(pTsdb->lruCache, keys_list[1], klen);
if (h) {
erase = true;
(void)taosLRUCacheRelease(pTsdb->lruCache, h, erase);
}
if (erase) {
taosLRUCacheErase(pTsdb->lruCache, keys_list[1], klen);
} }
} }
@ -1027,6 +1015,7 @@ static int32_t tsdbCacheUpdateValue(SValue *pOld, SValue *pNew) {
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
} }
#ifdef BUILD_NO_CALL
static void tsdbCacheUpdateLastCol(SLastCol *pLastCol, SRowKey *pRowKey, SColVal *pColVal) { static void tsdbCacheUpdateLastCol(SLastCol *pLastCol, SRowKey *pRowKey, SColVal *pColVal) {
// update rowkey // update rowkey
pLastCol->rowKey.ts = pRowKey->ts; pLastCol->rowKey.ts = pRowKey->ts;
@ -1047,6 +1036,7 @@ static void tsdbCacheUpdateLastCol(SLastCol *pLastCol, SRowKey *pRowKey, SColVal
pLastCol->dirty = 1; pLastCol->dirty = 1;
} }
} }
#endif
static void tsdbCacheUpdateLastColToNone(SLastCol *pLastCol, ELastCacheStatus cacheStatus) { static void tsdbCacheUpdateLastColToNone(SLastCol *pLastCol, ELastCacheStatus cacheStatus) {
// update rowkey // update rowkey
@ -1108,11 +1098,12 @@ static int32_t tsdbCachePutToLRU(STsdb *pTsdb, SLastKey *pLastKey, SLastCol *pLa
size_t charge = 0; size_t charge = 0;
*pLRULastCol = *pLastCol; *pLRULastCol = *pLastCol;
pLRULastCol->dirty = 1;
TAOS_CHECK_EXIT(tsdbCacheReallocSLastCol(pLRULastCol, &charge)); TAOS_CHECK_EXIT(tsdbCacheReallocSLastCol(pLRULastCol, &charge));
LRUStatus status = taosLRUCacheInsert(pTsdb->lruCache, pLastKey, ROCKS_KEY_LEN, pLRULastCol, charge, tsdbCacheDeleter, LRUStatus status = taosLRUCacheInsert(pTsdb->lruCache, pLastKey, ROCKS_KEY_LEN, pLRULastCol, charge, tsdbCacheDeleter,
NULL, TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState); NULL, TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState);
if (TAOS_LRU_STATUS_OK != status) { if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) {
tsdbError("tsdb/cache/putlru: vgId:%d, failed to insert status %d.", TD_VID(pTsdb->pVnode), status); tsdbError("tsdb/cache/putlru: vgId:%d, failed to insert status %d.", TD_VID(pTsdb->pVnode), status);
code = TSDB_CODE_INVALID_DATA_FMT; code = TSDB_CODE_INVALID_DATA_FMT;
} }
@ -1157,12 +1148,13 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray
if (pLastCol->cacheStatus != TSDB_LAST_CACHE_NO_CACHE) { if (pLastCol->cacheStatus != TSDB_LAST_CACHE_NO_CACHE) {
int32_t cmp_res = tRowKeyCompare(&pLastCol->rowKey, pRowKey); int32_t cmp_res = tRowKeyCompare(&pLastCol->rowKey, pRowKey);
if (cmp_res < 0 || (cmp_res == 0 && !COL_VAL_IS_NONE(pColVal))) { if (cmp_res < 0 || (cmp_res == 0 && !COL_VAL_IS_NONE(pColVal))) {
tsdbCacheUpdateLastCol(pLastCol, pRowKey, pColVal); SLastCol newLastCol = {.rowKey = *pRowKey, .colVal = *pColVal, .cacheStatus = TSDB_LAST_CACHE_VALID};
pLastCol->cacheStatus = TSDB_LAST_CACHE_VALID; code = tsdbCachePutToLRU(pTsdb, key, &newLastCol);
} }
} }
(void)taosLRUCacheRelease(pCache, h, false); (void)taosLRUCacheRelease(pCache, h, false);
TAOS_CHECK_EXIT(code);
} else { } else {
if (!remainCols) { if (!remainCols) {
remainCols = taosArrayInit(num_keys * 2, sizeof(SIdxKey)); remainCols = taosArrayInit(num_keys * 2, sizeof(SIdxKey));
@ -1880,9 +1872,13 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE
if (h) { if (h) {
SLastCol *pLastCol = (SLastCol *)taosLRUCacheValue(pTsdb->lruCache, h); SLastCol *pLastCol = (SLastCol *)taosLRUCacheValue(pTsdb->lruCache, h);
if (pLastCol->rowKey.ts <= eKey && pLastCol->rowKey.ts >= sKey) { if (pLastCol->rowKey.ts <= eKey && pLastCol->rowKey.ts >= sKey) {
tsdbCacheUpdateLastColToNone(pLastCol, TSDB_LAST_CACHE_NO_CACHE); SLastCol noneCol = {.rowKey.ts = TSKEY_MIN,
.colVal = COL_VAL_NONE(cid, pTSchema->columns[i].type),
.cacheStatus = TSDB_LAST_CACHE_NO_CACHE};
code = tsdbCachePutToLRU(pTsdb, &lastKey, &noneCol);
} }
(void)taosLRUCacheRelease(pTsdb->lruCache, h, false); (void)taosLRUCacheRelease(pTsdb->lruCache, h, false);
TAOS_CHECK_EXIT(code);
} else { } else {
if (!remainCols) { if (!remainCols) {
remainCols = taosArrayInit(numCols * 2, sizeof(SLastKey)); remainCols = taosArrayInit(numCols * 2, sizeof(SLastKey));