提交 9abfe52c 编写于 作者: H Hongze Cheng

more code

上级 4cb4c638
...@@ -376,23 +376,16 @@ static void tsdbSttFWriterDoClose(SSttFileWriter *pWriter) { ...@@ -376,23 +376,16 @@ static void tsdbSttFWriterDoClose(SSttFileWriter *pWriter) {
// TODO: do clear the struct // TODO: do clear the struct
} }
int32_t tsdbSttFWriterOpen(const SSttFileWriterConfig *config, SSttFileWriter **writer) {
writer[0] = taosMemoryMalloc(sizeof(*writer[0]));
if (writer[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
writer[0]->config = config[0];
writer[0]->ctx.opened = false;
return 0;
}
static int32_t tsdbSttFileDoWriteBloomFilter(SSttFileWriter *writer) { static int32_t tsdbSttFileDoWriteBloomFilter(SSttFileWriter *writer) {
// TODO // TODO
return 0; return 0;
} }
static int32_t tsdbSttFileDoUpdateHeader(SSttFileWriter *writer) { static int32_t tsdbSttFileDoUpdateHeader(SSttFileWriter *writer) {
// TODO // TODO
return 0; return 0;
} }
static int32_t tsdbSttFWriterCloseCommit(SSttFileWriter *writer, STFileOp *op) { static int32_t tsdbSttFWriterCloseCommit(SSttFileWriter *writer, STFileOp *op) {
int32_t lino; int32_t lino;
int32_t code; int32_t code;
...@@ -428,8 +421,7 @@ static int32_t tsdbSttFWriterCloseCommit(SSttFileWriter *writer, STFileOp *op) { ...@@ -428,8 +421,7 @@ static int32_t tsdbSttFWriterCloseCommit(SSttFileWriter *writer, STFileOp *op) {
code = tsdbFsyncFile(writer->fd); code = tsdbFsyncFile(writer->fd);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
code = tsdbCloseFile(&writer->fd); tsdbCloseFile(&writer->fd);
TSDB_CHECK_CODE(code, lino, _exit);
ASSERT(writer->config.file.size > writer->file.size); ASSERT(writer->config.file.size > writer->file.size);
op->optype = writer->config.file.size ? TSDB_FOP_MODIFY : TSDB_FOP_CREATE; op->optype = writer->config.file.size ? TSDB_FOP_MODIFY : TSDB_FOP_CREATE;
...@@ -443,11 +435,34 @@ _exit: ...@@ -443,11 +435,34 @@ _exit:
} }
return code; return code;
} }
static int32_t tsdbSttFWriterCloseAbort(SSttFileWriter *writer) { static int32_t tsdbSttFWriterCloseAbort(SSttFileWriter *writer) {
// TODO char fname[TSDB_FILENAME_LEN];
ASSERT(0);
tsdbTFileName(writer->config.tsdb, &writer->config.file, fname);
if (writer->config.file.size) { // truncate the file to the original size
ASSERT(writer->config.file.size <= writer->file.size);
if (writer->config.file.size < writer->file.size) {
taosFtruncateFile(writer->fd->pFD, writer->config.file.size);
tsdbCloseFile(&writer->fd);
}
} else { // remove the file
tsdbCloseFile(&writer->fd);
taosRemoveFile(fname);
}
return 0; return 0;
} }
int32_t tsdbSttFWriterOpen(const SSttFileWriterConfig *config, SSttFileWriter **writer) {
writer[0] = taosMemoryMalloc(sizeof(*writer[0]));
if (writer[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
writer[0]->config = config[0];
writer[0]->ctx.opened = false;
return 0;
}
int32_t tsdbSttFWriterClose(SSttFileWriter **writer, int8_t abort, STFileOp *op) { int32_t tsdbSttFWriterClose(SSttFileWriter **writer, int8_t abort, STFileOp *op) {
int32_t code = 0; int32_t code = 0;
int32_t lino = 0; int32_t lino = 0;
...@@ -456,11 +471,11 @@ int32_t tsdbSttFWriterClose(SSttFileWriter **writer, int8_t abort, STFileOp *op) ...@@ -456,11 +471,11 @@ int32_t tsdbSttFWriterClose(SSttFileWriter **writer, int8_t abort, STFileOp *op)
if (!writer[0]->ctx.opened) { if (!writer[0]->ctx.opened) {
op->optype = TSDB_FOP_NONE; op->optype = TSDB_FOP_NONE;
} else { } else {
if (!abort) { if (abort) {
code = tsdbSttFWriterCloseCommit(writer[0], op); code = tsdbSttFWriterCloseAbort(writer[0]);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} else { } else {
code = tsdbSttFWriterCloseAbort(writer[0]); code = tsdbSttFWriterCloseCommit(writer[0], op);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
tsdbSttFWriterDoClose(writer[0]); tsdbSttFWriterDoClose(writer[0]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册