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

taosdata / TDengine / #3608

12 Feb 2025 05:57AM UTC coverage: 63.066% (+1.4%) from 61.715%
#3608

push

travis-ci

web-flow
Merge pull request #29746 from taosdata/merge/mainto3.02

merge: from main to 3.0 branch

140199 of 286257 branches covered (48.98%)

Branch coverage included in aggregate %.

89 of 161 new or added lines in 18 files covered. (55.28%)

3211 existing lines in 190 files now uncovered.

218998 of 283298 relevant lines covered (77.3%)

5949310.66 hits per line

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

72.84
/source/dnode/vnode/src/tsdb/tsdbFSetRAW.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 "tsdbFSetRAW.h"
17
#include "tsdbFS2.h"
18

19
// SFSetRAWWriter ==================================================
20
struct SFSetRAWWriter {
21
  SFSetRAWWriterConfig config[1];
22

23
  struct {
24
    TFileOpArray fopArr[1];
25
    STFile       file;
26
    int64_t      offset;
27
  } ctx[1];
28

29
  // writer
30
  SDataFileRAWWriter *dataWriter;
31
};
32

33
int32_t tsdbFSetRAWWriterOpen(SFSetRAWWriterConfig *config, SFSetRAWWriter **writer) {
76✔
34
  int32_t code = 0;
76✔
35
  int32_t lino = 0;
76✔
36

37
  writer[0] = taosMemoryCalloc(1, sizeof(SFSetRAWWriter));
76!
38
  if (writer[0] == NULL) {
76!
39
    return terrno;
×
40
  }
41

42
  writer[0]->config[0] = config[0];
76✔
43

44
  TARRAY2_INIT(writer[0]->ctx->fopArr);
76✔
45

46
_exit:
76✔
47
  if (code) {
76!
48
    TSDB_ERROR_LOG(TD_VID(config->tsdb->pVnode), lino, code);
×
49
  }
50
  return code;
76✔
51
}
52

53
static int32_t tsdbFSetRAWWriterFinish(SFSetRAWWriter *writer, TFileOpArray *fopArr) {
76✔
54
  int32_t code = 0;
76✔
55
  int32_t lino = 0;
76✔
56

57
  STsdb *tsdb = writer->config->tsdb;
76✔
58

59
  STFileOp op;
60
  TARRAY2_FOREACH(writer->ctx->fopArr, op) {
270✔
61
    code = TARRAY2_APPEND(fopArr, op);
194✔
62
    TSDB_CHECK_CODE(code, lino, _exit);
194!
63
  }
64

65
  TARRAY2_CLEAR(writer->ctx->fopArr, NULL);
76✔
66
_exit:
76✔
67
  if (code) {
76!
68
    TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code);
×
69
  }
70
  return code;
76✔
71
}
72

73
static int32_t tsdbFSetRAWWriteFileDataBegin(SFSetRAWWriter *writer, STsdbDataRAWBlockHeader *bHdr) {
194✔
74
  int32_t code = 0;
194✔
75
  int32_t lino = 0;
194✔
76

77
  SDiskID diskID = {0};
194✔
78
  code = tsdbAllocateDisk(writer->config->tsdb, tsdbFTypeLabel(bHdr->file.type), writer->config->expLevel, &diskID);
194✔
79
  TSDB_CHECK_CODE(code, lino, _exit);
194!
80

81
  SDataFileRAWWriterConfig config = {
194✔
82
      .tsdb = writer->config->tsdb,
194✔
83
      .szPage = writer->config->szPage,
194✔
84
      .fid = bHdr->file.fid,
194✔
85
      .cid = bHdr->file.cid,
194✔
86
      .level = writer->config->level,
194✔
87

88
      .file =
89
          {
90
              .type = bHdr->file.type,
194✔
91
              .fid = bHdr->file.fid,
194✔
92
              .did = diskID,
93
              .cid = bHdr->file.cid,
194✔
94
              .size = bHdr->file.size,
194✔
95
              .minVer = bHdr->file.minVer,
194✔
96
              .maxVer = bHdr->file.maxVer,
194✔
97
              .stt = {{
98
                  .level = bHdr->file.stt->level,
194✔
99
              }},
100
          },
101
  };
102

103
  tsdbFSUpdateEid(config.tsdb->pFS, config.cid);
194✔
104
  writer->ctx->offset = 0;
194✔
105
  writer->ctx->file = config.file;
194✔
106

107
  code = tsdbDataFileRAWWriterOpen(&config, &writer->dataWriter);
194✔
108
  TSDB_CHECK_CODE(code, lino, _exit);
194!
109

110
_exit:
194✔
111
  if (code) {
194!
UNCOV
112
    TSDB_ERROR_LOG(TD_VID(writer->config->tsdb->pVnode), lino, code);
×
113
  }
114
  return code;
194✔
115
}
116

117
static int32_t tsdbFSetRAWWriteFileDataEnd(SFSetRAWWriter *writer) {
270✔
118
  int32_t code = 0;
270✔
119
  int32_t lino = 0;
270✔
120

121
  code = tsdbDataFileRAWWriterClose(&writer->dataWriter, false, writer->ctx->fopArr);
270✔
122
  TSDB_CHECK_CODE(code, lino, _exit);
270!
123

124
_exit:
270✔
125
  if (code) {
270!
UNCOV
126
    TSDB_ERROR_LOG(TD_VID(writer->config->tsdb->pVnode), lino, code);
×
127
  }
128
  return code;
270✔
129
}
130

131
int32_t tsdbFSetRAWWriterClose(SFSetRAWWriter **writer, bool abort, TFileOpArray *fopArr) {
76✔
132
  if (writer[0] == NULL) return 0;
76!
133

134
  int32_t code = 0;
76✔
135
  int32_t lino = 0;
76✔
136

137
  STsdb *tsdb = writer[0]->config->tsdb;
76✔
138

139
  // end
140
  code = tsdbFSetRAWWriteFileDataEnd(writer[0]);
76✔
141
  TSDB_CHECK_CODE(code, lino, _exit);
76!
142

143
  code = tsdbDataFileRAWWriterClose(&writer[0]->dataWriter, abort, writer[0]->ctx->fopArr);
76✔
144
  TSDB_CHECK_CODE(code, lino, _exit);
76!
145

146
  code = tsdbFSetRAWWriterFinish(writer[0], fopArr);
76✔
147
  TSDB_CHECK_CODE(code, lino, _exit);
76!
148
  // free
149
  TARRAY2_DESTROY(writer[0]->ctx->fopArr, NULL);
76!
150
  taosMemoryFree(writer[0]);
76!
151
  writer[0] = NULL;
76✔
152

153
_exit:
76✔
154
  if (code) {
76!
UNCOV
155
    TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code);
×
156
  }
157
  return code;
76✔
158
}
159

160
int32_t tsdbFSetRAWWriteBlockData(SFSetRAWWriter *writer, STsdbDataRAWBlockHeader *bHdr, int32_t encryptAlgorithm,
303✔
161
                                  char *encryptKey) {
162
  int32_t code = 0;
303✔
163
  int32_t lino = 0;
303✔
164

165
  if (writer->ctx->offset == writer->ctx->file.size) {
303✔
166
    code = tsdbFSetRAWWriteFileDataEnd(writer);
194✔
167
    TSDB_CHECK_CODE(code, lino, _exit);
194!
168

169
    code = tsdbFSetRAWWriteFileDataBegin(writer, bHdr);
194✔
170
    TSDB_CHECK_CODE(code, lino, _exit);
194!
171
  }
172

173
  code = tsdbDataFileRAWWriteBlockData(writer->dataWriter, bHdr, encryptAlgorithm, encryptKey);
303✔
174
  TSDB_CHECK_CODE(code, lino, _exit);
303!
175

176
  writer->ctx->offset += bHdr->dataLength;
303✔
177

178
_exit:
303✔
179
  if (code) {
303!
UNCOV
180
    TSDB_ERROR_LOG(TD_VID(writer->config->tsdb->pVnode), lino, code);
×
181
  }
182
  return code;
303✔
183
}
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