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

taosdata / TDengine / #3621

22 Feb 2025 11:44AM UTC coverage: 2.037% (-61.5%) from 63.573%
#3621

push

travis-ci

web-flow
Merge pull request #29874 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

4357 of 287032 branches covered (1.52%)

Branch coverage included in aggregate %.

0 of 174 new or added lines in 18 files covered. (0.0%)

213359 existing lines in 469 files now uncovered.

7260 of 283369 relevant lines covered (2.56%)

23737.72 hits per line

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

0.0
/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

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

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

UNCOV
42
  writer[0]->config[0] = config[0];
×
43

UNCOV
44
  TARRAY2_INIT(writer[0]->ctx->fopArr);
×
45

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

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

UNCOV
57
  STsdb *tsdb = writer->config->tsdb;
×
58

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

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

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

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

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

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

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

UNCOV
107
  code = tsdbDataFileRAWWriterOpen(&config, &writer->dataWriter);
×
UNCOV
108
  TSDB_CHECK_CODE(code, lino, _exit);
×
109

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

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

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

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

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

UNCOV
134
  int32_t code = 0;
×
UNCOV
135
  int32_t lino = 0;
×
136

UNCOV
137
  STsdb *tsdb = writer[0]->config->tsdb;
×
138

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

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

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

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

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

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

UNCOV
169
    code = tsdbFSetRAWWriteFileDataBegin(writer, bHdr);
×
UNCOV
170
    TSDB_CHECK_CODE(code, lino, _exit);
×
171
  }
172

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

UNCOV
176
  writer->ctx->offset += bHdr->dataLength;
×
177

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