提交 8f08aedc 编写于 作者: H Hongze Cheng

more work

上级 03f9012a
...@@ -158,6 +158,7 @@ int32_t tPutDelIdx(uint8_t *p, SDelIdx *pDelIdx); ...@@ -158,6 +158,7 @@ int32_t tPutDelIdx(uint8_t *p, SDelIdx *pDelIdx);
int32_t tGetDelIdx(uint8_t *p, SDelIdx *pDelIdx); int32_t tGetDelIdx(uint8_t *p, SDelIdx *pDelIdx);
// SDelData // SDelData
int32_t tDelDataClear(SDelData *pDelData);
int32_t tDelDataPutItem(SDelData *pDelData, SDelDataItem *pItem); int32_t tDelDataPutItem(SDelData *pDelData, SDelDataItem *pItem);
int32_t tDelDataGetItemByIdx(SDelData *pDelData, SDelDataItem *pItem, int32_t idx); int32_t tDelDataGetItemByIdx(SDelData *pDelData, SDelDataItem *pItem, int32_t idx);
int32_t tDelDataGetItem(SDelData *pDelData, SDelDataItem *pItem, int64_t version); int32_t tDelDataGetItem(SDelData *pDelData, SDelDataItem *pItem, int64_t version);
......
...@@ -37,13 +37,14 @@ struct SCommitter { ...@@ -37,13 +37,14 @@ struct SCommitter {
SArray *aOBlockIdx; SArray *aOBlockIdx;
SArray *aBlockIdx; SArray *aBlockIdx;
// commit table data // commit table data
STbData *pTbData;
SBlockIdx *pBlockIdx; SBlockIdx *pBlockIdx;
/* commit del */ /* commit del */
SDelFReader *pDelFReader; SDelFReader *pDelFReader;
SDelFWriter *pDelFWriter; SDelFWriter *pDelFWriter;
SDelIdx delIdxOld; SDelIdx delIdxOld;
SDelIdx delIdxNew; SDelIdx delIdxNew;
STbData *pTbData;
SDelIdxItem *pDelIdxItem;
SDelData delDataOld; SDelData delDataOld;
SDelData delDataNew; SDelData delDataNew;
SDelIdxItem delIdxItem; SDelIdxItem delIdxItem;
...@@ -210,27 +211,56 @@ static int32_t tsdbCommitDelImpl(SCommitter *pCommitter) { ...@@ -210,27 +211,56 @@ static int32_t tsdbCommitDelImpl(SCommitter *pCommitter) {
int32_t code = 0; int32_t code = 0;
STsdb *pTsdb = pCommitter->pTsdb; STsdb *pTsdb = pCommitter->pTsdb;
SMemTable *pMemTable = pTsdb->imem; SMemTable *pMemTable = pTsdb->imem;
int32_t c;
int32_t iTbData = 0; int32_t iTbData = 0;
int32_t nTbData = taosArrayGetSize(pMemTable->aTbData); int32_t nTbData = taosArrayGetSize(pMemTable->aTbData);
int32_t iDelIdx = 0; int32_t iDelIdxItem = 0;
int32_t nDelIdx = 0; // TODO int32_t nDelIdxItem = pCommitter->delIdxOld.offset.nOffset;
STbData *pTbData = NULL; STbData *pTbData = NULL;
SDelIdx *pDelIdx = NULL; SDelIdxItem *pDelIdxItem = NULL;
SDelIdx delIdx; SDelIdxItem item;
// if (iTbData < nTbData) { while (iTbData < nTbData || iDelIdxItem < nDelIdxItem) {
// pTbData = (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData); pTbData = NULL;
// } pDelIdxItem = NULL;
// if (iDelIdx < nDelIdx) { if (iTbData < nTbData) {
// // tIMapGet(); pTbData = (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData);
// pDelIdx = &delIdx; }
// } if (iDelIdxItem < nDelIdxItem) {
tDelIdxGetItemByIdx(&pCommitter->delIdxOld, &item, iDelIdxItem);
while (iTbData < nTbData || iDelIdx < nDelIdx) { pDelIdxItem = &item;
if (pTbData && pDelIdx) { }
if (pTbData && pDelIdxItem) {
c = tTABLEIDCmprFn(pTbData, pDelIdxItem);
if (c == 0) {
iTbData++;
iDelIdxItem++;
} else if (c < 0) {
iTbData++;
pDelIdxItem = NULL;
} else { } else {
iDelIdxItem++;
pTbData = NULL;
}
} else {
if (pTbData) {
iTbData++;
}
if (pDelIdxItem) {
iDelIdxItem++;
} }
}
if (pTbData && pTbData->pHead == NULL) {
pTbData = NULL;
}
if (pTbData == NULL && pDelIdxItem == NULL) continue;
// do merge
pCommitter->pTbData = pTbData;
pCommitter->pDelIdxItem = pDelIdxItem;
code = tsdbCommitTableDel(pCommitter); code = tsdbCommitTableDel(pCommitter);
if (code) goto _err; if (code) goto _err;
} }
...@@ -543,16 +573,40 @@ static int32_t tsdbCommitTableDataEnd(SCommitter *pCommitter) { ...@@ -543,16 +573,40 @@ static int32_t tsdbCommitTableDataEnd(SCommitter *pCommitter) {
static int32_t tsdbCommitTableDelStart(SCommitter *pCommitter) { static int32_t tsdbCommitTableDelStart(SCommitter *pCommitter) {
int32_t code = 0; int32_t code = 0;
tb_uid_t suid;
tb_uid_t uid;
if (pCommitter->pTbData) {
suid = pCommitter->pTbData->suid;
uid = pCommitter->pTbData->uid;
}
// load old // load old
pCommitter->delDataOld = (SDelData){0}; pCommitter->delDataOld = (SDelData){0};
if (0) { if (pCommitter->pDelIdxItem) {
code = tsdbReadDelData(pCommitter->pDelFReader, NULL /*TODO*/, &pCommitter->delDataOld, &pCommitter->pBuf4); suid = pCommitter->pDelIdxItem->suid;
uid = pCommitter->pDelIdxItem->uid;
code =
tsdbReadDelData(pCommitter->pDelFReader, pCommitter->pDelIdxItem, &pCommitter->delDataOld, &pCommitter->pBuf5);
if (code) goto _err; if (code) goto _err;
} }
// prepare new // prepare new
pCommitter->delDataNew = (SDelData){0}; pCommitter->delDataNew.suid = suid;
pCommitter->delDataNew.uid = uid;
pCommitter->delDataNew.offset.flag = 0;
pCommitter->delDataNew.offset.nOffset = 0;
pCommitter->delDataNew.nData = 0;
pCommitter->delIdxItem = (SDelIdxItem){
.suid = suid,
.uid = uid,
.minKey = TSKEY_MAX,
.maxKey = TSKEY_MIN,
.minVersion = INT64_MAX,
.maxVersion = INT64_MIN,
.offset = -1,
.size = -1,
};
return code; return code;
...@@ -563,13 +617,39 @@ _err: ...@@ -563,13 +617,39 @@ _err:
static int32_t tsdbCommitTableDelImpl(SCommitter *pCommitter) { static int32_t tsdbCommitTableDelImpl(SCommitter *pCommitter) {
int32_t code = 0; int32_t code = 0;
SDelOp *pDelOp = NULL; SDelDataItem item;
// old
if (pCommitter->pDelIdxItem) {
for (int32_t iDelIdxItem = 0; iDelIdxItem < pCommitter->delDataOld.offset.nOffset; iDelIdxItem++) {
code = tDelDataGetItemByIdx(&pCommitter->delDataOld, &item, iDelIdxItem);
if (code) goto _err;
for (; pDelOp; pDelOp = pDelOp->pNext) { code = tDelDataPutItem(&pCommitter->delDataNew, &item);
SDelDataItem item = {.version = pDelOp->version, .sKey = pDelOp->sKey, .eKey = pDelOp->eKey}; if (code) goto _err;
// update index
if (item.version < pCommitter->delIdxItem.minVersion) pCommitter->delIdxItem.minVersion = item.version;
if (item.version > pCommitter->delIdxItem.maxVersion) pCommitter->delIdxItem.maxVersion = item.version;
if (item.sKey < pCommitter->delIdxItem.minKey) pCommitter->delIdxItem.minKey = item.sKey;
if (item.eKey > pCommitter->delIdxItem.maxKey) pCommitter->delIdxItem.maxKey = item.eKey;
}
}
// new
if (pCommitter->pTbData) {
for (SDelOp *pDelOp = pCommitter->pTbData->pHead; pDelOp; pDelOp = pDelOp->pNext) {
item = (SDelDataItem){.version = pDelOp->version, .sKey = pDelOp->sKey, .eKey = pDelOp->eKey};
code = tDelDataPutItem(&pCommitter->delDataNew, &item); code = tDelDataPutItem(&pCommitter->delDataNew, &item);
if (code) goto _err; if (code) goto _err;
// update index
if (item.version < pCommitter->delIdxItem.minVersion) pCommitter->delIdxItem.minVersion = item.version;
if (item.version > pCommitter->delIdxItem.maxVersion) pCommitter->delIdxItem.maxVersion = item.version;
if (item.sKey < pCommitter->delIdxItem.minKey) pCommitter->delIdxItem.minKey = item.sKey;
if (item.eKey > pCommitter->delIdxItem.maxKey) pCommitter->delIdxItem.maxKey = item.eKey;
}
} }
return code; return code;
......
...@@ -147,7 +147,6 @@ int32_t tsdbWriteDelData(SDelFWriter *pWriter, SDelData *pDelData, uint8_t **ppB ...@@ -147,7 +147,6 @@ int32_t tsdbWriteDelData(SDelFWriter *pWriter, SDelData *pDelData, uint8_t **ppB
// prepare // prepare
pDelData->delimiter = TSDB_FILE_DLMT; pDelData->delimiter = TSDB_FILE_DLMT;
// todo
// alloc // alloc
if (!ppBuf) ppBuf = &pBuf; if (!ppBuf) ppBuf = &pBuf;
......
...@@ -350,6 +350,13 @@ static FORCE_INLINE int32_t tGetDelDataItem(uint8_t *p, SDelDataItem *pItem) { ...@@ -350,6 +350,13 @@ static FORCE_INLINE int32_t tGetDelDataItem(uint8_t *p, SDelDataItem *pItem) {
} }
// SDelData ====================================================== // 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 tDelDataPutItem(SDelData *pDelData, SDelDataItem *pItem) {
int32_t code = 0; int32_t code = 0;
uint32_t offset = pDelData->nData; uint32_t offset = pDelData->nData;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册