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

taosdata / TDengine / #3599

08 Feb 2025 11:23AM UTC coverage: 1.77% (-61.6%) from 63.396%
#3599

push

travis-ci

web-flow
Merge pull request #29712 from taosdata/fix/TD-33652-3.0

fix: reduce write rows from 30w to 3w

3776 of 278949 branches covered (1.35%)

Branch coverage included in aggregate %.

6012 of 274147 relevant lines covered (2.19%)

1642.73 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
  int32_t encryptAlgorithm = reader->config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
×
77
  char   *encryptKey = reader->config->tsdb->pVnode->config.tsdbCfg.encryptKey;
×
78
  TAOS_CHECK_GOTO(
×
79
      tsdbReadFile(reader->fd, pBlock->offset, pBlock->data, pBlock->dataLength, 0, encryptAlgorithm, encryptKey),
80
      &lino, _exit);
81

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

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

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

100
  writer->config[0] = config[0];
×
101

102
  TAOS_CHECK_GOTO(tsdbDataFileRAWWriterDoOpen(writer), &lino, _exit);
×
103

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

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

120
static void tsdbDataFileRAWWriterDoClose(SDataFileRAWWriter *writer) { return; }
×
121

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

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

133
  int32_t encryptAlgorithm = writer->config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
×
134
  char   *encryptKey = writer->config->tsdb->pVnode->config.tsdbCfg.encryptKey;
×
135

136
  if (writer->fd) {
×
137
    TAOS_CHECK_GOTO(tsdbFsyncFile(writer->fd, encryptAlgorithm, encryptKey), &lino, _exit);
×
138
    tsdbCloseFile(&writer->fd);
×
139
  }
140

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

149
static int32_t tsdbDataFileRAWWriterOpenDataFD(SDataFileRAWWriter *writer) {
×
150
  int32_t code = 0;
×
151
  int32_t lino = 0;
×
152

153
  char    fname[TSDB_FILENAME_LEN];
154
  int32_t flag = TD_FILE_READ | TD_FILE_WRITE;
×
155

156
  if (writer->ctx->offset == 0) {
×
157
    flag |= (TD_FILE_CREATE | TD_FILE_TRUNC);
×
158
  }
159

160
  tsdbTFileName(writer->config->tsdb, &writer->file, fname);
×
161
  TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd, writer->file.lcn), &lino, _exit);
×
162

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

171
int32_t tsdbDataFileRAWWriterDoOpen(SDataFileRAWWriter *writer) {
×
172
  int32_t code = 0;
×
173
  int32_t lino = 0;
×
174

175
  writer->file = writer->config->file;
×
176
  writer->ctx->offset = 0;
×
177

178
  TAOS_CHECK_GOTO(tsdbDataFileRAWWriterOpenDataFD(writer), &lino, _exit);
×
179

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

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

194
  int32_t code = 0;
×
195
  int32_t lino = 0;
×
196

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

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

216
int32_t tsdbDataFileRAWWriteBlockData(SDataFileRAWWriter *writer, const STsdbDataRAWBlockHeader *pDataBlock,
×
217
                                      int32_t encryptAlgorithm, char *encryptKey) {
218
  int32_t code = 0;
×
219
  int32_t lino = 0;
×
220

221
  TAOS_CHECK_GOTO(tsdbWriteFile(writer->fd, writer->ctx->offset, (const uint8_t *)pDataBlock->data,
×
222
                                pDataBlock->dataLength, encryptAlgorithm, encryptKey),
223
                  &lino, _exit);
224

225
  writer->ctx->offset += pDataBlock->dataLength;
×
226

227
_exit:
×
228
  if (code) {
×
229
    tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(writer->config->tsdb->pVnode), __func__, __FILE__, lino,
×
230
              tstrerror(code));
231
  }
232
  return code;
×
233
}
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