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

taosdata / TDengine / #4981

11 Mar 2026 06:29AM UTC coverage: 68.488% (-0.004%) from 68.492%
#4981

push

travis-ci

web-flow
enh: [6548485194] Support push down ts condition in vtable query. (#34718)

62 of 76 new or added lines in 2 files covered. (81.58%)

859 existing lines in 123 files now uncovered.

211924 of 309434 relevant lines covered (68.49%)

135102255.25 hits per line

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

69.72
/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) {
68,400,722✔
85
  int32_t code = 0;
68,400,722✔
86
  int32_t lino = 0;
68,400,722✔
87

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

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

99
  // name
100
  char *name = NULL;
68,402,246✔
101
  if (tDecodeCStr(pCoder, &name) < 0) {
68,400,999✔
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);
68,400,999✔
108
  if (uid == 0) {
68,400,798✔
109
    uid = tGenIdPI64();
68,047,914✔
110
  }
111
  taosSetInt64Aligned((int64_t *)(pCoder->data + pCoder->pos), uid);
68,394,882✔
112

113
  // btime
114
  taosSetInt64Aligned((int64_t *)(pCoder->data + pCoder->pos + 8), btime);
68,396,713✔
115

116
  tEndDecode(pCoder);
68,392,405✔
117

118
_exit:
68,399,084✔
119
  if (code) {
68,396,780✔
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);
68,396,780✔
123
    if (pUid) *pUid = uid;
68,393,608✔
124
  }
125
  return code;
68,393,608✔
126
}
127
static int32_t vnodePreProcessCreateTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
48,214,626✔
128
  int32_t code = 0;
48,214,626✔
129
  int32_t lino = 0;
48,214,626✔
130

131
  int64_t  btime = taosGetTimestampMs();
48,214,692✔
132
  SDecoder dc = {0};
48,214,692✔
133
  int32_t  nReqs;
48,213,896✔
134

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

141
  if (tDecodeI32v(&dc, &nReqs) < 0) {
48,214,383✔
142
    code = TSDB_CODE_INVALID_MSG;
×
143
    TSDB_CHECK_CODE(code, lino, _exit);
×
144
  }
145
  for (int32_t iReq = 0; iReq < nReqs; iReq++) {
101,581,750✔
146
    code = vnodePreprocessCreateTableReq(pVnode, &dc, btime, NULL);
53,373,333✔
147
    TSDB_CHECK_CODE(code, lino, _exit);
53,367,367✔
148
  }
149

150
  tEndDecode(&dc);
48,208,417✔
151

152
_exit:
48,212,344✔
153
  tDecoderClear(&dc);
48,212,344✔
154
  if (code) {
48,213,970✔
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;
48,212,027✔
159
}
160

161
static int32_t vnodePreProcessAlterTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
12,062,182✔
162
  int32_t code = TSDB_CODE_INVALID_MSG;
12,062,182✔
163
  int32_t lino = 0;
12,062,182✔
164

165
  if (pVnode->config.isAudit) {
12,062,182✔
166
    return TSDB_CODE_PAR_PERMISSION_DENIED;
×
167
  }
168

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

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

182
  code = 0;
12,062,182✔
183

184
_exit:
12,062,182✔
185
  tDecoderClear(&dc);
12,062,182✔
186
  if (code) {
12,062,182✔
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,
12,062,182✔
190
           ctimeMs);
191
  }
192
  return code;
12,062,182✔
193
}
194

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

199
  SMsgHead *pContOld = pMsg->pCont;
10,970,312✔
200
  int32_t   reqLenOld = pMsg->contLen - sizeof(SMsgHead);
10,971,645✔
201

202
  SArray *tbUids = NULL;
10,972,074✔
203
  int64_t timestampMs = 0;
10,972,074✔
204

205
  SVDropTtlTableReq ttlReq = {0};
10,972,074✔
206
  if (tDeserializeSVDropTtlTableReq((char *)pContOld + sizeof(SMsgHead), reqLenOld, &ttlReq) != 0) {
10,969,914✔
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,967,338✔
213
    if (tbUids == NULL) {
10,971,708✔
214
      code = terrno;
×
215
      TSDB_CHECK_CODE(code, lino, _exit);
×
216
    }
217

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

225
    ttlReq.nUids = taosArrayGetSize(tbUids);
10,961,854✔
226
    ttlReq.pTbUids = tbUids;
10,963,019✔
227
  }
228

229
  if (ttlReq.nUids == 0) {
10,963,019✔
230
    code = TSDB_CODE_MSG_PREPROCESSED;
10,941,717✔
231
    TSDB_CHECK_CODE(code, lino, _exit);
10,941,717✔
232
  }
233

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

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

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

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

255
  code = 0;
11,595✔
256

257
_exit:
10,961,140✔
258
  taosArrayDestroy(tbUids);
10,961,738✔
259

260
  if (code && code != TSDB_CODE_MSG_PREPROCESSED) {
10,949,669✔
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,949,669✔
265
  }
266

267
  return code;
10,949,669✔
268
}
269

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

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

280
  SSubmitTbData submitTbData;
610,815,307✔
281
  uint8_t       version;
282
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
610,817,200✔
283
    code = TSDB_CODE_INVALID_MSG;
×
284
    TSDB_CHECK_CODE(code, lino, _exit);
×
285
  }
286
  version = (submitTbData.flags >> 8) & 0xff;
610,817,200✔
287
  submitTbData.flags = submitTbData.flags & 0xff;
610,817,200✔
288

289
  int64_t uid;
610,814,091✔
290
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
610,819,282✔
291
    code = vnodePreprocessCreateTableReq(pVnode, pCoder, btimeMs, &uid);
15,027,209✔
292
    TSDB_CHECK_CODE(code, lino, _exit);
15,023,430✔
293
  }
294

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

301
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
610,815,251✔
302
    taosSetInt64Aligned((int64_t *)(pCoder->data + pCoder->pos), uid);
15,024,867✔
303
    pCoder->pos += sizeof(int64_t);
15,022,757✔
304
  } else {
305
    if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
595,789,541✔
306
      code = TSDB_CODE_INVALID_MSG;
×
307
      TSDB_CHECK_CODE(code, lino, _exit);
×
308
    }
309
  }
310

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

316
  // scan and check
317
  TSKEY now = btimeMs;
610,815,182✔
318
  if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_MICRO) {
610,815,182✔
319
    now *= 1000;
2,458,384✔
320
  } else if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_NANO) {
608,357,127✔
321
    now *= 1000000;
1,423,225✔
322
  }
323

324
  int32_t keep = pVnode->config.tsdbCfg.keep2;
610,816,284✔
325

326
  TSKEY minKey = now - tsTickPerMin[pVnode->config.tsdbCfg.precision] * keep;
610,815,931✔
327
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
610,817,477✔
328
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
610,812,123✔
329
    uint64_t nColData;
6,475,595✔
330
    if (tDecodeU64v(pCoder, &nColData) < 0) {
6,475,396✔
331
      code = TSDB_CODE_INVALID_MSG;
×
332
      TSDB_CHECK_CODE(code, lino, _exit);
×
333
    }
334

335
    SColData colData = {0};
6,475,396✔
336
    code = tDecodeColData(version, pCoder, &colData, false);
6,475,440✔
337
    if (code) {
6,475,371✔
338
      code = TSDB_CODE_INVALID_MSG;
×
339
      TSDB_CHECK_CODE(code, lino, _exit);
×
340
    }
341

342
    if (colData.flag != HAS_VALUE) {
6,475,371✔
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;
576✔
350
        TSDB_CHECK_CODE(code, lino, _exit);
576✔
351
      }
352
    }
353

354
    for (uint64_t i = 1; i < nColData; i++) {
19,755,168✔
355
      code = tDecodeColData(version, pCoder, &colData, true);
13,412,876✔
356
      if (code) {
13,413,464✔
357
        code = TSDB_CODE_INVALID_MSG;
×
358
        TSDB_CHECK_CODE(code, lino, _exit);
×
359
      }
360
    }
361
  } else {
362
    uint64_t nRow;
604,333,419✔
363
    if (tDecodeU64v(pCoder, &nRow) < 0) {
604,337,860✔
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;
66,610✔
378
        TSDB_CHECK_CODE(code, lino, _exit);
66,610✔
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)) {
610,743,821✔
390
    taosSetInt64Aligned((int64_t *)(pCoder->data + pCoder->pos), ctimeMs);
610,744,415✔
391
    pCoder->pos += sizeof(int64_t);
610,737,374✔
392
  }
393

394
  tEndDecode(pCoder);
610,741,152✔
395

396
_exit:
610,817,407✔
397
  if (code) {
610,814,161✔
398
    vError("vgId:%d, %s:%d failed to vnodePreProcessSubmitTbData submit request since %s", TD_VID(pVnode), __func__,
67,186✔
399
           lino, tstrerror(code));
400
  }
401
  return code;
610,814,161✔
402
}
403
static int32_t vnodePreProcessSubmitMsg(SVnode *pVnode, SRpcMsg *pMsg) {
582,683,143✔
404
  int32_t code = 0;
582,683,143✔
405
  int32_t lino = 0;
582,683,143✔
406

407
  if (tsBypassFlag & TSDB_BYPASS_RA_RPC_RECV_SUBMIT) {
582,683,143✔
408
    return TSDB_CODE_MSG_PREPROCESSED;
59✔
409
  }
410

411
  SDecoder *pCoder = &(SDecoder){0};
582,683,084✔
412

413
  if (taosHton64(((SSubmitReq2Msg *)pMsg->pCont)->version) != 1) {
582,685,314✔
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));
582,683,773✔
419

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

425
  uint64_t nSubmitTbData;
582,680,880✔
426
  if (tDecodeU64v(pCoder, &nSubmitTbData) < 0) {
582,682,378✔
427
    code = TSDB_CODE_INVALID_MSG;
×
428
    TSDB_CHECK_CODE(code, lino, _exit);
×
429
  }
430

431
  int64_t btimeMs = taosGetTimestampMs();
582,685,457✔
432
  int64_t ctimeMs = btimeMs;
582,685,457✔
433
  for (int32_t i = 0; i < nSubmitTbData; i++) {
1,193,430,575✔
434
    code = vnodePreProcessSubmitTbData(pVnode, pCoder, btimeMs, ctimeMs);
610,813,365✔
435
    TSDB_CHECK_CODE(code, lino, _exit);
610,812,304✔
436
  }
437

438
  tEndDecode(pCoder);
582,617,210✔
439

440
_exit:
582,680,553✔
441
  tDecoderClear(pCoder);
582,684,163✔
442
  if (code) {
582,684,202✔
443
    vError("vgId:%d, %s:%d failed to preprocess submit request since %s, msg type:%s", TD_VID(pVnode), __func__, lino,
67,186✔
444
           tstrerror(code), TMSG_INFO(pMsg->msgType));
445
  }
446
  return code;
582,681,586✔
447
}
448

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

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

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

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

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

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

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

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

485
  taosArrayDestroy(res.uidList);
1,714,775✔
486

487
_exit:
1,714,775✔
488
  return code;
1,714,775✔
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) {
43,289✔
517
  int32_t ret = 0;
43,289✔
518
  if ((ret = vnodeCheckState(pVnode)) != 0) {
43,289✔
519
    vDebug("vgId:%d, failed to preprocess vnode-arb-check-sync request since %s", TD_VID(pVnode), tstrerror(ret));
10,891✔
520
    return 0;
10,891✔
521
  }
522

523
  SVArbCheckSyncReq syncReq = {0};
32,398✔
524

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

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

535
  int32_t code = terrno;
32,398✔
536
  tFreeSVArbCheckSyncReq(&syncReq);
32,398✔
537

538
  return code;
32,398✔
539
}
540

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

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

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

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

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

583
  tEncodeSize(tEncodeSVDropTbBatchReq, &sentBatchReqs, size, code);
1,527,427✔
584
  tEncoderInit(&ec, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), size);
1,527,427✔
585
  code = tEncodeSVDropTbBatchReq(&ec, &sentBatchReqs);
1,527,427✔
586
  tEncoderClear(&ec);
1,527,427✔
587
  if (code != TSDB_CODE_SUCCESS) {
1,527,427✔
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,527,427✔
593
  tDecoderClear(&dc);
1,527,427✔
594
  if (sentBatchReqs.pArray) {
1,527,427✔
595
    taosArrayDestroy(sentBatchReqs.pArray);
1,527,427✔
596
  }
597
  return code;
1,527,427✔
598
}
599

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

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

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

615
_exit:
3,665✔
616
  return code;
3,665✔
617
}
618

619
int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
677,819,045✔
620
  int32_t code = 0;
677,819,045✔
621

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

628
  switch (pMsg->msgType) {
677,819,702✔
629
    case TDMT_VND_CREATE_TABLE: {
48,214,692✔
630
      code = vnodePreProcessCreateTableMsg(pVnode, pMsg);
48,214,692✔
631
    } break;
48,212,439✔
632
    case TDMT_VND_ALTER_TABLE: {
12,062,182✔
633
      code = vnodePreProcessAlterTableMsg(pVnode, pMsg);
12,062,182✔
634
    } break;
12,062,182✔
635
    case TDMT_VND_FETCH_TTL_EXPIRED_TBS:
10,972,508✔
636
    case TDMT_VND_DROP_TTL_TABLE: {
637
      code = vnodePreProcessDropTtlMsg(pVnode, pMsg);
10,972,508✔
638
    } break;
10,957,224✔
639
    case TDMT_VND_SUBMIT: {
582,684,639✔
640
      METRICS_TIMING_BLOCK(pVnode->writeMetrics.preprocess_time, METRIC_LEVEL_LOW,
582,684,639✔
641
                           { code = vnodePreProcessSubmitMsg(pVnode, pMsg); });
642
    } break;
582,681,475✔
643
    case TDMT_VND_DELETE: {
1,714,775✔
644
      code = vnodePreProcessDeleteMsg(pVnode, pMsg);
1,714,775✔
645
    } break;
1,714,775✔
646
    case TDMT_VND_BATCH_DEL: {
×
647
      code = vnodePreProcessBatchDeleteMsg(pVnode, pMsg);
×
648
    } break;
×
649
    case TDMT_VND_ARB_CHECK_SYNC: {
43,289✔
650
      code = vnodePreProcessArbCheckSyncMsg(pVnode, pMsg);
43,289✔
651
    } break;
43,289✔
652
    case TDMT_VND_DROP_TABLE: {
1,527,427✔
653
      code = vnodePreProcessDropTbMsg(pVnode, pMsg);
1,527,427✔
654
    } break;
1,527,427✔
655
#ifdef TD_ENTERPRISE
656
    case TDMT_VND_SSMIGRATE_FILESET: {
1,875✔
657
      code = vnodePreProcessSsMigrateFileSetReq(pVnode, pMsg);
1,875✔
658
    } break;
3,665✔
659
#endif
660
    default:
20,595,714✔
661
      break;
20,595,714✔
662
  }
663

664
  if (code && code != TSDB_CODE_MSG_PREPROCESSED) {
677,798,190✔
665
    vError("vgId:%d, failed to preprocess write request since %s, msg type:%s", TD_VID(pVnode), tstrerror(code),
97,802✔
666
           TMSG_INFO(pMsg->msgType));
667
  }
668
  return code;
677,802,395✔
669
}
670

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

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

679
  SBseBatch *pBatch = NULL;
30,803✔
680

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

684
  SRow  **pRow = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP);
30,803✔
685
  int32_t rowIdx = -1;
30,803✔
686
  for (int32_t i = 0; i < sz; i++) {
24,175,836✔
687
    int64_t     seq = 0;
24,145,033✔
688
    SBlobValue *p = taosArrayGet(pBlobSet->pSeqTable, i);
24,145,033✔
689
    if (p->type == TSDB_DATA_BLOB_EMPTY_VALUE || p->type == TSDB_DATA_BLOB_NULL_VALUE) {
24,145,033✔
690
      // skip empty or null blob
691
      continue;
2,397,898✔
692
    }
693

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

697
    SRow *row = taosArrayGetP(pSubmitTbData->aRowP, i);
21,747,135✔
698
    if (row == NULL) {
21,747,135✔
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) {
43,494,270✔
705
      code = TSDB_CODE_INVALID_MSG;
×
706
      TSDB_CHECK_CODE(code, lino, _exit);
×
707
    }
708
  }
709

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

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

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

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

735
  SBseBatch *pBatch = NULL;
54✔
736

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

740
  SColData *p = (SColData *)TARRAY_DATA(pSubmitTbData->aCol);
54✔
741
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitTbData->aCol); i++) {
738✔
742
    if (IS_STR_DATA_BLOB(p[i].type)) {
738✔
743
      pBlobCol = &p[i];
54✔
744
      break;
54✔
745
    }
746
  }
747
  if (pBlobCol == NULL) {
54✔
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;
54✔
754
  // int32_t   rowIdx = -1;
755
  for (int32_t i = 0; i < sz; i++) {
114✔
756
    int64_t     seq = 0;
60✔
757
    SBlobValue *p = taosArrayGet(pBlobSet->pSeqTable, i);
60✔
758
    if (p->type == TSDB_DATA_BLOB_EMPTY_VALUE || p->type == TSDB_DATA_BLOB_NULL_VALUE) {
60✔
759
      // skip empty or null blob
760
      continue;
34✔
761
    }
762
    code = bseBatchPut(pBatch, &seq, pBlobSet->data + p->offset, p->len);
26✔
763
    TSDB_CHECK_CODE(code, lino, _exit);
26✔
764

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

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

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

793
  return code;
30,857✔
794
}
795

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

803
  (void)taosThreadMutexLock(&pVnode->mutex);
800,460,863✔
804
  if (pVnode->disableWrite) {
800,522,059✔
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);
800,472,583✔
810

811
  if (ver <= pVnode->state.applied) {
800,490,147✔
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,
800,474,394✔
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)) {
800,516,655✔
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)) {
800,530,528✔
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);
800,530,774✔
836
  atomic_store_64(&pVnode->state.applyTerm, pMsg->info.conn.applyTerm);
800,531,680✔
837

838
  if (!syncUtilUserCommit(pMsg->msgType)) goto _exit;
800,531,035✔
839

840
  // skip header
841
  pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
790,150,754✔
842
  len = pMsg->contLen - sizeof(SMsgHead);
790,150,897✔
843
  bool needCommit = false;
790,148,991✔
844
  bool forceTrimWal = false;
790,148,991✔
845

846
  switch (pMsg->msgType) {
790,148,991✔
847
    /* META */
848
    case TDMT_VND_CREATE_STB:
5,041,116✔
849
      code = vnodeProcessCreateStbReq(pVnode, ver, pReq, len, pRsp);
5,041,116✔
850
      TSDB_CHECK_CODE(code, lino, _err);
5,038,453✔
851
      break;
5,036,230✔
852
    case TDMT_VND_ALTER_STB:
7,580,804✔
853
      code = vnodeProcessAlterStbReq(pVnode, ver, pReq, len, pRsp);
7,580,804✔
854
      TSDB_CHECK_CODE(code, lino, _err);
7,580,804✔
855
      break;
7,580,804✔
856
    case TDMT_VND_DROP_STB:
892,875✔
857
      code = vnodeProcessDropStbReq(pVnode, ver, pReq, len, pRsp, pMsg);
892,875✔
858
      TSDB_CHECK_CODE(code, lino, _err);
892,875✔
859
      break;
892,875✔
860
    case TDMT_VND_CREATE_TABLE:
50,777,389✔
861
      code = vnodeProcessCreateTbReq(pVnode, ver, pReq, len, pRsp, pMsg);
50,777,389✔
862
      TSDB_CHECK_CODE(code, lino, _err);
50,766,605✔
863
      break;
50,766,605✔
864
    case TDMT_VND_ALTER_TABLE:
12,062,800✔
865
      code = vnodeProcessAlterTbReq(pVnode, ver, pReq, len, pRsp);
12,062,800✔
866
      TSDB_CHECK_CODE(code, lino, _err);
12,062,800✔
867
      break;
12,062,800✔
868
    case TDMT_VND_DROP_TABLE:
1,527,732✔
869
    case TDMT_VND_SNODE_DROP_TABLE:
870
      code = vnodeProcessDropTbReq(pVnode, ver, pReq, len, pRsp, pMsg);
1,527,732✔
871
      TSDB_CHECK_CODE(code, lino, _err);
1,527,732✔
872
      break;
1,527,732✔
873
    case TDMT_VND_CREATE_RSMA:
38,116✔
874
      code = vnodeProcessCreateRsmaReq(pVnode, ver, pReq, len, pRsp);
38,116✔
875
      TSDB_CHECK_CODE(code, lino, _err);
37,383✔
876
      break;
37,383✔
877
    case TDMT_VND_DROP_RSMA:
19,058✔
878
      code = vnodeProcessDropRsmaReq(pVnode, ver, pReq, len, pRsp);
19,058✔
879
      TSDB_CHECK_CODE(code, lino, _err);
19,058✔
880
      break;
19,058✔
881
    case TDMT_VND_ALTER_RSMA:
11,728✔
882
      code = vnodeProcessAlterRsmaReq(pVnode, ver, pReq, len, pRsp);
11,728✔
883
      TSDB_CHECK_CODE(code, lino, _err);
11,728✔
884
      break;
11,728✔
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,595✔
890
      code = vnodeProcessFetchTtlExpiredTbs(pVnode, ver, pReq, len, pRsp);
11,595✔
891
      TSDB_CHECK_CODE(code, lino, _err);
11,595✔
892
      break;
11,595✔
893
    case TDMT_VND_TRIM:
98,698✔
894
      code = vnodeProcessTrimReq(pVnode, ver, pReq, len, pRsp);
98,698✔
895
      TSDB_CHECK_CODE(code, lino, _err);
98,698✔
896
      break;
98,698✔
897
      case TDMT_VND_TRIM_WAL:
6,636✔
898
        needCommit = true;
6,636✔
899
        forceTrimWal = true;
6,636✔
900
        break;
6,636✔
901
#ifdef TD_ENTERPRISE
902
    case TDMT_VND_SSMIGRATE_FILESET:
3,665✔
903
      if (vnodeProcessSsMigrateFileSetReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
3,665✔
904
      break;
3,665✔
905
    case TDMT_VND_FOLLOWER_SSMIGRATE:
7,330✔
906
      if (vnodeProcessFollowerSsMigrateReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
7,330✔
907
      break;
7,330✔
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: {
694,064,310✔
915
      METRICS_TIMING_BLOCK(pVnode->writeMetrics.apply_time, METRIC_LEVEL_LOW, {
694,064,310✔
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);
694,019,158✔
919
      break;
694,009,870✔
920
    }
921
    case TDMT_VND_DELETE:
2,084,951✔
922
      code = vnodeProcessDeleteReq(pVnode, ver, pReq, len, pRsp, pMsg);
2,084,951✔
923
      TSDB_CHECK_CODE(code, lino, _err);
2,084,951✔
924
      break;
2,084,951✔
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,320,179✔
932
      code = tqProcessSubscribeReq(pVnode->pTq, ver, pReq, len);
1,320,179✔
933
      TSDB_CHECK_CODE(code, lino, _err);
1,316,664✔
934
      break;
1,316,664✔
935
    case TDMT_VND_TMQ_DELETE_SUB:
285,201✔
936
      code = tqProcessDeleteSubReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen);
285,201✔
937
      TSDB_CHECK_CODE(code, lino, _err);
283,651✔
938
      break;
283,651✔
939
    case TDMT_VND_TMQ_COMMIT_OFFSET:
4,783,987✔
940
      code = tqProcessOffsetCommitReq(pVnode->pTq, ver, pReq, len);
4,783,987✔
941
      TSDB_CHECK_CODE(code, lino, _err);
4,782,683✔
942
      break;
4,782,683✔
943
#endif
944
    case TDMT_VND_ALTER_CONFIRM:
4,090,287✔
945
      needCommit = pVnode->config.hashChange;
4,090,287✔
946
      code = vnodeProcessAlterConfirmReq(pVnode, ver, pReq, len, pRsp);
4,090,287✔
947
      TSDB_CHECK_CODE(code, lino, _err);
4,090,287✔
948
      break;
4,090,287✔
949
    case TDMT_VND_ALTER_CONFIG:
323,325✔
950
      vnodeProcessAlterConfigReq(pVnode, ver, pReq, len, pRsp);
323,325✔
951
      break;
323,325✔
952
    case TDMT_VND_COMMIT:
4,990,074✔
953
      needCommit = true;
4,990,074✔
954
      break;
4,990,074✔
955
    case TDMT_VND_CREATE_INDEX:
16,845✔
956
      vnodeProcessCreateIndexReq(pVnode, ver, pReq, len, pRsp);
16,845✔
957
      break;
16,845✔
958
    case TDMT_VND_DROP_INDEX:
13,884✔
959
      vnodeProcessDropIndexReq(pVnode, ver, pReq, len, pRsp);
13,884✔
960
      break;
13,884✔
961
    case TDMT_VND_COMPACT:
68,526✔
962
      vnodeProcessCompactVnodeReq(pVnode, ver, pReq, len, pRsp);
68,526✔
963
      goto _exit;
68,526✔
964
    case TDMT_VND_SCAN:
205✔
965
      vnodeProcessScanVnodeReq(pVnode, ver, pReq, len, pRsp);
205✔
966
      goto _exit;
205✔
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,482✔
972
      vnodeProcessKillCompactReq(pVnode, ver, pReq, len, pRsp);
1,482✔
973
      break;
1,482✔
974
#endif
975
    case TDMT_VND_KILL_SCAN:
82✔
976
      vnodeProcessKillScanReq(pVnode, ver, pReq, len, pRsp);
82✔
977
      break;
82✔
978
    case TDMT_VND_KILL_TRIM:
×
979
      vnodeProcessKillRetentionReq(pVnode, ver, pReq, len, pRsp);
×
980
      break;
×
981
    /* ARB */
982
    case TDMT_VND_ARB_CHECK_SYNC:
25,387✔
983
      vnodeProcessArbCheckSyncReq(pVnode, pReq, len, pRsp);
25,387✔
984
      break;
25,387✔
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);
790,002,324✔
991

992
  walApplyVer(pVnode->pWal, ver);
790,031,305✔
993

994
  if (pVnode->pTq) {
790,037,010✔
995
    code = tqPushMsg(pVnode->pTq, pMsg->msgType);
790,037,010✔
996
    if (code) {
790,035,548✔
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) {
790,035,548✔
1004
    vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), ver);
5,021,445✔
1005
    code = vnodeAsyncCommit(pVnode, forceTrimWal);
5,021,445✔
1006
    if (code) {
5,021,661✔
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, {
5,021,661✔
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:
790,035,764✔
1022
  return 0;
800,478,281✔
1023

1024
_err:
44,708✔
1025
  if (code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
44,708✔
1026
    vInfo("vgId:%d, process %s request failed since %s, lino 1:%d ver:%" PRId64, TD_VID(pVnode),
2,223✔
1027
          TMSG_INFO(pMsg->msgType), tstrerror(code), lino, ver);
1028
  } else if (code) {
42,485✔
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;
44,708✔
1034
}
1035

1036
int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
409,547,938✔
1037
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) {
409,547,938✔
1038
    return 0;
79,325,340✔
1039
  }
1040

1041
  int32_t qType = 0;
330,239,400✔
1042
  return qWorkerPreprocessQueryMsg(pVnode->pQuery, pMsg, (TDMT_SCH_QUERY == pMsg->msgType), &qType);
330,248,568✔
1043
}
1044

1045
int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
409,565,869✔
1046
  const STraceId *trace = &pMsg->info.traceId;
409,565,869✔
1047
  vDebug("vgId:%d, msg:%s, %p in vnode query queue is processing, %" PRIx64 ":%" PRIx64, 
409,568,081✔
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)) {
409,579,458✔
1051
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
365,565✔
1052
    return 0;
365,565✔
1053
  }
1054

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

1060
  SReadHandle handle = {0};
409,220,152✔
1061
  handle.vnode = pVnode;
409,222,464✔
1062
  handle.pMsgCb = &pVnode->msgCb;
409,222,464✔
1063
  handle.pWorkerCb = pInfo->workerCb;
409,205,520✔
1064
  initStorageAPI(&handle.api);
409,205,654✔
1065
  int32_t code = TSDB_CODE_SUCCESS;
409,202,564✔
1066
  bool    redirected = false;
409,202,564✔
1067

1068
  switch (pMsg->msgType) {
409,202,564✔
1069
    case TDMT_SCH_QUERY:
271,812,111✔
1070
      if (!syncIsReadyForRead(pVnode->sync)) {
271,812,111✔
1071
        pMsg->code = (terrno) ? terrno : TSDB_CODE_SYN_NOT_LEADER;
1,806,887✔
1072
        redirected = true;
1,806,887✔
1073
      }
1074
      code = qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
271,812,050✔
1075
      if (redirected) {
271,797,943✔
1076
        vnodeRedirectRpcMsg(pVnode, pMsg, pMsg->code);
1,806,887✔
1077
        return 0;
1,806,887✔
1078
      }
1079

1080
      return code;
269,991,056✔
1081
    case TDMT_SCH_MERGE_QUERY:
58,445,500✔
1082
      return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
58,445,500✔
1083
    case TDMT_SCH_QUERY_CONTINUE:
38,671,029✔
1084
      return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
38,671,029✔
1085
    case TDMT_VND_TMQ_CONSUME:
30,310,708✔
1086
      return tqProcessPollReq(pVnode->pTq, pMsg);
30,310,708✔
1087
    case TDMT_VND_TMQ_CONSUME_PUSH:
9,968,135✔
1088
      return tqProcessPollPush(pVnode->pTq);
9,968,135✔
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) {
982,052,446✔
1096
  int32_t code = TSDB_CODE_SUCCESS;
982,052,446✔
1097
  const STraceId *trace = &pMsg->info.traceId;
982,052,446✔
1098
  vDebug("vgId:%d, msg:%s, %p in fetch queue is processing, %" PRIx64 ":%" PRIx64, 
982,087,145✔
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 ||
982,177,212✔
1101
       pMsg->msgType == TDMT_VND_BATCH_META || pMsg->msgType == TDMT_VND_TABLE_NAME ||
682,577,847✔
1102
       pMsg->msgType == TDMT_VND_VSUBTABLES_META || pMsg->msgType == TDMT_VND_VSTB_REF_DBS) &&
655,111,061✔
1103
      !syncIsReadyForRead(pVnode->sync)) {
327,066,241✔
1104
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
531,396✔
1105
    return 0;
531,396✔
1106
  }
1107

1108
  switch (pMsg->msgType) {
981,654,518✔
1109
    case TDMT_SCH_FETCH:
453,943,326✔
1110
    case TDMT_SCH_MERGE_FETCH:
1111
      return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg, 0);
453,943,326✔
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:
330,016,339✔
1117
      return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg, 0);
330,016,339✔
1118
    case TDMT_SCH_TASK_NOTIFY:
11,154✔
1119
      return qWorkerProcessNotifyMsg(pVnode, pVnode->pQuery, pMsg, 0);
11,154✔
1120
    case TDMT_SCH_QUERY_HEARTBEAT:
169,566,060✔
1121
      return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg, 0);
169,566,060✔
1122
    case TDMT_VND_TABLE_META:
898,231✔
1123
    case TDMT_VND_TABLE_NAME:
1124
      return vnodeGetTableMeta(pVnode, pMsg, true);
898,231✔
1125
    case TDMT_VND_TABLE_CFG:
×
1126
      return vnodeGetTableCfg(pVnode, pMsg, true);
×
1127
    case TDMT_VND_BATCH_META: {
26,936,798✔
1128
      METRICS_TIMING_BLOCK(pVnode->writeMetrics.fetch_batch_meta_time, METRIC_LEVEL_LOW,
26,936,798✔
1129
                           { code = vnodeGetBatchMeta(pVnode, pMsg); });
1130
      METRICS_UPDATE(pVnode->writeMetrics.fetch_batch_meta_count, METRIC_LEVEL_LOW, 1);
26,937,318✔
1131
      return code;
26,935,554✔
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:
410✔
1138
      return vnodeQueryScanProgress(pVnode, pMsg);
410✔
1139
#ifdef TD_ENTERPRISE
1140
    case TDMT_VND_QUERY_COMPACT_PROGRESS:
105,742✔
1141
      return vnodeQueryCompactProgress(pVnode, pMsg);
105,742✔
1142

1143
    case TDMT_VND_LIST_SSMIGRATE_FILESETS:
4,398✔
1144
      return vnodeListSsMigrateFileSets(pVnode, pMsg);
4,398✔
1145

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

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

1172
  tstrncpy(pMetaRsp->dbFName, pVnode->config.dbname, TSDB_DB_FNAME_LEN);
76,751,696✔
1173
  pMetaRsp->dbId = pVnode->config.dbId;
76,752,902✔
1174
  pMetaRsp->vgId = TD_VID(pVnode);
76,752,592✔
1175
  pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
76,752,586✔
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) {
98,698✔
1181
  if (!pVnode->restored) {
98,698✔
1182
    vInfo("vgId:%d, ignore trim req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
3,157✔
1183
    return 0;
3,157✔
1184
  }
1185

1186
  int32_t     code = 0;
95,541✔
1187
  SVTrimDbReq trimReq = {0};
95,541✔
1188

1189
  // decode
1190
  if (tDeserializeSVTrimDbReq(pReq, len, &trimReq) != 0) {
95,541✔
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,
95,541✔
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);
95,541✔
1199

1200
_exit:
95,541✔
1201
  return code;
95,541✔
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) {
3,665✔
1209
  int32_t code = 0;
3,665✔
1210

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

1218
  if (tDeserializeSSsMigrateFileSetReq(pReq, len, &req) != 0) {
3,665✔
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,
3,665✔
1224
        req.ssMigrateId, req.fid, req.startTimeSec);
1225
  rsp.ssMigrateId = req.ssMigrateId;
3,665✔
1226
  rsp.vgId = TD_VID(pVnode);
3,665✔
1227
  rsp.nodeId = req.nodeId;
3,665✔
1228
  rsp.fid = req.fid;
3,665✔
1229

1230
  code = vnodeAsyncSsMigrateFileSet(pVnode, &req);
3,665✔
1231
  if (code != TSDB_CODE_SUCCESS) {
3,665✔
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;
3,665✔
1238
  pRsp->contLen = tSerializeSSsMigrateFileSetRsp(NULL, 0, &rsp);
3,665✔
1239
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
3,665✔
1240
  if (pRsp->pCont == NULL) {
3,665✔
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));
3,665✔
1246

1247
_exit:
3,665✔
1248
  pRsp->code = code;
3,665✔
1249
  return code;
3,665✔
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) {
7,330✔
1255
  int32_t            code = 0;
7,330✔
1256
  SSsMigrateProgress req = {0};
7,330✔
1257

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

1264
  code = vnodeFollowerSsMigrate(pVnode, &req);
7,330✔
1265

1266
_exit:
7,330✔
1267
  pRsp->code = code;
7,330✔
1268
  return code;
7,330✔
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,595✔
1324
  int32_t                 code = -1;
11,595✔
1325
  SMetaReader             mr = {0};
11,595✔
1326
  SVDropTtlTableReq       ttlReq = {0};
11,595✔
1327
  SVFetchTtlExpiredTbsRsp rsp = {0};
11,595✔
1328
  SEncoder                encoder = {0};
11,595✔
1329
  SArray                 *pNames = NULL;
11,595✔
1330
  pRsp->msgType = TDMT_VND_FETCH_TTL_EXPIRED_TBS_RSP;
11,595✔
1331
  pRsp->code = TSDB_CODE_SUCCESS;
11,595✔
1332
  pRsp->pCont = NULL;
11,595✔
1333
  pRsp->contLen = 0;
11,595✔
1334

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

1340
  if (!(ttlReq.nUids == taosArrayGetSize(ttlReq.pTbUids))) {
11,595✔
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,595✔
1348
  metaReaderDoInit(&mr, pVnode->pMeta, 0);
11,595✔
1349
  rsp.vgId = TD_VID(pVnode);
11,595✔
1350
  rsp.pExpiredTbs = taosArrayInit(ttlReq.nUids, sizeof(SVDropTbReq));
11,595✔
1351
  if (!rsp.pExpiredTbs) goto _end;
11,595✔
1352

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

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

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

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

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

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

1407
  pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
5,041,116✔
1408
  pRsp->code = TSDB_CODE_SUCCESS;
5,041,116✔
1409
  pRsp->pCont = NULL;
5,041,116✔
1410
  pRsp->contLen = 0;
5,040,563✔
1411

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

1415
  code = tDecodeSVCreateStbReq(&coder, &req);
5,041,116✔
1416
  if (code) {
5,024,205✔
1417
    pRsp->code = code;
×
1418
    goto _err;
×
1419
  }
1420

1421
  code = metaCreateSuperTable(pVnode->pMeta, ver, &req);
5,024,205✔
1422
  if (code) {
5,040,549✔
1423
    pRsp->code = code;
2,223✔
1424
    goto _err;
2,223✔
1425
  }
1426

1427
  tDecoderClear(&coder);
5,038,326✔
1428
  return 0;
5,037,196✔
1429

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

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

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

1461
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(cRsp));
50,774,545✔
1462
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
50,774,745✔
1463
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
50,770,376✔
1464
  if (rsp.pArray == NULL || tbUids == NULL || tbNames == NULL) {
50,770,970✔
UNCOV
1465
    rcode = -1;
×
UNCOV
1466
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1467
    goto _exit;
×
1468
  }
1469

1470
  // loop to create table
1471
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
109,139,549✔
1472
    pCreateReq = req.pReqs + iReq;
58,364,736✔
1473
    memset(&cRsp, 0, sizeof(cRsp));
58,364,751✔
1474

1475
    if (tsEnableAudit && tsEnableAuditCreateTable && tsAuditLevel >= AUDIT_LEVEL_CHILDTABLE) {
58,364,751✔
1476
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
59✔
1477
      if (str == NULL) {
59✔
1478
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1479
        rcode = -1;
×
1480
        goto _exit;
×
1481
      }
1482
      tstrncpy(str, pCreateReq->name, TSDB_TABLE_FNAME_LEN);
59✔
1483
      if (taosArrayPush(tbNames, &str) == NULL) {
59✔
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);
58,364,751✔
1492
    if (vnodeValidateTableHash(pVnode, tbName) < 0) {
58,364,583✔
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) {
58,352,539✔
1505
      if (pCreateReq->flags & TD_CREATE_IF_NOT_EXISTS && terrno == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
14,946✔
1506
        cRsp.code = TSDB_CODE_SUCCESS;
3,417✔
1507
      } else {
1508
        cRsp.code = terrno;
11,491✔
1509
      }
1510
    } else {
1511
      cRsp.code = TSDB_CODE_SUCCESS;
58,352,497✔
1512
      if (taosArrayPush(tbUids, &pCreateReq->uid) == NULL) {
116,704,988✔
1513
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1514
        rcode = -1;
×
1515
        goto _exit;
×
1516
      }
1517
      vnodeUpdateMetaRsp(pVnode, cRsp.pMeta);
58,352,491✔
1518
    }
1519

1520
    if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
116,733,395✔
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));
50,774,813✔
1528
  if (tqAddTbUidList(pVnode->pTq, tbUids) < 0) {
50,774,813✔
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;
50,776,619✔
1534
  tEncodeSize(tEncodeSVCreateTbBatchRsp, &rsp, pRsp->contLen, ret);
50,776,619✔
1535
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
50,772,192✔
1536
  if (pRsp->pCont == NULL) {
50,766,279✔
1537
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1538
    rcode = -1;
×
1539
    goto _exit;
×
1540
  }
1541
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
50,766,367✔
1542
  if (tEncodeSVCreateTbBatchRsp(&encoder, &rsp) != 0) {
50,769,510✔
1543
    vError("vgId:%d, failed to encode create table batch response", TD_VID(pVnode));
×
1544
  }
1545

1546
  if (tsEnableAudit && tsEnableAuditCreateTable && tsAuditLevel >= AUDIT_LEVEL_CHILDTABLE) {
50,768,667✔
1547
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
59✔
1548

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

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

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

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

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

1577
_exit:
50,768,667✔
1578
  tDeleteSVCreateTbBatchReq(&req);
50,770,936✔
1579
  taosArrayDestroyEx(rsp.pArray, tFreeSVCreateTbRsp);
50,773,569✔
1580
  taosArrayDestroy(tbUids);
50,759,663✔
1581
  tDecoderClear(&decoder);
50,758,917✔
1582
  tEncoderClear(&encoder);
50,775,771✔
1583
  taosArrayDestroyP(tbNames, NULL);
50,774,300✔
1584
  return rcode;
50,771,297✔
1585
}
1586

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

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

1597
  tDecoderInit(&dc, pReq, len);
7,580,804✔
1598

1599
  // decode req
1600
  code = tDecodeSVCreateStbReq(&dc, &req);
7,580,804✔
1601
  if (code) {
7,573,744✔
1602
    tDecoderClear(&dc);
×
1603
    return code;
×
1604
  }
1605

1606
  code = metaAlterSuperTable(pVnode->pMeta, ver, &req);
7,573,744✔
1607
  if (code) {
7,580,804✔
1608
    pRsp->code = code;
×
1609
    tDecoderClear(&dc);
×
1610
    return code;
×
1611
  }
1612

1613
  tDecoderClear(&dc);
7,580,804✔
1614

1615
  return 0;
7,580,804✔
1616
}
1617

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

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

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

1635
  STraceId* trace = &(pOriginRpc->info.traceId);
892,875✔
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, 
892,875✔
1638
              trace ? trace->msgId : 0, req.name);
1639

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

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

1653
  // return rsp
1654
_exit:
892,875✔
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, 
892,603✔
1656
              trace ? trace->msgId : 0, req.name);
1657
  if (tbUidList) taosArrayDestroy(tbUidList);
892,875✔
1658
  pRsp->code = rcode;
892,875✔
1659
  tDecoderClear(&decoder);
892,875✔
1660
  return 0;
892,875✔
1661
}
1662

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

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

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

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

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

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

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

1714
  pRsp->msgType = TDMT_VND_ALTER_TABLE_RSP;
12,062,800✔
1715
  pRsp->pCont = NULL;
12,062,800✔
1716
  pRsp->contLen = 0;
12,062,800✔
1717
  pRsp->code = TSDB_CODE_SUCCESS;
12,062,800✔
1718

1719
  tDecoderInit(&dc, pReq, len);
12,062,800✔
1720

1721
  // decode
1722
  if (tDecodeSVAlterTbReq(&dc, &vAlterTbReq) < 0) {
12,062,800✔
1723
    vAlterTbRsp.code = TSDB_CODE_INVALID_MSG;
×
1724
    tDecoderClear(&dc);
×
1725
    goto _exit;
×
1726
  }
1727

1728
  // process
1729
  if (metaAlterTable(pVnode->pMeta, ver, &vAlterTbReq, &vMetaRsp) < 0) {
12,062,800✔
1730
    vAlterTbRsp.code = terrno;
706,713✔
1731
    tDecoderClear(&dc);
706,713✔
1732
    goto _exit;
706,713✔
1733
  }
1734
  tDecoderClear(&dc);
11,356,087✔
1735

1736
  if (NULL != vMetaRsp.pSchemas) {
11,356,087✔
1737
    vnodeUpdateMetaRsp(pVnode, &vMetaRsp);
3,695,438✔
1738
    vAlterTbRsp.pMeta = &vMetaRsp;
3,695,438✔
1739
  }
1740

1741
  if (vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL || vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL) {
11,356,087✔
1742
    alterTagForTmq(pVnode, &vAlterTbReq);
7,629,734✔
1743
  }
1744

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

1754
  tEncoderClear(&ec);
12,062,800✔
1755
  if (vMetaRsp.pSchemas) {
12,062,800✔
1756
    taosMemoryFree(vMetaRsp.pSchemas);
3,695,438✔
1757
    taosMemoryFree(vMetaRsp.pSchemaExt);
3,695,438✔
1758
  }
1759
  if (vMetaRsp.pColRefs) {
12,062,800✔
1760
    taosMemoryFree(vMetaRsp.pColRefs);
268,288✔
1761
  }
1762
  return 0;
12,062,800✔
1763
}
1764

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

1776
  pRsp->msgType = ((SRpcMsg *)pReq)->msgType + 1;
1,527,732✔
1777
  pRsp->pCont = NULL;
1,527,732✔
1778
  pRsp->contLen = 0;
1,527,732✔
1779
  pRsp->code = TSDB_CODE_SUCCESS;
1,527,732✔
1780

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

1790
  // process req
1791
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
1,527,732✔
1792
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(SVDropTbRsp));
1,527,732✔
1793
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
1,527,732✔
1794
  if (tbUids == NULL || rsp.pArray == NULL || tbNames == NULL) goto _exit;
1,527,732✔
1795

1796
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
3,101,149✔
1797
    SVDropTbReq *pDropTbReq = req.pReqs + iReq;
1,573,417✔
1798
    SVDropTbRsp  dropTbRsp = {0};
1,573,417✔
1799
    tb_uid_t     tbUid = 0;
1,573,417✔
1800

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

1813
    if (taosArrayPush(rsp.pArray, &dropTbRsp) == NULL) {
3,146,834✔
1814
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1815
      pRsp->code = terrno;
×
1816
      goto _exit;
×
1817
    }
1818

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

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

1838
  if (tsEnableAudit && tsEnableAuditCreateTable && tsAuditLevel >= AUDIT_LEVEL_CHILDTABLE) {
1,527,732✔
1839
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
×
1840

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

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

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

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

1866
    taosStringBuilderDestroy(&sb);
×
1867
  }
1868

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

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

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

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

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

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

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

1944
  suid = msgIter->suid;
1945
  rv = TD_ROW_SVER(blkIter.row);
1946

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

1953
  taosMemoryFreeClear(pSchema);
1954

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

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

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

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

2007
  return TSDB_CODE_SUCCESS;
×
2008
}
2009

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

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

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

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

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

2046
  pColVal->flag = CV_FLAG_VALUE;
×
2047
  return TSDB_CODE_SUCCESS;
×
2048
}
2049

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

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

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

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

2079
  return code;
×
2080
}
2081

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

2088
  SSubmitReqConvertCxt cxt = {0};
×
2089

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

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

2122
  vnodeDestroySubmitReqConvertCxt(&cxt);
×
2123
  return code;
×
2124
}
2125

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

2149
static int32_t buildExistSubTalbeRsp(SVnode *pVnode, SSubmitTbData *pSubmitTbData, STableMetaRsp **ppRsp) {
58,160✔
2150
  int32_t code = 0;
58,160✔
2151
  int32_t lino = 0;
58,160✔
2152

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

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

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

2208
static int32_t buildExistNormalTalbeRsp(SVnode *pVnode, int64_t uid, STableMetaRsp **ppRsp) {
38,147✔
2209
  int32_t code = 0;
38,147✔
2210
  int32_t lino = 0;
38,147✔
2211

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

2224
  *ppRsp = taosMemoryCalloc(1, sizeof(STableMetaRsp));
38,147✔
2225
  if (NULL == *ppRsp) {
38,147✔
2226
    TSDB_CHECK_CODE(code = terrno, lino, _exit);
×
2227
  }
2228

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

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

2257
static int32_t buildExistTableInStreamRsp(SVnode *pVnode, SSubmitTbData *pSubmitTbData, STableMetaRsp **ppRsp) {
292,853✔
2258
  if (pSubmitTbData->pCreateTbReq->flags & TD_CREATE_NORMAL_TB_IN_STREAM) {
292,853✔
2259
    int32_t code = buildExistNormalTalbeRsp(pVnode, pSubmitTbData->uid, ppRsp);
38,147✔
2260
    if (code) {
38,147✔
2261
      vError("vgId:%d, table uid:%" PRId64 " not exists, line:%d", TD_VID(pVnode), pSubmitTbData->uid, __LINE__);
×
2262
      return code;
×
2263
    }
2264
    return TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
38,147✔
2265
  } else if (pSubmitTbData->pCreateTbReq->flags & TD_CREATE_SUB_TB_IN_STREAM) {
254,706✔
2266
    return buildExistSubTalbeRsp(pVnode, pSubmitTbData, ppRsp);
57,944✔
2267
  }
2268
  return TSDB_CODE_SUCCESS;
196,546✔
2269
}
2270

2271
static int32_t vnodeHandleAutoCreateTable(SVnode      *pVnode,    // vnode
694,065,990✔
2272
                                          int64_t      version,   // version
2273
                                          SSubmitReq2 *pRequest,  // request
2274
                                          SSubmitRsp2 *pResponse  // response
2275
) {
2276
  int32_t code = TSDB_CODE_SUCCESS;
694,065,990✔
2277
  int32_t numTbData = taosArrayGetSize(pRequest->aSubmitTbData);
694,065,990✔
2278
  SArray *newTbUids = NULL;
694,065,957✔
2279

2280
  for (int32_t i = 0; i < numTbData; ++i) {
1,416,225,252✔
2281
    SSubmitTbData *pTbData = taosArrayGet(pRequest->aSubmitTbData, i);
722,199,329✔
2282

2283
    if (pTbData->pCreateTbReq == NULL) {
722,200,206✔
2284
      continue;
707,154,411✔
2285
    }
2286

2287
    pTbData->uid = pTbData->pCreateTbReq->uid;
15,044,632✔
2288

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

2301
    // Do create table
2302
    vDebug("vgId:%d start to handle auto create table, version:%" PRId64, TD_VID(pVnode), version);
15,044,202✔
2303

2304
    SVCreateTbRsp *pCreateTbRsp = taosArrayReserve(pResponse->aCreateTbRsp, 1);
15,044,236✔
2305
    code = metaCreateTable2(pVnode->pMeta, version, pTbData->pCreateTbReq, &pCreateTbRsp->pMeta);
15,044,632✔
2306
    if (code == TSDB_CODE_SUCCESS) {
15,044,599✔
2307
      // Allocate necessary resources
2308
      if (newTbUids == NULL) {
14,706,107✔
2309
        newTbUids = taosArrayInit(numTbData, sizeof(int64_t));
11,940,607✔
2310
        if (newTbUids == NULL) {
11,940,291✔
2311
          code = terrno;
×
2312
          vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
×
2313
                 tstrerror(code), version);
2314
          return code;
×
2315
        }
2316
      }
2317

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

2326
      if (pCreateTbRsp->pMeta) {
14,706,107✔
2327
        vnodeUpdateMetaRsp(pVnode, pCreateTbRsp->pMeta);
14,706,107✔
2328
      }
2329
    } else if (code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
338,492✔
2330
      code = terrno = 0;
337,456✔
2331
      pTbData->uid = pTbData->pCreateTbReq->uid;  // update uid if table exist for using below
337,456✔
2332

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

2354
  // Update the affected table uid list
2355
  if (taosArrayGetSize(newTbUids) > 0) {
694,025,923✔
2356
    vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
11,940,607✔
2357
           (int32_t)taosArrayGetSize(newTbUids));
2358
    if (tqAddTbUidList(pVnode->pTq, newTbUids) != 0) {
11,940,607✔
2359
      vError("vgId:%d, failed to update tbUid list", TD_VID(pVnode));
×
2360
    }
2361
  }
2362

2363
  vDebug("vgId:%d, handle auto create table done, version:%" PRId64, TD_VID(pVnode), version);
694,025,475✔
2364

2365
  taosArrayDestroy(newTbUids);
694,025,508✔
2366
  return code;
694,024,917✔
2367
}
2368

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

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

2407
static int32_t vnodeHandleDataWrite(SVnode *pVnode, int64_t version, SSubmitReq2 *pRequest, SSubmitRsp2 *pResponse) {
694,024,977✔
2408
  int32_t code = TSDB_CODE_SUCCESS;
694,024,977✔
2409
  int32_t numTbData = taosArrayGetSize(pRequest->aSubmitTbData);
694,024,977✔
2410
  int8_t  hasBlob = 0;
694,025,202✔
2411

2412
  // Scan submit data
2413
  for (int32_t i = 0; i < numTbData; ++i) {
1,416,181,462✔
2414
    SMetaInfo      info = {0};
722,158,250✔
2415
    SSubmitTbData *pTbData = taosArrayGet(pRequest->aSubmitTbData, i);
722,158,766✔
2416

2417
    if (pTbData->flags & SUBMIT_REQ_WITH_BLOB) {
722,160,625✔
2418
      hasBlob = 1;
30,857✔
2419
    }
2420
    if (pTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
722,160,482✔
2421
      continue;  // skip column data format
6,476,085✔
2422
    }
2423
    if (pTbData->flags & SUBMIT_REQ_ONLY_CREATE_TABLE) {
715,682,052✔
2424
      continue;  // skip only crate table request
2,428,740✔
2425
    }
2426

2427
    code = metaGetInfo(pVnode->pMeta, pTbData->uid, &info, NULL);
713,253,903✔
2428
    if (code) {
713,252,825✔
2429
      code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
2,458✔
2430
      vWarn("vgId:%d, error occurred at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __FILE__,
2,458✔
2431
            __LINE__, tstrerror(code), version, pTbData->uid);
2432
      return code;
2,458✔
2433
    }
2434

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

2444
    if (info.suid) {
713,248,959✔
2445
      code = metaGetInfo(pVnode->pMeta, info.suid, &info, NULL);
523,389,075✔
2446
      if (code) {
523,392,834✔
2447
        code = TSDB_CODE_INTERNAL_ERROR;
×
2448
        vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " suid:%" PRId64, TD_VID(pVnode), __func__,
×
2449
               __FILE__, __LINE__, tstrerror(code), version, info.suid);
2450
        return code;
×
2451
      }
2452
    }
2453

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

2466
  // Do write data
2467
  vDebug("vgId:%d start to handle data write, version:%" PRId64, TD_VID(pVnode), version);
694,023,212✔
2468

2469
  for (int32_t i = 0; i < numTbData; ++i) {
1,416,161,638✔
2470
    int32_t        affectedRows = 0;
722,151,652✔
2471
    SSubmitTbData *pTbData = taosArrayGet(pRequest->aSubmitTbData, i);
722,151,307✔
2472

2473
    if (pTbData->flags & SUBMIT_REQ_ONLY_CREATE_TABLE) {
722,153,568✔
2474
      continue;
2,428,740✔
2475
    }
2476

2477
    if (hasBlob) {
719,725,022✔
2478
      code = vnodeSubmitBlobData(pVnode, pTbData);
30,857✔
2479
      if (code) {
30,857✔
2480
        vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __func__,
×
2481
               __FILE__, __LINE__, tstrerror(code), version, pTbData->uid);
2482
        return code;
×
2483
      }
2484
    }
2485

2486
    code = tsdbInsertTableData(pVnode->pTsdb, version, pTbData, &affectedRows);
719,725,022✔
2487
    if (code) {
719,706,700✔
2488
      vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __func__,
×
2489
             __FILE__, __LINE__, tstrerror(code), version, pTbData->uid);
2490
      return code;
×
2491
    }
2492

2493
    code = metaUpdateChangeTimeWithLock(pVnode->pMeta, pTbData->uid, pTbData->ctimeMs);
719,706,700✔
2494
    if (code) {
719,699,428✔
2495
      vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __func__,
×
2496
             __FILE__, __LINE__, tstrerror(code), version, pTbData->uid);
2497
      return code;
×
2498
    }
2499
    pResponse->affectedRows += affectedRows;
719,699,428✔
2500
  }
2501

2502
  vDebug("vgId:%d, handle data write done, version:%" PRId64 ", affectedRows:%d", TD_VID(pVnode), version,
694,009,986✔
2503
         pResponse->affectedRows);
2504
  return code;
694,023,791✔
2505
}
2506

2507
static int32_t vnodeScanColumnData(SVnode *pVnode, SSubmitTbData *pTbData, TSKEY minKey, TSKEY maxKey) {
6,475,129✔
2508
  int32_t code = 0;
6,475,129✔
2509

2510
  int32_t   numCols = taosArrayGetSize(pTbData->aCol);
6,475,129✔
2511
  SColData *aColData = (SColData *)TARRAY_DATA(pTbData->aCol);
6,475,130✔
2512

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

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

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

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

2546
    tColDataArrGetRowKey(aColData, numCols, i, &key);
2,147,483,647✔
2547

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

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

2568
    *pLastKey = key;
2,147,483,647✔
2569
  }
2570

2571
  return code;
6,476,085✔
2572
}
2573

2574
static int32_t vnodeScanSubmitRowData(SVnode *pVnode, SSubmitTbData *pTbData, TSKEY minKey, TSKEY maxKey) {
715,711,908✔
2575
  int32_t code = 0;
715,711,908✔
2576

2577
  int32_t numRows = taosArrayGetSize(pTbData->aRowP);
715,711,908✔
2578
  SRow  **aRow = (SRow **)TARRAY_DATA(pTbData->aRowP);
715,716,210✔
2579

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

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

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

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

2621
    *pLastKey = key;
2,147,483,647✔
2622
  }
2623

2624
  return code;
717,810,103✔
2625
}
2626

2627
static int32_t vnodeScanSubmitReq(SVnode *pVnode, int64_t version, SSubmitReq2 *pRequest, SSubmitRsp2 *pResponse) {
694,055,942✔
2628
  int32_t code = TSDB_CODE_SUCCESS;
694,055,942✔
2629
  int32_t numTbData = taosArrayGetSize(pRequest->aSubmitTbData);
694,055,942✔
2630

2631
  TSKEY now = taosGetTimestamp(pVnode->config.tsdbCfg.precision);
694,053,891✔
2632
  TSKEY minKey = now - tsTickPerMin[pVnode->config.tsdbCfg.precision] * pVnode->config.tsdbCfg.keep2;
694,060,287✔
2633
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
694,061,595✔
2634
  for (int32_t i = 0; i < numTbData; i++) {
1,416,245,684✔
2635
    SSubmitTbData *pTbData = taosArrayGet(pRequest->aSubmitTbData, i);
722,189,608✔
2636

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

2644
    if (pTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
722,188,642✔
2645
      code = vnodeScanColumnData(pVnode, pTbData, minKey, maxKey);
6,475,452✔
2646
      if (code) {
6,475,136✔
2647
        vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __func__,
×
2648
               __FILE__, __LINE__, tstrerror(code), version, pTbData->uid);
2649
        return code;
×
2650
      }
2651
    } else {
2652
      code = vnodeScanSubmitRowData(pVnode, pTbData, minKey, maxKey);
715,712,031✔
2653
      if (code) {
715,714,651✔
2654
        vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " uid:%" PRId64, TD_VID(pVnode), __func__,
143✔
2655
               __FILE__, __LINE__, tstrerror(code), version, pTbData->uid);
2656
        return code;
×
2657
      }
2658
    }
2659
  }
2660

2661
  return code;
694,056,076✔
2662
}
2663

2664
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
694,065,847✔
2665
                                     SRpcMsg *pOriginalMsg) {
2666
  int32_t code = 0;
694,065,847✔
2667
  int32_t lino = 0;
694,065,847✔
2668
  terrno = 0;
694,065,847✔
2669

2670
  SSubmitReq2 *pSubmitReq = &(SSubmitReq2){0};
694,066,867✔
2671
  SSubmitRsp2 *pSubmitRsp = &(SSubmitRsp2){0};
694,067,010✔
2672
  int32_t      ret;
2673
  SEncoder     ec = {0};
694,065,113✔
2674

2675
  pRsp->code = TSDB_CODE_SUCCESS;
694,065,399✔
2676

2677
  void           *pAllocMsg = NULL;
694,065,990✔
2678
  SSubmitReq2Msg *pMsg = (SSubmitReq2Msg *)pReq;
694,065,990✔
2679
  SDecoder        dc = {0};
694,065,990✔
2680
  if (0 == taosHton64(pMsg->version)) {
694,065,071✔
2681
    code = vnodeSubmitReqConvertToSubmitReq2(pVnode, (SSubmitReq *)pMsg, pSubmitReq);
×
2682
    if (TSDB_CODE_SUCCESS == code) {
×
2683
      code = vnodeRebuildSubmitReqMsg(pSubmitReq, &pReq);
×
2684
    }
2685
    if (TSDB_CODE_SUCCESS == code) {
×
2686
      pAllocMsg = pReq;
×
2687
    }
2688
    TSDB_CHECK_CODE(code, lino, _exit);
×
2689
  } else {
2690
    // decode
2691
    pReq = POINTER_SHIFT(pReq, sizeof(SSubmitReq2Msg));
694,064,540✔
2692
    len -= sizeof(SSubmitReq2Msg);
694,065,145✔
2693

2694
    tDecoderInit(&dc, pReq, len);
694,065,145✔
2695
    if (tDecodeSubmitReq(&dc, pSubmitReq, NULL) < 0) {
694,066,867✔
2696
      code = TSDB_CODE_INVALID_MSG;
×
2697
      TSDB_CHECK_CODE(code, lino, _exit);
×
2698
    }
2699
  }
2700

2701
  // Scan the request
2702
  code = vnodeScanSubmitReq(pVnode, ver, pSubmitReq, pSubmitRsp);
694,062,425✔
2703
  if (code) {
694,056,108✔
2704
    vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
×
2705
           tstrerror(code), ver);
2706
    TSDB_CHECK_CODE(code, lino, _exit);
×
2707
  }
2708

2709
  vGDebug(pOriginalMsg ? &pOriginalMsg->info.traceId : NULL, "vgId:%d, index:%" PRId64 ", submit block, rows:%d",
694,056,108✔
2710
          TD_VID(pVnode), ver, (int32_t)taosArrayGetSize(pSubmitReq->aSubmitTbData));
2711

2712
  // Handle auto create table
2713
  code = vnodeHandleAutoCreateTable(pVnode, ver, pSubmitReq, pSubmitRsp);
694,067,791✔
2714
  if (code) {
694,064,905✔
2715
    vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
39,605✔
2716
           tstrerror(code), ver);
2717
    TSDB_CHECK_CODE(code, lino, _exit);
39,605✔
2718
  }
2719

2720
  // Handle data write
2721
  code = vnodeHandleDataWrite(pVnode, ver, pSubmitReq, pSubmitRsp);
694,025,300✔
2722
  if (code) {
694,026,355✔
2723
    vError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pVnode), __func__, __FILE__, __LINE__,
2,880✔
2724
           tstrerror(code), ver);
2725
    TSDB_CHECK_CODE(code, lino, _exit);
2,880✔
2726
  }
2727

2728
_exit:
694,065,810✔
2729
  // message
2730
  pRsp->code = code;
694,066,276✔
2731
  tEncodeSize(tEncodeSSubmitRsp2, pSubmitRsp, pRsp->contLen, ret);
694,067,010✔
2732
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
694,066,867✔
2733
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
694,065,441✔
2734
  if (tEncodeSSubmitRsp2(&ec, pSubmitRsp) < 0) {
694,066,464✔
2735
    vError("vgId:%d, failed to encode submit response", TD_VID(pVnode));
×
2736
  }
2737
  tEncoderClear(&ec);
694,066,695✔
2738

2739
  // update statistics
2740
  (void)atomic_add_fetch_64(&pVnode->statis.nInsert, pSubmitRsp->affectedRows);
694,064,044✔
2741
  (void)atomic_add_fetch_64(&pVnode->statis.nInsertSuccess, pSubmitRsp->affectedRows);
694,066,196✔
2742
  (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsert, 1);
694,066,228✔
2743

2744
  // update metrics
2745
  METRICS_UPDATE(pVnode->writeMetrics.total_requests, METRIC_LEVEL_LOW, 1);
694,063,871✔
2746
  METRICS_UPDATE(pVnode->writeMetrics.total_rows, METRIC_LEVEL_HIGH, pSubmitRsp->affectedRows);
694,062,511✔
2747
  METRICS_UPDATE(pVnode->writeMetrics.total_bytes, METRIC_LEVEL_LOW, pMsg->header.contLen);
694,061,777✔
2748

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

2761
  if (code == 0) {
694,061,918✔
2762
    (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
694,019,433✔
2763
  }
2764

2765
  // clear
2766
  tDestroySubmitReq(pSubmitReq, 0 == taosHton64(pMsg->version) ? TSDB_MSG_FLG_CMPT : TSDB_MSG_FLG_DECODE);
694,063,225✔
2767
  tDestroySSubmitRsp2(pSubmitRsp, TSDB_MSG_FLG_ENCODE);
694,060,703✔
2768

2769
  if (code) {
694,050,128✔
2770
    terrno = code;
42,485✔
2771
    if (code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
42,485✔
2772
      vInfo("vgId:%d, failed to process submit request since %s, lino:%d, version:%" PRId64, TD_VID(pVnode),
38,569✔
2773
            tstrerror(code), lino, ver);
2774

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

2781
  taosMemoryFree(pAllocMsg);
694,056,628✔
2782
  tDecoderClear(&dc);
694,056,039✔
2783

2784
  return code;
694,066,378✔
2785
}
2786

2787
static int32_t vnodeConsolidateAlterHashRange(SVnode *pVnode, int64_t ver) {
24,735✔
2788
  int32_t code = TSDB_CODE_SUCCESS;
24,735✔
2789

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

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

2796
  return code;
24,735✔
2797
}
2798

2799
static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
4,090,287✔
2800
  vInfo("vgId:%d, vnode handle msgType:alter-confirm, alter confirm msg is processed", TD_VID(pVnode));
4,090,287✔
2801
  int32_t code = TSDB_CODE_SUCCESS;
4,090,287✔
2802
  if (!pVnode->config.hashChange) {
4,090,287✔
2803
    goto _exit;
4,065,552✔
2804
  }
2805

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

2813
_exit:
4,090,287✔
2814
  pRsp->msgType = TDMT_VND_ALTER_CONFIRM_RSP;
4,090,287✔
2815
  pRsp->code = code;
4,090,287✔
2816
  pRsp->pCont = NULL;
4,090,287✔
2817
  pRsp->contLen = 0;
4,090,287✔
2818

2819
  return code;
4,090,287✔
2820
}
2821

2822
extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb);
2823
extern void    tsdbEnableBgTask(STsdb *pTsdb);
2824

2825
static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
323,325✔
2826
  bool walChanged = false;
323,325✔
2827
  bool tsdbChanged = false;
323,325✔
2828

2829
  SAlterVnodeConfigReq req = {0};
323,325✔
2830
  if (tDeserializeSAlterVnodeConfigReq(pReq, len, &req) != 0) {
323,325✔
2831
    terrno = TSDB_CODE_INVALID_MSG;
×
2832
    return TSDB_CODE_INVALID_MSG;
×
2833
  }
2834

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

2844
  if (pVnode->config.cacheLastSize != req.cacheLastSize) {
323,325✔
2845
    pVnode->config.cacheLastSize = req.cacheLastSize;
11,465✔
2846
    tsdbCacheSetCapacity(pVnode, (size_t)pVnode->config.cacheLastSize * 1024 * 1024);
11,465✔
2847
  }
2848

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

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

2866
  if (pVnode->config.cacheLast != req.cacheLast) {
323,325✔
2867
    pVnode->config.cacheLast = req.cacheLast;
92,927✔
2868
  }
2869

2870
  if (pVnode->config.walCfg.fsyncPeriod != req.walFsyncPeriod) {
323,325✔
2871
    pVnode->config.walCfg.fsyncPeriod = req.walFsyncPeriod;
51,944✔
2872
    walChanged = true;
51,944✔
2873
  }
2874

2875
  if (pVnode->config.walCfg.level != req.walLevel) {
323,325✔
2876
    if (pVnode->config.walCfg.level == 0) {
38,285✔
2877
      pVnode->config.walCfg.clearFiles = 1;
2,195✔
2878
    }
2879
    pVnode->config.walCfg.level = req.walLevel;
38,285✔
2880
    walChanged = true;
38,285✔
2881
  }
2882

2883
  if (pVnode->config.walCfg.retentionPeriod != req.walRetentionPeriod) {
323,325✔
2884
    pVnode->config.walCfg.retentionPeriod = req.walRetentionPeriod;
46,583✔
2885
    walChanged = true;
46,583✔
2886
  }
2887

2888
  if (pVnode->config.walCfg.retentionSize != req.walRetentionSize) {
323,325✔
2889
    pVnode->config.walCfg.retentionSize = req.walRetentionSize;
1,434✔
2890
    walChanged = true;
1,434✔
2891
  }
2892

2893
  if (pVnode->config.tsdbCfg.keep0 != req.daysToKeep0) {
323,325✔
2894
    pVnode->config.tsdbCfg.keep0 = req.daysToKeep0;
42,890✔
2895
    tsdbChanged = true;
42,890✔
2896
  }
2897

2898
  if (pVnode->config.tsdbCfg.keep1 != req.daysToKeep1) {
323,325✔
2899
    pVnode->config.tsdbCfg.keep1 = req.daysToKeep1;
41,424✔
2900
    tsdbChanged = true;
41,424✔
2901
  }
2902

2903
  if (pVnode->config.tsdbCfg.keep2 != req.daysToKeep2) {
323,325✔
2904
    pVnode->config.tsdbCfg.keep2 = req.daysToKeep2;
35,668✔
2905
    tsdbChanged = true;
35,668✔
2906
  }
2907

2908
  if (pVnode->config.tsdbCfg.keepTimeOffset != req.keepTimeOffset) {
323,325✔
2909
    pVnode->config.tsdbCfg.keepTimeOffset = req.keepTimeOffset;
7,286✔
2910
    tsdbChanged = true;
7,286✔
2911
  }
2912

2913
  if (req.sttTrigger != -1 && req.sttTrigger != pVnode->config.sttTrigger) {
323,325✔
2914
    if (req.sttTrigger > 1 && pVnode->config.sttTrigger > 1) {
2,502✔
2915
      pVnode->config.sttTrigger = req.sttTrigger;
1,434✔
2916
    } else {
2917
      vnodeAWait(&pVnode->commitTask);
1,068✔
2918

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

2924
      pVnode->config.sttTrigger = req.sttTrigger;
1,068✔
2925
      tsdbEnableBgTask(pVnode->pTsdb);
1,068✔
2926
    }
2927
  }
2928

2929
  if (req.minRows != -1 && req.minRows != pVnode->config.tsdbCfg.minRows) {
323,325✔
2930
    pVnode->config.tsdbCfg.minRows = req.minRows;
1,434✔
2931
  }
2932

2933
  if (req.ssKeepLocal != -1 && req.ssKeepLocal != pVnode->config.ssKeepLocal) {
323,325✔
2934
    pVnode->config.ssKeepLocal = req.ssKeepLocal;
1,434✔
2935
  }
2936
  if (req.ssCompact != -1 && req.ssCompact != pVnode->config.ssCompact) {
323,325✔
2937
    pVnode->config.ssCompact = req.ssCompact;
1,434✔
2938
  }
2939
  if (req.allowDrop != pVnode->config.allowDrop) {
323,325✔
2940
    pVnode->config.allowDrop = req.allowDrop;
×
2941
  }
2942

2943
  if (walChanged) {
323,325✔
2944
    if (walAlter(pVnode->pWal, &pVnode->config.walCfg) != 0) {
134,994✔
2945
      vError("vgId:%d, failed to alter wal config since %s", TD_VID(pVnode), tstrerror(ERRNO));
×
2946
    }
2947
  }
2948

2949
  if (tsdbChanged) {
323,325✔
2950
    tsdbSetKeepCfg(pVnode->pTsdb, &pVnode->config.tsdbCfg);
57,500✔
2951
  }
2952

2953
  return 0;
323,325✔
2954
}
2955

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

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

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

2978
    int64_t uid = mr.me.uid;
×
2979

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

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

3003
static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
2,084,951✔
3004
                                     SRpcMsg *pOriginalMsg) {
3005
  int32_t     code = 0;
2,084,951✔
3006
  SDecoder   *pCoder = &(SDecoder){0};
2,084,951✔
3007
  SDeleteRes *pRes = &(SDeleteRes){0};
2,084,951✔
3008

3009
  pRsp->msgType = TDMT_VND_DELETE_RSP;
2,084,951✔
3010
  pRsp->pCont = NULL;
2,084,951✔
3011
  pRsp->contLen = 0;
2,084,951✔
3012
  pRsp->code = TSDB_CODE_SUCCESS;
2,084,951✔
3013

3014
  pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t));
2,084,951✔
3015
  if (pRes->uidList == NULL) {
2,084,951✔
3016
    code = terrno;
×
3017
    goto _err;
×
3018
  }
3019

3020
  tDecoderInit(pCoder, pReq, len);
2,084,951✔
3021
  code = tDecodeDeleteRes(pCoder, pRes);
2,084,951✔
3022
  if (code) goto _err;
2,084,951✔
3023

3024
  if (pRes->affectedRows > 0) {
2,084,951✔
3025
    for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) {
3,711,407✔
3026
      uint64_t uid = *(uint64_t *)taosArrayGet(pRes->uidList, iUid);
2,119,239✔
3027
      code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, uid, pRes->skey, pRes->ekey);
2,119,239✔
3028
      if (code) goto _err;
2,119,239✔
3029
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, pRes->ctimeMs);
2,119,239✔
3030
      if (code) goto _err;
2,119,239✔
3031
    }
3032
  }
3033

3034
  tDecoderClear(pCoder);
2,084,951✔
3035
  taosArrayDestroy(pRes->uidList);
2,084,951✔
3036

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

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

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

3071
  pRsp->msgType = TDMT_VND_CREATE_INDEX_RSP;
16,845✔
3072
  pRsp->code = TSDB_CODE_SUCCESS;
16,845✔
3073
  pRsp->pCont = NULL;
16,845✔
3074
  pRsp->contLen = 0;
16,845✔
3075

3076
  tDecoderInit(&dc, pReq, len);
16,845✔
3077
  // decode req
3078
  if (tDecodeSVCreateStbReq(&dc, &req) < 0) {
16,845✔
3079
    tDecoderClear(&dc);
×
3080
    return terrno = TSDB_CODE_INVALID_MSG;
×
3081
  }
3082

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

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

3103
  if ((code = tDeserializeSDropIdxReq(pReq, len, &req))) {
13,884✔
3104
    pRsp->code = code;
×
3105
    return code;
×
3106
  }
3107

3108
  code = metaDropIndexFromSuperTable(pVnode->pMeta, ver, &req);
13,884✔
3109
  if (code) {
13,884✔
3110
    pRsp->code = code;
×
3111
    return code;
×
3112
  }
3113
  return TSDB_CODE_SUCCESS;
13,884✔
3114
}
3115

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

3118
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
68,526✔
3119
  if (!pVnode->restored) {
68,526✔
3120
    vInfo("vgId:%d, ignore compact req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
3,520✔
3121
    return 0;
3,520✔
3122
  }
3123
  return vnodeAsyncCompact(pVnode, ver, pReq, len, pRsp);
65,006✔
3124
}
3125

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

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

3136
  return 0;
×
3137
}
3138

3139
static int32_t vnodeCheckState(SVnode *pVnode) {
68,676✔
3140
  SSyncState syncState = syncGetState(pVnode->sync);
68,676✔
3141
  if (syncState.state != TAOS_SYNC_STATE_LEADER) {
68,676✔
3142
    return terrno = TSDB_CODE_SYN_NOT_LEADER;
26,048✔
3143
  }
3144
  return 0;
42,628✔
3145
}
3146

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

3153
  if (strncmp(token, member0Token, TSDB_ARB_TOKEN_SIZE) != 0 &&
42,628✔
3154
      strncmp(token, member1Token, TSDB_ARB_TOKEN_SIZE) != 0) {
39,644✔
3155
    return terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
39,064✔
3156
  }
3157

3158
  terrno = TSDB_CODE_SUCCESS;
3,564✔
3159
  return 0;
3,564✔
3160
}
3161

3162
static int32_t vnodeCheckSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
10,230✔
3163
  int32_t code = vnodeCheckToken(pVnode, member0Token, member1Token);
10,230✔
3164
  if (code != 0) {
10,230✔
3165
    return code;
8,448✔
3166
  }
3167

3168
  return syncCheckSynced(pVnode->sync);
1,782✔
3169
}
3170

3171
static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) {
25,387✔
3172
  int32_t code = 0;
25,387✔
3173

3174
  if ((code = vnodeCheckState(pVnode)) != 0) {
25,387✔
3175
    vDebug("vgId:%d, failed to preprocess vnode-arb-check-sync request since %s", TD_VID(pVnode), tstrerror(code));
15,157✔
3176
    return 0;
15,157✔
3177
  }
3178

3179
  SVArbCheckSyncReq syncReq = {0};
10,230✔
3180

3181
  code = tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq);
10,230✔
3182
  if (code) {
10,230✔
3183
    return code;
×
3184
  }
3185

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

3192
  pRsp->msgType = TDMT_VND_ARB_CHECK_SYNC_RSP;
10,230✔
3193
  pRsp->code = TSDB_CODE_SUCCESS;
10,230✔
3194
  pRsp->pCont = NULL;
10,230✔
3195
  pRsp->contLen = 0;
10,230✔
3196

3197
  SVArbCheckSyncRsp syncRsp = {0};
10,230✔
3198
  syncRsp.arbToken = syncReq.arbToken;
10,230✔
3199
  syncRsp.member0Token = syncReq.member0Token;
10,230✔
3200
  syncRsp.member1Token = syncReq.member1Token;
10,230✔
3201
  syncRsp.vgId = TD_VID(pVnode);
10,230✔
3202

3203
  if ((syncRsp.errCode = vnodeCheckSyncd(pVnode, syncReq.member0Token, syncReq.member1Token)) != 0) {
10,230✔
3204
    vError("vgId:%d, failed to check assigned log syncd since %s", TD_VID(pVnode), tstrerror(syncRsp.errCode));
8,448✔
3205
  }
3206

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

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

3225
  if (tSerializeSVArbCheckSyncRsp(pHead, contLen, &syncRsp) <= 0) {
10,230✔
3226
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
3227
    rpcFreeCont(pHead);
×
3228
    code = -1;
×
3229
    goto _OVER;
×
3230
  }
3231

3232
  pRsp->pCont = pHead;
10,230✔
3233
  pRsp->contLen = contLen;
10,230✔
3234

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

3240
  code = TSDB_CODE_SUCCESS;
10,230✔
3241

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

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