From 0c63eeccf9711c8e42601d85cdf562e635538047 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 14 Jun 2022 11:46:46 +0000 Subject: [PATCH] refact some code --- source/dnode/vnode/src/inc/tsdb.h | 21 +- source/dnode/vnode/src/tsdb/tsdbCommit.c | 273 ++++++++------- .../dnode/vnode/src/tsdb/tsdbReaderWriter.c | 32 +- source/dnode/vnode/src/tsdb/tsdbUtil.c | 316 ++---------------- 4 files changed, 177 insertions(+), 465 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 345f94cd16..191785895a 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -37,7 +37,6 @@ typedef struct TABLEID TABLEID; typedef struct SDelOp SDelOp; typedef struct SDelData SDelData; typedef struct SDelIdx SDelIdx; -typedef struct SDelDataInfo SDelDataInfo; typedef struct STbData STbData; typedef struct SMemTable SMemTable; typedef struct STbDataIter STbDataIter; @@ -48,7 +47,6 @@ typedef struct SMapData SMapData; typedef struct SColData SColData; typedef struct SColDataBlock SColDataBlock; typedef struct SBlockSMA SBlockSMA; -typedef struct SBlockIdxItem SBlockIdxItem; typedef struct SBlockIdx SBlockIdx; typedef struct SBlockInfo SBlockInfo; typedef struct SBlock SBlock; @@ -118,8 +116,7 @@ typedef struct SDelFWriter SDelFWriter; int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb); int32_t tsdbDelFWriterClose(SDelFWriter *pWriter, int8_t sync); -int32_t tsdbWriteDelData(SDelFWriter *pWriter, SDelDataInfo *pInfo, SMapData *pDelDataMap, uint8_t **ppBuf, - int64_t *rOffset, int64_t *rSize); +int32_t tsdbWriteDelData(SDelFWriter *pWriter, SMapData *pDelDataMap, uint8_t **ppBuf, SDelIdx *pDelIdx); int32_t tsdbWriteDelIdx(SDelFWriter *pWriter, SMapData *pDelIdxMap, uint8_t **ppBuf); int32_t tsdbUpdateDelFileHdr(SDelFWriter *pWriter, uint8_t **ppBuf); @@ -150,29 +147,17 @@ int32_t tPutMapData(uint8_t *p, SMapData *pMapData); int32_t tGetMapData(uint8_t *p, SMapData *pMapData); // SBlockIdx -int32_t tBlockIdxClear(SBlockIdx *pBlockIdx); -int32_t tBlockIdxPutItem(SBlockIdx *pBlockIdx, SBlockIdxItem *pItem); -int32_t tBlockIdxGetItemByIdx(SBlockIdx *pBlockIdx, SBlockIdxItem *pItem, int32_t idx); -int32_t tBlockIdxGetItem(SBlockIdx *pBlockIdx, SBlockIdxItem *pItem, TABLEID id); -int32_t tPutBlockIdx(uint8_t *p, SBlockIdx *pBlockIdx); -int32_t tGetBlockIdx(uint8_t *p, SBlockIdx *pBlockIdx); +int32_t tPutBlockIdx(uint8_t *p, void *ph); +int32_t tGetBlockIdx(uint8_t *p, void *ph); // SBlock int32_t tBlockCmprFn(const void *p1, const void *p2); // SDelIdx -// int32_t tDelIdxClear(SDelIdx *pDelIdx); -// int32_t tDelIdxPutItem(SDelIdx *pDelIdx, SDelIdxItem *pItem); -// int32_t tDelIdxGetItemByIdx(SDelIdx *pDelIdx, SDelIdxItem *pItem, int32_t idx); -// int32_t tDelIdxGetItem(SDelIdx *pDelIdx, SDelIdxItem *pItem, TABLEID id); int32_t tPutDelIdx(uint8_t *p, void *ph); int32_t tGetDelIdx(uint8_t *p, void *ph); // SDelData -// int32_t tDelDataClear(SDelData *pDelData); -// int32_t tDelDataPutItem(SDelData *pDelData, SDelDataItem *pItem); -// int32_t tDelDataGetItemByIdx(SDelData *pDelData, SDelDataItem *pItem, int32_t idx); -// int32_t tDelDataGetItem(SDelData *pDelData, SDelDataItem *pItem, int64_t version); int32_t tPutDelData(uint8_t *p, void *ph); int32_t tGetDelData(uint8_t *p, void *ph); diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 00eff4f84f..b440dac24f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -139,35 +139,6 @@ static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitter *pCommitter) { return code; } -static int32_t tsdbCommitData(SCommitter *pCommitter) { - int32_t code = 0; - STsdb *pTsdb = pCommitter->pTsdb; - SMemTable *pMemTable = pTsdb->imem; - - // check - if (pMemTable->nRow == 0) { - goto _exit; - } - - // loop - pCommitter->nextKey = pMemTable->minKey.ts; - while (pCommitter->nextKey < TSKEY_MAX) { - pCommitter->commitFid = tsdbKeyFid(pCommitter->nextKey, pCommitter->minutes, pCommitter->precision); - tsdbFidKeyRange(pCommitter->commitFid, pCommitter->minutes, pCommitter->precision, &pCommitter->minKey, - &pCommitter->maxKey); - code = tsdbCommitFileData(pCommitter); - if (code) goto _err; - } - -_exit: - tsdbDebug("vgId:%d commit data done, nRow:%" PRId64, TD_VID(pTsdb->pVnode), pMemTable->nRow); - return code; - -_err: - tsdbError("vgId:%d commit data failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); - return code; -} - static int32_t tsdbCommitDelStart(SCommitter *pCommitter) { int32_t code = 0; STsdb *pTsdb = pCommitter->pTsdb; @@ -200,6 +171,90 @@ _err: return code; } +static int32_t tsdbCommitTableDel(SCommitter *pCommitter, STbData *pTbData, SDelIdx *pDelIdx) { + int32_t code = 0; + SDelData delData; + SDelOp *pDelOp; + tb_uid_t suid; + tb_uid_t uid; + SDelIdx delIdx; // TODO + + // check no del data, just return + if (pTbData && pTbData->pHead == NULL) { + pTbData = NULL; + } + if (pTbData == NULL && pDelIdx == NULL) goto _exit; + + // prepare + if (pTbData) { + delIdx.suid = pTbData->suid; + delIdx.uid = pTbData->uid; + } else { + delIdx.suid = pDelIdx->suid; + delIdx.uid = pDelIdx->uid; + } + delIdx.minKey = TSKEY_MAX; + delIdx.maxKey = TSKEY_MIN; + delIdx.minVersion = INT64_MAX; + delIdx.maxVersion = -1; + + // start + tMapDataReset(&pCommitter->oDelDataMap); + tMapDataReset(&pCommitter->nDelDataMap); + + if (pDelIdx) { + code = tsdbReadDelData(pCommitter->pDelFReader, pDelIdx, &pCommitter->oDelDataMap, NULL); + if (code) goto _err; + } + + // disk + for (int32_t iDelData = 0; iDelData < pCommitter->oDelDataMap.nItem; iDelData++) { + code = tMapDataGetItemByIdx(&pCommitter->oDelDataMap, iDelData, &delData, tGetDelData); + if (code) goto _err; + + code = tMapDataPutItem(&pCommitter->nDelDataMap, &delData, tPutDelData); + if (code) goto _err; + + if (delIdx.minKey > delData.sKey) delIdx.minKey = delData.sKey; + if (delIdx.maxKey < delData.eKey) delIdx.maxKey = delData.eKey; + if (delIdx.minVersion > delData.version) delIdx.minVersion = delData.version; + if (delIdx.maxVersion < delData.version) delIdx.maxVersion = delData.version; + } + + // memory + pDelOp = pTbData ? pTbData->pHead : NULL; + for (; pDelOp; pDelOp = pDelOp->pNext) { + delData.version = pDelOp->version; + delData.sKey = pDelOp->sKey; + delData.eKey = pDelOp->eKey; + + code = tMapDataPutItem(&pCommitter->nDelDataMap, &delData, tPutDelData); + if (code) goto _err; + + if (delIdx.minKey > delData.sKey) delIdx.minKey = delData.sKey; + if (delIdx.maxKey < delData.eKey) delIdx.maxKey = delData.eKey; + if (delIdx.minVersion > delData.version) delIdx.minVersion = delData.version; + if (delIdx.maxVersion < delData.version) delIdx.maxVersion = delData.version; + } + + ASSERT(pCommitter->nDelDataMap.nItem > 0); + + // write + code = tsdbWriteDelData(pCommitter->pDelFWriter, &pCommitter->nDelDataMap, NULL, &delIdx); + if (code) goto _err; + + // put delIdx + code = tMapDataPutItem(&pCommitter->nDelIdxMap, &delIdx, tPutDelIdx); + if (code) goto _err; + +_exit: + return code; + +_err: + tsdbError("vgId:%d commit table del failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + return code; +} + static int32_t tsdbCommitDelImpl(SCommitter *pCommitter) { int32_t code = 0; STsdb *pTsdb = pCommitter->pTsdb; @@ -316,48 +371,6 @@ _err: return code; } -static int32_t tsdbCommitDel(SCommitter *pCommitter) { - int32_t code = 0; - STsdb *pTsdb = pCommitter->pTsdb; - SMemTable *pMemTable = pTsdb->imem; - - if (pMemTable->nDel == 0) { - goto _exit; - } - - // start - code = tsdbCommitDelStart(pCommitter); - if (code) { - goto _err; - } - - // impl - code = tsdbCommitDelImpl(pCommitter); - if (code) { - goto _err; - } - - // end - code = tsdbCommitDelEnd(pCommitter); - if (code) { - goto _err; - } - -_exit: - tsdbDebug("vgId:%d commit del done, nDel:%" PRId64, TD_VID(pTsdb->pVnode), pMemTable->nDel); - return code; - -_err: - tsdbError("vgId:%d commit del failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); - return code; -} - -static int32_t tsdbCommitCache(SCommitter *pCommitter) { - int32_t code = 0; - // TODO - return code; -} - static int32_t tsdbEndCommit(SCommitter *pCommitter, int32_t eno) { int32_t code = 0; // TODO @@ -619,89 +632,73 @@ static int32_t tsdbCommitTableDataEnd(SCommitter *pCommitter) { return code; } -static int32_t tsdbCommitTableDel(SCommitter *pCommitter, STbData *pTbData, SDelIdx *pDelIdx) { - int32_t code = 0; - SDelData delData; - SDelOp *pDelOp; - tb_uid_t suid; - tb_uid_t uid; - SDelIdx delIdx; // TODO - SDelDataInfo info; // TODO - - // check no del data, just return - if (pTbData && pTbData->pHead == NULL) { - pTbData = NULL; - } - if (pTbData == NULL && pDelIdx == NULL) goto _exit; +static int32_t tsdbCommitData(SCommitter *pCommitter) { + int32_t code = 0; + STsdb *pTsdb = pCommitter->pTsdb; + SMemTable *pMemTable = pTsdb->imem; - // prepare - if (pTbData) { - info.suid = pTbData->suid; - info.uid = pTbData->uid; - } else { - info.suid = pDelIdx->suid; - info.uid = pDelIdx->uid; + // check + if (pMemTable->nRow == 0) { + goto _exit; } - delIdx.suid = info.suid; - delIdx.uid = info.uid; - delIdx.minKey = TSKEY_MAX; - delIdx.maxKey = TSKEY_MIN; - delIdx.minVersion = INT64_MAX; - delIdx.maxVersion = -1; - - // start - tMapDataReset(&pCommitter->oDelDataMap); - tMapDataReset(&pCommitter->nDelDataMap); - if (pDelIdx) { - code = tsdbReadDelData(pCommitter->pDelFReader, pDelIdx, &pCommitter->oDelDataMap, NULL); + // loop + pCommitter->nextKey = pMemTable->minKey.ts; + while (pCommitter->nextKey < TSKEY_MAX) { + pCommitter->commitFid = tsdbKeyFid(pCommitter->nextKey, pCommitter->minutes, pCommitter->precision); + tsdbFidKeyRange(pCommitter->commitFid, pCommitter->minutes, pCommitter->precision, &pCommitter->minKey, + &pCommitter->maxKey); + code = tsdbCommitFileData(pCommitter); if (code) goto _err; } - // disk - for (int32_t iDelData = 0; iDelData < pCommitter->oDelDataMap.nItem; iDelData++) { - code = tMapDataGetItemByIdx(&pCommitter->oDelDataMap, iDelData, &delData, tGetDelData); - if (code) goto _err; - - code = tMapDataPutItem(&pCommitter->nDelDataMap, &delData, tPutDelData); - if (code) goto _err; - - if (delIdx.minKey > delData.sKey) delIdx.minKey = delData.sKey; - if (delIdx.maxKey < delData.eKey) delIdx.maxKey = delData.eKey; - if (delIdx.minVersion > delData.version) delIdx.minVersion = delData.version; - if (delIdx.maxVersion < delData.version) delIdx.maxVersion = delData.version; - } +_exit: + tsdbDebug("vgId:%d commit data done, nRow:%" PRId64, TD_VID(pTsdb->pVnode), pMemTable->nRow); + return code; - // memory - pDelOp = pTbData ? pTbData->pHead : NULL; - for (; pDelOp; pDelOp = pDelOp->pNext) { - delData.version = pDelOp->version; - delData.sKey = pDelOp->sKey; - delData.eKey = pDelOp->eKey; +_err: + tsdbError("vgId:%d commit data failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} - code = tMapDataPutItem(&pCommitter->nDelDataMap, &delData, tPutDelData); - if (code) goto _err; +static int32_t tsdbCommitDel(SCommitter *pCommitter) { + int32_t code = 0; + STsdb *pTsdb = pCommitter->pTsdb; + SMemTable *pMemTable = pTsdb->imem; - if (delIdx.minKey > delData.sKey) delIdx.minKey = delData.sKey; - if (delIdx.maxKey < delData.eKey) delIdx.maxKey = delData.eKey; - if (delIdx.minVersion > delData.version) delIdx.minVersion = delData.version; - if (delIdx.maxVersion < delData.version) delIdx.maxVersion = delData.version; + if (pMemTable->nDel == 0) { + goto _exit; } - ASSERT(pCommitter->nDelDataMap.nItem > 0); + // start + code = tsdbCommitDelStart(pCommitter); + if (code) { + goto _err; + } - // write - code = tsdbWriteDelData(pCommitter->pDelFWriter, &info, &pCommitter->nDelDataMap, NULL, &delIdx.offset, &delIdx.size); - if (code) goto _err; + // impl + code = tsdbCommitDelImpl(pCommitter); + if (code) { + goto _err; + } - // put delIdx - code = tMapDataPutItem(&pCommitter->nDelIdxMap, &delIdx, tPutDelIdx); - if (code) goto _err; + // end + code = tsdbCommitDelEnd(pCommitter); + if (code) { + goto _err; + } _exit: + tsdbDebug("vgId:%d commit del done, nDel:%" PRId64, TD_VID(pTsdb->pVnode), pMemTable->nDel); return code; _err: - tsdbError("vgId:%d commit table del failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + tsdbError("vgId:%d commit del failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); return code; -} \ No newline at end of file +} + +static int32_t tsdbCommitCache(SCommitter *pCommitter) { + int32_t code = 0; + // TODO + return code; +} diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index 1dc704b48a..45ffd42e86 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -139,8 +139,7 @@ _err: return code; } -int32_t tsdbWriteDelData(SDelFWriter *pWriter, SDelDataInfo *pInfo, SMapData *pDelDataMap, uint8_t **ppBuf, - int64_t *rOffset, int64_t *rSize) { +int32_t tsdbWriteDelData(SDelFWriter *pWriter, SMapData *pDelDataMap, uint8_t **ppBuf, SDelIdx *pDelIdx) { int32_t code = 0; uint8_t *pBuf = NULL; int64_t size = 0; @@ -148,8 +147,8 @@ int32_t tsdbWriteDelData(SDelFWriter *pWriter, SDelDataInfo *pInfo, SMapData *pD // prepare size += tPutU32(NULL, TSDB_FILE_DLMT); - size += tPutI64(NULL, pInfo->suid); - size += tPutI64(NULL, pInfo->uid); + size += tPutI64(NULL, pDelIdx->suid); + size += tPutI64(NULL, pDelIdx->uid); size = size + tPutMapData(NULL, pDelDataMap) + sizeof(TSCKSUM); // alloc @@ -159,8 +158,8 @@ int32_t tsdbWriteDelData(SDelFWriter *pWriter, SDelDataInfo *pInfo, SMapData *pD // build n += tPutU32(*ppBuf + n, TSDB_FILE_DLMT); - n += tPutI64(*ppBuf + n, pInfo->suid); - n += tPutI64(*ppBuf + n, pInfo->uid); + n += tPutI64(*ppBuf + n, pDelIdx->suid); + n += tPutI64(*ppBuf + n, pDelIdx->uid); n += tPutMapData(*ppBuf + n, pDelDataMap); taosCalcChecksumAppend(0, *ppBuf, size); @@ -176,8 +175,8 @@ int32_t tsdbWriteDelData(SDelFWriter *pWriter, SDelDataInfo *pInfo, SMapData *pD ASSERT(n == size); // update - *rOffset = pWriter->pFile->size; - *rSize = size; + pDelIdx->offset = pWriter->pFile->size; + pDelIdx->size = size; pWriter->pFile->offset = pWriter->pFile->size; pWriter->pFile->size += size; @@ -348,10 +347,11 @@ _exit: } int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SMapData *pDelDataMap, uint8_t **ppBuf) { - int32_t code = 0; - int64_t n; - uint32_t delimiter; - SDelDataInfo info; + int32_t code = 0; + int64_t n; + uint32_t delimiter; + tb_uid_t suid; + tb_uid_t uid; // seek if (taosLSeekFile(pReader->pReadH, pDelIdx->offset, SEEK_SET) < 0) { @@ -381,10 +381,10 @@ int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SMapData *pDelDa n = 0; n += tGetU32(*ppBuf + n, &delimiter); ASSERT(delimiter == TSDB_FILE_DLMT); - n += tGetI64(*ppBuf + n, &info.suid); - ASSERT(info.suid == pDelIdx->suid); - n += tGetI64(*ppBuf + n, &info.uid); - ASSERT(info.uid == pDelIdx->uid); + n += tGetI64(*ppBuf + n, &suid); + ASSERT(suid == pDelIdx->suid); + n += tGetI64(*ppBuf + n, &uid); + ASSERT(uid == pDelIdx->uid); n += tGetMapData(*ppBuf + n, pDelDataMap); ASSERT(n + sizeof(TSCKSUM) == pDelIdx->size); diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 5da7266b42..dd358ff3a1 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -356,143 +356,35 @@ static FORCE_INLINE int32_t tGetTSDBKEY(uint8_t *p, TSDBKEY *pKey) { return n; } -// // SDelIdxItem ====================================================== -// static FORCE_INLINE int32_t tPutDelIdxItem(uint8_t *p, SDelIdxItem *pDelIdxItem) { -// int32_t n = 0; - -// n += tPutI64(p ? p + n : p, pDelIdxItem->suid); -// n += tPutI64(p ? p + n : p, pDelIdxItem->uid); -// n += tPutI64(p ? p + n : p, pDelIdxItem->minKey); -// n += tPutI64(p ? p + n : p, pDelIdxItem->maxKey); -// n += tPutI64v(p ? p + n : p, pDelIdxItem->minVersion); -// n += tPutI64v(p ? p + n : p, pDelIdxItem->maxVersion); -// n += tPutI64v(p ? p + n : p, pDelIdxItem->offset); -// n += tPutI64v(p ? p + n : p, pDelIdxItem->size); - -// return n; -// } - -// static FORCE_INLINE int32_t tGetDelIdxItem(uint8_t *p, SDelIdxItem *pDelIdxItem) { -// int32_t n = 0; - -// n += tGetI64(p + n, &pDelIdxItem->suid); -// n += tGetI64(p + n, &pDelIdxItem->uid); -// n += tGetI64(p + n, &pDelIdxItem->minKey); -// n += tGetI64(p + n, &pDelIdxItem->maxKey); -// n += tGetI64v(p + n, &pDelIdxItem->minVersion); -// n += tGetI64v(p + n, &pDelIdxItem->maxVersion); -// n += tGetI64v(p + n, &pDelIdxItem->offset); -// n += tGetI64v(p + n, &pDelIdxItem->size); - -// return n; -// } - -// SBlockIdxItem ====================================================== -static FORCE_INLINE int32_t tPutBlockIdxItem(uint8_t *p, SBlockIdxItem *pItem) { - int32_t n = 0; - - n += tPutI64(p ? p + n : p, pItem->suid); - n += tPutI64(p ? p + n : p, pItem->uid); - n += tPutTSDBKEY(p ? p + n : p, &pItem->minKey); - n += tPutTSDBKEY(p ? p + n : p, &pItem->maxKey); - n += tPutI64v(p ? p + n : p, pItem->minVersion); - n += tPutI64v(p ? p + n : p, pItem->maxVersion); - n += tPutI64v(p ? p + n : p, pItem->offset); - n += tPutI64v(p ? p + n : p, pItem->size); - - return n; -} - -static FORCE_INLINE int32_t tGetBlockIdxItem(uint8_t *p, SBlockIdxItem *pItem) { - int32_t n = 0; - - n += tGetI64(p + n, &pItem->suid); - n += tGetI64(p + n, &pItem->uid); - n += tGetTSDBKEY(p + n, &pItem->minKey); - n += tGetTSDBKEY(p + n, &pItem->maxKey); - n += tGetI64v(p + n, &pItem->minVersion); - n += tGetI64v(p + n, &pItem->maxVersion); - n += tGetI64v(p + n, &pItem->offset); - n += tGetI64v(p + n, &pItem->size); - - return n; -} - // SBlockIdx ====================================================== -int32_t tBlockIdxClear(SBlockIdx *pBlockIdx) { - int32_t code = 0; - tsdbFree(pBlockIdx->offset.pOffset); - tsdbFree(pBlockIdx->pData); - return code; -} - -int32_t tBlockIdxPutItem(SBlockIdx *pBlockIdx, SBlockIdxItem *pItem) { - int32_t code = 0; - // TODO - return code; -} - -int32_t tBlockIdxGetItemByIdx(SBlockIdx *pBlockIdx, SBlockIdxItem *pItem, int32_t idx) { - int32_t code = 0; - int32_t offset; - - offset = tsdbGetOffset(&pBlockIdx->offset, idx); - if (offset < 0) { - code = TSDB_CODE_NOT_FOUND; - goto _exit; - } - - tGetBlockIdxItem(pBlockIdx->pData + offset, pItem); - -_exit: - return code; -} - -int32_t tBlockIdxGetItem(SBlockIdx *pBlockIdx, SBlockIdxItem *pItem, TABLEID id) { - int32_t code = 0; - int32_t lidx = 0; - int32_t ridx = pBlockIdx->offset.nOffset - 1; - int32_t midx; - int32_t c; - - while (lidx <= ridx) { - midx = (lidx + midx) / 2; - - code = tBlockIdxGetItemByIdx(pBlockIdx, pItem, midx); - if (code) goto _exit; - - c = tTABLEIDCmprFn(&id, pItem); - if (c == 0) { - goto _exit; - } else if (c < 0) { - ridx = midx - 1; - } else { - lidx = midx + 1; - } - } - - code = TSDB_CODE_NOT_FOUND; - -_exit: - return code; -} - -int32_t tPutBlockIdx(uint8_t *p, SBlockIdx *pBlockIdx) { - int32_t n = 0; - - n += tPutU32(p ? p + n : p, pBlockIdx->delimiter); - n += tPutOffset(p ? p + n : p, &pBlockIdx->offset); - n += tPutBinary(p ? p + n : p, pBlockIdx->pData, pBlockIdx->nData); +int32_t tPutBlockIdx(uint8_t *p, void *ph) { + int32_t n = 0; + SBlockIdx *pBlockIdx = (SBlockIdx *)ph; + + n += tPutI64(p ? p + n : p, pBlockIdx->suid); + n += tPutI64(p ? p + n : p, pBlockIdx->uid); + n += tPutTSDBKEY(p ? p + n : p, &pBlockIdx->minKey); + n += tPutTSDBKEY(p ? p + n : p, &pBlockIdx->maxKey); + n += tPutI64v(p ? p + n : p, pBlockIdx->minVersion); + n += tPutI64v(p ? p + n : p, pBlockIdx->maxVersion); + n += tPutI64v(p ? p + n : p, pBlockIdx->offset); + n += tPutI64v(p ? p + n : p, pBlockIdx->size); return n; } -int32_t tGetBlockIdx(uint8_t *p, SBlockIdx *pBlockIdx) { - int32_t n = 0; +int32_t tGetBlockIdx(uint8_t *p, void *ph) { + int32_t n = 0; + SBlockIdx *pBlockIdx = (SBlockIdx *)ph; - n += tGetU32(p + n, &pBlockIdx->delimiter); - n += tGetOffset(p + n, &pBlockIdx->offset); - n += tGetBinary(p + n, &pBlockIdx->pData, &pBlockIdx->nData); + n += tGetI64(p + n, &pBlockIdx->suid); + n += tGetI64(p + n, &pBlockIdx->uid); + n += tGetTSDBKEY(p + n, &pBlockIdx->minKey); + n += tGetTSDBKEY(p + n, &pBlockIdx->maxKey); + n += tGetI64v(p + n, &pBlockIdx->minVersion); + n += tGetI64v(p + n, &pBlockIdx->maxVersion); + n += tGetI64v(p + n, &pBlockIdx->offset); + n += tGetI64v(p + n, &pBlockIdx->size); return n; } @@ -513,78 +405,6 @@ int32_t tBlockCmprFn(const void *p1, const void *p2) { } // SDelIdx ====================================================== -// int32_t tDelIdxClear(SDelIdx *pDelIdx) { -// int32_t code = 0; -// tdbFree(pDelIdx->offset.pOffset); -// tdbFree(pDelIdx->pData); -// return code; -// } - -// int32_t tDelIdxPutItem(SDelIdx *pDelIdx, SDelIdxItem *pItem) { -// int32_t code = 0; -// uint32_t offset = pDelIdx->nData; - -// // offset -// code = tsdbAddOffset(&pDelIdx->offset, offset); -// if (code) goto _exit; - -// // alloc -// pDelIdx->nData += tPutDelIdxItem(NULL, pItem); -// code = tsdbRealloc(&pDelIdx->pData, pDelIdx->nData); -// if (code) goto _exit; - -// // put -// tPutDelIdxItem(pDelIdx->pData + offset, pItem); - -// _exit: -// return code; -// } - -// int32_t tDelIdxGetItemByIdx(SDelIdx *pDelIdx, SDelIdxItem *pItem, int32_t idx) { -// int32_t code = 0; -// int32_t offset; - -// offset = tsdbGetOffset(&pDelIdx->offset, idx); -// if (offset < 0) { -// code = TSDB_CODE_NOT_FOUND; -// goto _exit; -// } - -// tGetDelIdxItem(pDelIdx->pData + offset, pItem); - -// _exit: -// return code; -// } - -// int32_t tDelIdxGetItem(SDelIdx *pDelIdx, SDelIdxItem *pItem, TABLEID id) { -// int32_t code = 0; -// int32_t lidx = 0; -// int32_t ridx = pDelIdx->offset.nOffset - 1; -// int32_t midx; -// int32_t c; - -// while (lidx <= ridx) { -// midx = (lidx + ridx) / 2; - -// code = tDelIdxGetItemByIdx(pDelIdx, pItem, midx); -// if (code) goto _exit; - -// c = tTABLEIDCmprFn(&id, pItem); -// if (c == 0) { -// goto _exit; -// } else if (c < 0) { -// ridx = midx - 1; -// } else { -// lidx = midx + 1; -// } -// } - -// code = TSDB_CODE_NOT_FOUND; - -// _exit: -// return code; -// } - int32_t tPutDelIdx(uint8_t *p, void *ph) { SDelIdx *pDelIdx = (SDelIdx *)ph; int32_t n = 0; @@ -617,97 +437,7 @@ int32_t tGetDelIdx(uint8_t *p, void *ph) { return n; } -// // SDelDataItem ====================================================== -// static FORCE_INLINE int32_t tPutDelDataItem(uint8_t *p, SDelDataItem *pItem) { -// int32_t n = 0; - -// n += tPutI64v(p ? p + n : p, pItem->version); -// n += tPutI64(p ? p + n : p, pItem->sKey); -// n += tPutI64(p ? p + n : p, pItem->eKey); - -// return n; -// } - -// static FORCE_INLINE int32_t tGetDelDataItem(uint8_t *p, SDelDataItem *pItem) { -// int32_t n = 0; - -// n += tGetI64v(p + n, &pItem->version); -// n += tGetI64(p + n, &pItem->sKey); -// n += tGetI64(p + n, &pItem->eKey); - -// return n; -// } - // SDelData ====================================================== -// int32_t tDelDataClear(SDelData *pDelData) { -// int32_t code = 0; -// tsdbFree(pDelData->offset.pOffset); -// tsdbFree(pDelData->pData); -// return code; -// } - -// int32_t tDelDataPutItem(SDelData *pDelData, SDelDataItem *pItem) { -// int32_t code = 0; -// uint32_t offset = pDelData->nData; - -// // offset -// code = tsdbAddOffset(&pDelData->offset, offset); -// if (code) goto _exit; - -// // alloc -// pDelData->nData += tPutDelDataItem(NULL, pItem); -// code = tsdbRealloc(&pDelData->pData, pDelData->nData); -// if (code) goto _exit; - -// // put -// tPutDelDataItem(pDelData->pData + offset, pItem); - -// _exit: -// return code; -// } - -// int32_t tDelDataGetItemByIdx(SDelData *pDelData, SDelDataItem *pItem, int32_t idx) { -// int32_t code = 0; -// int32_t offset; - -// offset = tsdbGetOffset(&pDelData->offset, idx); -// if (offset < 0) { -// code = TSDB_CODE_NOT_FOUND; -// goto _exit; -// } -// tGetDelDataItem(pDelData->pData + offset, pItem); - -// _exit: -// return code; -// } - -// int32_t tDelDataGetItem(SDelData *pDelData, SDelDataItem *pItem, int64_t version) { -// int32_t code = 0; -// int32_t lidx = 0; -// int32_t ridx = pDelData->offset.nOffset - 1; -// int32_t midx; - -// while (lidx <= ridx) { -// midx = (lidx + ridx) / 2; - -// code = tDelDataGetItemByIdx(pDelData, pItem, midx); -// if (code) goto _exit; - -// if (version == pItem->version) { -// goto _exit; -// } else if (version < pItem->version) { -// ridx = midx - 1; -// } else { -// ridx = midx + 1; -// } -// } - -// code = TSDB_CODE_NOT_FOUND; - -// _exit: -// return code; -// } - int32_t tPutDelData(uint8_t *p, void *ph) { SDelData *pDelData = (SDelData *)ph; int32_t n = 0; -- GitLab