提交 0bc5300d 编写于 作者: H Hongze Cheng

more progress

上级 de32cab3
......@@ -39,13 +39,21 @@ typedef struct SDelOp SDelOp;
static int tsdbKeyCmprFn(const void *p1, const void *p2);
// tsdbMemTable2.c ==============================================================================================
typedef struct SMemTable SMemTable;
typedef struct SMemTable SMemTable;
typedef struct SMemData SMemData;
typedef struct SMemDataIter SMemDataIter;
int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTable);
void tsdbMemTableDestroy2(SMemTable *pMemTable);
int32_t tsdbInsertTableData2(STsdb *pTsdb, int64_t version, SVSubmitBlk *pSubmitBlk);
int32_t tsdbDeleteTableData2(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey);
/* SMemDataIter */
void tsdbMemDataIterOpen(SMemDataIter *pIter, TSDBKEY *pKey, int8_t backward);
void tsdbMemDataIterClose(SMemDataIter *pIter);
void tsdbMemDataIterNext(SMemDataIter *pIter);
void tsdbMemDataIterGet(SMemDataIter *pIter, TSDBROW **ppRow);
// tsdbCommit2.c ==============================================================================================
int32_t tsdbBegin2(STsdb *pTsdb);
int32_t tsdbCommit2(STsdb *pTsdb);
......@@ -254,6 +262,7 @@ typedef struct {
uint32_t offset;
uint32_t hasLast : 2;
uint32_t numOfBlocks : 30;
uint64_t suid;
uint64_t uid;
TSKEY maxKey;
} SBlockIdx;
......@@ -910,6 +919,11 @@ static FORCE_INLINE int tsdbKeyCmprFn(const void *p1, const void *p2) {
return 0;
}
struct SMemDataIter {
SMemData *pMemData;
TSDBROW row;
};
#endif
#ifdef __cplusplus
......
......@@ -78,7 +78,7 @@ static int32_t tsdbStartCommit(SCommitH *pCHandle, STsdb *pTsdb) {
ASSERT(pTsdb->imem == NULL && pTsdb->mem);
pTsdb->imem = pTsdb->mem;
pTsdb->mem = NULL;
// TODO
return code;
}
......@@ -89,16 +89,45 @@ static int32_t tsdbEndCommit(SCommitH *pCHandle) {
}
static int32_t tsdbCommitToFile(SCommitH *pCHandle, int32_t fid) {
int32_t code = 0;
TSKEY fidSKey;
TSKEY fidEKey;
int32_t code = 0;
SMemDataIter iter = {0};
TSDBROW *pRow = NULL;
int8_t hasData = 0;
TSKEY fidSKey;
TSKEY fidEKey;
int32_t iMemData = 0;
int32_t nMemData = taosArrayGetSize(pCHandle->pMemTable->aMemData);
int32_t iBlockIdx = 0;
int32_t nBlockIdx;
// check if there are data in the time range
for (int32_t iMemData = 0; iMemData < taosArrayGetSize(pCHandle->pMemTable->aMemData); iMemData++) {
/* code */
for (; iMemData < nMemData; iMemData++) {
SMemData *pMemData = (SMemData *)taosArrayGetP(pCHandle->pMemTable->aMemData, iMemData);
tsdbMemDataIterOpen(&iter, &(TSDBKEY){.ts = fidSKey, .version = 0}, 0);
tsdbMemDataIterGet(&iter, &pRow);
if (pRow->tsRow.ts >= fidSKey && pRow->tsRow.ts <= fidEKey) {
hasData = 1;
break;
}
}
// has data, do commit to file
if (!hasData) return code;
// loop to commit each table data
nBlockIdx = 0;
for (;;) {
if (iBlockIdx >= nBlockIdx && iMemData >= nMemData) break;
SMemData *pMemData = NULL;
SBlockIdx *pBlockIdx = NULL;
if (iMemData < nMemData) {
pMemData = (SMemData *)taosArrayGetP(pCHandle->pMemTable->aMemData, iBlockIdx);
}
if (iBlockIdx < nBlockIdx) {
// pBlockIdx
}
}
return code;
}
\ No newline at end of file
......@@ -15,7 +15,6 @@
#include "tsdb.h"
typedef struct SMemData SMemData;
typedef struct SMemSkipList SMemSkipList;
typedef struct SMemSkipListNode SMemSkipListNode;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册