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

taosdata / TDengine / #4875

09 Dec 2025 01:22AM UTC coverage: 64.472% (-0.2%) from 64.623%
#4875

push

travis-ci

guanshengliang
fix: temporarily disable memory leak detection for UDF tests (#33856)

162014 of 251293 relevant lines covered (64.47%)

104318075.66 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,
144,160✔
20
                                  SDataFileRAWReader **reader) {
21
  int32_t code = 0;
144,160✔
22
  int32_t lino = 0;
144,160✔
23

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

29
  reader[0]->config[0] = config[0];
144,160✔
30

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

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

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

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

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

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

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

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

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

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

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

98
  writer->config[0] = config[0];
144,244✔
99

100
  TAOS_CHECK_GOTO(tsdbDataFileRAWWriterDoOpen(writer), &lino, _exit);
144,244✔
101

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

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

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

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

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

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

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

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

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

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

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

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

172
  writer->file = writer->config->file;
144,244✔
173
  writer->ctx->offset = 0;
144,244✔
174

175
  TAOS_CHECK_GOTO(tsdbDataFileRAWWriterOpenDataFD(writer), &lino, _exit);
144,244✔
176

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

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

191
  int32_t code = 0;
144,244✔
192
  int32_t lino = 0;
144,244✔
193

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

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

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

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

222
  writer->ctx->offset += pDataBlock->dataLength;
175,472✔
223

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