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

taosdata / TDengine / #3562

20 Dec 2024 09:57AM UTC coverage: 26.655% (-32.2%) from 58.812%
#3562

push

travis-ci

web-flow
Merge pull request #29229 from taosdata/enh/TS-5749-3.0

enh: seperate tsdb async tasks to different thread pools

21498 of 109421 branches covered (19.65%)

Branch coverage included in aggregate %.

66 of 96 new or added lines in 7 files covered. (68.75%)

39441 existing lines in 157 files now uncovered.

35007 of 102566 relevant lines covered (34.13%)

53922.97 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 =============================================
UNCOV
19
int32_t tsdbDataFileRAWReaderOpen(const char *fname, const SDataFileRAWReaderConfig *config,
×
20
                                  SDataFileRAWReader **reader) {
UNCOV
21
  int32_t code = 0;
×
UNCOV
22
  int32_t lino = 0;
×
23

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

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

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

UNCOV
42
_exit:
×
UNCOV
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
  }
UNCOV
47
  return code;
×
48
}
49

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

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

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

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

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

UNCOV
76
  int32_t encryptAlgorithm = reader->config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
×
UNCOV
77
  char   *encryptKey = reader->config->tsdb->pVnode->config.tsdbCfg.encryptKey;
×
UNCOV
78
  TAOS_CHECK_GOTO(
×
79
      tsdbReadFile(reader->fd, pBlock->offset, pBlock->data, pBlock->dataLength, 0, encryptAlgorithm, encryptKey),
80
      &lino, _exit);
81

UNCOV
82
_exit:
×
UNCOV
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
  }
UNCOV
87
  return code;
×
88
}
89

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

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

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

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

UNCOV
104
_exit:
×
UNCOV
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
  }
UNCOV
111
  ppWriter[0] = writer;
×
UNCOV
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

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

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

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

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

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

141
_exit:
×
UNCOV
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
  }
UNCOV
146
  return code;
×
147
}
148

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

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

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

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

UNCOV
163
_exit:
×
UNCOV
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
  }
UNCOV
168
  return code;
×
169
}
170

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

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

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

UNCOV
180
  writer->ctx->opened = true;
×
UNCOV
181
_exit:
×
UNCOV
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
  }
UNCOV
186
  return code;
×
187
}
188

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

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

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

UNCOV
208
_exit:
×
UNCOV
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
  }
UNCOV
213
  return code;
×
214
}
215

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

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

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

UNCOV
227
_exit:
×
UNCOV
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
  }
UNCOV
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