提交 af1724fb 编写于 作者: H Hongze Cheng

more refact

上级 21ea4e3a
......@@ -59,7 +59,6 @@ typedef struct STsdbIndexFile STsdbIndexFile;
typedef struct STsdbDataFile STsdbDataFile;
typedef struct STsdbLastFile STsdbLastFile;
typedef struct STsdbSmaFile STsdbSmaFile;
typedef struct STsdbSmalFile STsdbSmalFile;
typedef struct SDFileSet SDFileSet;
typedef struct SDataFWriter SDataFWriter;
typedef struct SDataFReader SDataFReader;
......@@ -84,13 +83,11 @@ int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
// TSDBKEY
int32_t tsdbKeyCmprFn(const void *p1, const void *p2);
// KEYINFO
#define KEYINFO_INIT_VAL \
((KEYINFO){.maxKey.ts = TSKEY_MIN, \
.maxKey.version = 0, \
.minKey.ts = TSKEY_MAX, \
.minKey.version = INT64_MAX, \
.minVerion = INT64_MAX, \
.maxVersion = 0})
#define tKEYINFOInit() \
((KEYINFO){.maxKey = {.ts = TSKEY_MIN, .version = 0}, \
.minKey = {.ts = TSKEY_MAX, .version = -1}, \
.minVerion = INT64_MAX, \
.maxKey = -1})
int32_t tPutKEYINFO(uint8_t *p, KEYINFO *pKeyInfo);
int32_t tGetKEYINFO(uint8_t *p, KEYINFO *pKeyInfo);
// SColdata
......@@ -99,7 +96,9 @@ int32_t tColDataCmprFn(const void *p1, const void *p2);
int32_t tPutBlockIdx(uint8_t *p, void *ph);
int32_t tGetBlockIdx(uint8_t *p, void *ph);
// SBlock
#define BLOCK_INIT_VAL ((SBlock){})
#define tBlockInit() ((SBlock){.info = tKEYINFOInit()})
void tBlockReset(SBlock *pBlock);
void tBlockClear(SBlock *pBlock);
int32_t tPutBlock(uint8_t *p, void *ph);
int32_t tGetBlock(uint8_t *p, void *ph);
int32_t tBlockCmprFn(const void *p1, const void *p2);
......@@ -121,6 +120,7 @@ int32_t tGetDelData(uint8_t *p, void *ph);
int32_t tsdbRealloc(uint8_t **ppBuf, int64_t size);
void tsdbFree(uint8_t *pBuf);
// SMapData
#define tMapDataInit() ((SMapData){0})
void tMapDataReset(SMapData *pMapData);
void tMapDataClear(SMapData *pMapData);
int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(uint8_t *, void *));
......
......@@ -349,7 +349,7 @@ static int32_t tsdbCommitMemoryData(SCommitter *pCommitter, SBlockIdx *pBlockIdx
bool toDataOnly) {
int32_t code = 0;
TSDBROW *pRow;
SBlock block; // TODO
SBlock block = tBlockInit();
while (true) {
pRow = tsdbTbDataIterGet(pIter);
......@@ -382,7 +382,7 @@ static int32_t tsdbCommitMemoryData(SCommitter *pCommitter, SBlockIdx *pBlockIdx
code = tMapDataPutItem(&pCommitter->nBlock, &block, tPutBlock);
if (code) goto _err;
block = BLOCK_INIT_VAL;
tBlockReset(&block);
tsdbBlockDataClear(&pCommitter->bDataN);
}
......@@ -427,7 +427,7 @@ static int32_t tsdbMergeCommitImpl(SCommitter *pCommitter, SBlockIdx *pBlockIdx,
int32_t nRow = 0;
int32_t c;
TSDBROW *pRow;
SBlock block = BLOCK_INIT_VAL;
SBlock block = tBlockInit();
TSDBKEY key1;
TSDBKEY key2;
......@@ -461,7 +461,7 @@ static int32_t tsdbMergeCommitImpl(SCommitter *pCommitter, SBlockIdx *pBlockIdx,
if (code) goto _err;
}
block = BLOCK_INIT_VAL;
tBlockReset(&block);
tsdbBlockDataClear(&pCommitter->bDataN);
return code;
......@@ -474,7 +474,7 @@ _err:
static int32_t tsdbMergeCommit(SCommitter *pCommitter, SBlockIdx *pBlockIdx, STbDataIter *pIter, SBlock *pBlock) {
int32_t code = 0;
TSDBROW *pRow;
SBlock block = BLOCK_INIT_VAL;
SBlock block = tBlockInit();
SBlockData bDataN;
TSDBKEY key;
int32_t c;
......
......@@ -42,7 +42,7 @@ int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) {
taosInitRWLatch(&pMemTable->latch);
pMemTable->pTsdb = pTsdb;
pMemTable->nRef = 1;
pMemTable->info = KEYINFO_INIT_VAL;
pMemTable->info = tKEYINFOInit();
pMemTable->nRow = 0;
pMemTable->nDel = 0;
pMemTable->aTbData = taosArrayInit(128, sizeof(STbData *));
......@@ -318,7 +318,7 @@ static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid
}
pTbData->suid = suid;
pTbData->uid = uid;
pTbData->info = KEYINFO_INIT_VAL;
pTbData->info = tKEYINFOInit();
pTbData->pHead = NULL;
pTbData->pTail = NULL;
pTbData->sl.seed = taosRand();
......
......@@ -275,6 +275,26 @@ int32_t tGetBlockIdx(uint8_t *p, void *ph) {
}
// SBlock ======================================================
void tBlockReset(SBlock *pBlock) {
pBlock->info = tKEYINFOInit();
pBlock->nRow = 0;
pBlock->last = -1;
pBlock->cmprAlg = -1;
for (int8_t iSubBlock = 0; iSubBlock < pBlock->nSubBlock; iSubBlock++) {
pBlock->aSubBlock[iSubBlock].offset = -1;
pBlock->aSubBlock[iSubBlock].ksize = -1;
pBlock->aSubBlock[iSubBlock].bsize = -1;
tMapDataReset(&pBlock->aSubBlock->mBlockCol);
}
pBlock->nSubBlock = 0;
}
void tBlockClear(SBlock *pBlock) {
for (int8_t iSubBlock = 0; iSubBlock < TSDB_MAX_SUBBLOCKS; iSubBlock++) {
tMapDataClear(&pBlock->aSubBlock->mBlockCol);
}
}
int32_t tPutBlock(uint8_t *p, void *ph) {
int32_t n = 0;
SBlock *pBlock = (SBlock *)ph;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册