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

more refact

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