diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 1a95d90a21..7f554a1a5f 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -31,18 +31,21 @@ extern "C" { #define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) #define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) // clang-format on - -typedef struct TSDBROW TSDBROW; -typedef struct TSDBKEY TSDBKEY; -typedef struct TABLEID TABLEID; -typedef struct SDelOp SDelOp; +typedef struct TSDBROW TSDBROW; +typedef struct TSDBKEY TSDBKEY; +typedef struct TABLEID TABLEID; +typedef struct SDelOp SDelOp; +typedef struct SDelDataItem SDelDataItem; +typedef struct SDelData SDelData; +typedef struct SDelIdxItem SDelIdxItem; +typedef struct SDelIdx SDelIdx; +typedef struct STbData STbData; +typedef struct SMemTable SMemTable; +typedef struct STbDataIter STbDataIter; +typedef struct SMergeInfo SMergeInfo; +typedef struct STable STable; // tsdbMemTable ============================================================================================== -typedef struct STbData STbData; -typedef struct SMemTable SMemTable; -typedef struct STbDataIter STbDataIter; -typedef struct SMergeInfo SMergeInfo; -typedef struct STable STable; // SMemTable int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable); @@ -75,10 +78,6 @@ int32_t tsdbFSStart(STsdbFS *pFS); int32_t tsdbFSEnd(STsdbFS *pFS, int8_t rollback); // tsdbReaderWriter.c ============================================================================================== -typedef struct SDelDataItem SDelDataItem; -typedef struct SDelData SDelData; -typedef struct SDelIdxItem SDelIdxItem; -typedef struct SDelIdx SDelIdx; // SDataFWriter typedef struct SDataFWriter SDataFWriter; @@ -149,14 +148,19 @@ void tsdbFree(uint8_t *pBuf); int32_t tTABLEIDCmprFn(const void *p1, const void *p2); int32_t tsdbKeyCmprFn(const void *p1, const void *p2); +// SDelIdx +int32_t tDelIdxGetSize(SDelIdx *pDelIdx); +int32_t tDelIdxGetItem(SDelIdx *pDelIdx, int32_t idx, SDelIdxItem *pItem); int32_t tPutDelIdx(uint8_t *p, SDelIdx *pDelIdx); int32_t tGetDelIdx(uint8_t *p, SDelIdx *pDelIdx); +// SDelData int32_t tPutDelData(uint8_t *p, SDelData *pDelData); int32_t tGetDelData(uint8_t *p, SDelData *pDelData); int32_t tPutDelFileHdr(uint8_t *p, SDelFile *pDelFile); int32_t tGetDelFileHdr(uint8_t *p, SDelFile *pDelFile); + // structs typedef struct { int minFid; diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 4245eaf5ea..81f02d7ed0 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -210,44 +210,34 @@ static int32_t tsdbCommitDelImpl(SCommitter *pCommitter) { int32_t iTbData = 0; int32_t nTbData = taosArrayGetSize(pMemTable->aTbData); int32_t iDelIdx = 0; - int32_t nDelIdx; // TODO - int32_t c; + int32_t nDelIdx = 0; // TODO STbData *pTbData = NULL; SDelIdx *pDelIdx = NULL; + SDelIdx delIdx; + + if (iTbData < nTbData) { + pTbData = (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData); + } + if (iDelIdx < nDelIdx) { + // tIMapGet(); + pDelIdx = &delIdx; + } while (iTbData < nTbData || iDelIdx < nDelIdx) { - // if (iTbData < nTbData) { - // pTbData = (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData); - // } else { - // pTbData = NULL; - // } - // if (iDelIdx < nDelIdx) { - // // pDelIdx = ; // TODO - // } else { - // pDelIdx = NULL; - // } + if (pTbData && pDelIdx) { + } else { + } - // if (pTbData && pDelIdx) { - // c = tTABLEIDCmprFn(pTbData, pDelIdx); - // if (c == 0) { - // iTbData++; - // iDelIdx++; - // } else if (c < 0) { - // iTbData++; - // pDelIdx = NULL; - // } else { - // iDelIdx++; - // pTbData = NULL; - // } - // } else { - // if (pTbData) { - // iTbData++; - // } else { - // iDelIdx++; - // } - // } + // start + // 1. load table del if exist - // TODO: commit with the pTbData and pDelIdx + // impl + while (1) { + // do merge + } + + // end + // tsdbWriteDelData } return code; diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index e14d09e6c1..d222fc5b3d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -136,11 +136,45 @@ _err: return code; } -int32_t tsdbWriteDelData(SDelFWriter *pWriter, SDelData *pDelData, uint8_t **ppBuf, SDelIdxItem *pItem) { - int32_t code = 0; - int64_t size; +int32_t tsdbWriteDelDta(SDelFWriter *pWriter, SDelData *pDelData, uint8_t **ppBuf) { + int32_t code = 0; + uint8_t *pBuf = NULL; + int64_t size; + int64_t n; - // TODO + // prepare + + // alloc + if (!ppBuf) ppBuf = &pBuf; + size = tPutDelData(NULL, pDelData) + sizeof(TSCKSUM); + code = tsdbRealloc(ppBuf, size); + if (code) goto _err; + + // build + n = tPutDelData(*ppBuf, pDelData); + taosCalcChecksumAppend(0, *ppBuf, size); + + ASSERT(n + sizeof(TSCKSUM) == size); + + // write + n = taosWriteFile(pWriter->pWriteH, *ppBuf, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + ASSERT(n == size); + + // update + pWriter->pFile->offset = pWriter->pFile->size; + pWriter->pFile->size += size; + + tsdbFree(pBuf); + return code; + +_err: + tsdbError("vgId:%d failed to write del data since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + tsdbFree(pBuf); return code; } @@ -158,9 +192,7 @@ int32_t tsdbWriteDelIdx(SDelFWriter *pWriter, SDelIdx *pDelIdx, uint8_t **ppBuf) if (!ppBuf) ppBuf = &pBuf; size = tPutDelIdx(NULL, pDelIdx) + sizeof(TSCKSUM); code = tsdbRealloc(ppBuf, size); - if (code) { - goto _err; - } + if (code) goto _err; // build n = tPutDelIdx(*ppBuf, pDelIdx); @@ -291,10 +323,14 @@ int32_t tsdbDelFReaderClose(SDelFReader *pReader) { int32_t code = 0; if (pReader) { - taosCloseFile(&pReader->pReadH); + if (taosCloseFile(&pReader->pReadH) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _exit; + } taosMemoryFree(pReader); } +_exit: return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index df6d13ff7f..3fb484e52f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -88,6 +88,19 @@ int32_t tsdbKeyCmprFn(const void *p1, const void *p2) { return 0; } +// SDelIdx ====================================================== +int32_t tDelIdxGetSize(SDelIdx *pDelIdx) { + int32_t code = 0; + // TODO + return code; +} + +int32_t tDelIdxGetItem(SDelIdx *pDelIdx, int32_t idx, SDelIdxItem *pItem) { + int32_t code = 0; + // TODO + return code; +} + int32_t tPutDelIdx(uint8_t *p, SDelIdx *pDelIdx) { int32_t n = 0;