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

taosdata / TDengine / #4881

14 Dec 2025 03:48AM UTC coverage: 60.617% (+0.5%) from 60.092%
#4881

push

travis-ci

web-flow
test: update coverage workflow time (#33918)

156854 of 258761 relevant lines covered (60.62%)

75258957.81 hits per line

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

84.68
/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,
47,030✔
20
                                  SDataFileRAWReader **reader) {
21
  int32_t code = 0;
47,030✔
22
  int32_t lino = 0;
47,030✔
23

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

29
  reader[0]->config[0] = config[0];
47,030✔
30

31
  int32_t lcn = config->file.lcn;
47,030✔
32
  if (fname) {
47,030✔
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];
47,030✔
38
    tsdbTFileName(config->tsdb, &config->file, fname1);
47,030✔
39
    TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd, lcn), &lino, _exit);
47,030✔
40
  }
41

42
_exit:
47,030✔
43
  if (code) {
47,030✔
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;
47,030✔
48
}
49

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

55
  if (reader[0]->fd) {
47,030✔
56
    tsdbCloseFile(&reader[0]->fd);
47,030✔
57
  }
58

59
  taosMemoryFree(reader[0]);
47,030✔
60
  reader[0] = NULL;
47,030✔
61
  return 0;
47,030✔
62
}
63

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

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

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

80
_exit:
47,030✔
81
  if (code) {
47,030✔
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;
47,030✔
86
}
87

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

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

98
  writer->config[0] = config[0];
47,035✔
99

100
  TAOS_CHECK_GOTO(tsdbDataFileRAWWriterDoOpen(writer), &lino, _exit);
47,035✔
101

102
_exit:
47,035✔
103
  if (code) {
47,035✔
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;
47,035✔
110
  return code;
47,035✔
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; }
47,035✔
119

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

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

131
  SEncryptData *pEncryptData = &(writer->config->tsdb->pVnode->config.tsdbCfg.encryptData);
47,035✔
132

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

138
_exit:
47,035✔
139
  if (code) {
47,035✔
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;
47,035✔
144
}
145

146
static int32_t tsdbDataFileRAWWriterOpenDataFD(SDataFileRAWWriter *writer) {
47,035✔
147
  int32_t code = 0;
47,035✔
148
  int32_t lino = 0;
47,035✔
149

150
  char    fname[TSDB_FILENAME_LEN];
47,035✔
151
  int32_t flag = TD_FILE_READ | TD_FILE_WRITE;
47,035✔
152

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

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

160
_exit:
47,035✔
161
  if (code) {
47,035✔
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;
47,035✔
166
}
167

168
int32_t tsdbDataFileRAWWriterDoOpen(SDataFileRAWWriter *writer) {
47,035✔
169
  int32_t code = 0;
47,035✔
170
  int32_t lino = 0;
47,035✔
171

172
  writer->file = writer->config->file;
47,035✔
173
  writer->ctx->offset = 0;
47,035✔
174

175
  TAOS_CHECK_GOTO(tsdbDataFileRAWWriterOpenDataFD(writer), &lino, _exit);
47,035✔
176

177
  writer->ctx->opened = true;
47,035✔
178
_exit:
47,035✔
179
  if (code) {
47,035✔
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;
47,035✔
184
}
185

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

191
  int32_t code = 0;
47,035✔
192
  int32_t lino = 0;
47,035✔
193

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

205
_exit:
47,035✔
206
  if (code) {
47,035✔
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;
47,035✔
211
}
212

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

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

222
  writer->ctx->offset += pDataBlock->dataLength;
47,035✔
223

224
_exit:
47,035✔
225
  if (code) {
47,035✔
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;
47,035✔
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