提交 2f5f0b75 编写于 作者: H Hongze Cheng

refact code

上级 91c8391b
......@@ -75,16 +75,6 @@ static FORCE_INLINE int32_t tarray2_make_room( //
#define TARRAY2_INIT(a) TARRAY2_INIT_EX(a, 0, 0, NULL)
#define TARRAY2_INITIALIZER \
{ 0, 0, NULL }
#define TARRAY2_FREE(a) \
do { \
if ((a)->data) { \
taosMemoryFree((a)->data); \
} \
} while (0)
#define TARRAY2_CLEAR(a, cb) \
do { \
if ((cb) && (a)->size > 0) { \
......@@ -96,10 +86,14 @@ static FORCE_INLINE int32_t tarray2_make_room( //
(a)->size = 0; \
} while (0)
#define TARRAY2_CLEAR_FREE(a, cb) \
do { \
TARRAY2_CLEAR(a, cb); \
TARRAY2_FREE(a); \
#define TARRAY2_DESTROY(a, cb) \
do { \
TARRAY2_CLEAR(a, cb); \
if ((a)->data) { \
taosMemoryFree((a)->data); \
(a)->data = NULL; \
} \
(a)->capacity = 0; \
} while (0)
#define TARRAY2_INSERT(a, idx, e) \
......
......@@ -22,11 +22,10 @@
extern "C" {
#endif
// SDelBlock ----------
#define TOMB_RECORD_NUM_ELEM 5
// STombRecord ----------
#define TOMB_RECORD_ELEM_NUM 5
typedef union {
int64_t aData[TOMB_RECORD_NUM_ELEM];
int64_t dataArr[TOMB_RECORD_ELEM_NUM];
struct {
int64_t suid;
int64_t uid;
......@@ -37,7 +36,7 @@ typedef union {
} STombRecord;
typedef union {
TARRAY2(int64_t) dataArr[TOMB_RECORD_NUM_ELEM];
TARRAY2(int64_t) dataArr[TOMB_RECORD_ELEM_NUM];
struct {
TARRAY2(int64_t) suid[1];
TARRAY2(int64_t) uid[1];
......@@ -49,9 +48,9 @@ typedef union {
typedef struct {
int32_t numRec;
int32_t size[TOMB_RECORD_NUM_ELEM];
TABLEID minTid;
TABLEID maxTid;
int32_t size[TOMB_RECORD_ELEM_NUM];
TABLEID minTbid;
TABLEID maxTbid;
int64_t minVer;
int64_t maxVer;
SFDataPtr dp[1];
......@@ -59,17 +58,16 @@ typedef struct {
#define TOMB_BLOCK_SIZE(db) TARRAY2_SIZE((db)->suid)
int32_t tTombBlockInit(STombBlock *delBlock);
int32_t tTombBlockFree(STombBlock *delBlock);
int32_t tTombBlockClear(STombBlock *delBlock);
int32_t tTombBlockPut(STombBlock *delBlock, const STombRecord *delRecord);
int32_t tTombRecordCmpr(const STombRecord *r1, const STombRecord *r2);
int32_t tTombBlockInit(STombBlock *tombBlock);
int32_t tTombBlockDestroy(STombBlock *tombBlock);
int32_t tTombBlockClear(STombBlock *tombBlock);
int32_t tTombBlockPut(STombBlock *tombBlock, const STombRecord *record);
int32_t tTombRecordCompare(const STombRecord *record1, const STombRecord *record2);
// STbStatisBlock ----------
#define STATIS_RECORD_NUM_ELEM 9
typedef union {
int64_t aData[STATIS_RECORD_NUM_ELEM];
int64_t dataArr[STATIS_RECORD_NUM_ELEM];
struct {
int64_t suid;
int64_t uid;
......
......@@ -417,8 +417,8 @@ static int32_t tsdbCloseCommitter(SCommitter2 *committer, int32_t eno) {
ASSERT(committer->dataWriter == NULL);
ASSERT(committer->sttWriter == NULL);
ASSERT(committer->iterMerger == NULL);
TARRAY2_FREE(committer->iterArray);
TARRAY2_FREE(committer->fopArray);
TARRAY2_DESTROY(committer->iterArray, NULL);
TARRAY2_DESTROY(committer->fopArray, NULL);
tsdbFSDestroyCopySnapshot(&committer->fsetArr);
_exit:
......
......@@ -135,8 +135,8 @@ _exit:
int32_t tsdbDataFileReaderClose(SDataFileReader **reader) {
if (reader[0] == NULL) return 0;
TARRAY2_FREE(reader[0]->dataBlkArray);
TARRAY2_FREE(reader[0]->blockIdxArray);
TARRAY2_DESTROY(reader[0]->dataBlkArray, NULL);
TARRAY2_DESTROY(reader[0]->blockIdxArray, NULL);
for (int32_t i = 0; i < TSDB_FTYPE_MAX; ++i) {
tsdbCloseFile(&reader[0]->fd[i]);
......@@ -389,13 +389,13 @@ static int32_t tsdbDataFileWriterDoClose(SDataFileWriter *writer) {
tsdbDataFileReaderClose(&writer->ctx->reader);
}
tTombBlockFree(writer->tData);
tTombBlockDestroy(writer->tData);
tStatisBlockFree(writer->sData);
tBlockDataDestroy(writer->bData);
TARRAY2_FREE(writer->tombBlkArray);
TARRAY2_FREE(writer->dataBlkArray);
TARRAY2_FREE(writer->blockIdxArray);
tTombBlockFree(writer->ctx->tData);
TARRAY2_DESTROY(writer->tombBlkArray, NULL);
TARRAY2_DESTROY(writer->dataBlkArray, NULL);
TARRAY2_DESTROY(writer->blockIdxArray, NULL);
tTombBlockDestroy(writer->ctx->tData);
for (int32_t i = 0; i < ARRAY_SIZE(writer->bufArr); ++i) {
tFree(writer->bufArr[i]);
......@@ -587,7 +587,7 @@ static int32_t tsdbDataFileWriteDataBlock(SDataFileWriter *writer, SBlockData *b
writer->files[TSDB_FTYPE_SMA].size += dataBlk->smaInfo.size;
}
TARRAY2_FREE(smaArr);
TARRAY2_DESTROY(smaArr, NULL);
// to dataBlkArray
code = TARRAY2_APPEND_PTR(writer->dataBlkArray, dataBlk);
......@@ -857,12 +857,12 @@ static int32_t tsdbDataFileDoWriteTombBlock(SDataFileWriter *writer) {
STombBlk tombBlk[1] = {{
.numRec = TOMB_BLOCK_SIZE(writer->tData),
.minTid =
.minTbid =
{
.suid = TARRAY2_FIRST(writer->tData->suid),
.uid = TARRAY2_FIRST(writer->tData->uid),
},
.maxTid =
.maxTbid =
{
.suid = TARRAY2_LAST(writer->tData->suid),
.uid = TARRAY2_LAST(writer->tData->uid),
......@@ -961,7 +961,7 @@ static int32_t tsdbDataFileDoWriteTombRecord(SDataFileWriter *writer, const STom
.ekey = TARRAY2_GET(writer->ctx->tData->ekey, writer->ctx->iRowTomb),
}};
int32_t c = tTombRecordCmpr(record, record1);
int32_t c = tTombRecordCompare(record, record1);
if (c < 0) {
break;
} else if (c > 0) {
......
......@@ -56,8 +56,8 @@ static int32_t create_fs(STsdb *pTsdb, STFileSystem **fs) {
static int32_t destroy_fs(STFileSystem **fs) {
if (fs[0] == NULL) return 0;
TARRAY2_FREE(fs[0]->fSetArr);
TARRAY2_FREE(fs[0]->fSetArrTmp);
TARRAY2_DESTROY(fs[0]->fSetArr, NULL);
TARRAY2_DESTROY(fs[0]->fSetArrTmp, NULL);
tsem_destroy(&fs[0]->canEdit);
taosMemoryFree(fs[0]);
fs[0] = NULL;
......@@ -664,7 +664,7 @@ int32_t tsdbFSCreateCopySnapshot(STFileSystem *fs, TFileSetArray **fsetArr) {
taosThreadRwlockUnlock(&fs->tsdb->rwLock);
if (code) {
TARRAY2_CLEAR_FREE(fsetArr[0], tsdbTFileSetClear);
TARRAY2_DESTROY(fsetArr[0], tsdbTFileSetClear);
taosMemoryFree(fsetArr[0]);
fsetArr[0] = NULL;
}
......@@ -673,7 +673,7 @@ int32_t tsdbFSCreateCopySnapshot(STFileSystem *fs, TFileSetArray **fsetArr) {
int32_t tsdbFSDestroyCopySnapshot(TFileSetArray **fsetArr) {
if (fsetArr[0]) {
TARRAY2_CLEAR_FREE(fsetArr[0], tsdbTFileSetClear);
TARRAY2_DESTROY(fsetArr[0], tsdbTFileSetClear);
fsetArr[0] = NULL;
}
return 0;
......
......@@ -24,7 +24,7 @@ static int32_t tsdbSttLvlInit(int32_t level, SSttLvl **lvl) {
static void tsdbSttLvlClearFObj(void *data) { tsdbTFileObjUnref(*(STFileObj **)data); }
static int32_t tsdbSttLvlClear(SSttLvl **lvl) {
TARRAY2_CLEAR_FREE(lvl[0]->fobjArr, tsdbSttLvlClearFObj);
TARRAY2_DESTROY(lvl[0]->fobjArr, tsdbSttLvlClearFObj);
taosMemoryFree(lvl[0]);
lvl[0] = NULL;
return 0;
......@@ -50,7 +50,7 @@ static int32_t tsdbSttLvlInitEx(STsdb *pTsdb, const SSttLvl *lvl1, SSttLvl **lvl
static void tsdbSttLvlRemoveFObj(void *data) { tsdbTFileObjRemove(*(STFileObj **)data); }
static void tsdbSttLvlRemove(SSttLvl **lvl) {
TARRAY2_CLEAR_FREE(lvl[0]->fobjArr, tsdbSttLvlRemoveFObj);
TARRAY2_DESTROY(lvl[0]->fobjArr, tsdbSttLvlRemoveFObj);
taosMemoryFree(lvl[0]);
lvl[0] = NULL;
}
......@@ -443,7 +443,7 @@ int32_t tsdbTFileSetClear(STFileSet **fset) {
tsdbTFileObjUnref(fset[0]->farr[ftype]);
}
TARRAY2_CLEAR_FREE(fset[0]->lvlArr, tsdbSttLvlClear);
TARRAY2_DESTROY(fset[0]->lvlArr, tsdbSttLvlClear);
taosMemoryFree(fset[0]);
fset[0] = NULL;
......@@ -457,7 +457,7 @@ int32_t tsdbTFileSetRemove(STFileSet **fset) {
tsdbTFileObjRemove(fset[0]->farr[ftype]);
}
TARRAY2_CLEAR_FREE(fset[0]->lvlArr, tsdbSttLvlRemove);
TARRAY2_DESTROY(fset[0]->lvlArr, tsdbSttLvlRemove);
taosMemoryFree(fset[0]);
fset[0] = NULL;
return 0;
......
......@@ -246,8 +246,8 @@ static int32_t tsdbDataTombIterNext(STsdbIter *iter, const TABLEID *tbid) {
iter->dataTomb->tombBlkArrayIdx++) {
const STombBlk *tombBlk = TARRAY2_GET_PTR(iter->dataTomb->tombBlkArray, iter->dataTomb->tombBlkArrayIdx);
if (tbid && tbid->suid == tombBlk->minTid.suid && tbid->uid == tombBlk->minTid.uid &&
tbid->suid == tombBlk->maxTid.suid && tbid->uid == tombBlk->maxTid.uid) {
if (tbid && tbid->suid == tombBlk->minTbid.suid && tbid->uid == tombBlk->minTbid.uid &&
tbid->suid == tombBlk->maxTbid.suid && tbid->uid == tombBlk->maxTbid.uid) {
continue;
}
......@@ -372,8 +372,8 @@ static int32_t tsdbSttTombIterNext(STsdbIter *iter, const TABLEID *tbid) {
iter->sttTomb->tombBlkArrayIdx++) {
const STombBlk *tombBlk = TARRAY2_GET_PTR(iter->sttTomb->tombBlkArray, iter->sttTomb->tombBlkArrayIdx);
if (tbid && tbid->suid == tombBlk->minTid.suid && tbid->uid == tombBlk->minTid.uid &&
tbid->suid == tombBlk->maxTid.suid && tbid->uid == tombBlk->maxTid.uid) {
if (tbid && tbid->suid == tombBlk->minTbid.suid && tbid->uid == tombBlk->minTbid.uid &&
tbid->suid == tombBlk->maxTbid.suid && tbid->uid == tombBlk->maxTbid.uid) {
continue;
}
......@@ -453,12 +453,12 @@ int32_t tsdbIterOpen(const STsdbIterConfig *config, STsdbIter **iter) {
}
static int32_t tsdbSttTombIterClose(STsdbIter *iter) {
tTombBlockFree(iter->sttTomb->tData);
tTombBlockDestroy(iter->sttTomb->tData);
return 0;
}
static int32_t tsdbDataTombIterClose(STsdbIter *iter) {
tTombBlockFree(iter->dataTomb->tData);
tTombBlockDestroy(iter->dataTomb->tData);
return 0;
}
......
......@@ -93,9 +93,9 @@ static int32_t tsdbMergerClose(SMerger *merger) {
ASSERT(TARRAY2_SIZE(merger->sttReaderArr) == 0);
// clear the merge
TARRAY2_FREE(merger->dataIterArr);
TARRAY2_FREE(merger->sttReaderArr);
TARRAY2_FREE(merger->fopArr);
TARRAY2_DESTROY(merger->dataIterArr, NULL);
TARRAY2_DESTROY(merger->sttReaderArr, NULL);
TARRAY2_DESTROY(merger->fopArr, NULL);
for (int32_t i = 0; i < ARRAY_SIZE(merger->ctx->bData); i++) {
tBlockDataDestroy(merger->ctx->bData + i);
}
......
......@@ -69,9 +69,9 @@ _exit:
static int32_t tsdbSttSegReaderClose(SSttSegReader **reader) {
if (reader[0]) {
TARRAY2_FREE(reader[0]->sttBlkArray);
TARRAY2_FREE(reader[0]->tombBlkArray);
TARRAY2_FREE(reader[0]->statisBlkArray);
TARRAY2_DESTROY(reader[0]->sttBlkArray, NULL);
TARRAY2_DESTROY(reader[0]->tombBlkArray, NULL);
TARRAY2_DESTROY(reader[0]->statisBlkArray, NULL);
taosMemoryFree(reader[0]);
reader[0] = NULL;
}
......@@ -122,7 +122,7 @@ int32_t tsdbSttFileReaderClose(SSttFileReader **reader) {
tFree(reader[0]->bufArr[i]);
}
tsdbCloseFile(&reader[0]->fd);
TARRAY2_CLEAR_FREE(reader[0]->readerArray, tsdbSttSegReaderClose);
TARRAY2_DESTROY(reader[0]->readerArray, tsdbSttSegReaderClose);
taosMemoryFree(reader[0]);
reader[0] = NULL;
}
......@@ -454,12 +454,12 @@ static int32_t tsdbSttFileDoWriteTombBlock(SSttFileWriter *writer) {
STombBlk tombBlk[1] = {{
.numRec = TOMB_BLOCK_SIZE(writer->tData),
.minTid =
.minTbid =
{
.suid = TARRAY2_FIRST(writer->tData->suid),
.uid = TARRAY2_FIRST(writer->tData->uid),
},
.maxTid =
.maxTbid =
{
.suid = TARRAY2_LAST(writer->tData->suid),
.uid = TARRAY2_LAST(writer->tData->uid),
......@@ -625,12 +625,12 @@ static void tsdbSttFWriterDoClose(SSttFileWriter *writer) {
}
tDestroyTSchema(writer->skmRow->pTSchema);
tDestroyTSchema(writer->skmTb->pTSchema);
tTombBlockFree(writer->tData);
tTombBlockDestroy(writer->tData);
tStatisBlockFree(writer->sData);
tBlockDataDestroy(writer->bData);
TARRAY2_FREE(writer->tombBlkArray);
TARRAY2_FREE(writer->statisBlkArray);
TARRAY2_FREE(writer->sttBlkArray);
TARRAY2_DESTROY(writer->tombBlkArray, NULL);
TARRAY2_DESTROY(writer->statisBlkArray, NULL);
TARRAY2_DESTROY(writer->sttBlkArray, NULL);
}
static int32_t tsdbSttFileDoUpdateHeader(SSttFileWriter *writer) {
......
......@@ -16,36 +16,36 @@
#include "dev.h"
// SDelBlock ----------
int32_t tTombBlockInit(STombBlock *delBlock) {
for (int32_t i = 0; i < ARRAY_SIZE(delBlock->dataArr); ++i) {
TARRAY2_INIT(&delBlock->dataArr[i]);
int32_t tTombBlockInit(STombBlock *tombBlock) {
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
TARRAY2_INIT(&tombBlock->dataArr[i]);
}
return 0;
}
int32_t tTombBlockFree(STombBlock *delBlock) {
for (int32_t i = 0; i < ARRAY_SIZE(delBlock->dataArr); ++i) {
TARRAY2_FREE(&delBlock->dataArr[i]);
int32_t tTombBlockDestroy(STombBlock *tombBlock) {
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
TARRAY2_DESTROY(&tombBlock->dataArr[i], NULL);
}
return 0;
}
int32_t tTombBlockClear(STombBlock *delBlock) {
for (int32_t i = 0; i < ARRAY_SIZE(delBlock->dataArr); ++i) {
TARRAY2_CLEAR(&delBlock->dataArr[i], NULL);
int32_t tTombBlockClear(STombBlock *tombBlock) {
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
TARRAY2_CLEAR(&tombBlock->dataArr[i], NULL);
}
return 0;
}
int32_t tTombBlockPut(STombBlock *delBlock, const STombRecord *delRecord) {
for (int32_t i = 0; i < ARRAY_SIZE(delBlock->dataArr); ++i) {
int32_t code = TARRAY2_APPEND(&delBlock->dataArr[i], delRecord->aData[i]);
int32_t tTombBlockPut(STombBlock *tombBlock, const STombRecord *record) {
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
int32_t code = TARRAY2_APPEND(&tombBlock->dataArr[i], record->dataArr[i]);
if (code) return code;
}
return 0;
}
int32_t tTombRecordCmpr(const STombRecord *r1, const STombRecord *r2) {
int32_t tTombRecordCompare(const STombRecord *r1, const STombRecord *r2) {
if (r1->suid < r2->suid) return -1;
if (r1->suid > r2->suid) return 1;
if (r1->uid < r2->uid) return -1;
......@@ -65,7 +65,7 @@ int32_t tStatisBlockInit(STbStatisBlock *statisBlock) {
int32_t tStatisBlockFree(STbStatisBlock *statisBlock) {
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->dataArr); ++i) {
TARRAY2_FREE(&statisBlock->dataArr[i]);
TARRAY2_DESTROY(&statisBlock->dataArr[i], NULL);
}
return 0;
}
......@@ -79,7 +79,7 @@ int32_t tStatisBlockClear(STbStatisBlock *statisBlock) {
int32_t tStatisBlockPut(STbStatisBlock *statisBlock, const STbStatisRecord *statisRecord) {
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->dataArr); ++i) {
int32_t code = TARRAY2_APPEND(&statisBlock->dataArr[i], statisRecord->aData[i]);
int32_t code = TARRAY2_APPEND(&statisBlock->dataArr[i], statisRecord->dataArr[i]);
if (code) return code;
}
return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册