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

taosdata / TDengine / #4954

09 Feb 2026 01:16AM UTC coverage: 66.876% (-0.001%) from 66.877%
#4954

push

travis-ci

web-flow
docs: add support for recording STMT to CSV files (#34276)

* docs: add support for recording STMT to CSV files

* docs: update version for STMT recording feature in CSV files

205775 of 307696 relevant lines covered (66.88%)

127898023.42 hits per line

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

65.25
/source/dnode/vnode/src/vnd/vnodeSvr.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 <stdint.h>
17
#include "audit.h"
18
#include "cos.h"
19
#include "libs/new-stream/stream.h"
20
#include "monitor.h"
21
#include "taoserror.h"
22
#include "tencode.h"
23
#include "tglobal.h"
24
#include "tmsg.h"
25
#include "tmsgcb.h"
26
#include "tstrbuild.h"
27
#include "tutil.h"
28
#include "vnd.h"
29
#include "vnode.h"
30
#include "vnodeInt.h"
31

32
extern taos_counter_t *tsInsertCounter;
33

34
extern int32_t vnodeProcessScanVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
35
extern int32_t vnodeQueryScanProgress(SVnode *pVnode, SRpcMsg *pMsg);
36

37
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
38
static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
39
static int32_t vnodeProcessDropStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp, SRpcMsg *pOriginRpc);
40
static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
41
                                       SRpcMsg *pOriginRpc);
42
static int32_t vnodeProcessAlterTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
43
static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
44
                                     SRpcMsg *pOriginRpc);
45
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
46
                                     SRpcMsg *pOriginalMsg);
47
static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
48
static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
49
static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
50
static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
51
static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
52
                                     SRpcMsg *pOriginalMsg);
53
static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
54
static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
55
static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
56
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
57
static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
58
static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp);
59
static int32_t vnodeProcessDropTSmaCtbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
60
                                          SRpcMsg *pOriginRpc);
61
static int32_t vnodeProcessCreateRsmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
62
static int32_t vnodeProcessDropRsmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
63
static int32_t vnodeProcessAlterRsmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
64

65
static int32_t vnodeCheckState(SVnode *pVnode);
66
static int32_t vnodeCheckToken(SVnode *pVnode, char *member0Token, char *member1Token);
67
static int32_t vnodeCheckSyncd(SVnode *pVnode, char *member0Token, char *member1Token);
68
static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
69

70
extern int32_t vnodeProcessKillCompactReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
71
extern int32_t vnodeQueryCompactProgress(SVnode *pVnode, SRpcMsg *pMsg);
72

73
extern int32_t vnodeProcessKillRetentionReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
74
extern int32_t vnodeQueryRetentionProgress(SVnode *pVnode, SRpcMsg *pMsg);
75

76
extern int32_t vnodeProcessKillScanReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
77

78
extern int32_t vnodeListSsMigrateFileSets(SVnode *pVnode, SRpcMsg *pMsg);
79
static int32_t vnodeProcessSsMigrateFileSetReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
80
extern int32_t vnodeQuerySsMigrateProgress(SVnode *pVnode, SRpcMsg *pMsg);
81
static int32_t vnodeProcessFollowerSsMigrateReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
82
static int32_t vnodeProcessKillSsMigrateReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
83

84
static int32_t vnodePreprocessCreateTableReq(SVnode *pVnode, SDecoder *pCoder, int64_t btime, int64_t *pUid) {
57,575,087✔
85
  int32_t code = 0;
57,575,087✔
86
  int32_t lino = 0;
57,575,087✔
87

88
  if (tStartDecode(pCoder) < 0) {
57,575,087✔
89
    code = TSDB_CODE_INVALID_MSG;
×
90
    TSDB_CHECK_CODE(code, lino, _exit);
×
91
  }
92

93
  // flags
94
  if (tDecodeI32v(pCoder, NULL) < 0) {
57,577,272✔
95
    code = TSDB_CODE_INVALID_MSG;
×
96
    TSDB_CHECK_CODE(code, lino, _exit);
×
97
  }
98

99
  // name
100
  char *name = NULL;
57,577,272✔
101
  if (tDecodeCStr(pCoder, &name) < 0) {
57,573,199✔
102
    code = TSDB_CODE_INVALID_MSG;
×
103
    TSDB_CHECK_CODE(code, lino, _exit);
×
104
  }
105

106
  // uid
107
  int64_t uid = metaGetTableEntryUidByName(pVnode->pMeta, name);
57,573,199✔
108
  if (uid == 0) {
57,573,591✔
109
    uid = tGenIdPI64();
57,221,113✔
110
  }
111
  taosSetInt64Aligned((int64_t *)(pCoder->data + pCoder->pos), uid);
57,557,356✔
112

113
  // btime
114
  taosSetInt64Aligned((int64_t *)(pCoder->data + pCoder->pos + 8), btime);
57,557,566✔
115

116
  tEndDecode(pCoder);
57,558,981✔
117

118
_exit:
57,560,953✔
119
  if (code) {
57,560,952✔
120
    vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
×
121
  } else {
122
    vTrace("vgId:%d %s done, table:%s uid generated:%" PRId64, TD_VID(pVnode), __func__, name, uid);
57,560,952✔
123
    if (pUid) *pUid = uid;
57,559,576✔
124
  }
125
  return code;
57,559,576✔
126
}
127
static int32_t vnodePreProcessCreateTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
38,034,257✔
128
  int32_t code = 0;
38,034,257✔
129
  int32_t lino = 0;
38,034,257✔
130

131
  int64_t  btime = taosGetTimestampMs();
38,034,257✔
132
  SDecoder dc = {0};
38,034,257✔
133
  int32_t  nReqs;
38,033,117✔
134

135
  tDecoderInit(&dc, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead));
38,034,257✔
136
  if (tStartDecode(&dc) < 0) {
38,034,257✔
137
    code = TSDB_CODE_INVALID_MSG;
×
138
    return code;
×
139
  }
140

141
  if (tDecodeI32v(&dc, &nReqs) < 0) {
38,034,257✔
142
    code = TSDB_CODE_INVALID_MSG;
×
143
    TSDB_CHECK_CODE(code, lino, _exit);
×
144
  }
145
  for (int32_t iReq = 0; iReq < nReqs; iReq++) {
80,814,391✔
146
    code = vnodePreprocessCreateTableReq(pVnode, &dc, btime, NULL);
42,782,270✔
147
    TSDB_CHECK_CODE(code, lino, _exit);
42,780,134✔
148
  }
149

150
  tEndDecode(&dc);
38,032,121✔
151

152
_exit:
38,034,221✔
153
  tDecoderClear(&dc);
38,034,221✔
154
  if (code) {
38,034,255✔
155
    vError("vgId:%d, %s:%d failed to preprocess submit request since %s, msg type:%s", TD_VID(pVnode), __func__, lino,
×
156
           tstrerror(code), TMSG_INFO(pMsg->msgType));
157
  }
158
  return code;
38,034,253✔
159
}
160

161
static int32_t vnodePreProcessAlterTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
11,769,582✔
162
  int32_t code = TSDB_CODE_INVALID_MSG;
11,769,582✔
163
  int32_t lino = 0;
11,769,582✔
164

165
  if (pVnode->config.isAudit) {
11,769,582✔
166
    return TSDB_CODE_PAR_PERMISSION_DENIED;
×
167
  }
168

169
  SDecoder dc = {0};
11,769,582✔
170
  tDecoderInit(&dc, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead));
11,769,582✔
171

172
  SVAlterTbReq vAlterTbReq = {0};
11,769,582✔
173
  int64_t      ctimeMs = taosGetTimestampMs();
11,769,582✔
174
  if (tDecodeSVAlterTbReqSetCtime(&dc, &vAlterTbReq, ctimeMs) < 0) {
11,769,582✔
175
    taosArrayDestroy(vAlterTbReq.pMultiTag);
×
176
    vAlterTbReq.pMultiTag = NULL;
×
177
    goto _exit;
×
178
  }
179
  taosArrayDestroy(vAlterTbReq.pMultiTag);
11,769,582✔
180
  vAlterTbReq.pMultiTag = NULL;
11,769,582✔
181

182
  code = 0;
11,769,582✔
183

184
_exit:
11,769,582✔
185
  tDecoderClear(&dc);
11,769,582✔
186
  if (code) {
11,769,582✔
187
    vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
×
188
  } else {
189
    vTrace("vgId:%d %s done, table:%s ctimeMs generated:%" PRId64, TD_VID(pVnode), __func__, vAlterTbReq.tbName,
11,769,582✔
190
           ctimeMs);
191
  }
192
  return code;
11,769,582✔
193
}
194

195
static int32_t vnodePreProcessDropTtlMsg(SVnode *pVnode, SRpcMsg *pMsg) {
10,284,395✔
196
  int32_t code = TSDB_CODE_INVALID_MSG;
10,284,395✔
197
  int32_t lino = 0;
10,284,395✔
198

199
  SMsgHead *pContOld = pMsg->pCont;
10,284,395✔
200
  int32_t   reqLenOld = pMsg->contLen - sizeof(SMsgHead);
10,286,633✔
201

202
  SArray *tbUids = NULL;
10,286,823✔
203
  int64_t timestampMs = 0;
10,286,823✔
204

205
  SVDropTtlTableReq ttlReq = {0};
10,286,823✔
206
  if (tDeserializeSVDropTtlTableReq((char *)pContOld + sizeof(SMsgHead), reqLenOld, &ttlReq) != 0) {
10,285,731✔
207
    code = TSDB_CODE_INVALID_MSG;
×
208
    TSDB_CHECK_CODE(code, lino, _exit);
×
209
  }
210

211
  {  // find expired uids
212
    tbUids = taosArrayInit(8, sizeof(tb_uid_t));
10,287,312✔
213
    if (tbUids == NULL) {
10,288,152✔
214
      code = terrno;
×
215
      TSDB_CHECK_CODE(code, lino, _exit);
×
216
    }
217

218
    timestampMs = (int64_t)ttlReq.timestampSec * 1000;
10,288,152✔
219
    code = metaTtlFindExpired(pVnode->pMeta, timestampMs, tbUids, ttlReq.ttlDropMaxCount);
10,288,152✔
220
    if (code != 0) {
10,278,468✔
221
      code = TSDB_CODE_INVALID_MSG;
×
222
      TSDB_CHECK_CODE(code, lino, _exit);
×
223
    }
224

225
    ttlReq.nUids = taosArrayGetSize(tbUids);
10,278,468✔
226
    ttlReq.pTbUids = tbUids;
10,281,367✔
227
  }
228

229
  if (ttlReq.nUids == 0) {
10,281,367✔
230
    code = TSDB_CODE_MSG_PREPROCESSED;
10,263,839✔
231
    TSDB_CHECK_CODE(code, lino, _exit);
10,263,839✔
232
  }
233

234
  {  // prepare new content
235
    int32_t reqLenNew = tSerializeSVDropTtlTableReq(NULL, 0, &ttlReq);
11,979✔
236
    int32_t contLenNew = reqLenNew + sizeof(SMsgHead);
11,307✔
237

238
    SMsgHead *pContNew = rpcMallocCont(contLenNew);
11,307✔
239
    if (pContNew == NULL) {
11,307✔
240
      code = terrno;
×
241
      TSDB_CHECK_CODE(code, lino, _exit);
×
242
    }
243

244
    if (tSerializeSVDropTtlTableReq((char *)pContNew + sizeof(SMsgHead), reqLenNew, &ttlReq) != 0) {
11,307✔
245
      vError("vgId:%d %s:%d failed to serialize drop ttl request", TD_VID(pVnode), __func__, lino);
11,307✔
246
    }
247
    pContNew->contLen = htonl(reqLenNew);
11,307✔
248
    pContNew->vgId = pContOld->vgId;
11,307✔
249

250
    rpcFreeCont(pContOld);
11,307✔
251
    pMsg->pCont = pContNew;
11,307✔
252
    pMsg->contLen = contLenNew;
11,307✔
253
  }
254

255
  code = 0;
11,307✔
256

257
_exit:
10,280,695✔
258
  taosArrayDestroy(tbUids);
10,281,565✔
259

260
  if (code && code != TSDB_CODE_MSG_PREPROCESSED) {
10,264,209✔
261
    vError("vgId:%d, %s:%d failed to preprocess drop ttl request since %s, msg type:%s", TD_VID(pVnode), __func__, lino,
×
262
           tstrerror(code), TMSG_INFO(pMsg->msgType));
263
  } else {
264
    vTrace("vgId:%d, %s done, timestampSec:%d, nUids:%d", TD_VID(pVnode), __func__, ttlReq.timestampSec, ttlReq.nUids);
10,264,209✔
265
  }
266

267
  return code;
10,264,209✔
268
}
269

270
extern int64_t tsMaxKeyByPrecision[];
271
static int32_t vnodePreProcessSubmitTbData(SVnode *pVnode, SDecoder *pCoder, int64_t btimeMs, int64_t ctimeMs) {
595,012,429✔
272
  int32_t code = 0;
595,012,429✔
273
  int32_t lino = 0;
595,012,429✔
274

275
  if (tStartDecode(pCoder) < 0) {
595,012,429✔
276
    code = TSDB_CODE_INVALID_MSG;
×
277
    TSDB_CHECK_CODE(code, lino, _exit);
×
278
  }
279

280
  SSubmitTbData submitTbData;
595,012,963✔
281
  uint8_t       version;
282
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
595,011,571✔
283
    code = TSDB_CODE_INVALID_MSG;
×
284
    TSDB_CHECK_CODE(code, lino, _exit);
×
285
  }
286
  version = (submitTbData.flags >> 8) & 0xff;
595,011,571✔
287
  submitTbData.flags = submitTbData.flags & 0xff;
595,011,571✔
288

289
  int64_t uid;
595,008,867✔
290
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
595,010,917✔
291
    code = vnodePreprocessCreateTableReq(pVnode, pCoder, btimeMs, &uid);
14,790,259✔
292
    TSDB_CHECK_CODE(code, lino, _exit);
14,779,649✔
293
  }
294

295
  // submit data
296
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
594,998,589✔
297
    code = TSDB_CODE_INVALID_MSG;
×
298
    TSDB_CHECK_CODE(code, lino, _exit);
×
299
  }
300

301
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
594,998,589✔
302
    taosSetInt64Aligned((int64_t *)(pCoder->data + pCoder->pos), uid);
14,776,973✔
303
    pCoder->pos += sizeof(int64_t);
14,773,715✔
304
  } else {
305
    if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
580,220,106✔
306
      code = TSDB_CODE_INVALID_MSG;
×
307
      TSDB_CHECK_CODE(code, lino, _exit);
×
308
    }
309
  }
310

311
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
595,004,422✔
312
    code = TSDB_CODE_INVALID_MSG;
×
313
    TSDB_CHECK_CODE(code, lino, _exit);
×
314
  }
315

316
  // scan and check
317
  TSKEY now = btimeMs;
595,004,422✔
318
  if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_MICRO) {
595,004,422✔
319
    now *= 1000;
2,436,395✔
320
  } else if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_NANO) {
592,564,359✔
321
    now *= 1000000;
1,402,849✔
322
  }
323

324
  int32_t keep = pVnode->config.tsdbCfg.keep2;
595,001,156✔
325

326
  TSKEY minKey = now - tsTickPerMin[pVnode->config.tsdbCfg.precision] * keep;
594,999,459✔
327
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
595,003,977✔
328
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
595,003,307✔
329
    uint64_t nColData;
6,424,819✔
330
    if (tDecodeU64v(pCoder, &nColData) < 0) {
6,425,203✔
331
      code = TSDB_CODE_INVALID_MSG;
×
332
      TSDB_CHECK_CODE(code, lino, _exit);
×
333
    }
334

335
    SColData colData = {0};
6,425,203✔
336
    code = tDecodeColData(version, pCoder, &colData, false);
6,425,203✔
337
    if (code) {
6,424,569✔
338
      code = TSDB_CODE_INVALID_MSG;
×
339
      TSDB_CHECK_CODE(code, lino, _exit);
×
340
    }
341

342
    if (colData.flag != HAS_VALUE) {
6,424,569✔
343
      code = TSDB_CODE_INVALID_MSG;
×
344
      TSDB_CHECK_CODE(code, lino, _exit);
×
345
    }
346

347
    for (int32_t iRow = 0; iRow < colData.nVal; iRow++) {
2,147,483,647✔
348
      if (((TSKEY *)colData.pData)[iRow] < minKey || ((TSKEY *)colData.pData)[iRow] > maxKey) {
2,147,483,647✔
349
        code = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
569✔
350
        TSDB_CHECK_CODE(code, lino, _exit);
569✔
351
      }
352
    }
353

354
    for (uint64_t i = 1; i < nColData; i++) {
19,672,125✔
355
      code = tDecodeColData(version, pCoder, &colData, true);
13,311,964✔
356
      if (code) {
13,311,964✔
357
        code = TSDB_CODE_INVALID_MSG;
×
358
        TSDB_CHECK_CODE(code, lino, _exit);
×
359
      }
360
    }
361
  } else {
362
    uint64_t nRow;
588,575,784✔
363
    if (tDecodeU64v(pCoder, &nRow) < 0) {
588,587,279✔
364
      code = TSDB_CODE_INVALID_MSG;
×
365
      TSDB_CHECK_CODE(code, lino, _exit);
×
366
    }
367

368
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
2,147,483,647✔
369
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
2,147,483,647✔
370
      pCoder->pos += pRow->len;
2,147,483,647✔
371
#ifndef NO_UNALIGNED_ACCESS
372
      if (pRow->ts < minKey || pRow->ts > maxKey) {
2,147,483,647✔
373
#else
374
      TSKEY ts = taosGetInt64Aligned(&pRow->ts);
375
      if (ts < minKey || ts > maxKey) {
376
#endif
377
        code = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
64,835✔
378
        TSDB_CHECK_CODE(code, lino, _exit);
64,835✔
379
      }
380

381
      // Check pRow->sver
382
      if (pRow->sver != submitTbData.sver) {
2,147,483,647✔
383
        code = TSDB_CODE_INVALID_DATA_FMT;
×
384
        TSDB_CHECK_CODE(code, lino, _exit);
×
385
      }
386
    }
387
  }
388

389
  if (!tDecodeIsEnd(pCoder)) {
594,937,386✔
390
    taosSetInt64Aligned((int64_t *)(pCoder->data + pCoder->pos), ctimeMs);
594,938,468✔
391
    pCoder->pos += sizeof(int64_t);
594,899,129✔
392
  }
393

394
  tEndDecode(pCoder);
594,913,510✔
395

396
_exit:
594,997,708✔
397
  if (code) {
594,997,190✔
398
    vError("vgId:%d, %s:%d failed to vnodePreProcessSubmitTbData submit request since %s", TD_VID(pVnode), __func__,
65,404✔
399
           lino, tstrerror(code));
400
  }
401
  return code;
594,997,190✔
402
}
403
static int32_t vnodePreProcessSubmitMsg(SVnode *pVnode, SRpcMsg *pMsg) {
567,716,140✔
404
  int32_t code = 0;
567,716,140✔
405
  int32_t lino = 0;
567,716,140✔
406

407
  if (tsBypassFlag & TSDB_BYPASS_RA_RPC_RECV_SUBMIT) {
567,716,140✔
408
    return TSDB_CODE_MSG_PREPROCESSED;
60✔
409
  }
410

411
  SDecoder *pCoder = &(SDecoder){0};
567,716,080✔
412

413
  if (taosHton64(((SSubmitReq2Msg *)pMsg->pCont)->version) != 1) {
567,716,744✔
414
    code = TSDB_CODE_INVALID_MSG;
×
415
    TSDB_CHECK_CODE(code, lino, _exit);
×
416
  }
417

418
  tDecoderInit(pCoder, (uint8_t *)pMsg->pCont + sizeof(SSubmitReq2Msg), pMsg->contLen - sizeof(SSubmitReq2Msg));
567,717,022✔
419

420
  if (tStartDecode(pCoder) < 0) {
567,717,432✔
421
    code = TSDB_CODE_INVALID_MSG;
×
422
    TSDB_CHECK_CODE(code, lino, _exit);
×
423
  }
424

425
  uint64_t nSubmitTbData;
567,715,037✔
426
  if (tDecodeU64v(pCoder, &nSubmitTbData) < 0) {
567,716,744✔
427
    code = TSDB_CODE_INVALID_MSG;
×
428
    TSDB_CHECK_CODE(code, lino, _exit);
×
429
  }
430

431
  int64_t btimeMs = taosGetTimestampMs();
567,715,720✔
432
  int64_t ctimeMs = btimeMs;
567,715,720✔
433
  for (int32_t i = 0; i < nSubmitTbData; i++) {
1,162,644,976✔
434
    code = vnodePreProcessSubmitTbData(pVnode, pCoder, btimeMs, ctimeMs);
594,996,418✔
435
    TSDB_CHECK_CODE(code, lino, _exit);
594,994,660✔
436
  }
437

438
  tEndDecode(pCoder);
567,648,558✔
439

440
_exit:
567,716,693✔
441
  tDecoderClear(pCoder);
567,717,219✔
442
  if (code) {
567,715,289✔
443
    vError("vgId:%d, %s:%d failed to preprocess submit request since %s, msg type:%s", TD_VID(pVnode), __func__, lino,
65,404✔
444
           tstrerror(code), TMSG_INFO(pMsg->msgType));
445
  }
446
  return code;
567,713,212✔
447
}
448

449
static int32_t vnodePreProcessDeleteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
1,669,227✔
450
  int32_t code = 0;
1,669,227✔
451

452
  int32_t    size;
453
  int32_t    ret;
454
  uint8_t   *pCont;
455
  SEncoder  *pCoder = &(SEncoder){0};
1,669,227✔
456
  SDeleteRes res = {0};
1,669,227✔
457

458
  SReadHandle handle = {0};
1,669,227✔
459
  handle.vnode = pVnode;
1,669,227✔
460
  handle.pMsgCb = &pVnode->msgCb;
1,669,227✔
461
  handle.skipRollup = 1;
1,669,227✔
462
  initStorageAPI(&handle.api);
1,669,227✔
463

464
  code = qWorkerProcessDeleteMsg(&handle, pVnode->pQuery, pMsg, &res);
1,669,227✔
465
  if (code) goto _exit;
1,669,227✔
466

467
  res.ctimeMs = taosGetTimestampMs();
1,669,227✔
468
  // malloc and encode
469
  tEncodeSize(tEncodeDeleteRes, &res, size, ret);
1,669,227✔
470
  pCont = rpcMallocCont(size + sizeof(SMsgHead));
1,669,227✔
471

472
  ((SMsgHead *)pCont)->contLen = size + sizeof(SMsgHead);
1,669,227✔
473
  ((SMsgHead *)pCont)->vgId = TD_VID(pVnode);
1,669,227✔
474

475
  tEncoderInit(pCoder, pCont + sizeof(SMsgHead), size);
1,669,227✔
476
  if (tEncodeDeleteRes(pCoder, &res) != 0) {
1,669,227✔
477
    vError("vgId:%d %s failed to encode delete response", TD_VID(pVnode), __func__);
×
478
  }
479
  tEncoderClear(pCoder);
1,669,227✔
480

481
  rpcFreeCont(pMsg->pCont);
1,669,227✔
482
  pMsg->pCont = pCont;
1,669,227✔
483
  pMsg->contLen = size + sizeof(SMsgHead);
1,669,227✔
484

485
  taosArrayDestroy(res.uidList);
1,669,227✔
486

487
_exit:
1,669,227✔
488
  return code;
1,669,227✔
489
}
490

491
static int32_t vnodePreProcessBatchDeleteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
×
492
  int32_t code = 0;
×
493
  int32_t lino = 0;
×
494

495
  int64_t         ctimeMs = taosGetTimestampMs();
×
496
  SBatchDeleteReq pReq = {0};
×
497
  SDecoder       *pCoder = &(SDecoder){0};
×
498

499
  tDecoderInit(pCoder, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead));
×
500

501
  if (tDecodeSBatchDeleteReqSetCtime(pCoder, &pReq, ctimeMs) < 0) {
×
502
    code = TSDB_CODE_INVALID_MSG;
×
503
  }
504

505
  tDecoderClear(pCoder);
×
506
  taosArrayDestroy(pReq.deleteReqs);
×
507

508
  if (code) {
×
509
    vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
×
510
  } else {
511
    vTrace("vgId:%d %s done, ctimeMs generated:%" PRId64, TD_VID(pVnode), __func__, ctimeMs);
×
512
  }
513
  return code;
×
514
}
515

516
static int32_t vnodePreProcessArbCheckSyncMsg(SVnode *pVnode, SRpcMsg *pMsg) {
20,329✔
517
  int32_t ret = 0;
20,329✔
518
  if ((ret = vnodeCheckState(pVnode)) != 0) {
20,329✔
519
    vDebug("vgId:%d, failed to preprocess vnode-arb-check-sync request since %s", TD_VID(pVnode), tstrerror(ret));
2,544✔
520
    return 0;
2,544✔
521
  }
522

523
  SVArbCheckSyncReq syncReq = {0};
17,785✔
524

525
  if (tDeserializeSVArbCheckSyncReq((char *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead),
17,785✔
526
                                    &syncReq) != 0) {
527
    return TSDB_CODE_INVALID_MSG;
×
528
  }
529

530
  ret = vnodeCheckToken(pVnode, syncReq.member0Token, syncReq.member1Token);
17,785✔
531
  if (ret != 0) {
17,785✔
532
    vError("vgId:%d, failed to preprocess vnode-arb-check-sync request since %s", TD_VID(pVnode), tstrerror(ret));
14,267✔
533
  }
534

535
  int32_t code = terrno;
17,785✔
536
  tFreeSVArbCheckSyncReq(&syncReq);
17,785✔
537

538
  return code;
17,785✔
539
}
540

541
int32_t vnodePreProcessDropTbMsg(SVnode *pVnode, SRpcMsg *pMsg) {
1,316,939✔
542
  int32_t          code = TSDB_CODE_SUCCESS;
1,316,939✔
543
  int32_t          lino = 0;
1,316,939✔
544
  int32_t          size = 0;
1,316,939✔
545
  SDecoder         dc = {0};
1,316,939✔
546
  SEncoder         ec = {0};
1,316,939✔
547
  SVDropTbBatchReq receivedBatchReqs = {0};
1,316,939✔
548
  SVDropTbBatchReq sentBatchReqs = {0};
1,316,939✔
549

550
  if (pVnode->config.isAudit) {
1,316,939✔
551
    return TSDB_CODE_PAR_PERMISSION_DENIED;
×
552
  }
553

554
  tDecoderInit(&dc, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead));
1,316,939✔
555

556
  code = tDecodeSVDropTbBatchReq(&dc, &receivedBatchReqs);
1,316,939✔
557
  if (code < 0) {
1,316,939✔
558
    terrno = code;
×
559
    TSDB_CHECK_CODE(code, lino, _exit);
×
560
  }
561
  sentBatchReqs.pArray = taosArrayInit(receivedBatchReqs.nReqs, sizeof(SVDropTbReq));
1,316,939✔
562
  if (!sentBatchReqs.pArray) {
1,316,939✔
563
    code = terrno;
×
564
    goto _exit;
×
565
  }
566

567
  for (int32_t i = 0; i < receivedBatchReqs.nReqs; ++i) {
2,680,737✔
568
    SVDropTbReq *pReq = receivedBatchReqs.pReqs + i;
1,363,798✔
569
    tb_uid_t     uid = metaGetTableEntryUidByName(pVnode->pMeta, pReq->name);
1,363,798✔
570
    if (uid == 0) {
1,363,798✔
571
      vWarn("vgId:%d, preprocess drop ctb: %s not found", TD_VID(pVnode), pReq->name);
×
572
      continue;
×
573
    }
574
    pReq->uid = uid;
1,363,798✔
575
    vDebug("vgId:%d %s for: %s, uid: %" PRId64, TD_VID(pVnode), __func__, pReq->name, pReq->uid);
1,363,798✔
576
    if (taosArrayPush(sentBatchReqs.pArray, pReq) == NULL) {
2,727,596✔
577
      code = terrno;
×
578
      goto _exit;
×
579
    }
580
  }
581
  sentBatchReqs.nReqs = sentBatchReqs.pArray->size;
1,316,939✔
582

583
  tEncodeSize(tEncodeSVDropTbBatchReq, &sentBatchReqs, size, code);
1,316,939✔
584
  tEncoderInit(&ec, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), size);
1,316,939✔
585
  code = tEncodeSVDropTbBatchReq(&ec, &sentBatchReqs);
1,316,939✔
586
  tEncoderClear(&ec);
1,316,939✔
587
  if (code != TSDB_CODE_SUCCESS) {
1,316,939✔
588
    vError("vgId:%d %s failed to encode drop tb batch req: %s", TD_VID(pVnode), __func__, tstrerror(code));
×
589
    TSDB_CHECK_CODE(code, lino, _exit);
×
590
  }
591

592
_exit:
1,316,939✔
593
  tDecoderClear(&dc);
1,316,939✔
594
  if (sentBatchReqs.pArray) {
1,316,939✔
595
    taosArrayDestroy(sentBatchReqs.pArray);
1,316,939✔
596
  }
597
  return code;
1,316,939✔
598
}
599

600
int32_t vnodePreProcessSsMigrateFileSetReq(SVnode *pVnode, SRpcMsg *pMsg) {
×
601
  int32_t              code = TSDB_CODE_SUCCESS, lino = 0;
×
602
  SSsMigrateFileSetReq req = {0};
×
603

604
  code = tDeserializeSSsMigrateFileSetReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
×
605
                                          pMsg->contLen - sizeof(SMsgHead), &req);
×
606
  if (code < 0) {
×
607
    terrno = code;
×
608
    TSDB_CHECK_CODE(code, lino, _exit);
×
609
  }
610

611
  req.nodeId = vnodeNodeId(pVnode);
×
612
  TAOS_UNUSED(tSerializeSSsMigrateFileSetReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
×
613
                                             pMsg->contLen - sizeof(SMsgHead), &req));
614

615
_exit:
×
616
  return code;
×
617
}
618

619
int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
650,394,293✔
620
  int32_t code = 0;
650,394,293✔
621

622
  if (pVnode->mounted) {
650,394,293✔
623
    vError("vgId:%d, mountVgId:%d, skip write msg:%s", TD_VID(pVnode), pVnode->config.mountVgId,
1,185✔
624
           TMSG_INFO(pMsg->msgType));
625
    return TSDB_CODE_OPS_NOT_SUPPORT;
1,185✔
626
  }
627

628
  switch (pMsg->msgType) {
650,394,522✔
629
    case TDMT_VND_CREATE_TABLE: {
38,034,257✔
630
      code = vnodePreProcessCreateTableMsg(pVnode, pMsg);
38,034,257✔
631
    } break;
38,033,858✔
632
    case TDMT_VND_ALTER_TABLE: {
11,769,582✔
633
      code = vnodePreProcessAlterTableMsg(pVnode, pMsg);
11,769,582✔
634
    } break;
11,769,582✔
635
    case TDMT_VND_FETCH_TTL_EXPIRED_TBS:
10,288,894✔
636
    case TDMT_VND_DROP_TTL_TABLE: {
637
      code = vnodePreProcessDropTtlMsg(pVnode, pMsg);
10,288,894✔
638
    } break;
10,283,021✔
639
    case TDMT_VND_SUBMIT: {
567,716,665✔
640
      METRICS_TIMING_BLOCK(pVnode->writeMetrics.preprocess_time, METRIC_LEVEL_LOW,
567,716,665✔
641
                           { code = vnodePreProcessSubmitMsg(pVnode, pMsg); });
642
    } break;
567,714,186✔
643
    case TDMT_VND_DELETE: {
1,669,227✔
644
      code = vnodePreProcessDeleteMsg(pVnode, pMsg);
1,669,227✔
645
    } break;
1,669,227✔
646
    case TDMT_VND_BATCH_DEL: {
×
647
      code = vnodePreProcessBatchDeleteMsg(pVnode, pMsg);
×
648
    } break;
×
649
    case TDMT_VND_ARB_CHECK_SYNC: {
20,329✔
650
      code = vnodePreProcessArbCheckSyncMsg(pVnode, pMsg);
20,329✔
651
    } break;
20,329✔
652
    case TDMT_VND_DROP_TABLE: {
1,316,939✔
653
      code = vnodePreProcessDropTbMsg(pVnode, pMsg);
1,316,939✔
654
    } break;
1,316,939✔
655
#ifdef TD_ENTERPRISE
656
    case TDMT_VND_SSMIGRATE_FILESET: {
2,034✔
657
      code = vnodePreProcessSsMigrateFileSetReq(pVnode, pMsg);
2,034✔
658
    } break;
×
659
#endif
660
    default:
19,576,961✔
661
      break;
19,576,961✔
662
  }
663

664
  if (code && code != TSDB_CODE_MSG_PREPROCESSED) {
650,384,103✔
665
    vError("vgId:%d, failed to preprocess write request since %s, msg type:%s", TD_VID(pVnode), tstrerror(code),
79,671✔
666
           TMSG_INFO(pMsg->msgType));
667
  }
668
  return code;
650,382,076✔
669
}
670

671
static int32_t inline vnodeSubmitSubRowBlobData(SVnode *pVnode, SSubmitTbData *pSubmitTbData) {
21,726✔
672
  int32_t code = 0;
21,726✔
673
  int32_t lino = 0;
21,726✔
674

675
  int64_t   st = taosGetTimestampUs();
21,726✔
676
  SBlobSet *pBlobSet = pSubmitTbData->pBlobSet;
21,726✔
677
  int32_t   sz = taosArrayGetSize(pBlobSet->pSeqTable);
21,726✔
678

679
  SBseBatch *pBatch = NULL;
21,726✔
680

681
  code = bseBatchInit(pVnode->pBse, &pBatch, sz);
21,726✔
682
  TSDB_CHECK_CODE(code, lino, _exit);
21,726✔
683

684
  SRow  **pRow = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP);
21,726✔
685
  int32_t rowIdx = -1;
21,726✔
686
  for (int32_t i = 0; i < sz; i++) {
23,692,806✔
687
    int64_t     seq = 0;
23,671,080✔
688
    SBlobValue *p = taosArrayGet(pBlobSet->pSeqTable, i);
23,671,080✔
689
    if (p->type == TSDB_DATA_BLOB_EMPTY_VALUE || p->type == TSDB_DATA_BLOB_NULL_VALUE) {
23,671,080✔
690
      // skip empty or null blob
691
      continue;
2,378,064✔
692
    }
693

694
    code = bseBatchPut(pBatch, &seq, pBlobSet->data + p->offset, p->len);
21,293,016✔
695
    TSDB_CHECK_CODE(code, lino, _exit);
21,293,016✔
696

697
    SRow *row = taosArrayGetP(pSubmitTbData->aRowP, i);
21,293,016✔
698
    if (row == NULL) {
21,293,016✔
699
      int32_t tlen = taosArrayGetSize(pBlobSet->pSeqTable);
×
700
      uTrace("blob invalid row index:%d, sz:%d, pBlobSet size:%d", rowIdx, sz, tlen);
×
701
      break;
×
702
    }
703

704
    if (tPutU64(row->data + p->dataOffset, seq) < 0) {
42,586,032✔
705
      code = TSDB_CODE_INVALID_MSG;
×
706
      TSDB_CHECK_CODE(code, lino, _exit);
×
707
    }
708
  }
709

710
  code = bseCommitBatch(pVnode->pBse, pBatch);
21,726✔
711
  TSDB_CHECK_CODE(code, lino, _exit);
21,726✔
712

713
  int64_t cost = taosGetTimestampUs() - st;
21,726✔
714
  if (cost >= 500) {
21,726✔
715
    vDebug("vgId:%d, %s, cost:%" PRId64 "us, rows:%d, size:%" PRId64 "", TD_VID(pVnode), __func__, cost, sz,
7,514✔
716
           pBlobSet->len);
717
  }
718
_exit:
21,726✔
719
  if (code != 0) {
21,726✔
720
    vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
×
721
  }
722
  return code;
21,726✔
723
}
724

725
static int32_t inline vnodeSubmitSubColBlobData(SVnode *pVnode, SSubmitTbData *pSubmitTbData) {
×
726
  int32_t code = 0;
×
727
  int32_t lino = 0;
×
728

729
  int32_t   blobColIdx = 0;
×
730
  SColData *pBlobCol = NULL;
×
731
  int64_t   st = taosGetTimestampUs();
×
732
  SBlobSet *pBlobSet = pSubmitTbData->pBlobSet;
×
733
  int32_t   sz = taosArrayGetSize(pBlobSet->pSeqTable);
×
734

735
  SBseBatch *pBatch = NULL;
×
736

737
  code = bseBatchInit(pVnode->pBse, &pBatch, sz);
×
738
  TSDB_CHECK_CODE(code, lino, _exit);
×
739

740
  SColData *p = (SColData *)TARRAY_DATA(pSubmitTbData->aCol);
×
741
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitTbData->aCol); i++) {
×
742
    if (IS_STR_DATA_BLOB(p[i].type)) {
×
743
      pBlobCol = &p[i];
×
744
      break;
×
745
    }
746
  }
747
  if (pBlobCol == NULL) {
×
748
    vError("vgId:%d %s failed to find blob column in submit data", TD_VID(pVnode), __func__);
×
749
    code = TSDB_CODE_INVALID_MSG;
×
750
    goto _exit;
×
751
  }
752

753
  int32_t offset = 0;
×
754
  // int32_t   rowIdx = -1;
755
  for (int32_t i = 0; i < sz; i++) {
×
756
    int64_t     seq = 0;
×
757
    SBlobValue *p = taosArrayGet(pBlobSet->pSeqTable, i);
×
758
    if (p->type == TSDB_DATA_BLOB_EMPTY_VALUE || p->type == TSDB_DATA_BLOB_NULL_VALUE) {
×
759
      // skip empty or null blob
760
      continue;
×
761
    }
762
    code = bseBatchPut(pBatch, &seq, pBlobSet->data + p->offset, p->len);
×
763
    TSDB_CHECK_CODE(code, lino, _exit);
×
764

765
    memcpy(pBlobCol->pData + offset, (void *)&seq, BSE_SEQUECE_SIZE);
×
766
    offset += BSE_SEQUECE_SIZE;
×
767
  }
768

769
  code = bseCommitBatch(pVnode->pBse, pBatch);
×
770
  TSDB_CHECK_CODE(code, lino, _exit);
×
771

772
  int64_t cost = taosGetTimestampUs() - st;
×
773
  if (cost >= 500) {
×
774
    vDebug("vgId:%d, %s, cost:%" PRId64 "us, rows:%d, size:%" PRId64 "", TD_VID(pVnode), __func__, cost, sz,
×
775
           pBlobSet->len);
776
  }
777
_exit:
×
778
  if (code != 0) {
×
779
    vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
×
780
  }
781
  return code;
×
782
}
783
static int32_t inline vnodeSubmitBlobData(SVnode *pVnode, SSubmitTbData *pData) {
21,726✔
784
  int32_t code = 0;
21,726✔
785
  if (pData->flags & SUBMIT_REQ_WITH_BLOB) {
21,726✔
786
    if (pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
21,726✔
787
      code = vnodeSubmitSubColBlobData(pVnode, pData);
×
788
    } else {
789
      code = vnodeSubmitSubRowBlobData(pVnode, pData);
21,726✔
790
    }
791
  }
792

793
  return code;
21,726✔
794
}
795

796
int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg *pRsp) {
771,595,082✔
797
  int32_t code = 0;
771,595,082✔
798
  int32_t lino = 0;
771,595,082✔
799
  void   *ptr = NULL;
771,595,082✔
800
  void   *pReq;
801
  int32_t len;
802

803
  (void)taosThreadMutexLock(&pVnode->mutex);
771,595,082✔
804
  if (pVnode->disableWrite) {
771,646,978✔
805
    (void)taosThreadMutexUnlock(&pVnode->mutex);
×
806
    vError("vgId:%d write is disabled for snapshot, version:%" PRId64, TD_VID(pVnode), ver);
×
807
    return TSDB_CODE_VND_WRITE_DISABLED;
×
808
  }
809
  (void)taosThreadMutexUnlock(&pVnode->mutex);
771,607,356✔
810

811
  if (ver <= pVnode->state.applied) {
771,653,318✔
812
    vError("vgId:%d, duplicate write request. ver: %" PRId64 ", applied: %" PRId64, TD_VID(pVnode), ver,
×
813
           pVnode->state.applied);
814
    return terrno = TSDB_CODE_VND_DUP_REQUEST;
×
815
  }
816

817
  vGDebug(&pMsg->info.traceId,
771,593,524✔
818
          "vgId:%d, index:%" PRId64 ", process write request:%s, applied:%" PRId64 ", state.applyTerm:%" PRId64
819
          ", conn.applyTerm:%" PRId64 ", contLen:%d",
820
          TD_VID(pVnode), ver, TMSG_INFO(pMsg->msgType), pVnode->state.applied, pVnode->state.applyTerm,
821
          pMsg->info.conn.applyTerm, pMsg->contLen);
822

823
  if (!(pVnode->state.applyTerm <= pMsg->info.conn.applyTerm)) {
771,623,025✔
824
    vError("vgId:%d, applyTerm mismatch, expected: %" PRId64 ", received: %" PRId64, TD_VID(pVnode),
×
825
           pVnode->state.applyTerm, pMsg->info.conn.applyTerm);
826
    return terrno = TSDB_CODE_INTERNAL_ERROR;
×
827
  }
828

829
  if (!(pVnode->state.applied + 1 == ver)) {
771,654,408✔
830
    vError("vgId:%d, mountVgId:%d, ver mismatch, expected: %" PRId64 ", received: %" PRId64, TD_VID(pVnode),
×
831
           pVnode->config.mountVgId, pVnode->state.applied + 1, ver);
832
    return terrno = TSDB_CODE_INTERNAL_ERROR;
×
833
  }
834

835
  atomic_store_64(&pVnode->state.applied, ver);
771,652,697✔
836
  atomic_store_64(&pVnode->state.applyTerm, pMsg->info.conn.applyTerm);
771,655,003✔
837

838
  if (!syncUtilUserCommit(pMsg->msgType)) goto _exit;
771,655,266✔
839

840
  // skip header
841
  pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
761,608,597✔
842
  len = pMsg->contLen - sizeof(SMsgHead);
761,607,962✔
843
  bool needCommit = false;
761,607,504✔
844
  bool forceTrimWal = false;
761,607,504✔
845

846
  switch (pMsg->msgType) {
761,607,504✔
847
    /* META */
848
    case TDMT_VND_CREATE_STB:
5,013,487✔
849
      code = vnodeProcessCreateStbReq(pVnode, ver, pReq, len, pRsp);
5,013,487✔
850
      TSDB_CHECK_CODE(code, lino, _err);
5,014,479✔
851
      break;
5,011,587✔
852
    case TDMT_VND_ALTER_STB:
7,358,045✔
853
      code = vnodeProcessAlterStbReq(pVnode, ver, pReq, len, pRsp);
7,358,045✔
854
      TSDB_CHECK_CODE(code, lino, _err);
7,358,045✔
855
      break;
7,358,045✔
856
    case TDMT_VND_DROP_STB:
869,490✔
857
      code = vnodeProcessDropStbReq(pVnode, ver, pReq, len, pRsp, pMsg);
869,490✔
858
      TSDB_CHECK_CODE(code, lino, _err);
869,490✔
859
      break;
869,490✔
860
    case TDMT_VND_CREATE_TABLE:
40,627,684✔
861
      code = vnodeProcessCreateTbReq(pVnode, ver, pReq, len, pRsp, pMsg);
40,627,684✔
862
      TSDB_CHECK_CODE(code, lino, _err);
40,624,229✔
863
      break;
40,624,229✔
864
    case TDMT_VND_ALTER_TABLE:
11,770,197✔
865
      code = vnodeProcessAlterTbReq(pVnode, ver, pReq, len, pRsp);
11,770,197✔
866
      TSDB_CHECK_CODE(code, lino, _err);
11,770,197✔
867
      break;
11,770,197✔
868
    case TDMT_VND_DROP_TABLE:
1,317,242✔
869
    case TDMT_VND_SNODE_DROP_TABLE:
870
      code = vnodeProcessDropTbReq(pVnode, ver, pReq, len, pRsp, pMsg);
1,317,242✔
871
      TSDB_CHECK_CODE(code, lino, _err);
1,317,242✔
872
      break;
1,317,242✔
873
    case TDMT_VND_CREATE_RSMA:
21,750✔
874
      code = vnodeProcessCreateRsmaReq(pVnode, ver, pReq, len, pRsp);
21,750✔
875
      TSDB_CHECK_CODE(code, lino, _err);
21,750✔
876
      break;
21,750✔
877
    case TDMT_VND_DROP_RSMA:
4,350✔
878
      code = vnodeProcessDropRsmaReq(pVnode, ver, pReq, len, pRsp);
4,350✔
879
      TSDB_CHECK_CODE(code, lino, _err);
4,350✔
880
      break;
4,350✔
881
    case TDMT_VND_ALTER_RSMA:
11,600✔
882
      code = vnodeProcessAlterRsmaReq(pVnode, ver, pReq, len, pRsp);
11,600✔
883
      TSDB_CHECK_CODE(code, lino, _err);
11,600✔
884
      break;
11,600✔
885
    case TDMT_VND_DROP_TTL_TABLE:
×
886
      code = vnodeProcessDropTtlTbReq(pVnode, ver, pReq, len, pRsp);
×
887
      TSDB_CHECK_CODE(code, lino, _err);
×
888
      break;
×
889
    case TDMT_VND_FETCH_TTL_EXPIRED_TBS:
11,307✔
890
      code = vnodeProcessFetchTtlExpiredTbs(pVnode, ver, pReq, len, pRsp);
11,307✔
891
      TSDB_CHECK_CODE(code, lino, _err);
11,307✔
892
      break;
11,307✔
893
    case TDMT_VND_TRIM:
91,840✔
894
      code = vnodeProcessTrimReq(pVnode, ver, pReq, len, pRsp);
91,840✔
895
      TSDB_CHECK_CODE(code, lino, _err);
91,840✔
896
      break;
91,840✔
897
      case TDMT_VND_TRIM_WAL:
6,516✔
898
        needCommit = true;
6,516✔
899
        forceTrimWal = true;
6,516✔
900
        break;
6,516✔
901
#ifdef TD_ENTERPRISE
902
    case TDMT_VND_SSMIGRATE_FILESET:
×
903
      if (vnodeProcessSsMigrateFileSetReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
×
904
      break;
×
905
    case TDMT_VND_FOLLOWER_SSMIGRATE:
×
906
      if (vnodeProcessFollowerSsMigrateReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
×
907
      break;
×
908
    case TDMT_VND_KILL_SSMIGRATE:
×
909
      if (vnodeProcessKillSsMigrateReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
×
910
      break;
×
911
#endif
912

913
    /* TSDB */
914
    case TDMT_VND_SUBMIT: {
677,908,162✔
915
      METRICS_TIMING_BLOCK(pVnode->writeMetrics.apply_time, METRIC_LEVEL_LOW, {
677,908,162✔
916
        if (vnodeProcessSubmitReq(pVnode, ver, pMsg->pCont, pMsg->contLen, pRsp, pMsg) < 0) goto _err;
917
      });
918
      METRICS_UPDATE(pVnode->writeMetrics.apply_bytes, METRIC_LEVEL_LOW, (int64_t)pMsg->contLen);
677,870,704✔
919
      break;
677,870,631✔
920
    }
921
    case TDMT_VND_DELETE:
1,994,701✔
922
      code = vnodeProcessDeleteReq(pVnode, ver, pReq, len, pRsp, pMsg);
1,994,701✔
923
      TSDB_CHECK_CODE(code, lino, _err);
1,994,701✔
924
      break;
1,994,701✔
925
    case TDMT_VND_BATCH_DEL:
×
926
      code = vnodeProcessBatchDeleteReq(pVnode, ver, pReq, len, pRsp);
×
927
      TSDB_CHECK_CODE(code, lino, _err);
×
928
      break;
×
929
      /* TQ */
930
#if defined(USE_TQ) || defined(USE_STREAM)
931
    case TDMT_VND_TMQ_SUBSCRIBE:
1,232,130✔
932
      code = tqProcessSubscribeReq(pVnode->pTq, ver, pReq, len);
1,232,130✔
933
      TSDB_CHECK_CODE(code, lino, _err);
1,230,113✔
934
      break;
1,230,113✔
935
    case TDMT_VND_TMQ_DELETE_SUB:
282,855✔
936
      code = tqProcessDeleteSubReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen);
282,855✔
937
      TSDB_CHECK_CODE(code, lino, _err);
282,175✔
938
      break;
282,175✔
939
    case TDMT_VND_TMQ_COMMIT_OFFSET:
3,869,392✔
940
      code = tqProcessOffsetCommitReq(pVnode->pTq, ver, pReq, len);
3,869,392✔
941
      TSDB_CHECK_CODE(code, lino, _err);
3,869,392✔
942
      break;
3,869,392✔
943
#endif
944
    case TDMT_VND_ALTER_CONFIRM:
3,908,703✔
945
      needCommit = pVnode->config.hashChange;
3,908,703✔
946
      code = vnodeProcessAlterConfirmReq(pVnode, ver, pReq, len, pRsp);
3,908,703✔
947
      TSDB_CHECK_CODE(code, lino, _err);
3,908,703✔
948
      break;
3,908,703✔
949
    case TDMT_VND_ALTER_CONFIG:
306,966✔
950
      vnodeProcessAlterConfigReq(pVnode, ver, pReq, len, pRsp);
306,966✔
951
      break;
306,250✔
952
    case TDMT_VND_COMMIT:
4,898,682✔
953
      needCommit = true;
4,898,682✔
954
      break;
4,898,682✔
955
    case TDMT_VND_CREATE_INDEX:
4,380✔
956
      vnodeProcessCreateIndexReq(pVnode, ver, pReq, len, pRsp);
4,380✔
957
      break;
4,380✔
958
    case TDMT_VND_DROP_INDEX:
2,896✔
959
      vnodeProcessDropIndexReq(pVnode, ver, pReq, len, pRsp);
2,896✔
960
      break;
2,896✔
961
    case TDMT_VND_COMPACT:
62,901✔
962
      vnodeProcessCompactVnodeReq(pVnode, ver, pReq, len, pRsp);
62,901✔
963
      goto _exit;
62,901✔
964
    case TDMT_VND_SCAN:
215✔
965
      vnodeProcessScanVnodeReq(pVnode, ver, pReq, len, pRsp);
215✔
966
      goto _exit;
215✔
967
    case TDMT_SYNC_CONFIG_CHANGE:
×
968
      vnodeProcessConfigChangeReq(pVnode, ver, pReq, len, pRsp);
×
969
      break;
×
970
#ifdef TD_ENTERPRISE
971
    case TDMT_VND_KILL_COMPACT:
1,450✔
972
      vnodeProcessKillCompactReq(pVnode, ver, pReq, len, pRsp);
1,450✔
973
      break;
1,450✔
974
#endif
975
    case TDMT_VND_KILL_SCAN:
86✔
976
      vnodeProcessKillScanReq(pVnode, ver, pReq, len, pRsp);
86✔
977
      break;
86✔
978
    case TDMT_VND_KILL_TRIM:
×
979
      vnodeProcessKillRetentionReq(pVnode, ver, pReq, len, pRsp);
×
980
      break;
×
981
    /* ARB */
982
    case TDMT_VND_ARB_CHECK_SYNC:
29,137✔
983
      vnodeProcessArbCheckSyncReq(pVnode, pReq, len, pRsp);
29,137✔
984
      break;
29,137✔
985
    default:
×
986
      vError("vgId:%d, unprocessed msg, %d", TD_VID(pVnode), pMsg->msgType);
×
987
      return TSDB_CODE_INVALID_MSG;
×
988
  }
989

990
  vGDebug(&pMsg->info.traceId, "vgId:%d, index:%" PRId64 ", msg processed, code:0x%x", TD_VID(pVnode), ver, pRsp->code);
761,496,749✔
991

992
  walApplyVer(pVnode->pWal, ver);
761,507,503✔
993

994
  if (pVnode->pTq) {
761,509,525✔
995
    code = tqPushMsg(pVnode->pTq, pMsg->msgType);
761,509,525✔
996
    if (code) {
761,509,442✔
997
      vError("vgId:%d, failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno));
×
998
      return code;
×
999
    }
1000
  }
1001

1002
  // commit if need
1003
  if (needCommit) {
761,509,442✔
1004
    vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), ver);
4,929,659✔
1005
    code = vnodeAsyncCommit(pVnode, forceTrimWal);
4,929,659✔
1006
    if (code) {
4,929,659✔
1007
      vError("vgId:%d, failed to vnode async commit since %s.", TD_VID(pVnode), tstrerror(terrno));
×
1008
      goto _err;
×
1009
    }
1010

1011
    // start a new one
1012
    METRICS_TIMING_BLOCK(pVnode->writeMetrics.memtable_wait_time, METRIC_LEVEL_LOW, {
4,929,659✔
1013
      code = vnodeBegin(pVnode);
1014
      if (code) {
1015
        vError("vgId:%d, failed to begin vnode since %s.", TD_VID(pVnode), tstrerror(terrno));
1016
        goto _err;
1017
      }
1018
    });
1019
  }
1020

1021
_exit:
761,506,252✔
1022
  return 0;
771,614,503✔
1023

1024
_err:
35,373✔
1025
  if (code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
35,373✔
1026
    vInfo("vgId:%d, process %s request failed since %s, lino 1:%d ver:%" PRId64, TD_VID(pVnode),
2,892✔
1027
          TMSG_INFO(pMsg->msgType), tstrerror(code), lino, ver);
1028
  } else if (code) {
32,481✔
1029
    vError("vgId:%d, process %s request failed since %s, lino 2:%d ver:%" PRId64, TD_VID(pVnode),
×
1030
           TMSG_INFO(pMsg->msgType), tstrerror(code), lino, ver);
1031
  }
1032

1033
  return code;
35,373✔
1034
}
1035

1036
int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
339,325,542✔
1037
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) {
339,325,542✔
1038
    return 0;
78,313,659✔
1039
  }
1040

1041
  int32_t qType = 0;
261,035,462✔
1042
  return qWorkerPreprocessQueryMsg(pVnode->pQuery, pMsg, (TDMT_SCH_QUERY == pMsg->msgType), &qType);
261,023,244✔
1043
}
1044

1045
int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
339,359,536✔
1046
  const STraceId *trace = &pMsg->info.traceId;
339,359,536✔
1047
  vDebug("vgId:%d, msg:%s, %p in vnode query queue is processing, %" PRIx64 ":%" PRIx64, 
339,366,315✔
1048
    pVnode->config.vgId, TMSG_INFO(pMsg->msgType), pMsg, TRACE_GET_ROOTID(trace), TRACE_GET_MSGID(trace));
1049

1050
  if (pMsg->msgType == TDMT_VND_TMQ_CONSUME && !syncIsReadyForRead(pVnode->sync)) {
339,382,773✔
1051
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
426,962✔
1052
    return 0;
426,962✔
1053
  }
1054

1055
  if (pMsg->msgType == TDMT_VND_TMQ_CONSUME && !pVnode->restored) {
338,950,841✔
1056
    vnodeRedirectRpcMsg(pVnode, pMsg, TSDB_CODE_SYN_RESTORING);
×
1057
    return 0;
×
1058
  }
1059

1060
  SReadHandle handle = {0};
338,952,793✔
1061
  handle.vnode = pVnode;
338,952,657✔
1062
  handle.pMsgCb = &pVnode->msgCb;
338,952,657✔
1063
  handle.pWorkerCb = pInfo->workerCb;
338,928,747✔
1064
  initStorageAPI(&handle.api);
338,930,351✔
1065
  int32_t code = TSDB_CODE_SUCCESS;
338,931,495✔
1066
  bool    redirected = false;
338,931,495✔
1067

1068
  switch (pMsg->msgType) {
338,931,495✔
1069
    case TDMT_SCH_QUERY:
205,188,695✔
1070
      if (!syncIsReadyForRead(pVnode->sync)) {
205,188,695✔
1071
        pMsg->code = (terrno) ? terrno : TSDB_CODE_SYN_NOT_LEADER;
2,103,606✔
1072
        redirected = true;
2,103,606✔
1073
      }
1074
      code = qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
205,188,678✔
1075
      if (redirected) {
205,178,182✔
1076
        vnodeRedirectRpcMsg(pVnode, pMsg, pMsg->code);
2,103,606✔
1077
        return 0;
2,103,606✔
1078
      }
1079

1080
      return code;
203,074,576✔
1081
    case TDMT_SCH_MERGE_QUERY:
55,854,229✔
1082
      return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
55,854,229✔
1083
    case TDMT_SCH_QUERY_CONTINUE:
39,226,257✔
1084
      return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
39,226,257✔
1085
    case TDMT_VND_TMQ_CONSUME:
29,034,733✔
1086
      return tqProcessPollReq(pVnode->pTq, pMsg);
29,034,733✔
1087
    case TDMT_VND_TMQ_CONSUME_PUSH:
9,626,406✔
1088
      return tqProcessPollPush(pVnode->pTq);
9,626,406✔
1089
    default:
×
1090
      vError("unknown msg type:%d in query queue", pMsg->msgType);
×
1091
      return TSDB_CODE_APP_ERROR;
×
1092
  }
1093
}
1094

1095
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
731,357,047✔
1096
  int32_t code = TSDB_CODE_SUCCESS;
731,357,047✔
1097
  const STraceId *trace = &pMsg->info.traceId;
731,357,047✔
1098
  vDebug("vgId:%d, msg:%s, %p in fetch queue is processing, %" PRIx64 ":%" PRIx64, 
731,391,954✔
1099
    pVnode->config.vgId, TMSG_INFO(pMsg->msgType), pMsg, TRACE_GET_ROOTID(trace), TRACE_GET_MSGID(trace));
1100
  if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
731,509,826✔
1101
       pMsg->msgType == TDMT_VND_BATCH_META || pMsg->msgType == TDMT_VND_TABLE_NAME ||
497,123,099✔
1102
       pMsg->msgType == TDMT_VND_VSUBTABLES_META || pMsg->msgType == TDMT_VND_VSTB_REF_DBS) &&
470,688,778✔
1103
      !syncIsReadyForRead(pVnode->sync)) {
260,817,221✔
1104
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
606,225✔
1105
    return 0;
606,225✔
1106
  }
1107

1108
  switch (pMsg->msgType) {
730,908,041✔
1109
    case TDMT_SCH_FETCH:
310,116,197✔
1110
    case TDMT_SCH_MERGE_FETCH:
1111
      return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg, 0);
310,116,197✔
1112
    case TDMT_SCH_FETCH_RSP:
×
1113
      return qWorkerProcessRspMsg(pVnode, pVnode->pQuery, pMsg, 0);
×
1114
    // case TDMT_SCH_CANCEL_TASK:
1115
    //   return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg, 0);
1116
    case TDMT_SCH_DROP_TASK:
260,801,200✔
1117
      return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg, 0);
260,801,200✔
1118
    case TDMT_SCH_TASK_NOTIFY:
12,451✔
1119
      return qWorkerProcessNotifyMsg(pVnode, pVnode->pQuery, pMsg, 0);
12,451✔
1120
    case TDMT_SCH_QUERY_HEARTBEAT:
133,042,131✔
1121
      return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg, 0);
133,042,131✔
1122
    case TDMT_VND_TABLE_META:
874,261✔
1123
    case TDMT_VND_TABLE_NAME:
1124
      return vnodeGetTableMeta(pVnode, pMsg, true);
874,261✔
1125
    case TDMT_VND_TABLE_CFG:
×
1126
      return vnodeGetTableCfg(pVnode, pMsg, true);
×
1127
    case TDMT_VND_BATCH_META: {
25,820,278✔
1128
      METRICS_TIMING_BLOCK(pVnode->writeMetrics.fetch_batch_meta_time, METRIC_LEVEL_LOW,
25,820,278✔
1129
                           { code = vnodeGetBatchMeta(pVnode, pMsg); });
1130
      METRICS_UPDATE(pVnode->writeMetrics.fetch_batch_meta_count, METRIC_LEVEL_LOW, 1);
25,825,083✔
1131
      return code;
25,817,233✔
1132
    }
1133
    case TDMT_VND_VSUBTABLES_META:
×
1134
      return vnodeGetVSubtablesMeta(pVnode, pMsg);
×
1135
    case TDMT_VND_VSTB_REF_DBS:
×
1136
      return vnodeGetVStbRefDbs(pVnode, pMsg);
×
1137
    case TDMT_VND_QUERY_SCAN_PROGRESS:
430✔
1138
      return vnodeQueryScanProgress(pVnode, pMsg);
430✔
1139
#ifdef TD_ENTERPRISE
1140
    case TDMT_VND_QUERY_COMPACT_PROGRESS:
94,712✔
1141
      return vnodeQueryCompactProgress(pVnode, pMsg);
94,712✔
1142

1143
    case TDMT_VND_LIST_SSMIGRATE_FILESETS:
×
1144
      return vnodeListSsMigrateFileSets(pVnode, pMsg);
×
1145

1146
    case TDMT_VND_QUERY_SSMIGRATE_PROGRESS:
×
1147
      return vnodeQuerySsMigrateProgress(pVnode, pMsg);
×
1148
#endif
1149
    case TDMT_VND_QUERY_TRIM_PROGRESS:
130,145✔
1150
      return vnodeQueryRetentionProgress(pVnode, pMsg);
130,145✔
1151
      //    case TDMT_VND_TMQ_CONSUME:
1152
      //      return tqProcessPollReq(pVnode->pTq, pMsg);
1153
#ifdef USE_TQ
1154
    case TDMT_VND_TMQ_VG_WALINFO:
580✔
1155
      return tqProcessVgWalInfoReq(pVnode->pTq, pMsg);
580✔
1156
    case TDMT_VND_TMQ_VG_COMMITTEDINFO:
290✔
1157
      return tqProcessVgCommittedInfoReq(pVnode->pTq, pMsg);
290✔
1158
    case TDMT_VND_TMQ_SEEK:
1,160✔
1159
      return tqProcessSeekReq(pVnode->pTq, pMsg);
1,160✔
1160
#endif
1161
    default:
2,059✔
1162
      vError("unknown msg type:%d in fetch queue", pMsg->msgType);
2,059✔
1163
      return TSDB_CODE_APP_ERROR;
×
1164
  }
1165
}
1166

1167
void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) {
65,715,184✔
1168
  if (NULL == pMetaRsp) {
65,715,184✔
1169
    return;
×
1170
  }
1171

1172
  tstrncpy(pMetaRsp->dbFName, pVnode->config.dbname, TSDB_DB_FNAME_LEN);
65,715,184✔
1173
  pMetaRsp->dbId = pVnode->config.dbId;
65,715,290✔
1174
  pMetaRsp->vgId = TD_VID(pVnode);
65,715,785✔
1175
  pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
65,714,124✔
1176
}
1177

1178
extern int32_t vnodeAsyncRetention(SVnode *pVnode, STimeWindow tw, int8_t optrType, int8_t triggerType);
1179

1180
static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
91,840✔
1181
  if (!pVnode->restored) {
91,840✔
1182
    vInfo("vgId:%d, ignore trim req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
3,883✔
1183
    return 0;
3,883✔
1184
  }
1185

1186
  int32_t     code = 0;
87,957✔
1187
  SVTrimDbReq trimReq = {0};
87,957✔
1188

1189
  // decode
1190
  if (tDeserializeSVTrimDbReq(pReq, len, &trimReq) != 0) {
87,957✔
1191
    code = TSDB_CODE_INVALID_MSG;
×
1192
    goto _exit;
×
1193
  }
1194

1195
  vInfo("vgId:%d, process trim vnode request, time:%" PRIi64 ",%" PRIi64 ", optr:%d, trigger:%d", pVnode->config.vgId,
87,957✔
1196
        trimReq.tw.skey, trimReq.tw.ekey, (int32_t)trimReq.optrType, (int32_t)trimReq.triggerType);
1197

1198
  code = vnodeAsyncRetention(pVnode, trimReq.tw, (int8_t)trimReq.optrType, (int8_t)trimReq.triggerType);
87,957✔
1199

1200
_exit:
87,957✔
1201
  return code;
87,957✔
1202
}
1203

1204
extern int32_t vnodeAsyncSsMigrateFileSet(SVnode *pVnode, SSsMigrateFileSetReq *pReq);
1205

1206
extern int32_t vnodeAsyncS3Migrate(SVnode *pVnode, int64_t now);
1207

1208
static int32_t vnodeProcessSsMigrateFileSetReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
1209
  int32_t code = 0;
×
1210

1211
  SSsMigrateFileSetReq req = {0};
×
1212
  SSsMigrateFileSetRsp rsp = {0};
×
1213
  pRsp->msgType = TDMT_VND_SSMIGRATE_FILESET_RSP;
×
1214
  pRsp->code = 0;
×
1215
  pRsp->pCont = NULL;
×
1216
  pRsp->contLen = 0;
×
1217

1218
  if (tDeserializeSSsMigrateFileSetReq(pReq, len, &req) != 0) {
×
1219
    code = TSDB_CODE_INVALID_MSG;
×
1220
    goto _exit;
×
1221
  }
1222

1223
  vInfo("vgId:%d, ssmigrate:%d, fid:%d, process ssmigrate fileset request, time:%" PRId64, pVnode->config.vgId,
×
1224
        req.ssMigrateId, req.fid, req.startTimeSec);
1225
  rsp.ssMigrateId = req.ssMigrateId;
×
1226
  rsp.vgId = TD_VID(pVnode);
×
1227
  rsp.nodeId = req.nodeId;
×
1228
  rsp.fid = req.fid;
×
1229

1230
  code = vnodeAsyncSsMigrateFileSet(pVnode, &req);
×
1231
  if (code != TSDB_CODE_SUCCESS) {
×
1232
    vError("vgId:%d, failed to async ssmigrate since %s", TD_VID(pVnode), tstrerror(code));
×
1233
    pRsp->code = code;
×
1234
    goto _exit;
×
1235
  }
1236

1237
  pRsp->code = TSDB_CODE_SUCCESS;
×
1238
  pRsp->contLen = tSerializeSSsMigrateFileSetRsp(NULL, 0, &rsp);
×
1239
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
×
1240
  if (pRsp->pCont == NULL) {
×
1241
    vError("vgId:%d, failed to allocate memory for ssmigrate fileset response", TD_VID(pVnode));
×
1242
    code = TSDB_CODE_OUT_OF_MEMORY;
×
1243
    goto _exit;
×
1244
  }
1245
  TAOS_UNUSED(tSerializeSSsMigrateFileSetRsp(pRsp->pCont, pRsp->contLen, &rsp));
×
1246

1247
_exit:
×
1248
  pRsp->code = code;
×
1249
  return code;
×
1250
}
1251

1252
extern int32_t vnodeFollowerSsMigrate(SVnode *pVnode, SSsMigrateProgress *pReq);
1253

1254
static int32_t vnodeProcessFollowerSsMigrateReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
1255
  int32_t            code = 0;
×
1256
  SSsMigrateProgress req = {0};
×
1257

1258
  // decode
1259
  if (tDeserializeSSsMigrateProgress(pReq, len, &req) != 0) {
×
1260
    code = TSDB_CODE_INVALID_MSG;
×
1261
    goto _exit;
×
1262
  }
1263

1264
  code = vnodeFollowerSsMigrate(pVnode, &req);
×
1265

1266
_exit:
×
1267
  pRsp->code = code;
×
1268
  return code;
×
1269
}
1270

1271
extern int32_t vnodeKillSsMigrate(SVnode *pVnode, SVnodeKillSsMigrateReq *pReq);
1272

1273
static int32_t vnodeProcessKillSsMigrateReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
1274
  int32_t          code = 0;
×
1275
  SVnodeKillSsMigrateReq req = {0};
×
1276

1277
  // decode
1278
  if (tDeserializeSVnodeKillSsMigrateReq(pReq, len, &req) != 0) {
×
1279
    code = TSDB_CODE_INVALID_MSG;
×
1280
    goto _exit;
×
1281
  }
1282

1283
  code = vnodeKillSsMigrate(pVnode, &req);
×
1284

1285
_exit:
×
1286
  pRsp->code = code;
×
1287
  return code;
×
1288
}
1289

1290
static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
1291
  int               ret = 0;
×
1292
  SVDropTtlTableReq ttlReq = {0};
×
1293
  if (tDeserializeSVDropTtlTableReq(pReq, len, &ttlReq) != 0) {
×
1294
    ret = TSDB_CODE_INVALID_MSG;
×
1295
    goto end;
×
1296
  }
1297

1298
  if (ttlReq.nUids != taosArrayGetSize(ttlReq.pTbUids)) {
×
1299
    ret = TSDB_CODE_INVALID_MSG;
×
1300
    goto end;
×
1301
  }
1302

1303
  if (ttlReq.nUids != 0) {
×
1304
    vInfo("vgId:%d, process drop ttl table request, time:%d, ntbUids:%d", pVnode->config.vgId, ttlReq.timestampSec,
×
1305
          ttlReq.nUids);
1306
  }
1307

1308
  if (ttlReq.nUids > 0) {
×
1309
    int32_t code = metaDropMultipleTables(pVnode->pMeta, ver, ttlReq.pTbUids);
×
1310
    if (code) return code;
×
1311

1312
    code = tqDeleteTbUidList(pVnode->pTq, ttlReq.pTbUids);
×
1313
    if (code) {
×
1314
      vError("vgId:%d, failed to delete tbUid list since %s", TD_VID(pVnode), tstrerror(code));
×
1315
    }
1316
  }
1317

1318
end:
×
1319
  taosArrayDestroy(ttlReq.pTbUids);
×
1320
  return ret;
×
1321
}
1322

1323
static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
11,307✔
1324
  int32_t                 code = -1;
11,307✔
1325
  SMetaReader             mr = {0};
11,307✔
1326
  SVDropTtlTableReq       ttlReq = {0};
11,307✔
1327
  SVFetchTtlExpiredTbsRsp rsp = {0};
11,307✔
1328
  SEncoder                encoder = {0};
11,307✔
1329
  SArray                 *pNames = NULL;
11,307✔
1330
  pRsp->msgType = TDMT_VND_FETCH_TTL_EXPIRED_TBS_RSP;
11,307✔
1331
  pRsp->code = TSDB_CODE_SUCCESS;
11,307✔
1332
  pRsp->pCont = NULL;
11,307✔
1333
  pRsp->contLen = 0;
11,307✔
1334

1335
  if (tDeserializeSVDropTtlTableReq(pReq, len, &ttlReq) != 0) {
11,307✔
1336
    terrno = TSDB_CODE_INVALID_MSG;
×
1337
    goto _end;
×
1338
  }
1339

1340
  if (!(ttlReq.nUids == taosArrayGetSize(ttlReq.pTbUids))) {
11,307✔
1341
    terrno = TSDB_CODE_INVALID_MSG;
×
1342
    goto _end;
×
1343
  }
1344

1345
  tb_uid_t    suid;
1346
  char        ctbName[TSDB_TABLE_NAME_LEN];
1347
  SVDropTbReq expiredTb = {.igNotExists = true};
11,307✔
1348
  metaReaderDoInit(&mr, pVnode->pMeta, 0);
11,307✔
1349
  rsp.vgId = TD_VID(pVnode);
11,307✔
1350
  rsp.pExpiredTbs = taosArrayInit(ttlReq.nUids, sizeof(SVDropTbReq));
11,307✔
1351
  if (!rsp.pExpiredTbs) goto _end;
11,307✔
1352

1353
  pNames = taosArrayInit(ttlReq.nUids, TSDB_TABLE_NAME_LEN);
11,307✔
1354
  if (!pNames) {
11,307✔
1355
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1356
    goto _end;
×
1357
  }
1358
  char buf[TSDB_TABLE_NAME_LEN];
11,307✔
1359
  for (int32_t i = 0; i < ttlReq.nUids; ++i) {
57,787✔
1360
    tb_uid_t *uid = taosArrayGet(ttlReq.pTbUids, i);
46,480✔
1361
    expiredTb.suid = *uid;
46,480✔
1362
    terrno = metaReaderGetTableEntryByUid(&mr, *uid);
46,480✔
1363
    if (terrno < 0) goto _end;
46,480✔
1364
    tstrncpy(buf, mr.me.name, TSDB_TABLE_NAME_LEN);
46,480✔
1365
    void *p = taosArrayPush(pNames, buf);
46,480✔
1366
    if (p == NULL) {
46,480✔
1367
      goto _end;
×
1368
    }
1369

1370
    expiredTb.name = p;
46,480✔
1371
    if (mr.me.type == TSDB_CHILD_TABLE) {
46,480✔
1372
      expiredTb.suid = mr.me.ctbEntry.suid;
30,178✔
1373
    }
1374

1375
    if (taosArrayPush(rsp.pExpiredTbs, &expiredTb) == NULL) {
92,960✔
1376
      goto _end;
×
1377
    }
1378
  }
1379

1380
  int32_t ret = 0;
11,307✔
1381
  tEncodeSize(tEncodeVFetchTtlExpiredTbsRsp, &rsp, pRsp->contLen, ret);
11,307✔
1382
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
11,307✔
1383
  if (pRsp->pCont == NULL) {
11,307✔
1384
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1385
    code = -1;
×
1386
    goto _end;
×
1387
  }
1388
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
11,307✔
1389
  terrno = tEncodeVFetchTtlExpiredTbsRsp(&encoder, &rsp);
11,307✔
1390
  tEncoderClear(&encoder);
11,307✔
1391

1392
  if (terrno == 0) code = 0;
11,307✔
1393
_end:
11,307✔
1394
  metaReaderClear(&mr);
11,307✔
1395
  tFreeFetchTtlExpiredTbsRsp(&rsp);
11,307✔
1396
  taosArrayDestroy(ttlReq.pTbUids);
11,307✔
1397
  if (pNames) taosArrayDestroy(pNames);
11,307✔
1398
  pRsp->code = terrno;
11,307✔
1399
  return code;
11,307✔
1400
}
1401

1402
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
5,009,563✔
1403
  int32_t        code = 0;
5,009,563✔
1404
  SVCreateStbReq req = {0};
5,009,563✔
1405
  SDecoder       coder;
5,013,150✔
1406

1407
  pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
5,013,487✔
1408
  pRsp->code = TSDB_CODE_SUCCESS;
5,013,487✔
1409
  pRsp->pCont = NULL;
5,013,983✔
1410
  pRsp->contLen = 0;
5,013,311✔
1411

1412
  // decode and process req
1413
  tDecoderInit(&coder, pReq, len);
5,013,487✔
1414

1415
  code = tDecodeSVCreateStbReq(&coder, &req);
5,013,807✔
1416
  if (code) {
5,006,162✔
1417
    pRsp->code = code;
×
1418
    goto _err;
×
1419
  }
1420

1421
  code = metaCreateSuperTable(pVnode->pMeta, ver, &req);
5,006,162✔
1422
  if (code) {
5,014,479✔
1423
    pRsp->code = code;
2,892✔
1424
    goto _err;
2,892✔
1425
  }
1426

1427
  tDecoderClear(&coder);
5,011,587✔
1428
  return 0;
5,011,587✔
1429

1430
_err:
2,892✔
1431
  tDecoderClear(&coder);
2,892✔
1432
  return code;
2,892✔
1433
}
1434

1435
static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
40,627,683✔
1436
                                       SRpcMsg *pOriginRpc) {
1437
  SDecoder           decoder = {0};
40,627,683✔
1438
  SEncoder           encoder = {0};
40,627,684✔
1439
  int32_t            rcode = 0;
40,627,684✔
1440
  SVCreateTbBatchReq req = {0};
40,627,684✔
1441
  SVCreateTbReq     *pCreateReq;
1442
  SVCreateTbBatchRsp rsp = {0};
40,627,684✔
1443
  SVCreateTbRsp      cRsp = {0};
40,627,684✔
1444
  char               tbName[TSDB_TABLE_FNAME_LEN];
40,626,620✔
1445
  SArray            *tbUids = NULL;
40,627,684✔
1446
  SArray            *tbNames = NULL;
40,627,684✔
1447
  int64_t            tss = taosGetTimestampMs();
40,627,382✔
1448
  pRsp->msgType = TDMT_VND_CREATE_TABLE_RSP;
40,627,382✔
1449
  pRsp->code = TSDB_CODE_SUCCESS;
40,627,382✔
1450
  pRsp->pCont = NULL;
40,627,382✔
1451
  pRsp->contLen = 0;
40,627,382✔
1452

1453
  // decode
1454
  tDecoderInit(&decoder, pReq, len);
40,627,684✔
1455
  if (tDecodeSVCreateTbBatchReq(&decoder, &req) < 0) {
40,627,684✔
1456
    rcode = -1;
×
1457
    terrno = TSDB_CODE_INVALID_MSG;
×
1458
    goto _exit;
×
1459
  }
1460

1461
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(cRsp));
40,625,742✔
1462
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
40,626,483✔
1463
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
40,625,226✔
1464
  if (rsp.pArray == NULL || tbUids == NULL || tbNames == NULL) {
40,626,127✔
1465
    rcode = -1;
534✔
1466
    terrno = TSDB_CODE_OUT_OF_MEMORY;
534✔
1467
    goto _exit;
×
1468
  }
1469

1470
  // loop to create table
1471
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
88,264,215✔
1472
    pCreateReq = req.pReqs + iReq;
47,637,317✔
1473
    memset(&cRsp, 0, sizeof(cRsp));
47,636,049✔
1474

1475
    if (tsEnableAudit && tsEnableAuditCreateTable && tsAuditLevel >= AUDIT_LEVEL_CHILDTABLE) {
47,636,049✔
1476
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
57✔
1477
      if (str == NULL) {
57✔
1478
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1479
        rcode = -1;
×
1480
        goto _exit;
×
1481
      }
1482
      tstrncpy(str, pCreateReq->name, TSDB_TABLE_FNAME_LEN);
57✔
1483
      if (taosArrayPush(tbNames, &str) == NULL) {
57✔
1484
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1485
        rcode = -1;
×
1486
        goto _exit;
×
1487
      }
1488
    }
1489

1490
    // validate hash
1491
    (void)tsnprintf(tbName, TSDB_TABLE_FNAME_LEN, "%s.%s", pVnode->config.dbname, pCreateReq->name);
47,636,049✔
1492
    if (vnodeValidateTableHash(pVnode, tbName) < 0) {
47,637,316✔
1493
      cRsp.code = TSDB_CODE_VND_HASH_MISMATCH;
×
1494
      if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
×
1495
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1496
        rcode = -1;
×
1497
        goto _exit;
×
1498
      }
1499
      vError("vgId:%d create-table:%s failed due to hash value mismatch", TD_VID(pVnode), tbName);
×
1500
      continue;
×
1501
    }
1502

1503
    // do create table
1504
    if (metaCreateTable2(pVnode->pMeta, ver, pCreateReq, &cRsp.pMeta) < 0) {
47,631,805✔
1505
      if (pCreateReq->flags & TD_CREATE_IF_NOT_EXISTS && terrno == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
14,955✔
1506
        cRsp.code = TSDB_CODE_SUCCESS;
3,723✔
1507
      } else {
1508
        cRsp.code = terrno;
11,232✔
1509
      }
1510
    } else {
1511
      cRsp.code = TSDB_CODE_SUCCESS;
47,623,082✔
1512
      if (taosArrayPush(tbUids, &pCreateReq->uid) == NULL) {
95,247,288✔
1513
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1514
        rcode = -1;
×
1515
        goto _exit;
×
1516
      }
1517
      vnodeUpdateMetaRsp(pVnode, cRsp.pMeta);
47,624,206✔
1518
    }
1519

1520
    if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
95,276,290✔
1521
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1522
      rcode = -1;
×
1523
      goto _exit;
×
1524
    }
1525
  }
1526

1527
  vTrace("vgId:%d, add %d new created tables into query table list", TD_VID(pVnode), (int32_t)taosArrayGetSize(tbUids));
40,626,898✔
1528
  if (tqAddTbUidList(pVnode->pTq, tbUids) < 0) {
40,626,898✔
1529
    vError("vgId:%d, failed to add tbUid list since %s", TD_VID(pVnode), tstrerror(terrno));
×
1530
  }
1531

1532
  // prepare rsp
1533
  int32_t ret = 0;
40,627,289✔
1534
  tEncodeSize(tEncodeSVCreateTbBatchRsp, &rsp, pRsp->contLen, ret);
40,627,289✔
1535
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
40,626,879✔
1536
  if (pRsp->pCont == NULL) {
40,624,962✔
1537
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1538
    rcode = -1;
×
1539
    goto _exit;
×
1540
  }
1541
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
40,625,775✔
1542
  if (tEncodeSVCreateTbBatchRsp(&encoder, &rsp) != 0) {
40,624,441✔
1543
    vError("vgId:%d, failed to encode create table batch response", TD_VID(pVnode));
×
1544
  }
1545

1546
  if (tsEnableAudit && tsEnableAuditCreateTable && tsAuditLevel >= AUDIT_LEVEL_CHILDTABLE) {
40,625,651✔
1547
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
57✔
1548

1549
    SName name = {0};
57✔
1550
    if (tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB) < 0) {
57✔
1551
      vError("vgId:%d, failed to get name from string", TD_VID(pVnode));
×
1552
    }
1553

1554
    SStringBuilder sb = {0};
57✔
1555
    for (int32_t i = 0; i < tbNames->size; i++) {
114✔
1556
      char **key = (char **)taosArrayGet(tbNames, i);
57✔
1557
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
57✔
1558
      if (i < tbNames->size - 1) {
57✔
1559
        taosStringBuilderAppendChar(&sb, ',');
×
1560
      }
1561
      // taosMemoryFreeClear(*key);
1562
    }
1563

1564
    size_t len = 0;
57✔
1565
    char  *keyJoined = taosStringBuilderGetResult(&sb, &len);
57✔
1566

1567
    if (strlen(RPC_MSG_USER(pOriginRpc)) > 0) {
57✔
1568
      int64_t tse = taosGetTimestampMs();
57✔
1569
      double  duration = (double)(tse - tss);
57✔
1570
      duration = duration / 1000;
57✔
1571
      auditAddRecord(pOriginRpc, clusterId, "createTable", name.dbname, "", keyJoined, len, duration, 0);
57✔
1572
    }
1573

1574
    taosStringBuilderDestroy(&sb);
57✔
1575
  }
1576

1577
_exit:
40,625,651✔
1578
  tDeleteSVCreateTbBatchReq(&req);
40,625,957✔
1579
  taosArrayDestroyEx(rsp.pArray, tFreeSVCreateTbRsp);
40,625,291✔
1580
  taosArrayDestroy(tbUids);
40,621,121✔
1581
  tDecoderClear(&decoder);
40,621,410✔
1582
  tEncoderClear(&encoder);
40,626,066✔
1583
  taosArrayDestroyP(tbNames, NULL);
40,625,338✔
1584
  return rcode;
40,625,778✔
1585
}
1586

1587
static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
7,358,045✔
1588
  int32_t        code = 0;
7,358,045✔
1589
  SVCreateStbReq req = {0};
7,358,045✔
1590
  SDecoder       dc = {0};
7,358,045✔
1591

1592
  pRsp->msgType = TDMT_VND_ALTER_STB_RSP;
7,358,045✔
1593
  pRsp->code = TSDB_CODE_SUCCESS;
7,358,045✔
1594
  pRsp->pCont = NULL;
7,358,045✔
1595
  pRsp->contLen = 0;
7,358,045✔
1596

1597
  tDecoderInit(&dc, pReq, len);
7,358,045✔
1598

1599
  // decode req
1600
  code = tDecodeSVCreateStbReq(&dc, &req);
7,358,045✔
1601
  if (code) {
7,351,171✔
1602
    tDecoderClear(&dc);
×
1603
    return code;
×
1604
  }
1605

1606
  code = metaAlterSuperTable(pVnode->pMeta, ver, &req);
7,351,171✔
1607
  if (code) {
7,358,045✔
1608
    pRsp->code = code;
×
1609
    tDecoderClear(&dc);
×
1610
    return code;
×
1611
  }
1612

1613
  tDecoderClear(&dc);
7,358,045✔
1614

1615
  return 0;
7,358,045✔
1616
}
1617

1618
static int32_t vnodeProcessDropStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp, SRpcMsg *pOriginRpc) {
869,490✔
1619
  SVDropStbReq req = {0};
869,490✔
1620
  int32_t      rcode = TSDB_CODE_SUCCESS;
869,490✔
1621
  SDecoder     decoder = {0};
869,490✔
1622
  SArray      *tbUidList = NULL;
869,490✔
1623

1624
  pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
869,490✔
1625
  pRsp->pCont = NULL;
869,490✔
1626
  pRsp->contLen = 0;
869,490✔
1627

1628
  // decode request
1629
  tDecoderInit(&decoder, pReq, len);
869,490✔
1630
  if (tDecodeSVDropStbReq(&decoder, &req) < 0) {
869,490✔
1631
    rcode = TSDB_CODE_INVALID_MSG;
×
1632
    goto _exit;
×
1633
  }
1634

1635
  STraceId* trace = &(pOriginRpc->info.traceId);
869,490✔
1636

1637
  vInfo("vgId:%d, start to process vnode-drop-stb, QID:0x%" PRIx64 ":0x%" PRIx64 ", drop stb:%s", TD_VID(pVnode), trace ? trace->rootId : 0, 
869,490✔
1638
              trace ? trace->msgId : 0, req.name);
1639

1640
  // process request
1641
  tbUidList = taosArrayInit(8, sizeof(int64_t));
869,490✔
1642
  if (tbUidList == NULL) goto _exit;
869,490✔
1643
  if (metaDropSuperTable(pVnode->pMeta, ver, &req) < 0) {
869,490✔
1644
    rcode = terrno;
1,446✔
1645
    goto _exit;
1,446✔
1646
  }
1647

1648
  if (tqDeleteTbUidList(pVnode->pTq, tbUidList) < 0) {
868,044✔
1649
    rcode = terrno;
×
1650
    goto _exit;
×
1651
  }
1652

1653
  // return rsp
1654
_exit:
869,490✔
1655
  vInfo("vgId:%d, finished to process vnode-drop-stb, QID:0x%" PRIx64 ":0x%" PRIx64 ", drop stb:%s", TD_VID(pVnode), trace ? trace->rootId : 0, 
869,490✔
1656
              trace ? trace->msgId : 0, req.name);
1657
  if (tbUidList) taosArrayDestroy(tbUidList);
869,490✔
1658
  pRsp->code = rcode;
869,490✔
1659
  tDecoderClear(&decoder);
869,490✔
1660
  return 0;
869,490✔
1661
}
1662

1663
static void alterTagForTmq(SVnode *pVnode, SVAlterTbReq *vAlterTbReq) {
7,439,529✔
1664
  int32_t       code = 0;
7,439,529✔
1665
  int32_t       lino = 0;
7,439,529✔
1666
  SArray* tbUids = NULL;
7,439,529✔
1667
  SArray* cidList = NULL;
7,439,529✔
1668

1669
  int64_t uid = metaGetTableEntryUidByName(pVnode->pMeta, vAlterTbReq->tbName);
7,439,529✔
1670
  QUERY_CHECK_CONDITION(uid != 0, code, lino, end, TSDB_CODE_TDB_TABLE_NOT_EXIST);
7,439,529✔
1671
  
1672
  tbUids = taosArrayInit(4, sizeof(int64_t));
7,439,529✔
1673
  QUERY_CHECK_NULL(tbUids, code, lino, end, terrno);
7,439,529✔
1674

1675
  QUERY_CHECK_CONDITION(taosArrayPush(tbUids, &uid) != NULL, code, lino, end, terrno);
7,439,529✔
1676

1677
  cidList = taosArrayInit(4, sizeof(col_id_t));
7,439,529✔
1678
  QUERY_CHECK_NULL(cidList, code, lino, end, terrno);
7,439,529✔
1679

1680
  if (vAlterTbReq->action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL){
7,439,529✔
1681
    QUERY_CHECK_CONDITION(taosArrayPush(cidList, &vAlterTbReq->colId) != NULL, code, lino, end, terrno);
14,873,276✔
1682
  } else {
1683
    for (int32_t i = 0; i < taosArrayGetSize(vAlterTbReq->pMultiTag); i++) {
18,243✔
1684
      SMultiTagUpateVal *pTagVal = taosArrayGet(vAlterTbReq->pMultiTag, i);
15,352✔
1685
      QUERY_CHECK_NULL(pTagVal, code, lino, end, terrno);
15,352✔
1686
      QUERY_CHECK_CONDITION(taosArrayPush(cidList, &pTagVal->colId) != NULL, code, lino, end, terrno);
30,704✔
1687
    }
1688
  }
1689
  
1690
  vDebug("vgId:%d, try to add table:%s in query table list, cidList size:%"PRIzu, TD_VID(pVnode), vAlterTbReq->tbName, taosArrayGetSize(cidList));
7,439,529✔
1691
  code = tqUpdateTbUidList(pVnode->pTq, tbUids, cidList);
7,439,529✔
1692
  QUERY_CHECK_CODE(code, lino, end);
7,439,529✔
1693

1694
end:
7,439,529✔
1695
  if (code != 0) {
7,439,529✔
1696
    qError("vgId:%d, failed to alter table:%s since %s", TD_VID(pVnode), vAlterTbReq->tbName, tstrerror(code));
×
1697
  }
1698
  taosArrayDestroy(tbUids);
7,439,529✔
1699
  taosArrayDestroy(cidList);
7,439,529✔
1700
}
7,439,529✔
1701

1702
static int32_t vnodeProcessAlterTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
11,770,197✔
1703
  SVAlterTbReq  vAlterTbReq = {0};
11,770,197✔
1704
  SVAlterTbRsp  vAlterTbRsp = {0};
11,770,197✔
1705
  SDecoder      dc = {0};
11,770,197✔
1706
  int32_t       code = 0;
11,770,197✔
1707
  int32_t       lino = 0;
11,770,197✔
1708
  int32_t       ret;
1709
  SEncoder      ec = {0};
11,770,197✔
1710
  STableMetaRsp vMetaRsp = {0};
11,770,197✔
1711

1712
  pRsp->msgType = TDMT_VND_ALTER_TABLE_RSP;
11,770,197✔
1713
  pRsp->pCont = NULL;
11,770,197✔
1714
  pRsp->contLen = 0;
11,770,197✔
1715
  pRsp->code = TSDB_CODE_SUCCESS;
11,770,197✔
1716

1717
  tDecoderInit(&dc, pReq, len);
11,770,197✔
1718

1719
  // decode
1720
  if (tDecodeSVAlterTbReq(&dc, &vAlterTbReq) < 0) {
11,770,197✔
1721
    vAlterTbRsp.code = TSDB_CODE_INVALID_MSG;
×
1722
    tDecoderClear(&dc);
×
1723
    goto _exit;
×
1724
  }
1725

1726
  // process
1727
  if (metaAlterTable(pVnode->pMeta, ver, &vAlterTbReq, &vMetaRsp) < 0) {
11,770,197✔
1728
    vAlterTbRsp.code = terrno;
682,160✔
1729
    tDecoderClear(&dc);
682,160✔
1730
    goto _exit;
682,160✔
1731
  }
1732
  tDecoderClear(&dc);
11,088,037✔
1733

1734
  if (NULL != vMetaRsp.pSchemas) {
11,088,037✔
1735
    vnodeUpdateMetaRsp(pVnode, &vMetaRsp);
3,618,217✔
1736
    vAlterTbRsp.pMeta = &vMetaRsp;
3,618,217✔
1737
  }
1738

1739
  if (vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL || vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL) {
11,088,037✔
1740
    alterTagForTmq(pVnode, &vAlterTbReq);
7,439,529✔
1741
  }
1742

1743
_exit:
11,770,197✔
1744
  taosArrayDestroy(vAlterTbReq.pMultiTag);
11,770,197✔
1745
  tEncodeSize(tEncodeSVAlterTbRsp, &vAlterTbRsp, pRsp->contLen, ret);
11,770,197✔
1746
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
11,770,197✔
1747
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
11,770,197✔
1748
  if (tEncodeSVAlterTbRsp(&ec, &vAlterTbRsp) != 0) {
11,770,197✔
1749
    vError("vgId:%d, failed to encode alter table response", TD_VID(pVnode));
×
1750
  }
1751

1752
  tEncoderClear(&ec);
11,770,197✔
1753
  if (vMetaRsp.pSchemas) {
11,770,197✔
1754
    taosMemoryFree(vMetaRsp.pSchemas);
3,618,217✔
1755
    taosMemoryFree(vMetaRsp.pSchemaExt);
3,618,217✔
1756
  }
1757
  if (vMetaRsp.pColRefs) {
11,770,197✔
1758
    taosMemoryFree(vMetaRsp.pColRefs);
256,251✔
1759
  }
1760
  return 0;
11,770,197✔
1761
}
1762

1763
static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
1,317,242✔
1764
                                     SRpcMsg *pOriginRpc) {
1765
  SVDropTbBatchReq req = {0};
1,317,242✔
1766
  SVDropTbBatchRsp rsp = {0};
1,317,242✔
1767
  SDecoder         decoder = {0};
1,317,242✔
1768
  SEncoder         encoder = {0};
1,317,242✔
1769
  int32_t          ret;
1770
  SArray          *tbUids = NULL;
1,317,242✔
1771
  SArray          *tbNames = NULL;
1,317,242✔
1772
  int64_t          tss = taosGetTimestampMs();
1,317,242✔
1773

1774
  pRsp->msgType = ((SRpcMsg *)pReq)->msgType + 1;
1,317,242✔
1775
  pRsp->pCont = NULL;
1,317,242✔
1776
  pRsp->contLen = 0;
1,317,242✔
1777
  pRsp->code = TSDB_CODE_SUCCESS;
1,317,242✔
1778

1779
  // decode req
1780
  tDecoderInit(&decoder, pReq, len);
1,317,242✔
1781
  ret = tDecodeSVDropTbBatchReq(&decoder, &req);
1,317,242✔
1782
  if (ret < 0) {
1,317,242✔
1783
    terrno = TSDB_CODE_INVALID_MSG;
×
1784
    pRsp->code = terrno;
×
1785
    goto _exit;
×
1786
  }
1787

1788
  // process req
1789
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
1,317,242✔
1790
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(SVDropTbRsp));
1,317,242✔
1791
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
1,317,242✔
1792
  if (tbUids == NULL || rsp.pArray == NULL || tbNames == NULL) goto _exit;
1,317,242✔
1793

1794
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
2,681,343✔
1795
    SVDropTbReq *pDropTbReq = req.pReqs + iReq;
1,364,101✔
1796
    SVDropTbRsp  dropTbRsp = {0};
1,364,101✔
1797
    tb_uid_t     tbUid = 0;
1,364,101✔
1798

1799
    /* code */
1800
    ret = metaDropTable2(pVnode->pMeta, ver, pDropTbReq);
1,364,101✔
1801
    if (ret < 0) {
1,364,101✔
1802
      if (pDropTbReq->igNotExists && terrno == TSDB_CODE_TDB_TABLE_NOT_EXIST) {
×
1803
        dropTbRsp.code = TSDB_CODE_SUCCESS;
×
1804
      } else {
1805
        dropTbRsp.code = terrno;
×
1806
      }
1807
    } else {
1808
      dropTbRsp.code = TSDB_CODE_SUCCESS;
1,364,101✔
1809
    }
1810

1811
    if (taosArrayPush(rsp.pArray, &dropTbRsp) == NULL) {
2,728,202✔
1812
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1813
      pRsp->code = terrno;
×
1814
      goto _exit;
×
1815
    }
1816

1817
    if (tsEnableAudit && tsEnableAuditCreateTable && tsAuditLevel >= AUDIT_LEVEL_CHILDTABLE) {
1,364,101✔
1818
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
×
1819
      if (str == NULL) {
×
1820
        pRsp->code = terrno;
×
1821
        goto _exit;
×
1822
      }
1823
      tstrncpy(str, pDropTbReq->name, TSDB_TABLE_FNAME_LEN);
×
1824
      if (taosArrayPush(tbNames, &str) == NULL) {
×
1825
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1826
        pRsp->code = terrno;
×
1827
        goto _exit;
×
1828
      }
1829
    }
1830
  }
1831

1832
  if (tqDeleteTbUidList(pVnode->pTq, tbUids) < 0) {
1,317,242✔
1833
    vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(terrno));
×
1834
  }
1835

1836
  if (tsEnableAudit && tsEnableAuditCreateTable && tsAuditLevel >= AUDIT_LEVEL_CHILDTABLE) {
1,317,242✔
1837
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
×
1838

1839
    SName name = {0};
×
1840
    if (tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB) != 0) {
×
1841
      vError("vgId:%d, failed to get name from string", TD_VID(pVnode));
×
1842
    }
1843

1844
    SStringBuilder sb = {0};
×
1845
    for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
×
1846
      char **key = (char **)taosArrayGet(tbNames, iReq);
×
1847
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
×
1848
      if (iReq < req.nReqs - 1) {
×
1849
        taosStringBuilderAppendChar(&sb, ',');
×
1850
      }
1851
      taosMemoryFreeClear(*key);
×
1852
    }
1853

1854
    size_t len = 0;
×
1855
    char  *keyJoined = taosStringBuilderGetResult(&sb, &len);
×
1856

1857
    if (strlen(RPC_MSG_USER(pOriginRpc)) > 0) {
×
1858
      int64_t tse = taosGetTimestampMs();
×
1859
      double  duration = (double)(tse - tss);
×
1860
      duration = duration / 1000;
×
1861
      auditAddRecord(pOriginRpc, clusterId, "dropTable", name.dbname, "", keyJoined, len, duration, 0);
×
1862
    }
1863

1864
    taosStringBuilderDestroy(&sb);
×
1865
  }
1866

1867
_exit:
1,317,242✔
1868
  taosArrayDestroy(tbUids);
1,317,242✔
1869
  tDecoderClear(&decoder);
1,317,242✔
1870
  tEncodeSize(tEncodeSVDropTbBatchRsp, &rsp, pRsp->contLen, ret);
1,317,242✔
1871
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
1,317,242✔
1872
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
1,317,242✔
1873
  if (tEncodeSVDropTbBatchRsp(&encoder, &rsp) != 0) {
1,317,242✔
1874
    vError("vgId:%d, failed to encode drop table batch response", TD_VID(pVnode));
×
1875
  }
1876
  tEncoderClear(&encoder);
1,317,242✔
1877
  taosArrayDestroy(rsp.pArray);
1,317,242✔
1878
  taosArrayDestroy(tbNames);
1,317,242✔
1879
  return 0;
1,317,242✔
1880
}
1881

1882
static int32_t vnodeProcessCreateRsmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
21,750✔
1883
  int32_t         code = 0, lino = 0;
21,750✔
1884
  SVCreateRsmaReq req = {0};
21,750✔
1885
  TAOS_CHECK_EXIT(tDeserializeSVCreateRsmaReq(pReq, len, &req));
21,750✔
1886
  TAOS_CHECK_EXIT(metaCreateRsma(pVnode->pMeta, ver, &req));
21,750✔
1887
_exit:
21,750✔
1888
  pRsp->msgType = TDMT_VND_CREATE_RSMA_RSP;
21,750✔
1889
  pRsp->pCont = NULL;
21,750✔
1890
  pRsp->code = code;
21,750✔
1891
  pRsp->contLen = 0;
21,750✔
1892
  tFreeSVCreateRsmaReq(&req);
21,750✔
1893
  return code;
21,750✔
1894
}
1895

1896
static int32_t vnodeProcessDropRsmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
4,350✔
1897
  int32_t       code = 0, lino = 0;
4,350✔
1898
  SVDropRsmaReq req = {0};
4,350✔
1899
  TAOS_CHECK_EXIT(tDeserializeSVDropRsmaReq(pReq, len, &req));
4,350✔
1900
  TAOS_CHECK_EXIT(metaDropRsma(pVnode->pMeta, ver, &req));
4,350✔
1901
_exit:
4,350✔
1902
  pRsp->msgType = TDMT_VND_DROP_RSMA_RSP;
4,350✔
1903
  pRsp->pCont = NULL;
4,350✔
1904
  pRsp->code = code;
4,350✔
1905
  pRsp->contLen = 0;
4,350✔
1906
  return 0;
4,350✔
1907
}
1908

1909
static int32_t vnodeProcessAlterRsmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
11,600✔
1910
  int32_t         code = 0, lino = 0;
11,600✔
1911
  SVAlterRsmaReq req = {0};
11,600✔
1912
  TAOS_CHECK_EXIT(tDeserializeSVAlterRsmaReq(pReq, len, &req));
11,600✔
1913
  TAOS_CHECK_EXIT(metaAlterRsma(pVnode->pMeta, ver, &req));
11,600✔
1914
_exit:
11,600✔
1915
  pRsp->msgType = TDMT_VND_ALTER_RSMA_RSP;
11,600✔
1916
  pRsp->pCont = NULL;
11,600✔
1917
  pRsp->code = code;
11,600✔
1918
  pRsp->contLen = 0;
11,600✔
1919
  tFreeSVAlterRsmaReq(&req);
11,600✔
1920
  return code;
11,600✔
1921
}
1922

1923
#ifdef BUILD_NO_CALL
1924
static int32_t vnodeDebugPrintSingleSubmitMsg(SMeta *pMeta, SSubmitBlk *pBlock, SSubmitMsgIter *msgIter,
1925
                                              const char *tags) {
1926
  SSubmitBlkIter blkIter = {0};
1927
  STSchema      *pSchema = NULL;
1928
  tb_uid_t       suid = 0;
1929
  STSRow        *row = NULL;
1930
  int32_t        rv = -1;
1931

1932
  tInitSubmitBlkIter(msgIter, pBlock, &blkIter);
1933
  if (blkIter.row == NULL) return 0;
1934

1935
  int32_t code = metaGetTbTSchemaNotNull(pMeta, msgIter->suid, TD_ROW_SVER(blkIter.row), 1,
1936
                                         &pSchema);  // TODO: use the real schema
1937
  if (TSDB_CODE_SUCCESS != code) {
1938
    printf("%s:%d no valid schema\n", tags, __LINE__);
1939
    return code;
1940
  }
1941

1942
  suid = msgIter->suid;
1943
  rv = TD_ROW_SVER(blkIter.row);
1944

1945
  char __tags[128] = {0};
1946
  snprintf(__tags, 128, "%s: uid %" PRIi64 " ", tags, msgIter->uid);
1947
  while ((row = tGetSubmitBlkNext(&blkIter))) {
1948
    tdSRowPrint(row, pSchema, __tags);
1949
  }
1950

1951
  taosMemoryFreeClear(pSchema);
1952

1953
  return TSDB_CODE_SUCCESS;
1954
}
1955
#endif
1956
typedef struct SSubmitReqConvertCxt {
1957
  SSubmitMsgIter msgIter;
1958
  SSubmitBlk    *pBlock;
1959
  SSubmitBlkIter blkIter;
1960
  STSRow        *pRow;
1961
  STSRowIter     rowIter;
1962
  SSubmitTbData *pTbData;
1963
  STSchema      *pTbSchema;
1964
  SArray        *pColValues;
1965
} SSubmitReqConvertCxt;
1966

1967
static int32_t vnodeResetTableCxt(SMeta *pMeta, SSubmitReqConvertCxt *pCxt) {
×
1968
  taosMemoryFreeClear(pCxt->pTbSchema);
×
1969
  int32_t code = metaGetTbTSchemaNotNull(pMeta, pCxt->msgIter.suid > 0 ? pCxt->msgIter.suid : pCxt->msgIter.uid,
×
1970
                                         pCxt->msgIter.sversion, 1, &pCxt->pTbSchema);
1971
  if (TSDB_CODE_SUCCESS != code) {
×
1972
    return code;
×
1973
  }
1974
  tdSTSRowIterInit(&pCxt->rowIter, pCxt->pTbSchema);
×
1975

1976
  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
×
1977
  if (NULL == pCxt->pTbData) {
×
1978
    pCxt->pTbData = taosMemoryCalloc(1, sizeof(SSubmitTbData));
×
1979
    if (NULL == pCxt->pTbData) {
×
1980
      return terrno;
×
1981
    }
1982
  }
1983
  pCxt->pTbData->flags = 0;
×
1984
  pCxt->pTbData->suid = pCxt->msgIter.suid;
×
1985
  pCxt->pTbData->uid = pCxt->msgIter.uid;
×
1986
  pCxt->pTbData->sver = pCxt->msgIter.sversion;
×
1987
  pCxt->pTbData->pCreateTbReq = NULL;
×
1988
  pCxt->pTbData->aRowP = taosArrayInit(128, POINTER_BYTES);
×
1989
  if (NULL == pCxt->pTbData->aRowP) {
×
1990
    return terrno;
×
1991
  }
1992

1993
  taosArrayDestroy(pCxt->pColValues);
×
1994
  pCxt->pColValues = taosArrayInit(pCxt->pTbSchema->numOfCols, sizeof(SColVal));
×
1995
  if (NULL == pCxt->pColValues) {
×
1996
    return terrno;
×
1997
  }
1998
  for (int32_t i = 0; i < pCxt->pTbSchema->numOfCols; ++i) {
×
1999
    SColVal val = COL_VAL_NONE(pCxt->pTbSchema->columns[i].colId, pCxt->pTbSchema->columns[i].type);
×
2000
    if (taosArrayPush(pCxt->pColValues, &val) == NULL) {
×
2001
      return terrno;
×
2002
    }
2003
  }
2004

2005
  return TSDB_CODE_SUCCESS;
×
2006
}
2007

2008
static void vnodeDestroySubmitReqConvertCxt(SSubmitReqConvertCxt *pCxt) {
×
2009
  taosMemoryFreeClear(pCxt->pTbSchema);
×
2010
  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
×
2011
  taosMemoryFreeClear(pCxt->pTbData);
×
2012
  taosArrayDestroy(pCxt->pColValues);
×
2013
}
×
2014

2015
static int32_t vnodeCellValConvertToColVal(STColumn *pCol, SCellVal *pCellVal, SColVal *pColVal) {
×
2016
  if (tdValTypeIsNone(pCellVal->valType)) {
×
2017
    pColVal->flag = CV_FLAG_NONE;
×
2018
    return TSDB_CODE_SUCCESS;
×
2019
  }
2020

2021
  if (tdValTypeIsNull(pCellVal->valType)) {
×
2022
    pColVal->flag = CV_FLAG_NULL;
×
2023
    return TSDB_CODE_SUCCESS;
×
2024
  }
2025

2026
  if (IS_VAR_DATA_TYPE(pCol->type)) {
×
2027
    if (IS_STR_DATA_BLOB(pCol->type)) {
×
2028
      pColVal->value.nData = blobDataLen(pCellVal->val);
×
2029
      pColVal->value.pData = (uint8_t *)blobDataVal(pCellVal->val);
×
2030

2031
    } else {
2032
      pColVal->value.nData = varDataLen(pCellVal->val);
×
2033
      pColVal->value.pData = (uint8_t *)varDataVal(pCellVal->val);
×
2034
    }
2035
  } else if (TSDB_DATA_TYPE_FLOAT == pCol->type) {
×
2036
    float f = GET_FLOAT_VAL(pCellVal->val);
×
2037
    valueSetDatum(&pColVal->value, pCol->type, &f, sizeof(f));
×
2038
  } else if (TSDB_DATA_TYPE_DOUBLE == pCol->type) {
×
2039
    taosSetPInt64Aligned(&pColVal->value.val, (int64_t *)pCellVal->val);
×
2040
  } else {
2041
    valueSetDatum(&pColVal->value, pCol->type, pCellVal->val, tDataTypes[pCol->type].bytes);
×
2042
  }
2043

2044
  pColVal->flag = CV_FLAG_VALUE;
×
2045
  return TSDB_CODE_SUCCESS;
×
2046
}
2047

2048
static int32_t vnodeTSRowConvertToColValArray(SSubmitReqConvertCxt *pCxt) {
×
2049
  int32_t code = TSDB_CODE_SUCCESS;
×
2050
  tdSTSRowIterReset(&pCxt->rowIter, pCxt->pRow);
×
2051
  for (int32_t i = 0; TSDB_CODE_SUCCESS == code && i < pCxt->pTbSchema->numOfCols; ++i) {
×
2052
    STColumn *pCol = pCxt->pTbSchema->columns + i;
×
2053
    SCellVal  cellVal = {0};
×
2054
    if (!tdSTSRowIterFetch(&pCxt->rowIter, pCol->colId, pCol->type, &cellVal)) {
×
2055
      break;
×
2056
    }
2057
    code = vnodeCellValConvertToColVal(pCol, &cellVal, (SColVal *)taosArrayGet(pCxt->pColValues, i));
×
2058
  }
2059
  return code;
×
2060
}
2061

2062
static int32_t vnodeDecodeCreateTbReq(SSubmitReqConvertCxt *pCxt) {
×
2063
  if (pCxt->msgIter.schemaLen <= 0) {
×
2064
    return TSDB_CODE_SUCCESS;
×
2065
  }
2066

2067
  pCxt->pTbData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
×
2068
  if (NULL == pCxt->pTbData->pCreateTbReq) {
×
2069
    return terrno;
×
2070
  }
2071

2072
  SDecoder decoder = {0};
×
2073
  tDecoderInit(&decoder, (uint8_t *)pCxt->pBlock->data, pCxt->msgIter.schemaLen);
×
2074
  int32_t code = tDecodeSVCreateTbReq(&decoder, pCxt->pTbData->pCreateTbReq);
×
2075
  tDecoderClear(&decoder);
×
2076

2077
  return code;
×
2078
}
2079

2080
static int32_t vnodeSubmitReqConvertToSubmitReq2(SVnode *pVnode, SSubmitReq *pReq, SSubmitReq2 *pReq2) {
×
2081
  pReq2->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData));
×
2082
  if (NULL == pReq2->aSubmitTbData) {
×
2083
    return terrno;
×
2084
  }
2085

2086
  SSubmitReqConvertCxt cxt = {0};
×
2087

2088
  int32_t code = tInitSubmitMsgIter(pReq, &cxt.msgIter);
×
2089
  while (TSDB_CODE_SUCCESS == code) {
×
2090
    code = tGetSubmitMsgNext(&cxt.msgIter, &cxt.pBlock);
×
2091
    if (TSDB_CODE_SUCCESS == code) {
×
2092
      if (NULL == cxt.pBlock) {
×
2093
        break;
×
2094
      }
2095
      code = vnodeResetTableCxt(pVnode->pMeta, &cxt);
×
2096
    }
2097
    if (TSDB_CODE_SUCCESS == code) {
×
2098
      code = tInitSubmitBlkIter(&cxt.msgIter, cxt.pBlock, &cxt.blkIter);
×
2099
    }
2100
    if (TSDB_CODE_SUCCESS == code) {
×
2101
      code = vnodeDecodeCreateTbReq(&cxt);
×
2102
    }
2103
    while (TSDB_CODE_SUCCESS == code && (cxt.pRow = tGetSubmitBlkNext(&cxt.blkIter)) != NULL) {
×
2104
      code = vnodeTSRowConvertToColValArray(&cxt);
×
2105
      if (TSDB_CODE_SUCCESS == code) {
×
2106
        SRow **pNewRow = taosArrayReserve(cxt.pTbData->aRowP, 1);
×
2107

2108
        SRowBuildScanInfo sinfo = {0};
×
2109
        code = tRowBuild(cxt.pColValues, cxt.pTbSchema, pNewRow, &sinfo);
×
2110
      }
2111
    }
2112
    if (TSDB_CODE_SUCCESS == code) {
×
2113
      code = (NULL == taosArrayPush(pReq2->aSubmitTbData, cxt.pTbData) ? terrno : TSDB_CODE_SUCCESS);
×
2114
    }
2115
    if (TSDB_CODE_SUCCESS == code) {
×
2116
      taosMemoryFreeClear(cxt.pTbData);
×
2117
    }
2118
  }
2119

2120
  vnodeDestroySubmitReqConvertCxt(&cxt);
×
2121
  return code;
×
2122
}
2123

2124
static int32_t vnodeRebuildSubmitReqMsg(SSubmitReq2 *pSubmitReq, void **ppMsg) {
×
2125
  int32_t  code = TSDB_CODE_SUCCESS;
×
2126
  char    *pMsg = NULL;
×
2127
  uint32_t msglen = 0;
×
2128
  tEncodeSize(tEncodeSubmitReq, pSubmitReq, msglen, code);
×
2129
  if (TSDB_CODE_SUCCESS == code) {
×
2130
    pMsg = taosMemoryMalloc(msglen);
×
2131
    if (NULL == pMsg) {
×
2132
      code = terrno;
×
2133
    }
2134
  }
2135
  if (TSDB_CODE_SUCCESS == code) {
×
2136
    SEncoder encoder;
×
2137
    tEncoderInit(&encoder, (uint8_t *)pMsg, msglen);
×
2138
    code = tEncodeSubmitReq(&encoder, pSubmitReq);
×
2139
    tEncoderClear(&encoder);
×
2140
  }
2141
  if (TSDB_CODE_SUCCESS == code) {
×
2142
    *ppMsg = pMsg;
×
2143
  }
2144
  return code;
×
2145
}
2146

2147
static int32_t buildExistSubTalbeRsp(SVnode *pVnode, SSubmitTbData *pSubmitTbData, STableMetaRsp **ppRsp) {
60,140✔
2148
  int32_t code = 0;
60,140✔
2149
  int32_t lino = 0;
60,140✔
2150

2151
  SMetaEntry *pEntry = NULL;
60,140✔
2152
  code = metaFetchEntryByUid(pVnode->pMeta, pSubmitTbData->suid, &pEntry);
60,140✔
2153
  if (code) {
60,140✔
2154
    vError("vgId:%d, table uid:%" PRId64 " not exists, line:%d", TD_VID(pVnode), pSubmitTbData->uid, __LINE__);
×
2155
    TSDB_CHECK_CODE(code, lino, _exit);
×
2156
  }
2157
  if (pEntry->type != TSDB_SUPER_TABLE) {
60,140✔
2158
    vError("vgId:%d, table uid:%" PRId64 " exists, but is not super table, line:%d", TD_VID(pVnode), pSubmitTbData->uid,
×
2159
           __LINE__);
2160
    code = TSDB_CODE_STREAM_INSERT_SCHEMA_NOT_MATCH;
×
2161
    TSDB_CHECK_CODE(code, lino, _exit);
×
2162
  }
2163

2164
  *ppRsp = taosMemoryCalloc(1, sizeof(STableMetaRsp));
60,140✔
2165
  if (NULL == *ppRsp) {
60,140✔
2166
    TSDB_CHECK_CODE(code = terrno, lino, _exit);
×
2167
  }
2168
  (*ppRsp)->suid = pSubmitTbData->suid;
60,140✔
2169
  (*ppRsp)->tuid = pSubmitTbData->uid;
60,140✔
2170
  (*ppRsp)->sversion = pEntry->stbEntry.schemaRow.version;
60,140✔
2171
  (*ppRsp)->vgId = pVnode->config.vgId;
60,140✔
2172
  (*ppRsp)->numOfColumns = pEntry->stbEntry.schemaRow.nCols;
60,140✔
2173
  (*ppRsp)->numOfTags = pEntry->stbEntry.schemaTag.nCols;
60,140✔
2174
  (*ppRsp)->pSchemas =
60,140✔
2175
      taosMemoryCalloc(pEntry->stbEntry.schemaRow.nCols + pEntry->stbEntry.schemaTag.nCols, sizeof(SSchema));
60,140✔
2176
  if (NULL == (*ppRsp)->pSchemas) {
60,140✔
2177
    taosMemoryFree(*ppRsp);
×
2178
    *ppRsp = NULL;
×
2179
    TSDB_CHECK_CODE(code = terrno, lino, _exit);
×
2180
  }
2181
  memcpy((*ppRsp)->pSchemas, pEntry->stbEntry.schemaRow.pSchema, pEntry->stbEntry.schemaRow.nCols * sizeof(SSchema));
60,140✔
2182
  memcpy((*ppRsp)->pSchemas + pEntry->stbEntry.schemaRow.nCols, pEntry->stbEntry.schemaTag.pSchema,
60,140✔
2183
         pEntry->stbEntry.schemaTag.nCols * sizeof(SSchema));
60,140✔
2184
  if (pEntry->pExtSchemas != NULL) {
60,140✔
2185
    (*ppRsp)->pSchemaExt = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
×
2186
    if (NULL == (*ppRsp)->pSchemaExt) {
×
2187
      taosMemoryFree((*ppRsp)->pSchemas);
×
2188
      taosMemoryFree(*ppRsp);
×
2189
      *ppRsp = NULL;
×
2190
      TSDB_CHECK_CODE(code = terrno, lino, _exit);
×
2191
    }
2192
    memcpy((*ppRsp)->pSchemaExt, pEntry->pExtSchemas, pEntry->colCmpr.nCols * sizeof(SExtSchema));
×
2193
  }
2194

2195
  if (pEntry->stbEntry.schemaRow.version != pSubmitTbData->sver) {
60,140✔
2196
    TSDB_CHECK_CODE(code = TSDB_CODE_TDB_TABLE_ALREADY_EXIST, lino, _exit);
432✔
2197
  }
2198
_exit:
60,140✔
2199
  metaFetchEntryFree(&pEntry);
60,140✔
2200
  if (code != TSDB_CODE_SUCCESS) {
60,140✔
2201
    vError("vgId:%d, failed to build exist sub table response, code:0x%0x, line:%d", TD_VID(pVnode), code, lino);
432✔
2202
  }
2203
  return code;
60,140✔
2204
}
2205

2206
static int32_t buildExistNormalTalbeRsp(SVnode *pVnode, int64_t uid, STableMetaRsp **ppRsp) {
29,372✔
2207
  int32_t code = 0;
29,372✔
2208
  int32_t lino = 0;
29,372✔
2209

2210
  SMetaEntry *pEntry = NULL;
29,372✔
2211
  code = metaFetchEntryByUid(pVnode->pMeta, uid, &pEntry);
29,372✔
2212
  if (code) {
29,372✔
2213
    vError("vgId:%d, table uid:%" PRId64 " not exists, line:%d", TD_VID(pVnode), uid, __LINE__);
×
2214
    TSDB_CHECK_CODE(code, lino, _exit);
×
2215
  }
2216
  if (pEntry->type != TSDB_NORMAL_TABLE) {
29,372✔
2217
    vError("vgId:%d, table uid:%" PRId64 " exists, but is not normal table, line:%d", TD_VID(pVnode), uid, __LINE__);
×
2218
    code = TSDB_CODE_STREAM_INSERT_SCHEMA_NOT_MATCH;
×
2219
    TSDB_CHECK_CODE(code, lino, _exit);
×
2220
  }
2221

2222
  *ppRsp = taosMemoryCalloc(1, sizeof(STableMetaRsp));
29,372✔
2223
  if (NULL == *ppRsp) {
29,372✔
2224
    TSDB_CHECK_CODE(code = terrno, lino, _exit);
×
2225
  }
2226

2227
  (*ppRsp)->tuid = pEntry->uid;
29,372✔
2228
  (*ppRsp)->vgId = pVnode->config.vgId;
29,372✔
2229
  (*ppRsp)->sversion = pEntry->ntbEntry.schemaRow.version;
29,372✔
2230
  (*ppRsp)->numOfColumns = pEntry->ntbEntry.schemaRow.nCols;
29,372✔
2231
  (*ppRsp)->pSchemas = taosMemoryCalloc(pEntry->ntbEntry.schemaRow.nCols, sizeof(SSchema));
29,372✔
2232
  if (NULL == (*ppRsp)->pSchemas) {
29,372✔
2233
    taosMemoryFree(*ppRsp);
×
2234
    TSDB_CHECK_CODE(code = terrno, lino, _exit);
×
2235
  }
2236
  memcpy((*ppRsp)->pSchemas, pEntry->ntbEntry.schemaRow.pSchema, pEntry->ntbEntry.schemaRow.nCols * sizeof(SSchema));
29,372✔
2237
  if (pEntry->pExtSchemas != NULL) {
29,372✔
2238
    (*ppRsp)->pSchemaExt = taosMemoryCalloc(pEntry->ntbEntry.schemaRow.nCols, sizeof(SSchemaExt));
×
2239
    if (NULL == (*ppRsp)->pSchemaExt) {
×
2240
      taosMemoryFree((*ppRsp)->pSchemas);
×
2241
      taosMemoryFree(*ppRsp);
×
2242
      TSDB_CHECK_CODE(code = terrno, lino, _exit);
×
2243
    }
2244
    memcpy((*ppRsp)->pSchemaExt, pEntry->pExtSchemas, pEntry->ntbEntry.schemaRow.nCols * sizeof(SSchemaExt));
×
2245
  }
2246

2247
_exit:
29,372✔
2248
  metaFetchEntryFree(&pEntry);
29,372✔
2249
  if (code != TSDB_CODE_SUCCESS) {
29,372✔
2250
    vError("vgId:%d, failed to build exist normal table response, code:%d, line:%d", TD_VID(pVnode), code, lino);
×
2251
  }
2252
  return code;
29,372✔
2253
}
2254

2255
static int32_t buildExistTableInStreamRsp(SVnode *pVnode, SSubmitTbData *pSubmitTbData, STableMetaRsp **ppRsp) {
287,377✔
2256
  if (pSubmitTbData->pCreateTbReq->flags & TD_CREATE_NORMAL_TB_IN_STREAM) {
287,377✔
2257
    int32_t code = buildExistNormalTalbeRsp(pVnode, pSubmitTbData->uid, ppRsp);
29,372✔
2258
    if (code) {
29,372✔
2259
      vError("vgId:%d, table uid:%" PRId64 " not exists, line:%d", TD_VID(pVnode), pSubmitTbData->uid, __LINE__);
×
2260
      return code;
×
2261
    }
2262
    return TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
29,372✔
2263
  } else if (pSubmitTbData->pCreateTbReq->flags & TD_CREATE_SUB_TB_IN_STREAM) {
258,005✔
2264
    return buildExistSubTalbeRsp(pVnode, pSubmitTbData, ppRsp);
60,140✔
2265
  }
2266
  return TSDB_CODE_SUCCESS;
197,354✔
2267
}
2268

2269
static int32_t vnodeHandleAutoCreateTable(SVnode      *pVnode,    // vnode
677,908,751✔
2270
                                          int64_t      version,   // version
2271
                                          SSubmitReq2 *pRequest,  // request
2272
                                          SSubmitRsp2 *pResponse  // response
2273
) {
2274
  int32_t code = TSDB_CODE_SUCCESS;
677,908,751✔
2275
  int32_t numTbData = taosArrayGetSize(pRequest->aSubmitTbData);
677,908,751✔
2276
  SArray *newTbUids = NULL;
677,908,845✔
2277

2278
  for (int32_t i = 0; i < numTbData; ++i) {
1,383,084,992✔
2279
    SSubmitTbData *pTbData = taosArrayGet(pRequest->aSubmitTbData, i);
705,207,829✔
2280

2281
    if (pTbData->pCreateTbReq == NULL) {
705,208,889✔
2282
      continue;
690,397,044✔
2283
    }
2284

2285
    pTbData->uid = pTbData->pCreateTbReq->uid;
14,810,987✔
2286

2287
    // Alloc necessary resources
2288
    if (pResponse->aCreateTbRsp == NULL) {
14,810,987✔
2289
      pResponse->aCreateTbRsp = taosArrayInit(numTbData, sizeof(SVCreateTbRsp));
12,033,438✔
2290
      if (pResponse->aCreateTbRsp == NULL) {
12,033,438✔
2291
        code = terrno;
×
2292
        vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
×
2293
               tstrerror(code), version);
2294
        taosArrayDestroy(newTbUids);
×
2295
        return code;
×
2296
      }
2297
    }
2298

2299
    // Do create table
2300
    vDebug("vgId:%d start to handle auto create table, version:%" PRId64, TD_VID(pVnode), version);
14,810,987✔
2301

2302
    SVCreateTbRsp *pCreateTbRsp = taosArrayReserve(pResponse->aCreateTbRsp, 1);
14,810,987✔
2303
    code = metaCreateTable2(pVnode->pMeta, version, pTbData->pCreateTbReq, &pCreateTbRsp->pMeta);
14,810,987✔
2304
    if (code == TSDB_CODE_SUCCESS) {
14,810,987✔
2305
      // Allocate necessary resources
2306
      if (newTbUids == NULL) {
14,473,397✔
2307
        newTbUids = taosArrayInit(numTbData, sizeof(int64_t));
11,746,148✔
2308
        if (newTbUids == NULL) {
11,745,827✔
2309
          code = terrno;
×
2310
          vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
×
2311
                 tstrerror(code), version);
2312
          return code;
×
2313
        }
2314
      }
2315

2316
      if (taosArrayPush(newTbUids, &pTbData->uid) == NULL) {
28,946,473✔
2317
        code = terrno;
×
2318
        vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
×
2319
               tstrerror(code), version);
2320
        taosArrayDestroy(newTbUids);
×
2321
        return code;
×
2322
      }
2323

2324
      if (pCreateTbRsp->pMeta) {
14,473,397✔
2325
        vnodeUpdateMetaRsp(pVnode, pCreateTbRsp->pMeta);
14,473,361✔
2326
      }
2327
    } else if (code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
337,590✔
2328
      code = terrno = 0;
336,568✔
2329
      pTbData->uid = pTbData->pCreateTbReq->uid;  // update uid if table exist for using below
336,568✔
2330

2331
      // stream: get sver from meta, write to pCreateTbRsp, and need to check crateTbReq is same as meta.
2332
      if (i == 0) {
336,057✔
2333
        // In the streaming scenario, multiple grouped req requests will only operate on the same write table, and
2334
        // only the first one needs to be processed.
2335
        code = buildExistTableInStreamRsp(pVnode, pTbData, &pCreateTbRsp->pMeta);
287,377✔
2336
        if (code) {
286,355✔
2337
          vInfo("vgId:%d failed to create table in stream:%s, code(0x%0x):%s", TD_VID(pVnode),
29,804✔
2338
                pTbData->pCreateTbReq->name, code, tstrerror(code));
2339
          taosArrayDestroy(newTbUids);
29,804✔
2340
          return code;
29,804✔
2341
        }
2342
      }
2343
    } else {
2344
      code = terrno;
1,022✔
2345
      vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
1,022✔
2346
             tstrerror(code), version);
2347
      taosArrayDestroy(newTbUids);
1,022✔
2348
      return code;
1,022✔
2349
    }
2350
  }
2351

2352
  // Update the affected table uid list
2353
  if (taosArrayGetSize(newTbUids) > 0) {
677,877,163✔
2354
    vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
11,746,112✔
2355
           (int32_t)taosArrayGetSize(newTbUids));
2356
    if (tqAddTbUidList(pVnode->pTq, newTbUids) != 0) {
11,746,148✔
2357
      vError("vgId:%d, failed to update tbUid list", TD_VID(pVnode));
×
2358
    }
2359
  }
2360

2361
  vDebug("vgId:%d, handle auto create table done, version:%" PRId64, TD_VID(pVnode), version);
677,877,916✔
2362

2363
  taosArrayDestroy(newTbUids);
677,877,916✔
2364
  return code;
677,877,849✔
2365
}
2366

2367
static void addExistTableInfoIntoRes(SVnode *pVnode, SSubmitReq2 *pRequest, SSubmitRsp2 *pResponse,
432✔
2368
                                     SSubmitTbData *pTbData, int32_t numTbData) {
2369
  int32_t code = 0;
432✔
2370
  int32_t lino = 0;
432✔
2371
  if ((pTbData->flags & SUBMIT_REQ_SCHEMA_RES) == 0) {
432✔
2372
    return;
×
2373
  }
2374
  if (pResponse->aCreateTbRsp) {  // If aSubmitTbData is not NULL, it means that the request is a create table request,
432✔
2375
                                  // so table info has exitst and we do not need to add again.
2376
    return;
432✔
2377
  }
2378
  pResponse->aCreateTbRsp = taosArrayInit(numTbData, sizeof(SVCreateTbRsp));
×
2379
  if (pResponse->aCreateTbRsp == NULL) {
×
2380
    code = terrno;
×
2381
    TSDB_CHECK_CODE(code, lino, _exit);
×
2382
  }
2383
  SVCreateTbRsp *pCreateTbRsp = taosArrayReserve(pResponse->aCreateTbRsp, 1);
×
2384
  if (pCreateTbRsp == NULL) {
×
2385
    code = terrno;
×
2386
    TSDB_CHECK_CODE(code, lino, _exit);
×
2387
  }
2388
  if (pTbData->suid == 0) {
×
2389
    code = buildExistNormalTalbeRsp(pVnode, pTbData->uid, &pCreateTbRsp->pMeta);
×
2390
    if (code) {
×
2391
      vError("vgId:%d, table uid:%" PRId64 " not exists, line:%d", TD_VID(pVnode), pTbData->uid, __LINE__);
×
2392
    }
2393
  } else {
2394
    code = buildExistSubTalbeRsp(pVnode, pTbData, &pCreateTbRsp->pMeta);
×
2395
  }
2396

2397
  TSDB_CHECK_CODE(code, lino, _exit);
×
2398
_exit:
×
2399
  if (code != TSDB_CODE_SUCCESS) {
×
2400
    vError("vgId:%d, failed to add exist table info into response, code:0x%0x, line:%d", TD_VID(pVnode), code, lino);
×
2401
  }
2402
  return;
×
2403
}
2404

2405
static int32_t vnodeHandleDataWrite(SVnode *pVnode, int64_t version, SSubmitReq2 *pRequest, SSubmitRsp2 *pResponse) {
677,878,055✔
2406
  int32_t code = TSDB_CODE_SUCCESS;
677,878,055✔
2407
  int32_t numTbData = taosArrayGetSize(pRequest->aSubmitTbData);
677,878,055✔
2408
  int8_t  hasBlob = 0;
677,877,845✔
2409

2410
  // Scan submit data
2411
  for (int32_t i = 0; i < numTbData; ++i) {
1,383,054,029✔
2412
    SMetaInfo      info = {0};
705,177,638✔
2413
    SSubmitTbData *pTbData = taosArrayGet(pRequest->aSubmitTbData, i);
705,177,599✔
2414

2415
    if (pTbData->flags & SUBMIT_REQ_WITH_BLOB) {
705,177,077✔
2416
      hasBlob = 1;
21,726✔
2417
    }
2418
    if (pTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
705,177,599✔
2419
      continue;  // skip column data format
6,424,634✔
2420
    }
2421
    if (pTbData->flags & SUBMIT_REQ_ONLY_CREATE_TABLE) {
698,753,890✔
2422
      continue;  // skip only crate table request
2,196,248✔
2423
    }
2424

2425
    code = metaGetInfo(pVnode->pMeta, pTbData->uid, &info, NULL);
696,555,617✔
2426
    if (code) {
696,555,670✔
2427
      code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
1,223✔
2428
      vWarn("vgId:%d, error occurred at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __FILE__,
1,223✔
2429
            __LINE__, tstrerror(code), version, pTbData->uid);
2430
      return code;
1,223✔
2431
    }
2432

2433
    if (info.suid != pTbData->suid) {
696,554,447✔
2434
      code = TSDB_CODE_INVALID_MSG;
×
2435
      vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64 " suid:%" PRId64
×
2436
             " info.suid:%" PRId64,
2437
             TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code), version, pTbData->uid, pTbData->suid,
2438
             info.suid);
2439
      return code;
×
2440
    }
2441

2442
    if (info.suid) {
696,553,561✔
2443
      code = metaGetInfo(pVnode->pMeta, info.suid, &info, NULL);
508,573,897✔
2444
      if (code) {
508,575,255✔
2445
        code = TSDB_CODE_INTERNAL_ERROR;
×
2446
        vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " suid:%" PRId64, TD_VID(pVnode), __func__,
×
2447
               __FILE__, __LINE__, tstrerror(code), version, info.suid);
2448
        return code;
×
2449
      }
2450
    }
2451

2452
    if (pTbData->sver != info.skmVer) {
696,554,919✔
2453
      code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER;
432✔
2454
      addExistTableInfoIntoRes(pVnode, pRequest, pResponse, pTbData, numTbData);
432✔
2455
      vDebug("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64
432✔
2456
             " sver:%d"
2457
             " info.skmVer:%d",
2458
             TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code), version, pTbData->uid, pTbData->sver,
2459
             info.skmVer);
2460
      return code;
432✔
2461
    }
2462
  }
2463

2464
  // Do write data
2465
  vDebug("vgId:%d start to handle data write, version:%" PRId64, TD_VID(pVnode), version);
677,876,391✔
2466

2467
  for (int32_t i = 0; i < numTbData; ++i) {
1,383,043,770✔
2468
    int32_t        affectedRows = 0;
705,175,820✔
2469
    SSubmitTbData *pTbData = taosArrayGet(pRequest->aSubmitTbData, i);
705,175,820✔
2470

2471
    if (pTbData->flags & SUBMIT_REQ_ONLY_CREATE_TABLE) {
705,176,394✔
2472
      continue;
2,196,248✔
2473
    }
2474

2475
    if (hasBlob) {
702,980,146✔
2476
      code = vnodeSubmitBlobData(pVnode, pTbData);
21,726✔
2477
      if (code) {
21,726✔
2478
        vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __func__,
×
2479
               __FILE__, __LINE__, tstrerror(code), version, pTbData->uid);
2480
        return code;
×
2481
      }
2482
    }
2483

2484
    code = tsdbInsertTableData(pVnode->pTsdb, version, pTbData, &affectedRows);
702,980,146✔
2485
    if (code) {
702,973,398✔
2486
      vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __func__,
×
2487
             __FILE__, __LINE__, tstrerror(code), version, pTbData->uid);
2488
      return code;
×
2489
    }
2490

2491
    code = metaUpdateChangeTimeWithLock(pVnode->pMeta, pTbData->uid, pTbData->ctimeMs);
702,973,398✔
2492
    if (code) {
702,967,041✔
2493
      vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __func__,
×
2494
             __FILE__, __LINE__, tstrerror(code), version, pTbData->uid);
2495
      return code;
×
2496
    }
2497
    pResponse->affectedRows += affectedRows;
702,967,041✔
2498
  }
2499

2500
  vDebug("vgId:%d, handle data write done, version:%" PRId64 ", affectedRows:%d", TD_VID(pVnode), version,
677,867,950✔
2501
         pResponse->affectedRows);
2502
  return code;
677,877,258✔
2503
}
2504

2505
static int32_t vnodeScanColumnData(SVnode *pVnode, SSubmitTbData *pTbData, TSKEY minKey, TSKEY maxKey) {
6,424,321✔
2506
  int32_t code = 0;
6,424,321✔
2507

2508
  int32_t   numCols = taosArrayGetSize(pTbData->aCol);
6,424,321✔
2509
  SColData *aColData = (SColData *)TARRAY_DATA(pTbData->aCol);
6,424,000✔
2510

2511
  if (numCols <= 0) {
6,424,321✔
2512
    code = TSDB_CODE_INVALID_MSG;
×
2513
    vError("vgId:%d, %s failed at %s:%d since %s, version:%d uid:%" PRId64 " numCols:%d", TD_VID(pVnode), __func__,
×
2514
           __FILE__, __LINE__, tstrerror(code), pTbData->sver, pTbData->uid, numCols);
2515
    return code;
×
2516
  }
2517

2518
  if (aColData[0].cid != PRIMARYKEY_TIMESTAMP_COL_ID || aColData[0].type != TSDB_DATA_TYPE_TIMESTAMP ||
6,424,321✔
2519
      aColData[0].nVal <= 0) {
6,424,008✔
2520
    code = TSDB_CODE_INVALID_MSG;
×
2521
    vError("vgId:%d, %s failed at %s:%d since %s, version:%d uid:%" PRId64
×
2522
           " first column is not primary key timestamp, cid:%d type:%d nVal:%d",
2523
           TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code), pTbData->sver, pTbData->uid, aColData[0].cid,
2524
           aColData[0].type, aColData[0].nVal);
2525
    return code;
×
2526
  }
2527

2528
  for (int32_t i = 1; i < numCols; ++i) {
19,732,952✔
2529
    if (aColData[i].nVal != aColData[0].nVal) {
13,309,578✔
2530
      code = TSDB_CODE_INVALID_MSG;
×
2531
      vError("vgId:%d, %s failed at %s:%d since %s, version:%d uid:%" PRId64
×
2532
             " column cid:%d type:%d nVal:%d is not equal to primary key timestamp nVal:%d",
2533
             TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code), pTbData->sver, pTbData->uid,
2534
             aColData[i].cid, aColData[i].type, aColData[i].nVal, aColData[0].nVal);
2535
      return code;
×
2536
    }
2537
  }
2538

2539
  SRowKey *pLastKey = NULL;
6,423,374✔
2540
  SRowKey  lastKey = {0};
6,423,374✔
2541
  for (int32_t i = 0; i < aColData[0].nVal; ++i) {
2,147,483,647✔
2542
    SRowKey key = {0};
2,147,483,647✔
2543

2544
    tColDataArrGetRowKey(aColData, numCols, i, &key);
2,147,483,647✔
2545

2546
    if (key.ts < minKey || key.ts > maxKey) {
2,147,483,647✔
2547
      code = TSDB_CODE_INVALID_MSG;
×
2548
      vError("vgId:%d, %s failed at %s:%d since %s, version:%d uid:%" PRId64 " row[%d] key:%" PRId64
×
2549
             " is out of range [%" PRId64 ", %" PRId64 "]",
2550
             TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code), pTbData->sver, pTbData->uid, i, key.ts,
2551
             minKey, maxKey);
2552
      return code;
×
2553
    }
2554

2555
    if (pLastKey && tRowKeyCompare(pLastKey, &key) >= 0) {
2,147,483,647✔
2556
      code = TSDB_CODE_INVALID_MSG;
×
2557
      vError("vgId:%d, %s failed at %s:%d since %s, version:%d uid:%" PRId64 " row[%d] key:%" PRId64
×
2558
             " is not in order, lastKey:%" PRId64,
2559
             TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code), pTbData->sver, pTbData->uid, i, key.ts,
2560
             pLastKey->ts);
2561
      return code;
×
2562
    } else if (pLastKey == NULL) {
2,147,483,647✔
2563
      pLastKey = &lastKey;
6,424,321✔
2564
    }
2565

2566
    *pLastKey = key;
2,147,483,647✔
2567
  }
2568

2569
  return code;
6,424,634✔
2570
}
2571

2572
static int32_t vnodeScanSubmitRowData(SVnode *pVnode, SSubmitTbData *pTbData, TSKEY minKey, TSKEY maxKey) {
698,773,390✔
2573
  int32_t code = 0;
698,773,390✔
2574

2575
  int32_t numRows = taosArrayGetSize(pTbData->aRowP);
698,773,390✔
2576
  SRow  **aRow = (SRow **)TARRAY_DATA(pTbData->aRowP);
698,771,616✔
2577

2578
  if (numRows <= 0 && (pTbData->flags & SUBMIT_REQ_ONLY_CREATE_TABLE) == 0) {
698,776,318✔
2579
    code = TSDB_CODE_INVALID_MSG;
×
2580
    vError("vgId:%d, %s failed at %s:%d since %s, version:%d uid:%" PRId64 " numRows:%d", TD_VID(pVnode), __func__,
×
2581
           __FILE__, __LINE__, tstrerror(code), pTbData->sver, pTbData->uid, numRows);
2582
    return code;
×
2583
  }
2584

2585
  SRowKey *pLastKey = NULL;
698,776,318✔
2586
  SRowKey  lastKey = {0};
698,776,318✔
2587
  for (int32_t i = 0; i < numRows; ++i) {
2,147,483,647✔
2588
    SRow *pRow = aRow[i];
2,147,483,647✔
2589
    if (pRow->sver != pTbData->sver) {
2,147,483,647✔
2590
      code = TSDB_CODE_INVALID_MSG;
×
2591
      vError("vgId:%d, %s failed at %s:%d since %s, version:%d uid:%" PRId64 " row[%d] sver:%d pTbData->sver:%d",
×
2592
             TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code), pTbData->sver, pTbData->uid, i, pRow->sver,
2593
             pTbData->sver);
2594
      return code;
×
2595
    }
2596

2597
    SRowKey key = {0};
2,147,483,647✔
2598
    tRowGetKey(pRow, &key);
2,147,483,647✔
2599
    if (key.ts < minKey || key.ts > maxKey) {
2,147,483,647✔
2600
      code = TSDB_CODE_INVALID_MSG;
10,147✔
2601
      vError("vgId:%d, %s failed at %s:%d since %s, version:%d uid:%" PRId64 " row[%d] key:%" PRId64
10,147✔
2602
             " is out of range [%" PRId64 ", %" PRId64 "]",
2603
             TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code), pTbData->sver, pTbData->uid, i, key.ts,
2604
             minKey, maxKey);
2605
      return code;
×
2606
    }
2607

2608
    if (pLastKey && tRowKeyCompare(pLastKey, &key) >= 0) {
2,147,483,647✔
2609
      code = TSDB_CODE_INVALID_MSG;
×
2610
      vError("vgId:%d, %s failed at %s:%d since %s, version:%d uid:%" PRId64 " row[%d] key:%" PRId64
×
2611
             " is not in order, lastKey:%" PRId64,
2612
             TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code), pTbData->sver, pTbData->uid, i, key.ts,
2613
             pLastKey->ts);
2614
      return code;
×
2615
    } else if (pLastKey == NULL) {
2,147,483,647✔
2616
      pLastKey = &lastKey;
696,577,082✔
2617
    }
2618

2619
    *pLastKey = key;
2,147,483,647✔
2620
  }
2621

2622
  return code;
689,479,827✔
2623
}
2624

2625
static int32_t vnodeScanSubmitReq(SVnode *pVnode, int64_t version, SSubmitReq2 *pRequest, SSubmitRsp2 *pResponse) {
677,899,893✔
2626
  int32_t code = TSDB_CODE_SUCCESS;
677,899,893✔
2627
  int32_t numTbData = taosArrayGetSize(pRequest->aSubmitTbData);
677,899,893✔
2628

2629
  TSKEY now = taosGetTimestamp(pVnode->config.tsdbCfg.precision);
677,905,224✔
2630
  TSKEY minKey = now - tsTickPerMin[pVnode->config.tsdbCfg.precision] * pVnode->config.tsdbCfg.keep2;
677,899,783✔
2631
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
677,902,718✔
2632
  for (int32_t i = 0; i < numTbData; i++) {
1,383,100,592✔
2633
    SSubmitTbData *pTbData = taosArrayGet(pRequest->aSubmitTbData, i);
705,197,694✔
2634

2635
    if (pTbData->pCreateTbReq && pTbData->pCreateTbReq->uid == 0) {
705,197,294✔
2636
      code = TSDB_CODE_INVALID_MSG;
×
2637
      vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
×
2638
             tstrerror(code), version);
2639
      return code;
×
2640
    }
2641

2642
    if (pTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
705,197,872✔
2643
      code = vnodeScanColumnData(pVnode, pTbData, minKey, maxKey);
6,424,000✔
2644
      if (code) {
6,424,634✔
2645
        vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __func__,
×
2646
               __FILE__, __LINE__, tstrerror(code), version, pTbData->uid);
2647
        return code;
×
2648
      }
2649
    } else {
2650
      code = vnodeScanSubmitRowData(pVnode, pTbData, minKey, maxKey);
698,773,334✔
2651
      if (code) {
698,773,253✔
2652
        vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __func__,
175✔
2653
               __FILE__, __LINE__, tstrerror(code), version, pTbData->uid);
2654
        return code;
×
2655
      }
2656
    }
2657
  }
2658

2659
  return code;
677,902,898✔
2660
}
2661

2662
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
677,907,142✔
2663
                                     SRpcMsg *pOriginalMsg) {
2664
  int32_t code = 0;
677,907,142✔
2665
  int32_t lino = 0;
677,907,142✔
2666
  terrno = 0;
677,907,142✔
2667

2668
  SSubmitReq2 *pSubmitReq = &(SSubmitReq2){0};
677,908,355✔
2669
  SSubmitRsp2 *pSubmitRsp = &(SSubmitRsp2){0};
677,908,494✔
2670
  int32_t      ret;
2671
  SEncoder     ec = {0};
677,908,355✔
2672

2673
  pRsp->code = TSDB_CODE_SUCCESS;
677,908,355✔
2674

2675
  void           *pAllocMsg = NULL;
677,907,663✔
2676
  SSubmitReq2Msg *pMsg = (SSubmitReq2Msg *)pReq;
677,907,663✔
2677
  SDecoder        dc = {0};
677,907,663✔
2678
  if (0 == taosHton64(pMsg->version)) {
677,907,636✔
2679
    code = vnodeSubmitReqConvertToSubmitReq2(pVnode, (SSubmitReq *)pMsg, pSubmitReq);
×
2680
    if (TSDB_CODE_SUCCESS == code) {
×
2681
      code = vnodeRebuildSubmitReqMsg(pSubmitReq, &pReq);
×
2682
    }
2683
    if (TSDB_CODE_SUCCESS == code) {
×
2684
      pAllocMsg = pReq;
×
2685
    }
2686
    TSDB_CHECK_CODE(code, lino, _exit);
×
2687
  } else {
2688
    // decode
2689
    pReq = POINTER_SHIFT(pReq, sizeof(SSubmitReq2Msg));
677,907,605✔
2690
    len -= sizeof(SSubmitReq2Msg);
677,907,636✔
2691

2692
    tDecoderInit(&dc, pReq, len);
677,907,636✔
2693
    if (tDecodeSubmitReq(&dc, pSubmitReq, NULL) < 0) {
677,909,020✔
2694
      code = TSDB_CODE_INVALID_MSG;
×
2695
      TSDB_CHECK_CODE(code, lino, _exit);
×
2696
    }
2697
  }
2698

2699
  // Scan the request
2700
  code = vnodeScanSubmitReq(pVnode, ver, pSubmitReq, pSubmitRsp);
677,899,956✔
2701
  if (code) {
677,900,819✔
2702
    vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
×
2703
           tstrerror(code), ver);
2704
    TSDB_CHECK_CODE(code, lino, _exit);
×
2705
  }
2706

2707
  vGDebug(pOriginalMsg ? &pOriginalMsg->info.traceId : NULL, "vgId:%d, index:%" PRId64 ", submit block, rows:%d",
677,900,819✔
2708
          TD_VID(pVnode), ver, (int32_t)taosArrayGetSize(pSubmitReq->aSubmitTbData));
2709

2710
  // Handle auto create table
2711
  code = vnodeHandleAutoCreateTable(pVnode, ver, pSubmitReq, pSubmitRsp);
677,911,276✔
2712
  if (code) {
677,908,675✔
2713
    vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
30,826✔
2714
           tstrerror(code), ver);
2715
    TSDB_CHECK_CODE(code, lino, _exit);
30,826✔
2716
  }
2717

2718
  // Handle data write
2719
  code = vnodeHandleDataWrite(pVnode, ver, pSubmitReq, pSubmitRsp);
677,877,849✔
2720
  if (code) {
677,878,913✔
2721
    vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
1,655✔
2722
           tstrerror(code), ver);
2723
    TSDB_CHECK_CODE(code, lino, _exit);
1,655✔
2724
  }
2725

2726
_exit:
677,909,613✔
2727
  // message
2728
  pRsp->code = code;
677,909,739✔
2729
  tEncodeSize(tEncodeSSubmitRsp2, pSubmitRsp, pRsp->contLen, ret);
677,909,677✔
2730
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
677,909,564✔
2731
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
677,909,739✔
2732
  if (tEncodeSSubmitRsp2(&ec, pSubmitRsp) < 0) {
677,909,426✔
2733
    vError("vgId:%d, failed to encode submit response", TD_VID(pVnode));
×
2734
  }
2735
  tEncoderClear(&ec);
677,908,631✔
2736

2737
  // update statistics
2738
  (void)atomic_add_fetch_64(&pVnode->statis.nInsert, pSubmitRsp->affectedRows);
677,907,494✔
2739
  (void)atomic_add_fetch_64(&pVnode->statis.nInsertSuccess, pSubmitRsp->affectedRows);
677,908,873✔
2740
  (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsert, 1);
677,908,882✔
2741

2742
  // update metrics
2743
  METRICS_UPDATE(pVnode->writeMetrics.total_requests, METRIC_LEVEL_LOW, 1);
677,908,305✔
2744
  METRICS_UPDATE(pVnode->writeMetrics.total_rows, METRIC_LEVEL_HIGH, pSubmitRsp->affectedRows);
677,906,726✔
2745
  METRICS_UPDATE(pVnode->writeMetrics.total_bytes, METRIC_LEVEL_LOW, pMsg->header.contLen);
677,906,937✔
2746

2747
  if (tsEnableMonitor && tsMonitorFqdn[0] != 0 && tsMonitorPort != 0 && pSubmitRsp->affectedRows > 0 &&
677,907,494✔
2748
      strlen(RPC_MSG_USER(pOriginalMsg)) > 0 && tsInsertCounter != NULL) {
×
2749
    const char *sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT_AFFECTED_ROWS,
×
2750
                                   pVnode->monitor.strClusterId,
×
2751
                                   pVnode->monitor.strDnodeId,
×
2752
                                   tsLocalEp,
2753
                                   pVnode->monitor.strVgId,
×
2754
                                   RPC_MSG_USER(pOriginalMsg),
×
2755
                                   "Success"};
2756
    int         tv = taos_counter_add(tsInsertCounter, pSubmitRsp->affectedRows, sample_labels);
×
2757
  }
2758

2759
  if (code == 0) {
677,907,494✔
2760
    (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
677,875,013✔
2761
  }
2762

2763
  // clear
2764
  tDestroySubmitReq(pSubmitReq, 0 == taosHton64(pMsg->version) ? TSDB_MSG_FLG_CMPT : TSDB_MSG_FLG_DECODE);
677,907,669✔
2765
  tDestroySSubmitRsp2(pSubmitRsp, TSDB_MSG_FLG_ENCODE);
677,904,763✔
2766

2767
  if (code) {
677,894,795✔
2768
    terrno = code;
32,481✔
2769
    if (code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
32,481✔
2770
      vInfo("vgId:%d, failed to process submit request since %s, lino:%d, version:%" PRId64, TD_VID(pVnode),
29,804✔
2771
            tstrerror(code), lino, ver);
2772

2773
    } else {
2774
      vError("vgId:%d, failed to process submit request since %s, lino:%d, version:%" PRId64, TD_VID(pVnode),
2,677✔
2775
             tstrerror(code), lino, ver);
2776
    }
2777
  }
2778

2779
  taosMemoryFree(pAllocMsg);
677,903,170✔
2780
  tDecoderClear(&dc);
677,901,452✔
2781

2782
  return code;
677,907,678✔
2783
}
2784

2785
static int32_t vnodeConsolidateAlterHashRange(SVnode *pVnode, int64_t ver) {
24,461✔
2786
  int32_t code = TSDB_CODE_SUCCESS;
24,461✔
2787

2788
  vInfo("vgId:%d, trim meta of tables per hash range [%" PRIu32 ", %" PRIu32 "]. apply-index:%" PRId64, TD_VID(pVnode),
24,461✔
2789
        pVnode->config.hashBegin, pVnode->config.hashEnd, ver);
2790

2791
  // TODO: trim meta of tables from TDB per hash range [pVnode->config.hashBegin, pVnode->config.hashEnd]
2792
  code = metaTrimTables(pVnode->pMeta, ver);
24,461✔
2793

2794
  return code;
24,461✔
2795
}
2796

2797
static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
3,908,703✔
2798
  vInfo("vgId:%d, vnode handle msgType:alter-confirm, alter confirm msg is processed", TD_VID(pVnode));
3,908,703✔
2799
  int32_t code = TSDB_CODE_SUCCESS;
3,908,703✔
2800
  if (!pVnode->config.hashChange) {
3,908,703✔
2801
    goto _exit;
3,884,242✔
2802
  }
2803

2804
  code = vnodeConsolidateAlterHashRange(pVnode, ver);
24,461✔
2805
  if (code < 0) {
24,461✔
2806
    vError("vgId:%d, failed to consolidate alter hashrange since %s. version:%" PRId64, TD_VID(pVnode), terrstr(), ver);
×
2807
    goto _exit;
×
2808
  }
2809
  pVnode->config.hashChange = false;
24,461✔
2810

2811
_exit:
3,908,703✔
2812
  pRsp->msgType = TDMT_VND_ALTER_CONFIRM_RSP;
3,908,703✔
2813
  pRsp->code = code;
3,908,703✔
2814
  pRsp->pCont = NULL;
3,908,703✔
2815
  pRsp->contLen = 0;
3,908,703✔
2816

2817
  return code;
3,908,703✔
2818
}
2819

2820
extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb);
2821
extern void    tsdbEnableBgTask(STsdb *pTsdb);
2822

2823
static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
306,966✔
2824
  bool walChanged = false;
306,966✔
2825
  bool tsdbChanged = false;
306,966✔
2826

2827
  SAlterVnodeConfigReq req = {0};
306,966✔
2828
  if (tDeserializeSAlterVnodeConfigReq(pReq, len, &req) != 0) {
306,966✔
2829
    terrno = TSDB_CODE_INVALID_MSG;
×
2830
    return TSDB_CODE_INVALID_MSG;
×
2831
  }
2832

2833
  vInfo("vgId:%d, start to alter vnode config, page:%d pageSize:%d buffer:%d szPage:%d szBuf:%" PRIu64
306,966✔
2834
        " cacheLast:%d cacheLastSize:%d days:%d keep0:%d keep1:%d keep2:%d keepTimeOffset:%d ssKeepLocal:%d "
2835
        "ssCompact:%d allowDrop:%d fsync:%d level:%d "
2836
        "walRetentionPeriod:%d walRetentionSize:%d",
2837
        TD_VID(pVnode), req.pages, req.pageSize, req.buffer, req.pageSize * 1024, (uint64_t)req.buffer * 1024 * 1024,
2838
        req.cacheLast, req.cacheLastSize, req.daysPerFile, req.daysToKeep0, req.daysToKeep1, req.daysToKeep2,
2839
        req.keepTimeOffset, req.ssKeepLocal, req.ssCompact, req.allowDrop, req.walFsyncPeriod, req.walLevel,
2840
        req.walRetentionPeriod, req.walRetentionSize);
2841

2842
  if (pVnode->config.cacheLastSize != req.cacheLastSize) {
306,966✔
2843
    pVnode->config.cacheLastSize = req.cacheLastSize;
5,560✔
2844
    tsdbCacheSetCapacity(pVnode, (size_t)pVnode->config.cacheLastSize * 1024 * 1024);
5,560✔
2845
  }
2846

2847
  if (pVnode->config.szBuf != req.buffer * 1024LL * 1024LL) {
306,966✔
2848
    vInfo("vgId:%d, vnode buffer is changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pVnode->config.szBuf,
9,014✔
2849
          (uint64_t)(req.buffer * 1024LL * 1024LL));
2850
    pVnode->config.szBuf = req.buffer * 1024LL * 1024LL;
9,014✔
2851
  }
2852

2853
  if (pVnode->config.szCache != req.pages) {
306,966✔
2854
    if ((terrno = metaAlterCache(pVnode->pMeta, req.pages)) < 0) {
4,398✔
2855
      vError("vgId:%d, failed to change vnode pages from %d to %d failed since %s", TD_VID(pVnode),
×
2856
             pVnode->config.szCache, req.pages, tstrerror(terrno));
2857
      return terrno;
×
2858
    } else {
2859
      vInfo("vgId:%d, vnode pages is changed from %d to %d", TD_VID(pVnode), pVnode->config.szCache, req.pages);
4,398✔
2860
      pVnode->config.szCache = req.pages;
4,398✔
2861
    }
2862
  }
2863

2864
  if (pVnode->config.cacheLast != req.cacheLast) {
306,966✔
2865
    pVnode->config.cacheLast = req.cacheLast;
84,461✔
2866
  }
2867

2868
  if (pVnode->config.walCfg.fsyncPeriod != req.walFsyncPeriod) {
306,966✔
2869
    pVnode->config.walCfg.fsyncPeriod = req.walFsyncPeriod;
50,902✔
2870
    walChanged = true;
50,902✔
2871
  }
2872

2873
  if (pVnode->config.walCfg.level != req.walLevel) {
306,966✔
2874
    if (pVnode->config.walCfg.level == 0) {
37,514✔
2875
      pVnode->config.walCfg.clearFiles = 1;
2,144✔
2876
    }
2877
    pVnode->config.walCfg.level = req.walLevel;
37,514✔
2878
    walChanged = true;
37,514✔
2879
  }
2880

2881
  if (pVnode->config.walCfg.retentionPeriod != req.walRetentionPeriod) {
306,966✔
2882
    pVnode->config.walCfg.retentionPeriod = req.walRetentionPeriod;
44,161✔
2883
    walChanged = true;
44,161✔
2884
  }
2885

2886
  if (pVnode->config.walCfg.retentionSize != req.walRetentionSize) {
306,966✔
2887
    pVnode->config.walCfg.retentionSize = req.walRetentionSize;
1,404✔
2888
    walChanged = true;
1,404✔
2889
  }
2890

2891
  if (pVnode->config.tsdbCfg.keep0 != req.daysToKeep0) {
306,966✔
2892
    pVnode->config.tsdbCfg.keep0 = req.daysToKeep0;
40,660✔
2893
    tsdbChanged = true;
40,660✔
2894
  }
2895

2896
  if (pVnode->config.tsdbCfg.keep1 != req.daysToKeep1) {
306,966✔
2897
    pVnode->config.tsdbCfg.keep1 = req.daysToKeep1;
39,210✔
2898
    tsdbChanged = true;
39,210✔
2899
  }
2900

2901
  if (pVnode->config.tsdbCfg.keep2 != req.daysToKeep2) {
306,966✔
2902
    pVnode->config.tsdbCfg.keep2 = req.daysToKeep2;
33,522✔
2903
    tsdbChanged = true;
33,522✔
2904
  }
2905

2906
  if (pVnode->config.tsdbCfg.keepTimeOffset != req.keepTimeOffset) {
306,966✔
2907
    pVnode->config.tsdbCfg.keepTimeOffset = req.keepTimeOffset;
7,104✔
2908
    tsdbChanged = true;
7,104✔
2909
  }
2910

2911
  if (req.sttTrigger != -1 && req.sttTrigger != pVnode->config.sttTrigger) {
306,966✔
2912
    if (req.sttTrigger > 1 && pVnode->config.sttTrigger > 1) {
2,456✔
2913
      pVnode->config.sttTrigger = req.sttTrigger;
1,404✔
2914
    } else {
2915
      vnodeAWait(&pVnode->commitTask);
1,052✔
2916

2917
      int32_t ret = tsdbDisableAndCancelAllBgTask(pVnode->pTsdb);
1,052✔
2918
      if (ret != 0) {
1,052✔
2919
        vError("vgId:%d, failed to disable bg task since %s", TD_VID(pVnode), tstrerror(ERRNO));
×
2920
      }
2921

2922
      pVnode->config.sttTrigger = req.sttTrigger;
1,052✔
2923
      tsdbEnableBgTask(pVnode->pTsdb);
1,052✔
2924
    }
2925
  }
2926

2927
  if (req.minRows != -1 && req.minRows != pVnode->config.tsdbCfg.minRows) {
306,250✔
2928
    pVnode->config.tsdbCfg.minRows = req.minRows;
1,404✔
2929
  }
2930

2931
  if (req.ssKeepLocal != -1 && req.ssKeepLocal != pVnode->config.ssKeepLocal) {
306,250✔
2932
    pVnode->config.ssKeepLocal = req.ssKeepLocal;
1,404✔
2933
  }
2934
  if (req.ssCompact != -1 && req.ssCompact != pVnode->config.ssCompact) {
306,250✔
2935
    pVnode->config.ssCompact = req.ssCompact;
1,404✔
2936
  }
2937
  if (req.allowDrop != pVnode->config.allowDrop) {
306,250✔
2938
    pVnode->config.allowDrop = req.allowDrop;
×
2939
  }
2940

2941
  if (walChanged) {
306,250✔
2942
    if (walAlter(pVnode->pWal, &pVnode->config.walCfg) != 0) {
131,079✔
2943
      vError("vgId:%d, failed to alter wal config since %s", TD_VID(pVnode), tstrerror(ERRNO));
×
2944
    }
2945
  }
2946

2947
  if (tsdbChanged) {
306,250✔
2948
    tsdbSetKeepCfg(pVnode->pTsdb, &pVnode->config.tsdbCfg);
54,280✔
2949
  }
2950

2951
  return 0;
306,966✔
2952
}
2953

2954
static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
2955
  SBatchDeleteReq deleteReq;
×
2956
  SDecoder        decoder;
×
2957
  tDecoderInit(&decoder, pReq, len);
×
2958
  if (tDecodeSBatchDeleteReq(&decoder, &deleteReq) < 0) {
×
2959
    tDecoderClear(&decoder);
×
2960
    return terrno = TSDB_CODE_INVALID_MSG;
×
2961
  }
2962

2963
  SMetaReader mr = {0};
×
2964
  metaReaderDoInit(&mr, pVnode->pMeta, META_READER_NOLOCK);
×
2965
  STsdb *pTsdb = pVnode->pTsdb;
×
2966

2967
  int32_t sz = taosArrayGetSize(deleteReq.deleteReqs);
×
2968
  for (int32_t i = 0; i < sz; i++) {
×
2969
    SSingleDeleteReq *pOneReq = taosArrayGet(deleteReq.deleteReqs, i);
×
2970
    char             *name = pOneReq->tbname;
×
2971
    if (metaGetTableEntryByName(&mr, name) < 0) {
×
2972
      vDebug("vgId:%d, stream delete msg, skip since no table: %s", pVnode->config.vgId, name);
×
2973
      continue;
×
2974
    }
2975

2976
    int64_t uid = mr.me.uid;
×
2977

2978
    int32_t code = tsdbDeleteTableData(pTsdb, ver, deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
×
2979
    if (code < 0) {
×
2980
      terrno = code;
×
2981
      vError("vgId:%d, delete error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64 ", end ts:%" PRId64,
×
2982
             TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
2983
    }
2984

2985
    if (deleteReq.level == 0) {
×
2986
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, deleteReq.ctimeMs);
×
2987
      if (code < 0) {
×
2988
        terrno = code;
×
2989
        vError("vgId:%d, update change time error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64
×
2990
               ", end ts:%" PRId64,
2991
               TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
2992
      }
2993
    }
2994
    tDecoderClear(&mr.coder);
×
2995
  }
2996
  metaReaderClear(&mr);
×
2997
  taosArrayDestroy(deleteReq.deleteReqs);
×
2998
  return 0;
×
2999
}
3000

3001
static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
1,994,701✔
3002
                                     SRpcMsg *pOriginalMsg) {
3003
  int32_t     code = 0;
1,994,701✔
3004
  SDecoder   *pCoder = &(SDecoder){0};
1,994,701✔
3005
  SDeleteRes *pRes = &(SDeleteRes){0};
1,994,701✔
3006

3007
  pRsp->msgType = TDMT_VND_DELETE_RSP;
1,994,701✔
3008
  pRsp->pCont = NULL;
1,994,701✔
3009
  pRsp->contLen = 0;
1,994,701✔
3010
  pRsp->code = TSDB_CODE_SUCCESS;
1,994,701✔
3011

3012
  pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t));
1,994,701✔
3013
  if (pRes->uidList == NULL) {
1,994,701✔
3014
    code = terrno;
×
3015
    goto _err;
×
3016
  }
3017

3018
  tDecoderInit(pCoder, pReq, len);
1,994,701✔
3019
  code = tDecodeDeleteRes(pCoder, pRes);
1,994,701✔
3020
  if (code) goto _err;
1,994,701✔
3021

3022
  if (pRes->affectedRows > 0) {
1,994,701✔
3023
    for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) {
3,537,667✔
3024
      uint64_t uid = *(uint64_t *)taosArrayGet(pRes->uidList, iUid);
2,028,549✔
3025
      code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, uid, pRes->skey, pRes->ekey);
2,028,549✔
3026
      if (code) goto _err;
2,028,549✔
3027
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, pRes->ctimeMs);
2,028,549✔
3028
      if (code) goto _err;
2,028,549✔
3029
    }
3030
  }
3031

3032
  tDecoderClear(pCoder);
1,994,701✔
3033
  taosArrayDestroy(pRes->uidList);
1,994,701✔
3034

3035
  SVDeleteRsp rsp = {.affectedRows = pRes->affectedRows};
1,994,701✔
3036
  int32_t     ret = 0;
1,994,701✔
3037
  tEncodeSize(tEncodeSVDeleteRsp, &rsp, pRsp->contLen, ret);
1,994,701✔
3038
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
1,994,701✔
3039
  SEncoder ec = {0};
1,994,701✔
3040
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
1,994,701✔
3041
  code = tEncodeSVDeleteRsp(&ec, &rsp);
1,994,701✔
3042
  if (code) goto _err;
1,994,701✔
3043
  tEncoderClear(&ec);
1,994,701✔
3044
  return code;
1,994,701✔
3045

3046
_err:
×
3047
  /*
3048
  if(code == TSDB_CODE_SUCCESS){
3049
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_DELETE, pVnode->monitor.strClusterId,
3050
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
3051
                                        RPC_MSG_USER(pOriginalMsg), "Success"};
3052
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
3053
  }
3054
  else{
3055
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_DELETE, pVnode->monitor.strClusterId,
3056
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
3057
                                        RPC_MSG_USER(pOriginalMsg), "Failed"};
3058
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
3059
  }
3060
  */
3061

3062
  return code;
×
3063
}
3064
static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
4,380✔
3065
  SVCreateStbReq req = {0};
4,380✔
3066
  SDecoder       dc = {0};
4,380✔
3067
  int32_t        code = 0;
4,380✔
3068

3069
  pRsp->msgType = TDMT_VND_CREATE_INDEX_RSP;
4,380✔
3070
  pRsp->code = TSDB_CODE_SUCCESS;
4,380✔
3071
  pRsp->pCont = NULL;
4,380✔
3072
  pRsp->contLen = 0;
4,380✔
3073

3074
  tDecoderInit(&dc, pReq, len);
4,380✔
3075
  // decode req
3076
  if (tDecodeSVCreateStbReq(&dc, &req) < 0) {
4,380✔
3077
    tDecoderClear(&dc);
×
3078
    return terrno = TSDB_CODE_INVALID_MSG;
×
3079
  }
3080

3081
  code = metaAddIndexToSuperTable(pVnode->pMeta, ver, &req);
4,380✔
3082
  if (code) {
4,380✔
3083
    pRsp->code = code;
×
3084
    goto _err;
×
3085
  }
3086
  tDecoderClear(&dc);
4,380✔
3087
  return 0;
4,380✔
3088

3089
_err:
×
3090
  tDecoderClear(&dc);
×
3091
  return code;
×
3092
}
3093
static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
2,896✔
3094
  SDropIndexReq req = {0};
2,896✔
3095
  int32_t       code = 0;
2,896✔
3096
  pRsp->msgType = TDMT_VND_DROP_INDEX_RSP;
2,896✔
3097
  pRsp->code = TSDB_CODE_SUCCESS;
2,896✔
3098
  pRsp->pCont = NULL;
2,896✔
3099
  pRsp->contLen = 0;
2,896✔
3100

3101
  if ((code = tDeserializeSDropIdxReq(pReq, len, &req))) {
2,896✔
3102
    pRsp->code = code;
×
3103
    return code;
×
3104
  }
3105

3106
  code = metaDropIndexFromSuperTable(pVnode->pMeta, ver, &req);
2,896✔
3107
  if (code) {
2,896✔
3108
    pRsp->code = code;
×
3109
    return code;
×
3110
  }
3111
  return TSDB_CODE_SUCCESS;
2,896✔
3112
}
3113

3114
extern int32_t vnodeAsyncCompact(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
3115

3116
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
62,901✔
3117
  if (!pVnode->restored) {
62,901✔
3118
    vInfo("vgId:%d, ignore compact req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
2,448✔
3119
    return 0;
2,448✔
3120
  }
3121
  return vnodeAsyncCompact(pVnode, ver, pReq, len, pRsp);
60,453✔
3122
}
3123

3124
static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
3125
  if (syncCheckMember(pVnode->sync) != 0) {
×
3126
    vError("vgId:%d, failed to check member", TD_VID(pVnode));
×
3127
  }
3128

3129
  pRsp->msgType = TDMT_SYNC_CONFIG_CHANGE_RSP;
×
3130
  pRsp->code = TSDB_CODE_SUCCESS;
×
3131
  pRsp->pCont = NULL;
×
3132
  pRsp->contLen = 0;
×
3133

3134
  return 0;
×
3135
}
3136

3137
static int32_t vnodeCheckState(SVnode *pVnode) {
49,466✔
3138
  SSyncState syncState = syncGetState(pVnode->sync);
49,466✔
3139
  if (syncState.state != TAOS_SYNC_STATE_LEADER) {
49,466✔
3140
    return terrno = TSDB_CODE_SYN_NOT_LEADER;
19,871✔
3141
  }
3142
  return 0;
29,595✔
3143
}
3144

3145
static int32_t vnodeCheckToken(SVnode *pVnode, char *member0Token, char *member1Token) {
29,595✔
3146
  char token[TSDB_ARB_TOKEN_SIZE] = {0};
29,595✔
3147
  if (vnodeGetArbToken(pVnode, token) != 0) {
29,595✔
3148
    return terrno = TSDB_CODE_NOT_FOUND;
×
3149
  }
3150

3151
  if (strncmp(token, member0Token, TSDB_ARB_TOKEN_SIZE) != 0 &&
29,595✔
3152
      strncmp(token, member1Token, TSDB_ARB_TOKEN_SIZE) != 0) {
27,427✔
3153
    return terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
22,559✔
3154
  }
3155

3156
  terrno = TSDB_CODE_SUCCESS;
7,036✔
3157
  return 0;
7,036✔
3158
}
3159

3160
static int32_t vnodeCheckSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
11,810✔
3161
  int32_t code = vnodeCheckToken(pVnode, member0Token, member1Token);
11,810✔
3162
  if (code != 0) {
11,810✔
3163
    return code;
8,292✔
3164
  }
3165

3166
  return syncCheckSynced(pVnode->sync);
3,518✔
3167
}
3168

3169
static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) {
29,137✔
3170
  int32_t code = 0;
29,137✔
3171

3172
  if ((code = vnodeCheckState(pVnode)) != 0) {
29,137✔
3173
    vDebug("vgId:%d, failed to preprocess vnode-arb-check-sync request since %s", TD_VID(pVnode), tstrerror(code));
17,327✔
3174
    return 0;
17,327✔
3175
  }
3176

3177
  SVArbCheckSyncReq syncReq = {0};
11,810✔
3178

3179
  code = tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq);
11,810✔
3180
  if (code) {
11,810✔
3181
    return code;
×
3182
  }
3183

3184
  vInfo("vgId:%d, start to process vnode-arb-check-sync req QID:0x%" PRIx64 ":0x%" PRIx64 ", seqNum:%" PRIx64
11,810✔
3185
        ", arbToken:%s, member0Token:%s, member1Token:%s, "
3186
        "arbTerm:%" PRId64,
3187
        TD_VID(pVnode), pRsp->info.traceId.rootId, pRsp->info.traceId.msgId, pRsp->info.seqNum, syncReq.arbToken,
3188
        syncReq.member0Token, syncReq.member1Token, syncReq.arbTerm);
3189

3190
  pRsp->msgType = TDMT_VND_ARB_CHECK_SYNC_RSP;
11,810✔
3191
  pRsp->code = TSDB_CODE_SUCCESS;
11,810✔
3192
  pRsp->pCont = NULL;
11,810✔
3193
  pRsp->contLen = 0;
11,810✔
3194

3195
  SVArbCheckSyncRsp syncRsp = {0};
11,810✔
3196
  syncRsp.arbToken = syncReq.arbToken;
11,810✔
3197
  syncRsp.member0Token = syncReq.member0Token;
11,810✔
3198
  syncRsp.member1Token = syncReq.member1Token;
11,810✔
3199
  syncRsp.vgId = TD_VID(pVnode);
11,810✔
3200

3201
  if ((syncRsp.errCode = vnodeCheckSyncd(pVnode, syncReq.member0Token, syncReq.member1Token)) != 0) {
11,810✔
3202
    vError("vgId:%d, failed to check assigned log syncd since %s", TD_VID(pVnode), tstrerror(syncRsp.errCode));
8,292✔
3203
  }
3204

3205
  if ((code = vnodeUpdateArbTerm(pVnode, syncReq.arbTerm)) != 0) {
11,810✔
3206
    vError("vgId:%d, failed to update arb term since %s", TD_VID(pVnode), tstrerror(code));
×
3207
    goto _OVER;
×
3208
  }
3209

3210
  int32_t contLen = tSerializeSVArbCheckSyncRsp(NULL, 0, &syncRsp);
11,810✔
3211
  if (contLen <= 0) {
11,810✔
3212
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
3213
    code = -1;
×
3214
    goto _OVER;
×
3215
  }
3216
  void *pHead = rpcMallocCont(contLen);
11,810✔
3217
  if (!pHead) {
11,810✔
3218
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
3219
    code = -1;
×
3220
    goto _OVER;
×
3221
  }
3222

3223
  if (tSerializeSVArbCheckSyncRsp(pHead, contLen, &syncRsp) <= 0) {
11,810✔
3224
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
3225
    rpcFreeCont(pHead);
×
3226
    code = -1;
×
3227
    goto _OVER;
×
3228
  }
3229

3230
  pRsp->pCont = pHead;
11,810✔
3231
  pRsp->contLen = contLen;
11,810✔
3232

3233
  vInfo(
11,810✔
3234
      "vgId:%d, suceed to process vnode-arb-check-sync req rsp.code:%s, arbToken:%s, member0Token:%s, "
3235
      "member1Token:%s",
3236
      TD_VID(pVnode), tstrerror(syncRsp.errCode), syncRsp.arbToken, syncRsp.member0Token, syncRsp.member1Token);
3237

3238
  code = TSDB_CODE_SUCCESS;
11,810✔
3239

3240
_OVER:
11,810✔
3241
  if (code != 0) {
11,810✔
3242
    vError("vgId:%d, failed to process arb check req rsp.code:%s since %s", TD_VID(pVnode), tstrerror(syncRsp.errCode),
×
3243
           tstrerror(code));
3244
  }
3245
  tFreeSVArbCheckSyncReq(&syncReq);
11,810✔
3246
  return code;
11,810✔
3247
}
3248

3249
#ifndef TD_ENTERPRISE
3250
int32_t vnodeAsyncCompact(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) { return 0; }
3251
int32_t tsdbAsyncCompact(STsdb *tsdb, const STimeWindow *tw, ETsdbOpType type) { return 0; }
3252
#endif
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