提交 632c6fb4 编写于 作者: H Hongze Cheng

more code

上级 a2dafefe
......@@ -68,7 +68,7 @@ typedef struct SDataFileWriterConfig {
} SDataFileWriterConfig;
int32_t tsdbDataFileWriterOpen(const SDataFileWriterConfig *config, SDataFileWriter **writer);
int32_t tsdbDataFileWriterClose(SDataFileWriter **writer, bool abort, STFileOp op[/*TSDB_FTYPE_MAX*/]);
int32_t tsdbDataFileWriterClose(SDataFileWriter **writer, bool abort, TFileOpArray *opArr);
int32_t tsdbDataFileWriteTSData(SDataFileWriter *writer, SRowInfo *row);
int32_t tsdbDataFileWriteTSDataBlock(SDataFileWriter *writer, SBlockData *bData);
int32_t tsdbDataFileFlushTSDataBlock(SDataFileWriter *writer);
......
......@@ -60,7 +60,7 @@ typedef struct SSttFileWriter SSttFileWriter;
typedef struct SSttFileWriterConfig SSttFileWriterConfig;
int32_t tsdbSttFileWriterOpen(const SSttFileWriterConfig *config, SSttFileWriter **writer);
int32_t tsdbSttFileWriterClose(SSttFileWriter **writer, int8_t abort, STFileOp *op);
int32_t tsdbSttFileWriterClose(SSttFileWriter **writer, int8_t abort, TFileOpArray *opArray);
int32_t tsdbSttFileWriteTSData(SSttFileWriter *writer, SRowInfo *row);
int32_t tsdbSttFileWriteTSDataBlock(SSttFileWriter *writer, SBlockData *pBlockData);
int32_t tsdbSttFileWriteDLData(SSttFileWriter *writer, TABLEID *tbid, SDelData *pDelData);
......
......@@ -299,15 +299,9 @@ static int32_t tsdbCommitFileSetEnd(SCommitter2 *committer) {
int32_t code = 0;
int32_t lino = 0;
STFileOp op[1];
code = tsdbSttFileWriterClose(&committer->sttWriter, 0, op);
code = tsdbSttFileWriterClose(&committer->sttWriter, 0, committer->fopArray);
TSDB_CHECK_CODE(code, lino, _exit);
if (op->optype != TSDB_FOP_NONE) {
code = TARRAY2_APPEND_PTR(committer->fopArray, op);
TSDB_CHECK_CODE(code, lino, _exit);
}
tsdbIterMergerClose(&committer->iterMerger);
TARRAY2_CLEAR(committer->iterArray, tsdbIterClose);
......
......@@ -299,13 +299,13 @@ static int32_t tsdbDataFileWriterDoOpenReader(SDataFileWriter *writer) {
code = tsdbDataFileReaderOpen(NULL, config, &writer->ctx->reader);
TSDB_CHECK_CODE(code, lino, _exit);
code = tsdbDataFileReadBlockIdx(writer->ctx->reader, &writer->ctx->blockIdxArray);
TSDB_CHECK_CODE(code, lino, _exit);
break;
}
}
code = tsdbDataFileReadBlockIdx(writer->ctx->reader, &writer->ctx->blockIdxArray);
TSDB_CHECK_CODE(code, lino, _exit);
_exit:
if (code) {
TSDB_ERROR_LOG(TD_VID(writer->config->tsdb->pVnode), lino, code);
......@@ -709,7 +709,7 @@ _exit:
return code;
}
static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, STFileOp *op) {
static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArray *opArr) {
int32_t code = 0;
int32_t lino = 0;
TABLEID tbid[1] = {{INT64_MAX, INT64_MAX}};
......@@ -726,64 +726,81 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, STFileOp *
code = tsdbDataFileWriteFooter(writer);
TSDB_CHECK_CODE(code, lino, _exit);
STFileOp op;
int32_t ftype;
// .head
int32_t ftype = TSDB_FTYPE_HEAD;
op[ftype] = (STFileOp){
ftype = TSDB_FTYPE_HEAD;
if (writer->config->files[ftype].exist) {
op = (STFileOp){
.optype = TSDB_FOP_REMOVE,
.fid = writer->config->fid,
.of = writer->config->files[ftype].file,
};
code = TARRAY2_APPEND(opArr, op);
TSDB_CHECK_CODE(code, lino, _exit);
}
op = (STFileOp){
.optype = TSDB_FOP_CREATE,
.fid = writer->config->fid,
.nf = writer->files[ftype],
};
code = TARRAY2_APPEND(opArr, op);
TSDB_CHECK_CODE(code, lino, _exit);
// .data
ftype = TSDB_FTYPE_DATA;
if (writer->fd[ftype]) {
if (!writer->config->files[ftype].exist) {
op[ftype] = (STFileOp){
op = (STFileOp){
.optype = TSDB_FOP_CREATE,
.fid = writer->config->fid,
.nf = writer->files[ftype],
};
} else if (writer->config->files[ftype].file.size == writer->files[ftype].size) {
op[ftype].optype = TSDB_FOP_NONE;
} else {
op[ftype] = (STFileOp){
code = TARRAY2_APPEND(opArr, op);
TSDB_CHECK_CODE(code, lino, _exit);
} else if (writer->config->files[ftype].file.size != writer->files[ftype].size) {
op = (STFileOp){
.optype = TSDB_FOP_MODIFY,
.fid = writer->config->fid,
.of = writer->config->files[ftype].file,
.nf = writer->files[ftype],
};
code = TARRAY2_APPEND(opArr, op);
TSDB_CHECK_CODE(code, lino, _exit);
}
} else {
op[ftype].optype = TSDB_FOP_NONE;
}
// .sma
ftype = TSDB_FTYPE_SMA;
if (writer->fd[ftype]) {
if (!writer->config->files[ftype].exist) {
op[ftype] = (STFileOp){
op = (STFileOp){
.optype = TSDB_FOP_CREATE,
.fid = writer->config->fid,
.nf = writer->files[ftype],
};
} else if (writer->config->files[ftype].file.size == writer->files[ftype].size) {
op[ftype].optype = TSDB_FOP_NONE;
} else {
op[ftype] = (STFileOp){
code = TARRAY2_APPEND(opArr, op);
TSDB_CHECK_CODE(code, lino, _exit);
} else if (writer->config->files[ftype].file.size != writer->files[ftype].size) {
op = (STFileOp){
.optype = TSDB_FOP_MODIFY,
.fid = writer->config->fid,
.of = writer->config->files[ftype].file,
.nf = writer->files[ftype],
};
code = TARRAY2_APPEND(opArr, op);
TSDB_CHECK_CODE(code, lino, _exit);
}
} else {
op[ftype].optype = TSDB_FOP_NONE;
}
// .tomb
op[TSDB_FTYPE_TOMB] = (STFileOp){
.optype = TSDB_FOP_NONE,
};
// .tomb (TODO)
ftype = TSDB_FTYPE_TOMB;
for (int32_t i = 0; i < TSDB_FTYPE_MAX; ++i) {
if (!writer->fd[i]) continue;
......@@ -807,25 +824,21 @@ int32_t tsdbDataFileWriterOpen(const SDataFileWriterConfig *config, SDataFileWri
return 0;
}
int32_t tsdbDataFileWriterClose(SDataFileWriter **writer, bool abort, STFileOp op[/*TSDB_FTYPE_MAX*/]) {
int32_t tsdbDataFileWriterClose(SDataFileWriter **writer, bool abort, TFileOpArray *opArr) {
int32_t code = 0;
int32_t lino = 0;
if (!writer[0]->ctx->opened) {
for (int32_t i = 0; i < TSDB_FTYPE_MAX; ++i) {
op[i].optype = TSDB_FOP_NONE;
}
} else {
if (writer[0]->ctx->opened) {
if (abort) {
code = tsdbDataFileWriterCloseAbort(writer[0]);
TSDB_CHECK_CODE(code, lino, _exit);
} else {
code = tsdbDataFileWriterCloseCommit(writer[0], op);
code = tsdbDataFileWriterCloseCommit(writer[0], opArr);
TSDB_CHECK_CODE(code, lino, _exit);
}
tsdbDataFileWriterDoClose(writer[0]);
}
taosMemoryFree(writer);
taosMemoryFree(writer[0]);
writer[0] = NULL;
_exit:
......
......@@ -270,7 +270,16 @@ static int32_t tsdbMergeFileSetBeginOpenReader(SMerger *merger) {
merger->ctx->toData = true;
merger->ctx->level = 0;
TARRAY2_FOREACH(merger->ctx->fset->lvlArr, merger->ctx->lvl) {
// TARRAY2_FOREACH(merger->ctx->fset->lvlArr, merger->ctx->lvl) {
for (int32_t i = 0;; ++i) {
if (i >= TARRAY2_SIZE(merger->ctx->fset->lvlArr)) {
merger->ctx->lvl = NULL;
break;
}
merger->ctx->lvl = TARRAY2_GET(merger->ctx->fset->lvlArr, i);
if (merger->ctx->lvl->level != merger->ctx->level || TARRAY2_SIZE(merger->ctx->lvl->fobjArr) == 0) {
merger->ctx->toData = false;
merger->ctx->lvl = NULL;
......@@ -486,25 +495,12 @@ static int32_t tsdbMergeFileSetEndCloseWriter(SMerger *merger) {
int32_t lino = 0;
int32_t vid = TD_VID(merger->tsdb->pVnode);
STFileOp op[TSDB_FTYPE_MAX];
code = tsdbSttFileWriterClose(&merger->sttWriter, 0, op);
code = tsdbSttFileWriterClose(&merger->sttWriter, 0, merger->fopArr);
TSDB_CHECK_CODE(code, lino, _exit);
if (op->optype != TSDB_FOP_NONE) {
code = TARRAY2_APPEND_PTR(merger->fopArr, op);
TSDB_CHECK_CODE(code, lino, _exit);
}
if (merger->ctx->toData) {
// TODO
code = tsdbDataFileWriterClose(&merger->dataWriter, 0, op);
code = tsdbDataFileWriterClose(&merger->dataWriter, 0, merger->fopArr);
TSDB_CHECK_CODE(code, lino, _exit);
if (op->optype != TSDB_FOP_NONE) {
code = TARRAY2_APPEND_PTR(merger->fopArr, op);
TSDB_CHECK_CODE(code, lino, _exit);
}
}
_exit:
......
......@@ -621,7 +621,7 @@ static int32_t tsdbSttFileDoUpdateHeader(SSttFileWriter *writer) {
return 0;
}
static int32_t tsdbSttFWriterCloseCommit(SSttFileWriter *writer, STFileOp *op) {
static int32_t tsdbSttFWriterCloseCommit(SSttFileWriter *writer, TFileOpArray *opArray) {
int32_t lino;
int32_t code;
int32_t vid = TD_VID(writer->config->tsdb->pVnode);
......@@ -656,10 +656,15 @@ static int32_t tsdbSttFWriterCloseCommit(SSttFileWriter *writer, STFileOp *op) {
tsdbCloseFile(&writer->fd);
ASSERT(writer->config->file.size < writer->file->size);
op->optype = writer->config->file.size ? TSDB_FOP_MODIFY : TSDB_FOP_CREATE;
op->fid = writer->config->file.fid;
op->of = writer->config->file;
op->nf = writer->file[0];
STFileOp op = {
.optype = writer->config->file.size ? TSDB_FOP_MODIFY : TSDB_FOP_CREATE,
.fid = writer->config->file.fid,
.of = writer->config->file,
.nf = writer->file[0],
};
code = TARRAY2_APPEND(opArray, op);
TSDB_CHECK_CODE(code, lino, _exit);
_exit:
if (code) {
......@@ -694,19 +699,17 @@ int32_t tsdbSttFileWriterOpen(const SSttFileWriterConfig *config, SSttFileWriter
return 0;
}
int32_t tsdbSttFileWriterClose(SSttFileWriter **writer, int8_t abort, STFileOp *op) {
int32_t tsdbSttFileWriterClose(SSttFileWriter **writer, int8_t abort, TFileOpArray *opArray) {
int32_t code = 0;
int32_t lino = 0;
int32_t vid = TD_VID(writer[0]->config->tsdb->pVnode);
if (!writer[0]->ctx->opened) {
if (op) op->optype = TSDB_FOP_NONE;
} else {
if (writer[0]->ctx->opened) {
if (abort) {
code = tsdbSttFWriterCloseAbort(writer[0]);
TSDB_CHECK_CODE(code, lino, _exit);
} else {
code = tsdbSttFWriterCloseCommit(writer[0], op);
code = tsdbSttFWriterCloseCommit(writer[0], opArray);
TSDB_CHECK_CODE(code, lino, _exit);
}
tsdbSttFWriterDoClose(writer[0]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册