TDengine/source/dnode/vnode/src/tsdb/dev/tsdbDataFileRW.c

106 lines
3 KiB
C
Raw Normal View History

2023-03-27 11:12:25 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2023-04-06 06:27:18 +00:00
*/
2023-05-27 15:08:08 +00:00
#include "inc/tsdbDataFileRW.h"
2023-04-23 06:02:43 +00:00
2023-04-23 10:00:02 +00:00
// SDataFileReader =============================================
struct SDataFileReader {
// TODO
};
2023-04-06 06:27:18 +00:00
2023-04-23 10:00:02 +00:00
// SDataFileWriter =============================================
struct SDataFileWriter {
2023-05-28 15:33:03 +00:00
SDataFileWriterConfig config[1];
struct {
bool opened;
} ctx[1];
2023-04-23 10:00:02 +00:00
// TODO
2023-05-26 07:57:31 +00:00
};
2023-05-28 15:33:03 +00:00
int32_t tsdbDataFileWriterOpen(const SDataFileWriterConfig *config, SDataFileWriter **writer) {
writer[0] = taosMemoryCalloc(1, sizeof(SDataFileWriter));
if (!writer[0]) return TSDB_CODE_OUT_OF_MEMORY;
writer[0]->ctx->opened = false;
return 0;
2023-05-26 07:57:31 +00:00
}
2023-05-28 15:33:03 +00:00
static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer) {
// TODO
return 0;
}
static int32_t tsdbDataFileWriterCloseAbort(SDataFileWriter *writer) {
// TODO
return 0;
}
static int32_t tsdbDataFileWriterDoClose(SDataFileWriter *writer) {
// TODO
return 0;
}
static int32_t tsdbDataFileWriterCloseImpl(SDataFileWriter *writer, bool abort, STFileOp op[/*TSDB_FTYPE_MAX*/]) {
2023-05-26 07:57:31 +00:00
int32_t code = 0;
int32_t lino = 0;
2023-05-28 15:33:03 +00:00
int32_t vid = TD_VID(writer->config->tsdb->pVnode);
if (!writer->ctx->opened) {
for (int32_t i = 0; i < TSDB_FTYPE_MAX; ++i) op[i].optype = TSDB_FOP_NONE;
} else {
if (abort) {
code = tsdbDataFileWriterCloseAbort(writer);
TSDB_CHECK_CODE(code, lino, _exit);
} else {
code = tsdbDataFileWriterCloseCommit(writer);
TSDB_CHECK_CODE(code, lino, _exit);
}
tsdbDataFileWriterDoClose(writer);
}
taosMemoryFree(writer);
2023-05-26 07:57:31 +00:00
_exit:
if (code) {
tsdbError("vgId:%d %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
}
return code;
}
2023-05-28 15:33:03 +00:00
int32_t tsdbDataFileWriterClose(SDataFileWriter **writer, bool abort, STFileOp op[/*TSDB_FTYPE_MAX*/]) {
int32_t code = tsdbDataFileWriterCloseImpl(writer[0], abort, op);
2023-05-26 07:57:31 +00:00
if (code) {
2023-05-28 15:33:03 +00:00
return code;
} else {
writer[0] = NULL;
return 0;
2023-05-26 07:57:31 +00:00
}
}
2023-05-28 15:33:03 +00:00
static int32_t tsdbDataFileWriterDoOpen(SDataFileWriter *writer) {
// TODO
return 0;
}
int32_t tsdbDataFileWriteTSData(SDataFileWriter *writer, SBlockData *bData) {
2023-05-26 07:57:31 +00:00
int32_t code = 0;
int32_t lino = 0;
2023-05-28 15:33:03 +00:00
int32_t vid = TD_VID(writer->config->tsdb->pVnode);
if (!writer->ctx->opened) {
code = tsdbDataFileWriterDoOpen(writer);
TSDB_CHECK_CODE(code, lino, _exit);
}
2023-05-26 07:57:31 +00:00
_exit:
if (code) {
tsdbError("vgId:%d %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
}
return code;
2023-05-28 15:33:03 +00:00
}