From 4d8d1df2e5dd7b272315ac14af1fe8fb11714f18 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 23 Jun 2022 03:54:20 +0000 Subject: [PATCH] more work --- source/dnode/vnode/src/tsdb/tsdbMemTable.c | 8 +++-- source/dnode/vnode/src/tsdb/tsdbUtil.c | 37 +++++++++++----------- source/dnode/vnode/src/vnd/vnodeCommit.c | 19 ++++------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index 6b3e682f82..42fff7469c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -522,7 +522,6 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i } if (pTbData->minKey > key.ts) pTbData->minKey = key.ts; - if (pMemTable->minKey > key.ts) pMemTable->minKey = key.ts; pLastRow = row.pTSRow; @@ -554,9 +553,14 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i tsdbCacheInsertLastrow(pMemTable->pTsdb->lruCache, pTbData->uid, pLastRow); } } - if (key.ts > pMemTable->maxKey) pMemTable->maxKey = key.ts; if (pTbData->minVersion > version) pTbData->minVersion = version; if (pTbData->maxVersion < version) pTbData->maxVersion = version; + + // SMemTable + if (pMemTable->minKey > pTbData->minKey) pMemTable->minKey = pTbData->minKey; + if (pMemTable->maxKey < pTbData->maxKey) pMemTable->maxKey = pTbData->maxKey; + if (pMemTable->minVersion > pTbData->minVersion) pMemTable->minVersion = pTbData->minVersion; + if (pMemTable->maxVersion < pTbData->maxVersion) pMemTable->maxVersion = pTbData->maxVersion; pMemTable->nRow += nRow; pRsp->numOfRows = nRow; diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index b68e9571e6..68b649869e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -47,6 +47,7 @@ int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(u if (code) goto _err; // put + ASSERT(pMapData->flag == TSDB_OFFSET_I32); ((int32_t *)pMapData->pOfst)[nItem] = offset; tPutItemFn(pMapData->pData + offset, pItem); @@ -54,31 +55,31 @@ _err: return code; } +static int32_t tMapDataGetOffset(SMapData *pMapData, int32_t idx) { + switch (pMapData->flag) { + case TSDB_OFFSET_I8: + return ((int8_t *)pMapData->pOfst)[idx]; + break; + case TSDB_OFFSET_I16: + return ((int16_t *)pMapData->pOfst)[idx]; + break; + case TSDB_OFFSET_I32: + return ((int32_t *)pMapData->pOfst)[idx]; + break; + default: + ASSERT(0); + } +} + int32_t tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *)) { int32_t code = 0; - int32_t offset; if (idx < 0 || idx >= pMapData->nItem) { code = TSDB_CODE_NOT_FOUND; goto _exit; } - switch (pMapData->flag) { - case TSDB_OFFSET_I8: - offset = ((int8_t *)pMapData->pOfst)[idx]; - break; - case TSDB_OFFSET_I16: - offset = ((int16_t *)pMapData->pOfst)[idx]; - break; - case TSDB_OFFSET_I32: - offset = ((int32_t *)pMapData->pOfst)[idx]; - break; - - default: - ASSERT(0); - } - - tGetItemFn(pMapData->pData + offset, pItem); + tGetItemFn(pMapData->pData + tMapDataGetOffset(pMapData, idx), pItem); _exit: return code; @@ -91,7 +92,7 @@ int32_t tPutMapData(uint8_t *p, SMapData *pMapData) { ASSERT(pMapData->flag == TSDB_OFFSET_I32); ASSERT(pMapData->nItem > 0); - maxOffset = ((int32_t *)pMapData->pOfst)[pMapData->nItem - 1]; + maxOffset = tMapDataGetOffset(pMapData, pMapData->nItem - 1); n += tPutI32v(p ? p + n : p, pMapData->nItem); if (maxOffset <= INT8_MAX) { diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 6aa51cde8e..0da9b285c0 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -48,26 +48,21 @@ int vnodeBegin(SVnode *pVnode) { } // begin tsdb - if (pVnode->pSma) { - if (tsdbBegin(VND_RSMA0(pVnode)) < 0) { - vError("vgId:%d, failed to begin rsma0 since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } + if (tsdbBegin(pVnode->pTsdb) < 0) { + vError("vgId:%d, failed to begin tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); + return -1; + } - if (tsdbBegin(VND_RSMA1(pVnode)) < 0) { + if (pVnode->pSma) { + if (VND_RSMA1(pVnode) && tsdbBegin(VND_RSMA1(pVnode)) < 0) { vError("vgId:%d, failed to begin rsma1 since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } - if (tsdbBegin(VND_RSMA2(pVnode)) < 0) { + if (VND_RSMA2(pVnode) && tsdbBegin(VND_RSMA2(pVnode)) < 0) { vError("vgId:%d, failed to begin rsma2 since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } - } else { - if (tsdbBegin(pVnode->pTsdb) < 0) { - vError("vgId:%d, failed to begin tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } } return 0;