提交 63802f06 编写于 作者: H Hongze Cheng

more work

上级 c268437c
...@@ -346,75 +346,56 @@ _err: ...@@ -346,75 +346,56 @@ _err:
return code; return code;
} }
static int32_t tsdbCommitTableData(SCommitter *pCommitter, STbData *pTbData, SBlockIdx *pBlockIdx) { static FORCE_INLINE bool tsdbCommitIterEnd(SCommitter *pCommitter, STbDataIter *pIter) {
TSDBROW *pRow = tsdbTbDataIterGet(pIter);
return ((pRow == NULL) || (pRow->pTSRow->ts <= pCommitter->maxKey));
}
static int32_t tsdbCommitTableDataImpl(SCommitter *pCommitter, STbDataIter *pIter, SBlockIdx *pBlockIdx) {
int32_t code = 0; int32_t code = 0;
STbDataIter *pIter = NULL; TSDBROW *pRow;
STbDataIter iter;
TSDBROW *pRow = NULL;
SBlockIdx blockIdx;
int32_t iBlock; int32_t iBlock;
int32_t nBlock; int32_t nBlock;
SBlock *pBlock; SBlock *pBlock;
SBlock block; SBlock block;
// check // start(todo)
if (pTbData) {
pIter = &iter;
tsdbTbDataIterOpen(pTbData, &(TSDBKEY){.ts = pCommitter->minKey, .version = 0}, 0, pIter);
pRow = tsdbTbDataIterGet(pIter);
if ((pRow == NULL || pRow->pTSRow->ts > pCommitter->maxKey) && pBlockIdx == NULL) goto _exit;
}
// start
tMapDataReset(&pCommitter->oBlock);
tMapDataReset(&pCommitter->nBlock);
if (pBlockIdx) {
code = tsdbReadBlock(pCommitter->pReader, pBlockIdx, &pCommitter->oBlock, NULL);
if (code) goto _err;
}
if (pTbData) { // impl
blockIdx.suid = pTbData->suid;
blockIdx.uid = pTbData->uid;
} else {
blockIdx.suid = pBlockIdx->suid;
blockIdx.uid = pBlockIdx->uid;
}
blockIdx.minKey.version = INT64_MAX;
blockIdx.minKey.ts = TSKEY_MAX;
blockIdx.maxKey.version = 0;
blockIdx.maxKey.ts = TSKEY_MIN;
blockIdx.minVersion = INT64_MAX;
blockIdx.maxVersion = INT64_MIN;
blockIdx.offset = -1;
blockIdx.size = -1;
// impl (todo)
iBlock = 0;
nBlock = pCommitter->oBlock.nItem;
do {
pRow = tsdbTbDataIterGet(pIter); pRow = tsdbTbDataIterGet(pIter);
if (iBlock < nBlock) { if (iBlock < nBlock) {
pBlock = &block; pBlock = &block;
code = tMapDataGetItemByIdx(&pCommitter->oBlock, iBlock, pBlock, tGetBlock); tMapDataGetItemByIdx(&pCommitter->oBlock, iBlock, pBlock, tGetBlock);
if (code) goto _err;
} else {
pBlock == NULL;
} }
while (true) {
if ((pRow == NULL || pRow->pTSRow->ts > pCommitter->maxKey) && pBlock == NULL) break; if ((pRow == NULL || pRow->pTSRow->ts > pCommitter->maxKey) && pBlock == NULL) break;
}
code = tsdbMergeData(pCommitter, pIter, pBlock); // end
if (code) goto _err;
if (iBlock < nBlock) iBlock++; return code;
} while (true);
// end _err:
code = tsdbWriteBlock(pCommitter->pWriter, &pCommitter->nBlock, NULL, &blockIdx); return code;
if (code) goto _err; }
code = tMapDataPutItem(&pCommitter->nBlockIdx, &blockIdx, tPutBlockIdx); static int32_t tsdbCommitTableData(SCommitter *pCommitter, STbData *pTbData, SBlockIdx *pBlockIdx) {
int32_t code = 0;
STbDataIter *pIter = NULL;
STbDataIter iter;
TSDBROW *pRow;
// create iter if can
if (pTbData) {
pIter = &iter;
tsdbTbDataIterOpen(pTbData, &(TSDBKEY){.ts = pCommitter->minKey, .version = 0}, 0, pIter);
}
// check
if (tsdbCommitIterEnd(pCommitter, pIter) && pBlockIdx == NULL) goto _exit;
// impl
code = tsdbCommitTableDataImpl(pCommitter, pIter, pBlockIdx);
if (code) goto _err; if (code) goto _err;
_exit: _exit:
...@@ -485,7 +466,7 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) { ...@@ -485,7 +466,7 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) {
pTbData = (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData); pTbData = (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData);
if (iBlockIdx < nBlockIdx) { if (iBlockIdx < nBlockIdx) {
pBlockIdx = &blockIdx; pBlockIdx = &blockIdx;
code = tMapDataGetItemByIdx(&pCommitter->oBlockIdx, iBlockIdx, &blockIdx, tGetBlockIdx); code = tMapDataGetItemByIdx(&pCommitter->oBlockIdx, iBlockIdx, pBlockIdx, tGetBlockIdx);
if (code) goto _err; if (code) goto _err;
} else { } else {
pBlockIdx = NULL; pBlockIdx = NULL;
...@@ -529,7 +510,7 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) { ...@@ -529,7 +510,7 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) {
iBlockIdx++; iBlockIdx++;
if (iBlockIdx < nBlockIdx) { if (iBlockIdx < nBlockIdx) {
pBlockIdx = &blockIdx; pBlockIdx = &blockIdx;
code = tMapDataGetItemByIdx(&pCommitter->oBlockIdx, iBlockIdx, &blockIdx, tGetBlockIdx); code = tMapDataGetItemByIdx(&pCommitter->oBlockIdx, iBlockIdx, pBlockIdx, tGetBlockIdx);
if (code) goto _err; if (code) goto _err;
} else { } else {
pBlockIdx = NULL; pBlockIdx = NULL;
...@@ -549,7 +530,7 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) { ...@@ -549,7 +530,7 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) {
} }
if (iBlockIdx < nBlockIdx) { if (iBlockIdx < nBlockIdx) {
pBlockIdx = &blockIdx; pBlockIdx = &blockIdx;
code = tMapDataGetItemByIdx(&pCommitter->oBlockIdx, iBlockIdx, &blockIdx, tGetBlockIdx); code = tMapDataGetItemByIdx(&pCommitter->oBlockIdx, iBlockIdx, pBlockIdx, tGetBlockIdx);
if (code) goto _err; if (code) goto _err;
} else { } else {
pBlockIdx = NULL; pBlockIdx = NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册