Skip to content

Commit

Permalink
tsdb/cache: reuse update ctx array
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenkgu committed Nov 14, 2024
1 parent a546250 commit e3f57a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions source/dnode/vnode/src/inc/tsdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ typedef struct {
tb_uid_t suid;
tb_uid_t uid;
STSchema *pTSchema;
SArray *ctxArray;
} SRocksCache;

typedef struct {
Expand Down
14 changes: 9 additions & 5 deletions source/dnode/vnode/src/tsdb/tsdbCache.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ static int32_t tsdbOpenRocksCache(STsdb *pTsdb) {
pTsdb->rCache.suid = -1;
pTsdb->rCache.uid = -1;
pTsdb->rCache.pTSchema = NULL;
pTsdb->rCache.ctxArray = NULL;

TAOS_RETURN(code);

Expand Down Expand Up @@ -267,6 +268,7 @@ static void tsdbCloseRocksCache(STsdb *pTsdb) {
rocksdb_cache_destroy(pTsdb->rCache.blockcache);
rocksdb_comparator_destroy(pTsdb->rCache.my_comparator);
taosMemoryFree(pTsdb->rCache.pTSchema);
taosArrayDestroy(pTsdb->rCache.ctxArray);
}

static void rocksMayWrite(STsdb *pTsdb, bool force) {
Expand Down Expand Up @@ -1340,7 +1342,6 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6
TSDBROW lRow = {.type = TSDBROW_ROW_FMT, .pTSRow = aRow[nRow - 1], .version = version};
STSchema *pTSchema = NULL;
int32_t sver = TSDBROW_SVERSION(&lRow);
SArray *ctxArray = NULL;
SSHashObj *iColHash = NULL;

TAOS_CHECK_GOTO(tsdbUpdateSkm(pTsdb, suid, uid, sver), &lino, _exit);
Expand All @@ -1349,10 +1350,13 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6
TSDBROW tRow = {.type = TSDBROW_ROW_FMT, .version = version};
int32_t nCol = pTSchema->numOfCols;

ctxArray = taosArrayInit(nCol * 2, sizeof(SLastUpdateCtx));
if (ctxArray == NULL) {
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
if (!pTsdb->rCache.ctxArray) {
pTsdb->rCache.ctxArray = taosArrayInit(nCol * 2, sizeof(SLastUpdateCtx));
if (!pTsdb->rCache.ctxArray) {
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
}
}
SArray *ctxArray = pTsdb->rCache.ctxArray;

// 1. prepare by lrow
STsdbRowKey tsdbRowKey = {0};
Expand Down Expand Up @@ -1436,8 +1440,8 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6
tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, tstrerror(code));
}

taosArrayDestroy(ctxArray);
tSimpleHashCleanup(iColHash);
taosArrayClear(ctxArray);

TAOS_RETURN(code);
}
Expand Down

0 comments on commit e3f57a1

Please sign in to comment.