• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4986

15 Mar 2026 08:32AM UTC coverage: 37.305% (-31.3%) from 68.601%
#4986

push

travis-ci

tomchon
test: keep docs and unit test

125478 of 336361 relevant lines covered (37.3%)

1134847.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/source/dnode/vnode/src/tsdb/tsdbDataFileRAW.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "tsdbDataFileRAW.h"
17

18
// SDataFileRAWReader =============================================
19
int32_t tsdbDataFileRAWReaderOpen(const char *fname, const SDataFileRAWReaderConfig *config,
×
20
                                  SDataFileRAWReader **reader) {
21
  int32_t code = 0;
×
22
  int32_t lino = 0;
×
23

24
  reader[0] = taosMemoryCalloc(1, sizeof(SDataFileRAWReader));
×
25
  if (reader[0] == NULL) {
×
26
    TAOS_CHECK_GOTO(terrno, &lino, _exit);
×
27
  }
28

29
  reader[0]->config[0] = config[0];
×
30

31
  int32_t lcn = config->file.lcn;
×
32
  if (fname) {
×
33
    if (fname) {
×
34
      TAOS_CHECK_GOTO(tsdbOpenFile(fname, config->tsdb, TD_FILE_READ, &reader[0]->fd, lcn), &lino, _exit);
×
35
    }
36
  } else {
37
    char fname1[TSDB_FILENAME_LEN];
38
    tsdbTFileName(config->tsdb, &config->file, fname1);
×
39
    TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd, lcn), &lino, _exit);
×
40
  }
41

42
_exit:
×
43
  if (code) {
×
44
    tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(config->tsdb->pVnode), __func__, __FILE__, lino,
×
45
              tstrerror(code));
46
  }
47
  return code;
×
48
}
49

50
int32_t tsdbDataFileRAWReaderClose(SDataFileRAWReader **reader) {
×
51
  if (reader[0] == NULL) {
×
52
    return 0;
×
53
  }
54

55
  if (reader[0]->fd) {
×
56
    tsdbCloseFile(&reader[0]->fd);
×
57
  }
58

59
  taosMemoryFree(reader[0]);
×
60
  reader[0] = NULL;
×
61
  return 0;
×
62
}
63

64
int32_t tsdbDataFileRAWReadBlockData(SDataFileRAWReader *reader, STsdbDataRAWBlockHeader *pBlock) {
×
65
  int32_t code = 0;
×
66
  int32_t lino = 0;
×
67

68
  pBlock->file.type = reader->config->file.type;
×
69
  pBlock->file.fid = reader->config->file.fid;
×
70
  pBlock->file.cid = reader->config->file.cid;
×
71
  pBlock->file.size = reader->config->file.size;
×
72
  pBlock->file.minVer = reader->config->file.minVer;
×
73
  pBlock->file.maxVer = reader->config->file.maxVer;
×
74
  pBlock->file.stt->level = reader->config->file.stt->level;
×
75

76
  SEncryptData *pEncryptData = &(reader->config->tsdb->pVnode->config.tsdbCfg.encryptData);
×
77
  TAOS_CHECK_GOTO(tsdbReadFile(reader->fd, pBlock->offset, pBlock->data, pBlock->dataLength, 0, pEncryptData), &lino,
×
78
                  _exit);
79

80
_exit:
×
81
  if (code) {
×
82
    tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(reader->config->tsdb->pVnode), __func__, __FILE__, lino,
×
83
              tstrerror(code));
84
  }
85
  return code;
×
86
}
87

88
// SDataFileRAWWriter =============================================
89
int32_t tsdbDataFileRAWWriterOpen(const SDataFileRAWWriterConfig *config, SDataFileRAWWriter **ppWriter) {
×
90
  int32_t code = 0;
×
91
  int32_t lino = 0;
×
92

93
  SDataFileRAWWriter *writer = taosMemoryCalloc(1, sizeof(SDataFileRAWWriter));
×
94
  if (!writer) {
×
95
    TAOS_CHECK_GOTO(terrno, &lino, _exit);
×
96
  }
97

98
  writer->config[0] = config[0];
×
99

100
  TAOS_CHECK_GOTO(tsdbDataFileRAWWriterDoOpen(writer), &lino, _exit);
×
101

102
_exit:
×
103
  if (code) {
×
104
    tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(config->tsdb->pVnode), __func__, __FILE__, lino,
×
105
              tstrerror(code));
106
    taosMemoryFree(writer);
×
107
    writer = NULL;
×
108
  }
109
  ppWriter[0] = writer;
×
110
  return code;
×
111
}
112

113
static int32_t tsdbDataFileRAWWriterCloseAbort(SDataFileRAWWriter *writer) {
×
114
  tsdbError("vgId:%d %s failed since not implemented", TD_VID(writer->config->tsdb->pVnode), __func__);
×
115
  return 0;
×
116
}
117

118
static void tsdbDataFileRAWWriterDoClose(SDataFileRAWWriter *writer) { return; }
×
119

120
static int32_t tsdbDataFileRAWWriterCloseCommit(SDataFileRAWWriter *writer, TFileOpArray *opArr) {
×
121
  int32_t code = 0;
×
122
  int32_t lino = 0;
×
123

124
  STFileOp op = (STFileOp){
×
125
      .optype = TSDB_FOP_CREATE,
126
      .fid = writer->config->fid,
×
127
      .nf = writer->file,
128
  };
129
  TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit);
×
130

131
  SEncryptData *pEncryptData = &(writer->config->tsdb->pVnode->config.tsdbCfg.encryptData);
×
132

133
  if (writer->fd) {
×
134
    TAOS_CHECK_GOTO(tsdbFsyncFile(writer->fd, pEncryptData), &lino, _exit);
×
135
    tsdbCloseFile(&writer->fd);
×
136
  }
137

138
_exit:
×
139
  if (code) {
×
140
    tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(writer->config->tsdb->pVnode), __func__, __FILE__, lino,
×
141
              tstrerror(code));
142
  }
143
  return code;
×
144
}
145

146
static int32_t tsdbDataFileRAWWriterOpenDataFD(SDataFileRAWWriter *writer) {
×
147
  int32_t code = 0;
×
148
  int32_t lino = 0;
×
149

150
  char    fname[TSDB_FILENAME_LEN];
151
  int32_t flag = TD_FILE_READ | TD_FILE_WRITE;
×
152

153
  if (writer->ctx->offset == 0) {
×
154
    flag |= (TD_FILE_CREATE | TD_FILE_TRUNC);
×
155
  }
156

157
  tsdbTFileName(writer->config->tsdb, &writer->file, fname);
×
158
  TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd, writer->file.lcn), &lino, _exit);
×
159

160
_exit:
×
161
  if (code) {
×
162
    tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(writer->config->tsdb->pVnode), __func__, __FILE__, lino,
×
163
              tstrerror(code));
164
  }
165
  return code;
×
166
}
167

168
int32_t tsdbDataFileRAWWriterDoOpen(SDataFileRAWWriter *writer) {
×
169
  int32_t code = 0;
×
170
  int32_t lino = 0;
×
171

172
  writer->file = writer->config->file;
×
173
  writer->ctx->offset = 0;
×
174

175
  TAOS_CHECK_GOTO(tsdbDataFileRAWWriterOpenDataFD(writer), &lino, _exit);
×
176

177
  writer->ctx->opened = true;
×
178
_exit:
×
179
  if (code) {
×
180
    tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(writer->config->tsdb->pVnode), __func__, __FILE__, lino,
×
181
              tstrerror(code));
182
  }
183
  return code;
×
184
}
185

186
int32_t tsdbDataFileRAWWriterClose(SDataFileRAWWriter **writer, bool abort, TFileOpArray *opArr) {
×
187
  if (writer[0] == NULL) {
×
188
    return 0;
×
189
  }
190

191
  int32_t code = 0;
×
192
  int32_t lino = 0;
×
193

194
  if (writer[0]->ctx->opened) {
×
195
    if (abort) {
×
196
      TAOS_CHECK_GOTO(tsdbDataFileRAWWriterCloseAbort(writer[0]), &lino, _exit);
×
197
    } else {
198
      TAOS_CHECK_GOTO(tsdbDataFileRAWWriterCloseCommit(writer[0], opArr), &lino, _exit);
×
199
    }
200
    tsdbDataFileRAWWriterDoClose(writer[0]);
×
201
  }
202
  taosMemoryFree(writer[0]);
×
203
  writer[0] = NULL;
×
204

205
_exit:
×
206
  if (code) {
×
207
    tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(writer[0]->config->tsdb->pVnode), __func__, __FILE__, lino,
×
208
              tstrerror(code));
209
  }
210
  return code;
×
211
}
212

213
int32_t tsdbDataFileRAWWriteBlockData(SDataFileRAWWriter *writer, const STsdbDataRAWBlockHeader *pDataBlock,
×
214
                                      SEncryptData *encryptData) {
215
  int32_t code = 0;
×
216
  int32_t lino = 0;
×
217

218
  TAOS_CHECK_GOTO(tsdbWriteFile(writer->fd, writer->ctx->offset, (const uint8_t *)pDataBlock->data,
×
219
                                pDataBlock->dataLength, encryptData),
220
                  &lino, _exit);
221

222
  writer->ctx->offset += pDataBlock->dataLength;
×
223

224
_exit:
×
225
  if (code) {
×
226
    tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(writer->config->tsdb->pVnode), __func__, __FILE__, lino,
×
227
              tstrerror(code));
228
  }
229
  return code;
×
230
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc