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

taosdata / TDengine / #3561

19 Dec 2024 03:15AM UTC coverage: 58.812% (-1.3%) from 60.124%
#3561

push

travis-ci

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

merge: from main to 3.0 branch

130770 of 287658 branches covered (45.46%)

Branch coverage included in aggregate %.

32 of 78 new or added lines in 4 files covered. (41.03%)

7347 existing lines in 166 files now uncovered.

205356 of 283866 relevant lines covered (72.34%)

7187865.64 hits per line

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

59.07
/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 "audit.h"
17
#include "cos.h"
18
#include "monitor.h"
19
#include "tencode.h"
20
#include "tglobal.h"
21
#include "tmsg.h"
22
#include "tstrbuild.h"
23
#include "vnd.h"
24
#include "vnode.h"
25
#include "vnodeInt.h"
26

27
extern taos_counter_t *tsInsertCounter;
28

29
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
30
static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
31
static int32_t vnodeProcessDropStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
32
static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
33
                                       SRpcMsg *pOriginRpc);
34
static int32_t vnodeProcessAlterTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
35
static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
36
                                     SRpcMsg *pOriginRpc);
37
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
38
                                     SRpcMsg *pOriginalMsg);
39
static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
40
static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
41
static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
42
static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
43
static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
44
static int32_t vnodeProcessS3MigrateReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
45
static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
46
                                     SRpcMsg *pOriginalMsg);
47
static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
48
static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
49
static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
50
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
51
static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
52
static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp);
53
static int32_t vnodeProcessDropTSmaCtbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
54
                                          SRpcMsg *pOriginRpc);
55

56
static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token);
57
static int32_t vnodeCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token);
58
static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
59

60
extern int32_t vnodeProcessKillCompactReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
61
extern int32_t vnodeQueryCompactProgress(SVnode *pVnode, SRpcMsg *pMsg);
62

63
static int32_t vnodePreprocessCreateTableReq(SVnode *pVnode, SDecoder *pCoder, int64_t btime, int64_t *pUid) {
134,100✔
64
  int32_t code = 0;
134,100✔
65
  int32_t lino = 0;
134,100✔
66

67
  if (tStartDecode(pCoder) < 0) {
134,100!
68
    code = TSDB_CODE_INVALID_MSG;
×
69
    TSDB_CHECK_CODE(code, lino, _exit);
×
70
  }
71

72
  // flags
73
  if (tDecodeI32v(pCoder, NULL) < 0) {
134,146!
74
    code = TSDB_CODE_INVALID_MSG;
×
75
    TSDB_CHECK_CODE(code, lino, _exit);
×
76
  }
77

78
  // name
79
  char *name = NULL;
134,146✔
80
  if (tDecodeCStr(pCoder, &name) < 0) {
134,119!
81
    code = TSDB_CODE_INVALID_MSG;
×
82
    TSDB_CHECK_CODE(code, lino, _exit);
×
83
  }
84

85
  // uid
86
  int64_t uid = metaGetTableEntryUidByName(pVnode->pMeta, name);
134,119✔
87
  if (uid == 0) {
134,127✔
88
    uid = tGenIdPI64();
107,973✔
89
  }
90
  *(int64_t *)(pCoder->data + pCoder->pos) = uid;
134,147✔
91

92
  // btime
93
  *(int64_t *)(pCoder->data + pCoder->pos + 8) = btime;
134,147✔
94

95
  tEndDecode(pCoder);
134,147✔
96

97
_exit:
134,126✔
98
  if (code) {
134,126!
99
    vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
×
100
  } else {
101
    vTrace("vgId:%d %s done, table:%s uid generated:%" PRId64, TD_VID(pVnode), __func__, name, uid);
134,126✔
102
    if (pUid) *pUid = uid;
134,126✔
103
  }
104
  return code;
134,125✔
105
}
106
static int32_t vnodePreProcessCreateTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
52,320✔
107
  int32_t code = 0;
52,320✔
108
  int32_t lino = 0;
52,320✔
109

110
  int64_t  btime = taosGetTimestampMs();
52,335✔
111
  SDecoder dc = {0};
52,335✔
112
  int32_t  nReqs;
113

114
  tDecoderInit(&dc, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead));
52,335✔
115
  if (tStartDecode(&dc) < 0) {
52,320!
116
    code = TSDB_CODE_INVALID_MSG;
×
117
    return code;
×
118
  }
119

120
  if (tDecodeI32v(&dc, &nReqs) < 0) {
52,332!
121
    code = TSDB_CODE_INVALID_MSG;
×
122
    TSDB_CHECK_CODE(code, lino, _exit);
×
123
  }
124
  for (int32_t iReq = 0; iReq < nReqs; iReq++) {
125,255✔
125
    code = vnodePreprocessCreateTableReq(pVnode, &dc, btime, NULL);
72,919✔
126
    TSDB_CHECK_CODE(code, lino, _exit);
72,923!
127
  }
128

129
  tEndDecode(&dc);
52,336✔
130

131
_exit:
52,335✔
132
  tDecoderClear(&dc);
52,335✔
133
  if (code) {
52,336!
134
    vError("vgId:%d, %s:%d failed to preprocess submit request since %s, msg type:%s", TD_VID(pVnode), __func__, lino,
×
135
           tstrerror(code), TMSG_INFO(pMsg->msgType));
136
  }
137
  return code;
52,333✔
138
}
139

140
static int32_t vnodePreProcessAlterTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
896✔
141
  int32_t code = TSDB_CODE_INVALID_MSG;
896✔
142
  int32_t lino = 0;
896✔
143

144
  SDecoder dc = {0};
896✔
145
  tDecoderInit(&dc, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead));
896✔
146

147
  SVAlterTbReq vAlterTbReq = {0};
896✔
148
  int64_t      ctimeMs = taosGetTimestampMs();
896✔
149
  if (tDecodeSVAlterTbReqSetCtime(&dc, &vAlterTbReq, ctimeMs) < 0) {
896!
150
    taosArrayDestroy(vAlterTbReq.pMultiTag);
×
151
    vAlterTbReq.pMultiTag = NULL;
×
152
    goto _exit;
×
153
  }
154
  taosArrayDestroy(vAlterTbReq.pMultiTag);
896✔
155
  vAlterTbReq.pMultiTag = NULL;
896✔
156

157
  code = 0;
896✔
158

159
_exit:
896✔
160
  tDecoderClear(&dc);
896✔
161
  if (code) {
896!
162
    vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
×
163
  } else {
164
    vTrace("vgId:%d %s done, table:%s ctimeMs generated:%" PRId64, TD_VID(pVnode), __func__, vAlterTbReq.tbName,
896✔
165
           ctimeMs);
166
  }
167
  return code;
896✔
168
}
169

170
static int32_t vnodePreProcessDropTtlMsg(SVnode *pVnode, SRpcMsg *pMsg) {
15,158✔
171
  int32_t code = TSDB_CODE_INVALID_MSG;
15,158✔
172
  int32_t lino = 0;
15,158✔
173

174
  SMsgHead *pContOld = pMsg->pCont;
15,158✔
175
  int32_t   reqLenOld = pMsg->contLen - sizeof(SMsgHead);
15,158✔
176

177
  SArray *tbUids = NULL;
15,158✔
178
  int64_t timestampMs = 0;
15,158✔
179

180
  SVDropTtlTableReq ttlReq = {0};
15,158✔
181
  if (tDeserializeSVDropTtlTableReq((char *)pContOld + sizeof(SMsgHead), reqLenOld, &ttlReq) != 0) {
15,158!
182
    code = TSDB_CODE_INVALID_MSG;
×
183
    TSDB_CHECK_CODE(code, lino, _exit);
×
184
  }
185

186
  {  // find expired uids
187
    tbUids = taosArrayInit(8, sizeof(tb_uid_t));
15,155✔
188
    if (tbUids == NULL) {
15,171!
189
      code = terrno;
×
190
      TSDB_CHECK_CODE(code, lino, _exit);
×
191
    }
192

193
    timestampMs = (int64_t)ttlReq.timestampSec * 1000;
15,171✔
194
    code = metaTtlFindExpired(pVnode->pMeta, timestampMs, tbUids, ttlReq.ttlDropMaxCount);
15,171✔
195
    if (code != 0) {
15,129!
196
      code = TSDB_CODE_INVALID_MSG;
×
197
      TSDB_CHECK_CODE(code, lino, _exit);
×
198
    }
199

200
    ttlReq.nUids = taosArrayGetSize(tbUids);
15,129✔
201
    ttlReq.pTbUids = tbUids;
15,131✔
202
  }
203

204
  if (ttlReq.nUids == 0) {
15,131!
205
    code = TSDB_CODE_MSG_PREPROCESSED;
15,141✔
206
    TSDB_CHECK_CODE(code, lino, _exit);
15,141!
207
  }
208

209
  {  // prepare new content
210
    int32_t reqLenNew = tSerializeSVDropTtlTableReq(NULL, 0, &ttlReq);
×
211
    int32_t contLenNew = reqLenNew + sizeof(SMsgHead);
5✔
212

213
    SMsgHead *pContNew = rpcMallocCont(contLenNew);
5✔
214
    if (pContNew == NULL) {
5!
215
      code = terrno;
×
216
      TSDB_CHECK_CODE(code, lino, _exit);
×
217
    }
218

219
    if (tSerializeSVDropTtlTableReq((char *)pContNew + sizeof(SMsgHead), reqLenNew, &ttlReq) != 0) {
5!
220
      vError("vgId:%d %s:%d failed to serialize drop ttl request", TD_VID(pVnode), __func__, lino);
5!
221
    }
222
    pContNew->contLen = htonl(reqLenNew);
5✔
223
    pContNew->vgId = pContOld->vgId;
5✔
224

225
    rpcFreeCont(pContOld);
5✔
226
    pMsg->pCont = pContNew;
5✔
227
    pMsg->contLen = contLenNew;
5✔
228
  }
229

230
  code = 0;
5✔
231

232
_exit:
15,158✔
233
  taosArrayDestroy(tbUids);
15,158✔
234

235
  if (code && code != TSDB_CODE_MSG_PREPROCESSED) {
15,141!
236
    vError("vgId:%d, %s:%d failed to preprocess drop ttl request since %s, msg type:%s", TD_VID(pVnode), __func__, lino,
×
237
           tstrerror(code), TMSG_INFO(pMsg->msgType));
238
  } else {
239
    vTrace("vgId:%d, %s done, timestampSec:%d, nUids:%d", TD_VID(pVnode), __func__, ttlReq.timestampSec, ttlReq.nUids);
15,141✔
240
  }
241

242
  return code;
15,128✔
243
}
244

245
extern int64_t tsMaxKeyByPrecision[];
246
static int32_t vnodePreProcessSubmitTbData(SVnode *pVnode, SDecoder *pCoder, int64_t btimeMs, int64_t ctimeMs) {
10,129,946✔
247
  int32_t code = 0;
10,129,946✔
248
  int32_t lino = 0;
10,129,946✔
249

250
  if (tStartDecode(pCoder) < 0) {
10,129,946!
251
    code = TSDB_CODE_INVALID_MSG;
×
252
    TSDB_CHECK_CODE(code, lino, _exit);
×
253
  }
254

255
  SSubmitTbData submitTbData;
256
  uint8_t       version;
257
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
10,145,249!
258
    code = TSDB_CODE_INVALID_MSG;
×
259
    TSDB_CHECK_CODE(code, lino, _exit);
×
260
  }
261
  version = (submitTbData.flags >> 8) & 0xff;
10,145,249✔
262
  submitTbData.flags = submitTbData.flags & 0xff;
10,145,249✔
263

264
  int64_t uid;
265
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
10,145,249✔
266
    code = vnodePreprocessCreateTableReq(pVnode, pCoder, btimeMs, &uid);
61,184✔
267
    TSDB_CHECK_CODE(code, lino, _exit);
61,206!
268
  }
269

270
  // submit data
271
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
10,132,561!
272
    code = TSDB_CODE_INVALID_MSG;
×
273
    TSDB_CHECK_CODE(code, lino, _exit);
×
274
  }
275

276
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
10,132,561✔
277
    *(int64_t *)(pCoder->data + pCoder->pos) = uid;
61,207✔
278
    pCoder->pos += sizeof(int64_t);
61,207✔
279
  } else {
280
    if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
10,068,594!
281
      code = TSDB_CODE_INVALID_MSG;
×
282
      TSDB_CHECK_CODE(code, lino, _exit);
×
283
    }
284
  }
285

286
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
10,119,695!
287
    code = TSDB_CODE_INVALID_MSG;
×
288
    TSDB_CHECK_CODE(code, lino, _exit);
×
289
  }
290

291
  // scan and check
292
  TSKEY now = btimeMs;
10,119,695✔
293
  if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_MICRO) {
10,119,695✔
294
    now *= 1000;
22,337✔
295
  } else if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_NANO) {
10,097,358✔
296
    now *= 1000000;
3,534✔
297
  }
298

299
  int32_t keep = pVnode->config.tsdbCfg.keep2;
10,119,695✔
300
  /*
301
  int32_t nlevel = tfsGetLevel(pVnode->pTfs);
302
  if (nlevel > 1 && tsS3Enabled) {
303
    if (nlevel == 3) {
304
      keep = pVnode->config.tsdbCfg.keep1;
305
    } else if (nlevel == 2) {
306
      keep = pVnode->config.tsdbCfg.keep0;
307
    }
308
  }
309
  */
310

311
  TSKEY minKey = now - tsTickPerMin[pVnode->config.tsdbCfg.precision] * keep;
10,119,695✔
312
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
10,119,695✔
313
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,119,695✔
314
    uint64_t nColData;
315
    if (tDecodeU64v(pCoder, &nColData) < 0) {
132!
316
      code = TSDB_CODE_INVALID_MSG;
×
317
      goto _exit;
×
318
    }
319

320
    SColData colData = {0};
132✔
321
    pCoder->pos += tGetColData(version, pCoder->data + pCoder->pos, &colData);
132✔
322
    if (colData.flag != HAS_VALUE) {
132!
323
      code = TSDB_CODE_INVALID_MSG;
×
324
      goto _exit;
×
325
    }
326

327
    for (int32_t iRow = 0; iRow < colData.nVal; iRow++) {
354✔
328
      if (((TSKEY *)colData.pData)[iRow] < minKey || ((TSKEY *)colData.pData)[iRow] > maxKey) {
222!
329
        code = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
×
330
        goto _exit;
×
331
      }
332
    }
333

334
    for (uint64_t i = 1; i < nColData; i++) {
564✔
335
      pCoder->pos += tGetColData(version, pCoder->data + pCoder->pos, &colData);
432✔
336
    }
337
  } else {
338
    uint64_t nRow;
339
    if (tDecodeU64v(pCoder, &nRow) < 0) {
10,129,012!
340
      code = TSDB_CODE_INVALID_MSG;
×
341
      goto _exit;
487✔
342
    }
343

344
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
246,388,972✔
345
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
236,260,447✔
346
      pCoder->pos += pRow->len;
236,260,447✔
347

348
      if (pRow->ts < minKey || pRow->ts > maxKey) {
236,260,447!
349
        code = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
487✔
350
        goto _exit;
487✔
351
      }
352
    }
353
  }
354

355
  if (!tDecodeIsEnd(pCoder)) {
10,128,657!
356
    *(int64_t *)(pCoder->data + pCoder->pos) = ctimeMs;
10,132,687✔
357
    pCoder->pos += sizeof(int64_t);
10,132,687✔
358
  }
359

360
  tEndDecode(pCoder);
10,128,657✔
361

362
_exit:
10,129,844✔
363
  return code;
10,129,844✔
364
}
365
static int32_t vnodePreProcessSubmitMsg(SVnode *pVnode, SRpcMsg *pMsg) {
9,451,292✔
366
  int32_t code = 0;
9,451,292✔
367
  int32_t lino = 0;
9,451,292✔
368

369
  if (tsBypassFlag & TSDB_BYPASS_RA_RPC_RECV_SUBMIT) {
9,451,292!
370
    return TSDB_CODE_MSG_PREPROCESSED;
×
371
  }
372

373
  SDecoder *pCoder = &(SDecoder){0};
9,451,292✔
374

375
  if (taosHton64(((SSubmitReq2Msg *)pMsg->pCont)->version) != 1) {
9,451,292!
376
    code = TSDB_CODE_INVALID_MSG;
×
377
    TSDB_CHECK_CODE(code, lino, _exit);
×
378
  }
379

380
  tDecoderInit(pCoder, (uint8_t *)pMsg->pCont + sizeof(SSubmitReq2Msg), pMsg->contLen - sizeof(SSubmitReq2Msg));
9,451,325✔
381

382
  if (tStartDecode(pCoder) < 0) {
9,451,301!
383
    code = TSDB_CODE_INVALID_MSG;
×
384
    TSDB_CHECK_CODE(code, lino, _exit);
×
385
  }
386

387
  uint64_t nSubmitTbData;
388
  if (tDecodeU64v(pCoder, &nSubmitTbData) < 0) {
9,451,310!
389
    code = TSDB_CODE_INVALID_MSG;
×
390
    TSDB_CHECK_CODE(code, lino, _exit);
×
391
  }
392

393
  int64_t btimeMs = taosGetTimestampMs();
9,451,346✔
394
  int64_t ctimeMs = btimeMs;
9,451,346✔
395
  for (int32_t i = 0; i < nSubmitTbData; i++) {
19,580,652✔
396
    code = vnodePreProcessSubmitTbData(pVnode, pCoder, btimeMs, ctimeMs);
10,130,277✔
397
    TSDB_CHECK_CODE(code, lino, _exit);
10,129,793✔
398
  }
399

400
  tEndDecode(pCoder);
9,450,375✔
401

402
_exit:
9,451,335✔
403
  tDecoderClear(pCoder);
9,451,335✔
404
  if (code) {
9,451,306✔
405
    vError("vgId:%d, %s:%d failed to preprocess submit request since %s, msg type:%s", TD_VID(pVnode), __func__, lino,
487!
406
           tstrerror(code), TMSG_INFO(pMsg->msgType));
407
  }
408
  return code;
9,451,305✔
409
}
410

411
static int32_t vnodePreProcessDeleteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
12,615✔
412
  int32_t code = 0;
12,615✔
413

414
  int32_t    size;
415
  int32_t    ret;
416
  uint8_t   *pCont;
417
  SEncoder  *pCoder = &(SEncoder){0};
12,615✔
418
  SDeleteRes res = {0};
12,615✔
419

420
  SReadHandle handle = {.vnode = pVnode, .pMsgCb = &pVnode->msgCb, .skipRollup = 1};
12,615✔
421
  initStorageAPI(&handle.api);
12,615✔
422

423
  code = qWorkerProcessDeleteMsg(&handle, pVnode->pQuery, pMsg, &res);
12,615✔
424
  if (code) goto _exit;
12,614!
425

426
  res.ctimeMs = taosGetTimestampMs();
12,614✔
427
  // malloc and encode
428
  tEncodeSize(tEncodeDeleteRes, &res, size, ret);
12,614!
429
  pCont = rpcMallocCont(size + sizeof(SMsgHead));
12,614✔
430

431
  ((SMsgHead *)pCont)->contLen = size + sizeof(SMsgHead);
12,615✔
432
  ((SMsgHead *)pCont)->vgId = TD_VID(pVnode);
12,615✔
433

434
  tEncoderInit(pCoder, pCont + sizeof(SMsgHead), size);
12,615✔
435
  if (tEncodeDeleteRes(pCoder, &res) != 0) {
12,615!
436
    vError("vgId:%d %s failed to encode delete response", TD_VID(pVnode), __func__);
×
437
  }
438
  tEncoderClear(pCoder);
12,615✔
439

440
  rpcFreeCont(pMsg->pCont);
12,615✔
441
  pMsg->pCont = pCont;
12,615✔
442
  pMsg->contLen = size + sizeof(SMsgHead);
12,615✔
443

444
  taosArrayDestroy(res.uidList);
12,615✔
445

446
_exit:
12,615✔
447
  return code;
12,615✔
448
}
449

450
static int32_t vnodePreProcessBatchDeleteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
2,600✔
451
  int32_t code = 0;
2,600✔
452
  int32_t lino = 0;
2,600✔
453

454
  int64_t         ctimeMs = taosGetTimestampMs();
2,602✔
455
  SBatchDeleteReq pReq = {0};
2,602✔
456
  SDecoder       *pCoder = &(SDecoder){0};
2,602✔
457

458
  tDecoderInit(pCoder, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead));
2,602✔
459

460
  if (tDecodeSBatchDeleteReqSetCtime(pCoder, &pReq, ctimeMs) < 0) {
2,600!
461
    code = TSDB_CODE_INVALID_MSG;
×
462
  }
463

464
  tDecoderClear(pCoder);
2,600✔
465
  taosArrayDestroy(pReq.deleteReqs);
2,601✔
466

467
  if (code) {
2,603!
468
    vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
×
469
  } else {
470
    vTrace("vgId:%d %s done, ctimeMs generated:%" PRId64, TD_VID(pVnode), __func__, ctimeMs);
2,603✔
471
  }
472
  return code;
2,602✔
473
}
474

475
static int32_t vnodePreProcessArbCheckSyncMsg(SVnode *pVnode, SRpcMsg *pMsg) {
2✔
476
  SVArbCheckSyncReq syncReq = {0};
2✔
477

478
  if (tDeserializeSVArbCheckSyncReq((char *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead),
2!
479
                                    &syncReq) != 0) {
480
    return TSDB_CODE_INVALID_MSG;
×
481
  }
482

483
  int32_t ret = vnodePreCheckAssignedLogSyncd(pVnode, syncReq.member0Token, syncReq.member1Token);
2✔
484
  if (ret != 0) {
2!
485
    vError("vgId:%d, failed to preprocess arb check sync request since %s", TD_VID(pVnode), tstrerror(ret));
2!
486
  }
487

488
  int32_t code = terrno;
2✔
489
  tFreeSVArbCheckSyncReq(&syncReq);
2✔
490

491
  return code;
2✔
492
}
493

494
int32_t vnodePreProcessDropTbMsg(SVnode *pVnode, SRpcMsg *pMsg) {
1,890✔
495
  int32_t          code = TSDB_CODE_SUCCESS;
1,890✔
496
  int32_t          lino = 0;
1,890✔
497
  int32_t          size = 0;
1,890✔
498
  SDecoder         dc = {0};
1,890✔
499
  SEncoder         ec = {0};
1,890✔
500
  SVDropTbBatchReq receivedBatchReqs = {0};
1,890✔
501
  SVDropTbBatchReq sentBatchReqs = {0};
1,890✔
502

503
  tDecoderInit(&dc, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead));
1,890✔
504

505
  code = tDecodeSVDropTbBatchReq(&dc, &receivedBatchReqs);
1,890✔
506
  if (code < 0) {
1,890!
507
    terrno = code;
×
508
    TSDB_CHECK_CODE(code, lino, _exit);
×
509
  }
510
  sentBatchReqs.pArray = taosArrayInit(receivedBatchReqs.nReqs, sizeof(SVDropTbReq));
1,890✔
511
  if (!sentBatchReqs.pArray) {
1,890!
512
    code = terrno;
×
513
    goto _exit;
×
514
  }
515

516
  for (int32_t i = 0; i < receivedBatchReqs.nReqs; ++i) {
3,787✔
517
    SVDropTbReq *pReq = receivedBatchReqs.pReqs + i;
1,897✔
518
    tb_uid_t     uid = metaGetTableEntryUidByName(pVnode->pMeta, pReq->name);
1,897✔
519
    if (uid == 0) {
1,897!
520
      vWarn("vgId:%d, preprocess drop ctb: %s not found", TD_VID(pVnode), pReq->name);
×
521
      continue;
×
522
    }
523
    pReq->uid = uid;
1,897✔
524
    vDebug("vgId:%d %s for: %s, uid: %" PRId64, TD_VID(pVnode), __func__, pReq->name, pReq->uid);
1,897✔
525
    if (taosArrayPush(sentBatchReqs.pArray, pReq) == NULL) {
3,794!
526
      code = terrno;
×
527
      goto _exit;
×
528
    }
529
  }
530
  sentBatchReqs.nReqs = sentBatchReqs.pArray->size;
1,890✔
531

532
  tEncodeSize(tEncodeSVDropTbBatchReq, &sentBatchReqs, size, code);
1,890!
533
  tEncoderInit(&ec, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), size);
1,890✔
534
  code = tEncodeSVDropTbBatchReq(&ec, &sentBatchReqs);
1,890✔
535
  tEncoderClear(&ec);
1,890✔
536
  if (code != TSDB_CODE_SUCCESS) {
1,890!
537
    vError("vgId:%d %s failed to encode drop tb batch req: %s", TD_VID(pVnode), __func__, tstrerror(code));
×
538
    TSDB_CHECK_CODE(code, lino, _exit);
×
539
  }
540

541
_exit:
1,890✔
542
  tDecoderClear(&dc);
1,890✔
543
  if (sentBatchReqs.pArray) {
1,890!
544
    taosArrayDestroy(sentBatchReqs.pArray);
1,890✔
545
  }
546
  return code;
1,890✔
547
}
548

549
int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
9,610,108✔
550
  int32_t code = 0;
9,610,108✔
551

552
  switch (pMsg->msgType) {
9,610,108✔
553
    case TDMT_VND_CREATE_TABLE: {
52,333✔
554
      code = vnodePreProcessCreateTableMsg(pVnode, pMsg);
52,333✔
555
    } break;
52,332✔
556
    case TDMT_VND_ALTER_TABLE: {
896✔
557
      code = vnodePreProcessAlterTableMsg(pVnode, pMsg);
896✔
558
    } break;
896✔
559
    case TDMT_VND_FETCH_TTL_EXPIRED_TBS:
15,160✔
560
    case TDMT_VND_DROP_TTL_TABLE: {
561
      code = vnodePreProcessDropTtlMsg(pVnode, pMsg);
15,160✔
562
    } break;
15,128✔
563
    case TDMT_VND_SUBMIT: {
9,451,342✔
564
      code = vnodePreProcessSubmitMsg(pVnode, pMsg);
9,451,342✔
565
    } break;
9,451,303✔
566
    case TDMT_VND_DELETE: {
12,615✔
567
      code = vnodePreProcessDeleteMsg(pVnode, pMsg);
12,615✔
568
    } break;
12,614✔
569
    case TDMT_VND_BATCH_DEL: {
2,600✔
570
      code = vnodePreProcessBatchDeleteMsg(pVnode, pMsg);
2,600✔
571
    } break;
2,600✔
572
    case TDMT_VND_ARB_CHECK_SYNC: {
2✔
573
      code = vnodePreProcessArbCheckSyncMsg(pVnode, pMsg);
2✔
574
    } break;
2✔
575
    case TDMT_VND_DROP_TABLE: {
1,890✔
576
      code = vnodePreProcessDropTbMsg(pVnode, pMsg);
1,890✔
577
    } break;
1,890✔
578
    default:
73,270✔
579
      break;
73,270✔
580
  }
581

582
  if (code && code != TSDB_CODE_MSG_PREPROCESSED) {
9,610,035✔
583
    vError("vgId:%d, failed to preprocess write request since %s, msg type:%s", TD_VID(pVnode), tstrerror(code),
489!
584
           TMSG_INFO(pMsg->msgType));
585
  }
586
  return code;
9,610,040✔
587
}
588

589
int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg *pRsp) {
12,657,264✔
590
  int32_t code = 0;
12,657,264✔
591
  void   *ptr = NULL;
12,657,264✔
592
  void   *pReq;
593
  int32_t len;
594

595
  (void)taosThreadMutexLock(&pVnode->mutex);
12,657,264✔
596
  if (pVnode->disableWrite) {
12,657,569!
597
    (void)taosThreadMutexUnlock(&pVnode->mutex);
×
598
    vError("vgId:%d write is disabled for snapshot, version:%" PRId64, TD_VID(pVnode), ver);
×
599
    return TSDB_CODE_VND_WRITE_DISABLED;
×
600
  }
601
  (void)taosThreadMutexUnlock(&pVnode->mutex);
12,657,569✔
602

603
  if (ver <= pVnode->state.applied) {
12,657,575!
604
    vError("vgId:%d, duplicate write request. ver: %" PRId64 ", applied: %" PRId64 "", TD_VID(pVnode), ver,
×
605
           pVnode->state.applied);
606
    return terrno = TSDB_CODE_VND_DUP_REQUEST;
×
607
  }
608

609
  vDebug("vgId:%d, start to process write request %s, index:%" PRId64 ", applied:%" PRId64 ", state.applyTerm:%" PRId64
12,657,575!
610
         ", conn.applyTerm:%" PRId64,
611
         TD_VID(pVnode), TMSG_INFO(pMsg->msgType), ver, pVnode->state.applied, pVnode->state.applyTerm,
612
         pMsg->info.conn.applyTerm);
613

614
  if (!(pVnode->state.applyTerm <= pMsg->info.conn.applyTerm)) {
12,657,376!
615
    return terrno = TSDB_CODE_INTERNAL_ERROR;
×
616
  }
617

618
  if (!(pVnode->state.applied + 1 == ver)) {
12,657,376!
619
    return terrno = TSDB_CODE_INTERNAL_ERROR;
×
620
  }
621

622
  atomic_store_64(&pVnode->state.applied, ver);
12,657,376✔
623
  atomic_store_64(&pVnode->state.applyTerm, pMsg->info.conn.applyTerm);
12,657,570✔
624

625
  if (!syncUtilUserCommit(pMsg->msgType)) goto _exit;
12,657,561✔
626

627
  // skip header
628
  pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
12,634,975✔
629
  len = pMsg->contLen - sizeof(SMsgHead);
12,634,975✔
630
  bool needCommit = false;
12,634,975✔
631

632
  switch (pMsg->msgType) {
12,634,975!
633
    /* META */
634
    case TDMT_VND_CREATE_STB:
16,439✔
635
      if (vnodeProcessCreateStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
16,439✔
636
      break;
16,521✔
637
    case TDMT_VND_ALTER_STB:
6,099✔
638
      if (vnodeProcessAlterStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
6,099!
639
      break;
6,102✔
640
    case TDMT_VND_DROP_STB:
2,080✔
641
      if (vnodeProcessDropStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
2,080!
642
      break;
2,091✔
643
    case TDMT_VND_CREATE_TABLE:
60,012✔
644
      if (vnodeProcessCreateTbReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
60,012!
645
      break;
60,051✔
646
    case TDMT_VND_ALTER_TABLE:
898✔
647
      if (vnodeProcessAlterTbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
898!
648
      break;
898✔
649
    case TDMT_VND_DROP_TABLE:
1,890✔
650
      if (vnodeProcessDropTbReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
1,890!
651
      break;
1,890✔
652
    case TDMT_VND_DROP_TTL_TABLE:
×
653
      if (vnodeProcessDropTtlTbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
×
654
      break;
×
655
    case TDMT_VND_FETCH_TTL_EXPIRED_TBS:
5✔
656
      if (vnodeProcessFetchTtlExpiredTbs(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
5!
657
      break;
5✔
658
    case TDMT_VND_TRIM:
13✔
659
      if (vnodeProcessTrimReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
13!
660
      break;
13✔
661
    case TDMT_VND_S3MIGRATE:
×
662
      if (vnodeProcessS3MigrateReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
×
663
      break;
×
664
    case TDMT_VND_CREATE_SMA:
27✔
665
      if (vnodeProcessCreateTSmaReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
27!
666
      break;
27✔
667
    /* TSDB */
668
    case TDMT_VND_SUBMIT:
12,465,441✔
669
      if (vnodeProcessSubmitReq(pVnode, ver, pMsg->pCont, pMsg->contLen, pRsp, pMsg) < 0) goto _err;
12,465,441✔
670
      break;
12,465,409✔
671
    case TDMT_VND_DELETE:
13,924✔
672
      if (vnodeProcessDeleteReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
13,924!
673
      break;
13,925✔
674
    case TDMT_VND_BATCH_DEL:
2,896✔
675
      if (vnodeProcessBatchDeleteReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
2,896!
676
      break;
2,903✔
677
    /* TQ */
678
    case TDMT_VND_TMQ_SUBSCRIBE:
2,970✔
679
      if (tqProcessSubscribeReq(pVnode->pTq, ver, pReq, len) < 0) {
2,970✔
680
        goto _err;
1✔
681
      }
682
      break;
2,978✔
683
    case TDMT_VND_TMQ_DELETE_SUB:
855✔
684
      if (tqProcessDeleteSubReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen) < 0) {
855!
685
        goto _err;
×
686
      }
687
      break;
854✔
688
    case TDMT_VND_TMQ_COMMIT_OFFSET:
9,226✔
689
      if (tqProcessOffsetCommitReq(pVnode->pTq, ver, pReq, len) < 0) {
9,226!
690
        goto _err;
×
691
      }
692
      break;
9,233✔
693
    case TDMT_VND_TMQ_ADD_CHECKINFO:
117✔
694
      if (tqProcessAddCheckInfoReq(pVnode->pTq, ver, pReq, len) < 0) {
117!
695
        goto _err;
×
696
      }
697
      break;
118✔
698
    case TDMT_VND_TMQ_DEL_CHECKINFO:
12✔
699
      if (tqProcessDelCheckInfoReq(pVnode->pTq, ver, pReq, len) < 0) {
12✔
700
        goto _err;
2✔
701
      }
702
      break;
10✔
703
    case TDMT_STREAM_TASK_DEPLOY: {
13,713✔
704
      if ((code = tqProcessTaskDeployReq(pVnode->pTq, ver, pReq, len)) != TSDB_CODE_SUCCESS) {
13,713!
705
        goto _err;
×
706
      }
707
    } break;
13,734✔
708
    case TDMT_STREAM_TASK_DROP: {
6,947✔
709
      if ((code = tqProcessTaskDropReq(pVnode->pTq, pMsg->pCont, pMsg->contLen)) < 0) {
6,947!
710
        goto _err;
×
711
      }
712
    } break;
6,973✔
713
    case TDMT_STREAM_TASK_UPDATE_CHKPT: {
3,559✔
714
      if ((code = tqProcessTaskUpdateCheckpointReq(pVnode->pTq, pMsg->pCont, pMsg->contLen)) < 0) {
3,559!
715
        goto _err;
×
716
      }
717
    } break;
3,562✔
718
    case TDMT_STREAM_CONSEN_CHKPT: {
164✔
719
      if (pVnode->restored && (code = tqProcessTaskConsenChkptIdReq(pVnode->pTq, pMsg)) < 0) {
164!
720
        goto _err;
×
721
      }
722

723
    } break;
164✔
724
    case TDMT_STREAM_TASK_PAUSE: {
2,118✔
725
      if (pVnode->restored && vnodeIsLeader(pVnode) &&
3,517!
726
          (code = tqProcessTaskPauseReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen)) < 0) {
1,396✔
727
        goto _err;
×
728
      }
729
    } break;
2,122✔
730
    case TDMT_STREAM_TASK_RESUME: {
3,785✔
731
      if (pVnode->restored && vnodeIsLeader(pVnode) &&
6,351!
732
          (code = tqProcessTaskResumeReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen)) < 0) {
2,561✔
733
        goto _err;
×
734
      }
735
    } break;
3,792✔
736
    case TDMT_VND_STREAM_TASK_RESET: {
×
737
      if (pVnode->restored && vnodeIsLeader(pVnode) && (code = tqProcessTaskResetReq(pVnode->pTq, pMsg)) < 0) {
×
738
        goto _err;
×
739
      }
740

741
    } break;
×
742
    case TDMT_VND_ALTER_CONFIRM:
7,895✔
743
      needCommit = pVnode->config.hashChange;
7,895✔
744
      if (vnodeProcessAlterConfirmReq(pVnode, ver, pReq, len, pRsp) < 0) {
7,895!
745
        goto _err;
×
746
      }
747
      break;
7,895✔
748
    case TDMT_VND_ALTER_CONFIG:
361✔
749
      vnodeProcessAlterConfigReq(pVnode, ver, pReq, len, pRsp);
361✔
750
      break;
362✔
751
    case TDMT_VND_COMMIT:
11,148✔
752
      needCommit = true;
11,148✔
753
      break;
11,148✔
754
    case TDMT_VND_CREATE_INDEX:
21✔
755
      vnodeProcessCreateIndexReq(pVnode, ver, pReq, len, pRsp);
21✔
756
      break;
21✔
757
    case TDMT_VND_DROP_INDEX:
8✔
758
      vnodeProcessDropIndexReq(pVnode, ver, pReq, len, pRsp);
8✔
759
      break;
8✔
760
    case TDMT_VND_STREAM_CHECK_POINT_SOURCE:  // always return true
2,267✔
761
      tqProcessTaskCheckPointSourceReq(pVnode->pTq, pMsg, pRsp);
2,267✔
762
      break;
2,267✔
763
    case TDMT_VND_STREAM_TASK_UPDATE:  // always return true
80✔
764
      tqProcessTaskUpdateReq(pVnode->pTq, pMsg);
80✔
765
      break;
80✔
766
    case TDMT_VND_COMPACT:
5✔
767
      vnodeProcessCompactVnodeReq(pVnode, ver, pReq, len, pRsp);
5✔
768
      goto _exit;
5✔
769
    case TDMT_SYNC_CONFIG_CHANGE:
×
770
      vnodeProcessConfigChangeReq(pVnode, ver, pReq, len, pRsp);
×
771
      break;
×
772
#ifdef TD_ENTERPRISE
773
    case TDMT_VND_KILL_COMPACT:
×
774
      vnodeProcessKillCompactReq(pVnode, ver, pReq, len, pRsp);
×
775
      break;
×
776
#endif
777
    /* ARB */
778
    case TDMT_VND_ARB_CHECK_SYNC:
×
779
      vnodeProcessArbCheckSyncReq(pVnode, pReq, len, pRsp);
×
780
      break;
×
781
    default:
×
782
      vError("vgId:%d, unprocessed msg, %d", TD_VID(pVnode), pMsg->msgType);
×
783
      return TSDB_CODE_INVALID_MSG;
×
784
  }
785

786
  vTrace("vgId:%d, process %s request, code:0x%x index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), pRsp->code,
12,635,156!
787
         ver);
788

789
  walApplyVer(pVnode->pWal, ver);
12,635,156✔
790

791
  code = tqPushMsg(pVnode->pTq, pMsg->msgType);
12,635,136✔
792
  if (code) {
12,635,194✔
793
    vError("vgId:%d, failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno));
426!
794
    return code;
426✔
795
  }
796

797
  // commit if need
798
  if (needCommit) {
12,634,768✔
799
    vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), ver);
10,779!
800
    code = vnodeAsyncCommit(pVnode);
10,791✔
801
    if (code) {
10,798!
802
      vError("vgId:%d, failed to vnode async commit since %s.", TD_VID(pVnode), tstrerror(terrno));
×
803
      goto _err;
×
804
    }
805

806
    // start a new one
807
    code = vnodeBegin(pVnode);
10,798✔
808
    if (code) {
10,793✔
809
      vError("vgId:%d, failed to begin vnode since %s.", TD_VID(pVnode), tstrerror(terrno));
24!
810
      goto _err;
×
811
    }
812
  }
813

814
_exit:
12,634,758✔
815
  return 0;
12,656,972✔
816

817
_err:
17✔
818
  vError("vgId:%d, process %s request failed since %s, ver:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType),
17!
819
         tstrerror(code), ver);
820
  return code;
17✔
821
}
822

823
int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
1,304,860✔
824
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) {
1,304,860✔
825
    return 0;
105,383✔
826
  }
827

828
  return qWorkerPreprocessQueryMsg(pVnode->pQuery, pMsg, TDMT_SCH_QUERY == pMsg->msgType);
1,199,477✔
829
}
830

831
int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
1,307,826✔
832
  vTrace("message in vnode query queue is processing");
1,307,826✔
833
  if (pMsg->msgType == TDMT_VND_TMQ_CONSUME && !syncIsReadyForRead(pVnode->sync)) {
1,307,826✔
834
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
1,452✔
835
    return 0;
1,452✔
836
  }
837

838
  if (pMsg->msgType == TDMT_VND_TMQ_CONSUME && !pVnode->restored) {
1,306,370!
839
    vnodeRedirectRpcMsg(pVnode, pMsg, TSDB_CODE_SYN_RESTORING);
×
840
    return 0;
×
841
  }
842

843
  SReadHandle handle = {.vnode = pVnode, .pMsgCb = &pVnode->msgCb, .pWorkerCb = pInfo->workerCb};
1,306,370✔
844
  initStorageAPI(&handle.api);
1,306,370✔
845
  int32_t code = TSDB_CODE_SUCCESS;
1,306,283✔
846
  bool redirected = false;
1,306,283✔
847

848
  switch (pMsg->msgType) {
1,306,283✔
849
    case TDMT_SCH_QUERY:
1,067,563✔
850
      if (!syncIsReadyForRead(pVnode->sync)) {
1,067,563✔
851
        pMsg->code = (terrno) ? terrno : TSDB_CODE_SYN_NOT_LEADER;
1,564!
852
        redirected = true;
1,564✔
853
      }
854
      code = qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
1,067,547✔
855
      if (redirected) {
1,067,086✔
856
        vnodeRedirectRpcMsg(pVnode, pMsg, pMsg->code);
1,347✔
857
        return 0;
1,564✔
858
      }
859
      return code;
1,065,739✔
860
    case TDMT_SCH_MERGE_QUERY:
134,774✔
861
      return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
134,774✔
862
    case TDMT_SCH_QUERY_CONTINUE:
9,818✔
863
      return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
9,818✔
864
    case TDMT_VND_TMQ_CONSUME:
69,289✔
865
      return tqProcessPollReq(pVnode->pTq, pMsg);
69,289✔
866
    case TDMT_VND_TMQ_CONSUME_PUSH:
24,823✔
867
      return tqProcessPollPush(pVnode->pTq, pMsg);
24,823✔
868
    default:
16✔
869
      vError("unknown msg type:%d in query queue", pMsg->msgType);
16!
870
      return TSDB_CODE_APP_ERROR;
×
871
  }
872
}
873

874
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
3,121,080✔
875
  vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg);
3,121,080✔
876
  if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
3,121,080!
877
       pMsg->msgType == TDMT_VND_BATCH_META || pMsg->msgType == TDMT_VND_TABLE_NAME) &&
2,051,778✔
878
      !syncIsReadyForRead(pVnode->sync)) {
1,118,903✔
879
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
5,589✔
880
    return 0;
5,589✔
881
  }
882

883
  switch (pMsg->msgType) {
3,115,699!
884
    case TDMT_SCH_FETCH:
1,235,793✔
885
    case TDMT_SCH_MERGE_FETCH:
886
      return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg, 0);
1,235,793✔
887
    case TDMT_SCH_FETCH_RSP:
×
888
      return qWorkerProcessRspMsg(pVnode, pVnode->pQuery, pMsg, 0);
×
889
    // case TDMT_SCH_CANCEL_TASK:
890
    //   return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg, 0);
891
    case TDMT_SCH_DROP_TASK:
1,200,959✔
892
      return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg, 0);
1,200,959✔
893
    case TDMT_SCH_TASK_NOTIFY:
×
894
      return qWorkerProcessNotifyMsg(pVnode, pVnode->pQuery, pMsg, 0);
×
895
    case TDMT_SCH_QUERY_HEARTBEAT:
634,274✔
896
      return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg, 0);
634,274✔
897
    case TDMT_VND_TABLE_META:
1,770✔
898
    case TDMT_VND_TABLE_NAME:
899
      return vnodeGetTableMeta(pVnode, pMsg, true);
1,770✔
900
    case TDMT_VND_TABLE_CFG:
×
901
      return vnodeGetTableCfg(pVnode, pMsg, true);
×
902
    case TDMT_VND_BATCH_META:
42,860✔
903
      return vnodeGetBatchMeta(pVnode, pMsg);
42,860✔
904
#ifdef TD_ENTERPRISE
905
    case TDMT_VND_QUERY_COMPACT_PROGRESS:
4✔
906
      return vnodeQueryCompactProgress(pVnode, pMsg);
4✔
907
#endif
908
      //    case TDMT_VND_TMQ_CONSUME:
909
      //      return tqProcessPollReq(pVnode->pTq, pMsg);
910
    case TDMT_VND_TMQ_VG_WALINFO:
13✔
911
      return tqProcessVgWalInfoReq(pVnode->pTq, pMsg);
13✔
912
    case TDMT_VND_TMQ_VG_COMMITTEDINFO:
2✔
913
      return tqProcessVgCommittedInfoReq(pVnode->pTq, pMsg);
2✔
914
    case TDMT_VND_TMQ_SEEK:
24✔
915
      return tqProcessSeekReq(pVnode->pTq, pMsg);
24✔
916

917
    default:
×
918
      vError("unknown msg type:%d in fetch queue", pMsg->msgType);
×
919
      return TSDB_CODE_APP_ERROR;
×
920
  }
921
}
922

923
int32_t vnodeProcessStreamMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
318,885✔
924
  vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg);
318,885✔
925
  if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
318,885!
926
       pMsg->msgType == TDMT_VND_BATCH_META) &&
318,898!
927
      !syncIsReadyForRead(pVnode->sync)) {
×
928
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
×
929
    return 0;
×
930
  }
931

932
  switch (pMsg->msgType) {
318,898!
933
    case TDMT_STREAM_TASK_RUN:
141,182✔
934
      return tqProcessTaskRunReq(pVnode->pTq, pMsg);
141,182✔
935
    case TDMT_STREAM_TASK_DISPATCH:
52,084✔
936
      return tqProcessTaskDispatchReq(pVnode->pTq, pMsg);
52,084✔
937
    case TDMT_STREAM_TASK_DISPATCH_RSP:
52,027✔
938
      return tqProcessTaskDispatchRsp(pVnode->pTq, pMsg);
52,027✔
939
    case TDMT_VND_STREAM_TASK_CHECK:
20,828✔
940
      return tqProcessTaskCheckReq(pVnode->pTq, pMsg);
20,828✔
941
    case TDMT_VND_STREAM_TASK_CHECK_RSP:
20,898✔
942
      return tqProcessTaskCheckRsp(pVnode->pTq, pMsg);
20,898✔
943
    case TDMT_STREAM_RETRIEVE:
570✔
944
      return tqProcessTaskRetrieveReq(pVnode->pTq, pMsg);
570✔
945
    case TDMT_STREAM_RETRIEVE_RSP:
462✔
946
      return tqProcessTaskRetrieveRsp(pVnode->pTq, pMsg);
462✔
947
    case TDMT_VND_STREAM_SCAN_HISTORY:
2,550✔
948
      return tqProcessTaskScanHistory(pVnode->pTq, pMsg);
2,550✔
949
    case TDMT_STREAM_TASK_CHECKPOINT_READY:
6,530✔
950
      return tqProcessTaskCheckpointReadyMsg(pVnode->pTq, pMsg);
6,530✔
951
    case TDMT_STREAM_TASK_CHECKPOINT_READY_RSP:
6,515✔
952
      return tqProcessTaskCheckpointReadyRsp(pVnode->pTq, pMsg);
6,515✔
953
    case TDMT_STREAM_RETRIEVE_TRIGGER:
×
954
      return tqProcessTaskRetrieveTriggerReq(pVnode->pTq, pMsg);
×
955
    case TDMT_STREAM_RETRIEVE_TRIGGER_RSP:
×
956
      return tqProcessTaskRetrieveTriggerRsp(pVnode->pTq, pMsg);
×
957
    case TDMT_MND_STREAM_HEARTBEAT_RSP:
6,629✔
958
      return tqProcessStreamHbRsp(pVnode->pTq, pMsg);
6,629✔
959
    case TDMT_MND_STREAM_REQ_CHKPT_RSP:
4,403✔
960
      return tqProcessStreamReqCheckpointRsp(pVnode->pTq, pMsg);
4,403✔
961
    case TDMT_VND_GET_STREAM_PROGRESS:
×
962
      return tqStreamProgressRetrieveReq(pVnode->pTq, pMsg);
×
963
    case TDMT_MND_STREAM_CHKPT_REPORT_RSP:
4,220✔
964
      return tqProcessTaskChkptReportRsp(pVnode->pTq, pMsg);
4,220✔
965
    default:
×
966
      vError("unknown msg type:%d in stream queue", pMsg->msgType);
×
967
      return TSDB_CODE_APP_ERROR;
×
968
  }
969
}
970

971
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
4✔
972
  int32_t code = tdProcessTSmaInsert(((SVnode *)pVnode)->pSma, smaId, (const char *)data);
4✔
973
  if (code) {
4!
974
    vError("failed to process sma result since %s", tstrerror(code));
×
975
  }
976
}
4✔
977

978
void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) {
128,302✔
979
  if (NULL == pMetaRsp) {
128,302!
980
    return;
×
981
  }
982

983
  tstrncpy(pMetaRsp->dbFName, pVnode->config.dbname, TSDB_DB_FNAME_LEN);
128,302✔
984
  pMetaRsp->dbId = pVnode->config.dbId;
128,302✔
985
  pMetaRsp->vgId = TD_VID(pVnode);
128,302✔
986
  pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
128,302✔
987
}
988

989
extern int32_t vnodeAsyncRetention(SVnode *pVnode, int64_t now);
990

991
static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
13✔
992
  if (!pVnode->restored) {
13✔
993
    vInfo("vgId:%d, ignore trim req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
7!
994
    return 0;
7✔
995
  }
996

997
  int32_t     code = 0;
6✔
998
  SVTrimDbReq trimReq = {0};
6✔
999

1000
  // decode
1001
  if (tDeserializeSVTrimDbReq(pReq, len, &trimReq) != 0) {
6!
1002
    code = TSDB_CODE_INVALID_MSG;
×
1003
    goto _exit;
×
1004
  }
1005

1006
  vInfo("vgId:%d, trim vnode request will be processed, time:%d", pVnode->config.vgId, trimReq.timestamp);
6!
1007

1008
  code = vnodeAsyncRetention(pVnode, trimReq.timestamp);
6✔
1009

1010
_exit:
6✔
1011
  return code;
6✔
1012
}
1013

1014
extern int32_t vnodeAsyncS3Migrate(SVnode *pVnode, int64_t now);
1015

1016
static int32_t vnodeProcessS3MigrateReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
1017
  int32_t          code = 0;
×
1018
  SVS3MigrateDbReq s3migrateReq = {0};
×
1019

1020
  // decode
1021
  if (tDeserializeSVS3MigrateDbReq(pReq, len, &s3migrateReq) != 0) {
×
1022
    code = TSDB_CODE_INVALID_MSG;
×
1023
    goto _exit;
×
1024
  }
1025

1026
  vInfo("vgId:%d, s3migrate vnode request will be processed, time:%d", pVnode->config.vgId, s3migrateReq.timestamp);
×
1027

1028
  code = vnodeAsyncS3Migrate(pVnode, s3migrateReq.timestamp);
×
1029

1030
_exit:
×
1031
  return code;
×
1032
}
1033

1034
static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
1035
  int               ret = 0;
×
1036
  SVDropTtlTableReq ttlReq = {0};
×
1037
  if (tDeserializeSVDropTtlTableReq(pReq, len, &ttlReq) != 0) {
×
1038
    ret = TSDB_CODE_INVALID_MSG;
×
1039
    goto end;
×
1040
  }
1041

1042
  if (ttlReq.nUids != taosArrayGetSize(ttlReq.pTbUids)) {
×
1043
    ret = TSDB_CODE_INVALID_MSG;
×
1044
    goto end;
×
1045
  }
1046

1047
  if (ttlReq.nUids != 0) {
×
1048
    vInfo("vgId:%d, drop ttl table req will be processed, time:%d, ntbUids:%d", pVnode->config.vgId,
×
1049
          ttlReq.timestampSec, ttlReq.nUids);
1050
  }
1051

1052
  if (ttlReq.nUids > 0) {
×
1053
    int32_t code = metaDropMultipleTables(pVnode->pMeta, ver, ttlReq.pTbUids);
×
1054
    if (code) return code;
×
1055

1056
    code = tqUpdateTbUidList(pVnode->pTq, ttlReq.pTbUids, false);
×
1057
    if (code) {
×
1058
      vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(code));
×
1059
    }
1060
  }
1061

1062
end:
×
1063
  taosArrayDestroy(ttlReq.pTbUids);
×
1064
  return ret;
×
1065
}
1066

1067
static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
5✔
1068
  int32_t                 code = -1;
5✔
1069
  SMetaReader             mr = {0};
5✔
1070
  SVDropTtlTableReq       ttlReq = {0};
5✔
1071
  SVFetchTtlExpiredTbsRsp rsp = {0};
5✔
1072
  SEncoder                encoder = {0};
5✔
1073
  SArray                 *pNames = NULL;
5✔
1074
  pRsp->msgType = TDMT_VND_FETCH_TTL_EXPIRED_TBS_RSP;
5✔
1075
  pRsp->code = TSDB_CODE_SUCCESS;
5✔
1076
  pRsp->pCont = NULL;
5✔
1077
  pRsp->contLen = 0;
5✔
1078

1079
  if (tDeserializeSVDropTtlTableReq(pReq, len, &ttlReq) != 0) {
5!
1080
    terrno = TSDB_CODE_INVALID_MSG;
×
1081
    goto _end;
×
1082
  }
1083

1084
  if (!(ttlReq.nUids == taosArrayGetSize(ttlReq.pTbUids))) {
5!
1085
    terrno = TSDB_CODE_INVALID_MSG;
×
1086
    goto _end;
×
1087
  }
1088

1089
  tb_uid_t    suid;
1090
  char        ctbName[TSDB_TABLE_NAME_LEN];
1091
  SVDropTbReq expiredTb = {.igNotExists = true};
5✔
1092
  metaReaderDoInit(&mr, pVnode->pMeta, 0);
5✔
1093
  rsp.vgId = TD_VID(pVnode);
5✔
1094
  rsp.pExpiredTbs = taosArrayInit(ttlReq.nUids, sizeof(SVDropTbReq));
5✔
1095
  if (!rsp.pExpiredTbs) goto _end;
5!
1096

1097
  pNames = taosArrayInit(ttlReq.nUids, TSDB_TABLE_NAME_LEN);
5✔
1098
  if (!pNames) {
5!
1099
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1100
    goto _end;
×
1101
  }
1102
  char buf[TSDB_TABLE_NAME_LEN];
1103
  for (int32_t i = 0; i < ttlReq.nUids; ++i) {
10✔
1104
    tb_uid_t *uid = taosArrayGet(ttlReq.pTbUids, i);
5✔
1105
    expiredTb.suid = *uid;
5✔
1106
    terrno = metaReaderGetTableEntryByUid(&mr, *uid);
5✔
1107
    if (terrno < 0) goto _end;
5!
1108
    tstrncpy(buf, mr.me.name, TSDB_TABLE_NAME_LEN);
5✔
1109
    void *p = taosArrayPush(pNames, buf);
5✔
1110
    if (p == NULL) {
5!
1111
      goto _end;
×
1112
    }
1113

1114
    expiredTb.name = p;
5✔
1115
    if (mr.me.type == TSDB_CHILD_TABLE) {
5!
1116
      expiredTb.suid = mr.me.ctbEntry.suid;
5✔
1117
    }
1118

1119
    if (taosArrayPush(rsp.pExpiredTbs, &expiredTb) == NULL) {
10!
1120
      goto _end;
×
1121
    }
1122
  }
1123

1124
  int32_t ret = 0;
5✔
1125
  tEncodeSize(tEncodeVFetchTtlExpiredTbsRsp, &rsp, pRsp->contLen, ret);
5!
1126
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
5✔
1127
  if (pRsp->pCont == NULL) {
5!
1128
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1129
    code = -1;
×
1130
    goto _end;
×
1131
  }
1132
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
5✔
1133
  terrno = tEncodeVFetchTtlExpiredTbsRsp(&encoder, &rsp);
5✔
1134
  tEncoderClear(&encoder);
5✔
1135

1136
  if (terrno == 0) code = 0;
5!
1137
_end:
×
1138
  metaReaderClear(&mr);
5✔
1139
  tFreeFetchTtlExpiredTbsRsp(&rsp);
5✔
1140
  taosArrayDestroy(ttlReq.pTbUids);
5✔
1141
  if (pNames) taosArrayDestroy(pNames);
5!
1142
  pRsp->code = terrno;
5✔
1143
  return code;
5✔
1144
}
1145

1146
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
16,434✔
1147
  int32_t        code = 0;
16,434✔
1148
  SVCreateStbReq req = {0};
16,434✔
1149
  SDecoder       coder;
1150

1151
  pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
16,434✔
1152
  pRsp->code = TSDB_CODE_SUCCESS;
16,434✔
1153
  pRsp->pCont = NULL;
16,434✔
1154
  pRsp->contLen = 0;
16,434✔
1155

1156
  // decode and process req
1157
  tDecoderInit(&coder, pReq, len);
16,434✔
1158

1159
  code = tDecodeSVCreateStbReq(&coder, &req);
16,440✔
1160
  if (code) {
16,431!
1161
    pRsp->code = code;
×
1162
    goto _err;
×
1163
  }
1164

1165
  code = metaCreateSuperTable(pVnode->pMeta, ver, &req);
16,431✔
1166
  if (code) {
16,530✔
1167
    pRsp->code = code;
4✔
1168
    goto _err;
4✔
1169
  }
1170

1171
  if ((code = tdProcessRSmaCreate(pVnode->pSma, &req)) < 0) {
16,526!
1172
    pRsp->code = code;
×
1173
    goto _err;
×
1174
  }
1175

1176
  tDecoderClear(&coder);
16,521✔
1177
  return 0;
16,508✔
1178

1179
_err:
4✔
1180
  tDecoderClear(&coder);
4✔
1181
  return code;
4✔
1182
}
1183

1184
static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
60,009✔
1185
                                       SRpcMsg *pOriginRpc) {
1186
  SDecoder           decoder = {0};
60,009✔
1187
  SEncoder           encoder = {0};
60,009✔
1188
  int32_t            rcode = 0;
60,009✔
1189
  SVCreateTbBatchReq req = {0};
60,009✔
1190
  SVCreateTbReq     *pCreateReq;
1191
  SVCreateTbBatchRsp rsp = {0};
60,009✔
1192
  SVCreateTbRsp      cRsp = {0};
60,009✔
1193
  char               tbName[TSDB_TABLE_FNAME_LEN];
1194
  STbUidStore       *pStore = NULL;
60,009✔
1195
  SArray            *tbUids = NULL;
60,009✔
1196
  SArray            *tbNames = NULL;
60,009✔
1197
  pRsp->msgType = TDMT_VND_CREATE_TABLE_RSP;
60,009✔
1198
  pRsp->code = TSDB_CODE_SUCCESS;
60,009✔
1199
  pRsp->pCont = NULL;
60,009✔
1200
  pRsp->contLen = 0;
60,009✔
1201

1202
  // decode
1203
  tDecoderInit(&decoder, pReq, len);
60,009✔
1204
  if (tDecodeSVCreateTbBatchReq(&decoder, &req) < 0) {
60,009!
1205
    rcode = -1;
×
1206
    terrno = TSDB_CODE_INVALID_MSG;
×
1207
    goto _exit;
×
1208
  }
1209

1210
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(cRsp));
60,044✔
1211
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
60,048✔
1212
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
60,050✔
1213
  if (rsp.pArray == NULL || tbUids == NULL || tbNames == NULL) {
60,049!
1214
    rcode = -1;
×
1215
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1216
    goto _exit;
×
1217
  }
1218

1219
  // loop to create table
1220
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
149,792✔
1221
    pCreateReq = req.pReqs + iReq;
89,733✔
1222
    memset(&cRsp, 0, sizeof(cRsp));
89,733✔
1223

1224
    if (tsEnableAudit && tsEnableAuditCreateTable) {
89,733!
1225
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
89,733!
1226
      if (str == NULL) {
89,732!
1227
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1228
        rcode = -1;
×
1229
        goto _exit;
×
1230
      }
1231
      tstrncpy(str, pCreateReq->name, TSDB_TABLE_FNAME_LEN);
89,732✔
1232
      if (taosArrayPush(tbNames, &str) == NULL) {
89,732!
1233
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1234
        rcode = -1;
×
1235
        goto _exit;
×
1236
      }
1237
    }
1238

1239
    // validate hash
1240
    (void)tsnprintf(tbName, TSDB_TABLE_FNAME_LEN, "%s.%s", pVnode->config.dbname, pCreateReq->name);
89,732✔
1241
    if (vnodeValidateTableHash(pVnode, tbName) < 0) {
89,739!
1242
      cRsp.code = TSDB_CODE_VND_HASH_MISMATCH;
×
1243
      if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
×
1244
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1245
        rcode = -1;
×
1246
        goto _exit;
×
1247
      }
1248
      vError("vgId:%d create-table:%s failed due to hash value mismatch", TD_VID(pVnode), tbName);
×
1249
      continue;
×
1250
    }
1251

1252
    // do create table
1253
    if (metaCreateTable2(pVnode->pMeta, ver, pCreateReq, &cRsp.pMeta) < 0) {
89,737✔
1254
      if (pCreateReq->flags & TD_CREATE_IF_NOT_EXISTS && terrno == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
1,341!
1255
        cRsp.code = TSDB_CODE_SUCCESS;
3✔
1256
      } else {
1257
        cRsp.code = terrno;
1,338✔
1258
      }
1259
    } else {
1260
      cRsp.code = TSDB_CODE_SUCCESS;
88,404✔
1261
      if (tdFetchTbUidList(pVnode->pSma, &pStore, pCreateReq->ctb.suid, pCreateReq->uid) < 0) {
88,404!
1262
        vError("vgId:%d, failed to fetch tbUid list", TD_VID(pVnode));
×
1263
      }
1264
      if (taosArrayPush(tbUids, &pCreateReq->uid) == NULL) {
176,807!
1265
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1266
        rcode = -1;
×
1267
        goto _exit;
×
1268
      }
1269
      vnodeUpdateMetaRsp(pVnode, cRsp.pMeta);
88,403✔
1270
    }
1271

1272
    if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
179,487!
1273
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1274
      rcode = -1;
×
1275
      goto _exit;
×
1276
    }
1277
  }
1278

1279
  vDebug("vgId:%d, add %d new created tables into query table list", TD_VID(pVnode), (int32_t)taosArrayGetSize(tbUids));
60,059✔
1280
  if (tqUpdateTbUidList(pVnode->pTq, tbUids, true) < 0) {
60,059!
1281
    vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(terrno));
×
1282
  }
1283
  if (tdUpdateTbUidList(pVnode->pSma, pStore, true) < 0) {
60,053!
1284
    goto _exit;
×
1285
  }
1286
  pStore = tdUidStoreFree(pStore);
60,053✔
1287

1288
  // prepare rsp
1289
  int32_t ret = 0;
60,053✔
1290
  tEncodeSize(tEncodeSVCreateTbBatchRsp, &rsp, pRsp->contLen, ret);
60,053!
1291
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
60,049✔
1292
  if (pRsp->pCont == NULL) {
60,051!
1293
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1294
    rcode = -1;
×
1295
    goto _exit;
×
1296
  }
1297
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
60,051✔
1298
  if (tEncodeSVCreateTbBatchRsp(&encoder, &rsp) != 0) {
60,051!
1299
    vError("vgId:%d, failed to encode create table batch response", TD_VID(pVnode));
×
1300
  }
1301

1302
  if (tsEnableAudit && tsEnableAuditCreateTable) {
60,052!
1303
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
60,052✔
1304

1305
    SName name = {0};
60,052✔
1306
    if (tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB) < 0) {
60,052!
1307
      vError("vgId:%d, failed to get name from string", TD_VID(pVnode));
×
1308
    }
1309

1310
    SStringBuilder sb = {0};
60,049✔
1311
    for (int32_t i = 0; i < tbNames->size; i++) {
149,787✔
1312
      char **key = (char **)taosArrayGet(tbNames, i);
89,741✔
1313
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
89,741✔
1314
      if (i < tbNames->size - 1) {
89,738✔
1315
        taosStringBuilderAppendChar(&sb, ',');
29,692✔
1316
      }
1317
      // taosMemoryFreeClear(*key);
1318
    }
1319

1320
    size_t len = 0;
60,046✔
1321
    char  *keyJoined = taosStringBuilderGetResult(&sb, &len);
60,046✔
1322

1323
    if (pOriginRpc->info.conn.user != NULL && strlen(pOriginRpc->info.conn.user) > 0) {
60,049!
1324
      auditAddRecord(pOriginRpc, clusterId, "createTable", name.dbname, "", keyJoined, len);
45,650✔
1325
    }
1326

1327
    taosStringBuilderDestroy(&sb);
60,047✔
1328
  }
1329

1330
_exit:
×
1331
  tDeleteSVCreateTbBatchReq(&req);
60,050✔
1332
  taosArrayDestroyEx(rsp.pArray, tFreeSVCreateTbRsp);
60,053✔
1333
  taosArrayDestroy(tbUids);
60,052✔
1334
  tDecoderClear(&decoder);
60,051✔
1335
  tEncoderClear(&encoder);
60,051✔
1336
  taosArrayDestroyP(tbNames, NULL);
60,051✔
1337
  return rcode;
60,051✔
1338
}
1339

1340
static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
6,099✔
1341
  int32_t        code = 0;
6,099✔
1342
  SVCreateStbReq req = {0};
6,099✔
1343
  SDecoder       dc = {0};
6,099✔
1344

1345
  pRsp->msgType = TDMT_VND_ALTER_STB_RSP;
6,099✔
1346
  pRsp->code = TSDB_CODE_SUCCESS;
6,099✔
1347
  pRsp->pCont = NULL;
6,099✔
1348
  pRsp->contLen = 0;
6,099✔
1349

1350
  tDecoderInit(&dc, pReq, len);
6,099✔
1351

1352
  // decode req
1353
  code = tDecodeSVCreateStbReq(&dc, &req);
6,099✔
1354
  if (code) {
6,100!
1355
    tDecoderClear(&dc);
×
1356
    return code;
×
1357
  }
1358

1359
  code = metaAlterSuperTable(pVnode->pMeta, ver, &req);
6,100✔
1360
  if (code) {
6,102!
1361
    pRsp->code = code;
×
1362
    tDecoderClear(&dc);
×
1363
    return code;
×
1364
  }
1365

1366
  tDecoderClear(&dc);
6,102✔
1367

1368
  return 0;
6,102✔
1369
}
1370

1371
static int32_t vnodeProcessDropStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
2,081✔
1372
  SVDropStbReq req = {0};
2,081✔
1373
  int32_t      rcode = TSDB_CODE_SUCCESS;
2,081✔
1374
  SDecoder     decoder = {0};
2,081✔
1375
  SArray      *tbUidList = NULL;
2,081✔
1376

1377
  pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
2,081✔
1378
  pRsp->pCont = NULL;
2,081✔
1379
  pRsp->contLen = 0;
2,081✔
1380

1381
  // decode request
1382
  tDecoderInit(&decoder, pReq, len);
2,081✔
1383
  if (tDecodeSVDropStbReq(&decoder, &req) < 0) {
2,081!
1384
    rcode = TSDB_CODE_INVALID_MSG;
×
1385
    goto _exit;
×
1386
  }
1387

1388
  // process request
1389
  tbUidList = taosArrayInit(8, sizeof(int64_t));
2,087✔
1390
  if (tbUidList == NULL) goto _exit;
2,084!
1391
  if (metaDropSuperTable(pVnode->pMeta, ver, &req) < 0) {
2,084✔
1392
    rcode = terrno;
2✔
1393
    goto _exit;
2✔
1394
  }
1395

1396
  if (tqUpdateTbUidList(pVnode->pTq, tbUidList, false) < 0) {
2,089!
1397
    rcode = terrno;
×
1398
    goto _exit;
×
1399
  }
1400

1401
  if (tdProcessRSmaDrop(pVnode->pSma, &req) < 0) {
2,089!
1402
    rcode = terrno;
×
1403
    goto _exit;
×
1404
  }
1405

1406
  // return rsp
1407
_exit:
2,089✔
1408
  if (tbUidList) taosArrayDestroy(tbUidList);
2,091!
1409
  pRsp->code = rcode;
2,091✔
1410
  tDecoderClear(&decoder);
2,091✔
1411
  return 0;
2,091✔
1412
}
1413

1414
static int32_t vnodeProcessAlterTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
898✔
1415
  SVAlterTbReq  vAlterTbReq = {0};
898✔
1416
  SVAlterTbRsp  vAlterTbRsp = {0};
898✔
1417
  SDecoder      dc = {0};
898✔
1418
  int32_t       rcode = 0;
898✔
1419
  int32_t       ret;
1420
  SEncoder      ec = {0};
898✔
1421
  STableMetaRsp vMetaRsp = {0};
898✔
1422

1423
  pRsp->msgType = TDMT_VND_ALTER_TABLE_RSP;
898✔
1424
  pRsp->pCont = NULL;
898✔
1425
  pRsp->contLen = 0;
898✔
1426
  pRsp->code = TSDB_CODE_SUCCESS;
898✔
1427

1428
  tDecoderInit(&dc, pReq, len);
898✔
1429

1430
  // decode
1431
  if (tDecodeSVAlterTbReq(&dc, &vAlterTbReq) < 0) {
898!
1432
    vAlterTbRsp.code = TSDB_CODE_INVALID_MSG;
×
1433
    tDecoderClear(&dc);
×
1434
    rcode = -1;
×
1435
    goto _exit;
×
1436
  }
1437

1438
  // process
1439
  if (metaAlterTable(pVnode->pMeta, ver, &vAlterTbReq, &vMetaRsp) < 0) {
898✔
1440
    vAlterTbRsp.code = terrno;
38✔
1441
    tDecoderClear(&dc);
38✔
1442
    rcode = -1;
38✔
1443
    goto _exit;
38✔
1444
  }
1445
  tDecoderClear(&dc);
860✔
1446

1447
  if (NULL != vMetaRsp.pSchemas) {
860✔
1448
    vnodeUpdateMetaRsp(pVnode, &vMetaRsp);
160✔
1449
    vAlterTbRsp.pMeta = &vMetaRsp;
160✔
1450
  }
1451

1452
_exit:
700✔
1453
  taosArrayDestroy(vAlterTbReq.pMultiTag);
898✔
1454
  tEncodeSize(tEncodeSVAlterTbRsp, &vAlterTbRsp, pRsp->contLen, ret);
898!
1455
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
898✔
1456
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
898✔
1457
  if (tEncodeSVAlterTbRsp(&ec, &vAlterTbRsp) != 0) {
898!
1458
    vError("vgId:%d, failed to encode alter table response", TD_VID(pVnode));
×
1459
  }
1460
  tEncoderClear(&ec);
898✔
1461
  if (vMetaRsp.pSchemas) {
898✔
1462
    taosMemoryFree(vMetaRsp.pSchemas);
160!
1463
    taosMemoryFree(vMetaRsp.pSchemaExt);
160!
1464
  }
1465
  return 0;
898✔
1466
}
1467

1468
static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
1,890✔
1469
                                     SRpcMsg *pOriginRpc) {
1470
  SVDropTbBatchReq req = {0};
1,890✔
1471
  SVDropTbBatchRsp rsp = {0};
1,890✔
1472
  SDecoder         decoder = {0};
1,890✔
1473
  SEncoder         encoder = {0};
1,890✔
1474
  int32_t          ret;
1475
  SArray          *tbUids = NULL;
1,890✔
1476
  STbUidStore     *pStore = NULL;
1,890✔
1477
  SArray          *tbNames = NULL;
1,890✔
1478

1479
  pRsp->msgType = TDMT_VND_DROP_TABLE_RSP;
1,890✔
1480
  pRsp->pCont = NULL;
1,890✔
1481
  pRsp->contLen = 0;
1,890✔
1482
  pRsp->code = TSDB_CODE_SUCCESS;
1,890✔
1483

1484
  // decode req
1485
  tDecoderInit(&decoder, pReq, len);
1,890✔
1486
  ret = tDecodeSVDropTbBatchReq(&decoder, &req);
1,890✔
1487
  if (ret < 0) {
1,890!
1488
    terrno = TSDB_CODE_INVALID_MSG;
×
1489
    pRsp->code = terrno;
×
1490
    goto _exit;
×
1491
  }
1492

1493
  // process req
1494
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
1,890✔
1495
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(SVDropTbRsp));
1,890✔
1496
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
1,890✔
1497
  if (tbUids == NULL || rsp.pArray == NULL || tbNames == NULL) goto _exit;
1,890!
1498

1499
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
3,787✔
1500
    SVDropTbReq *pDropTbReq = req.pReqs + iReq;
1,897✔
1501
    SVDropTbRsp  dropTbRsp = {0};
1,897✔
1502
    tb_uid_t     tbUid = 0;
1,897✔
1503

1504
    /* code */
1505
    ret = metaDropTable2(pVnode->pMeta, ver, pDropTbReq);
1,897✔
1506
    if (ret < 0) {
1,897!
1507
      if (pDropTbReq->igNotExists && terrno == TSDB_CODE_TDB_TABLE_NOT_EXIST) {
×
1508
        dropTbRsp.code = TSDB_CODE_SUCCESS;
×
1509
      } else {
1510
        dropTbRsp.code = terrno;
×
1511
      }
1512
    } else {
1513
      dropTbRsp.code = TSDB_CODE_SUCCESS;
1,897✔
1514
      if (tbUid > 0) {
1,897!
1515
        if (tdFetchTbUidList(pVnode->pSma, &pStore, pDropTbReq->suid, tbUid) < 0) {
×
1516
          vError("vgId:%d, failed to fetch tbUid list", TD_VID(pVnode));
×
1517
        }
1518
      }
1519
    }
1520

1521
    if (taosArrayPush(rsp.pArray, &dropTbRsp) == NULL) {
3,794!
1522
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1523
      pRsp->code = terrno;
×
1524
      goto _exit;
×
1525
    }
1526

1527
    if (tsEnableAuditCreateTable) {
1,897!
1528
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
1,897!
1529
      if (str == NULL) {
1,897!
1530
        pRsp->code = terrno;
×
1531
        goto _exit;
×
1532
      }
1533
      tstrncpy(str, pDropTbReq->name, TSDB_TABLE_FNAME_LEN);
1,897✔
1534
      if (taosArrayPush(tbNames, &str) == NULL) {
1,897!
1535
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1536
        pRsp->code = terrno;
×
1537
        goto _exit;
×
1538
      }
1539
    }
1540
  }
1541

1542
  if (tqUpdateTbUidList(pVnode->pTq, tbUids, false) < 0) {
1,890!
1543
    vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(terrno));
×
1544
  }
1545

1546
  if (tdUpdateTbUidList(pVnode->pSma, pStore, false) < 0) {
1,890!
1547
    goto _exit;
×
1548
  }
1549

1550
  if (tsEnableAuditCreateTable) {
1,890!
1551
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
1,890✔
1552

1553
    SName name = {0};
1,890✔
1554
    if (tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB) != 0) {
1,890!
1555
      vError("vgId:%d, failed to get name from string", TD_VID(pVnode));
×
1556
    }
1557

1558
    SStringBuilder sb = {0};
1,890✔
1559
    for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
3,787✔
1560
      char **key = (char **)taosArrayGet(tbNames, iReq);
1,897✔
1561
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
1,897✔
1562
      if (iReq < req.nReqs - 1) {
1,897✔
1563
        taosStringBuilderAppendChar(&sb, ',');
7✔
1564
      }
1565
      taosMemoryFreeClear(*key);
1,897!
1566
    }
1567

1568
    size_t len = 0;
1,890✔
1569
    char  *keyJoined = taosStringBuilderGetResult(&sb, &len);
1,890✔
1570

1571
    if (pOriginRpc->info.conn.user != NULL && strlen(pOriginRpc->info.conn.user) > 0) {
1,890!
1572
      auditAddRecord(pOriginRpc, clusterId, "dropTable", name.dbname, "", keyJoined, len);
1,835✔
1573
    }
1574

1575
    taosStringBuilderDestroy(&sb);
1,890✔
1576
  }
1577

1578
_exit:
×
1579
  taosArrayDestroy(tbUids);
1,890✔
1580
  pStore = tdUidStoreFree(pStore);
1,890✔
1581
  tDecoderClear(&decoder);
1,890✔
1582
  tEncodeSize(tEncodeSVDropTbBatchRsp, &rsp, pRsp->contLen, ret);
1,890!
1583
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
1,890✔
1584
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
1,890✔
1585
  if (tEncodeSVDropTbBatchRsp(&encoder, &rsp) != 0) {
1,890!
1586
    vError("vgId:%d, failed to encode drop table batch response", TD_VID(pVnode));
×
1587
  }
1588
  tEncoderClear(&encoder);
1,890✔
1589
  taosArrayDestroy(rsp.pArray);
1,890✔
1590
  taosArrayDestroy(tbNames);
1,890✔
1591
  return 0;
1,890✔
1592
}
1593

1594
#ifdef BUILD_NO_CALL
1595
static int32_t vnodeDebugPrintSingleSubmitMsg(SMeta *pMeta, SSubmitBlk *pBlock, SSubmitMsgIter *msgIter,
1596
                                              const char *tags) {
1597
  SSubmitBlkIter blkIter = {0};
1598
  STSchema      *pSchema = NULL;
1599
  tb_uid_t       suid = 0;
1600
  STSRow        *row = NULL;
1601
  int32_t        rv = -1;
1602

1603
  tInitSubmitBlkIter(msgIter, pBlock, &blkIter);
1604
  if (blkIter.row == NULL) return 0;
1605

1606
  int32_t code = metaGetTbTSchemaNotNull(pMeta, msgIter->suid, TD_ROW_SVER(blkIter.row), 1,
1607
                                         &pSchema);  // TODO: use the real schema
1608
  if (TSDB_CODE_SUCCESS != code) {
1609
    printf("%s:%d no valid schema\n", tags, __LINE__);
1610
    return code;
1611
  }
1612

1613
  suid = msgIter->suid;
1614
  rv = TD_ROW_SVER(blkIter.row);
1615

1616
  char __tags[128] = {0};
1617
  snprintf(__tags, 128, "%s: uid %" PRIi64 " ", tags, msgIter->uid);
1618
  while ((row = tGetSubmitBlkNext(&blkIter))) {
1619
    tdSRowPrint(row, pSchema, __tags);
1620
  }
1621

1622
  taosMemoryFreeClear(pSchema);
1623

1624
  return TSDB_CODE_SUCCESS;
1625
}
1626
#endif
1627
typedef struct SSubmitReqConvertCxt {
1628
  SSubmitMsgIter msgIter;
1629
  SSubmitBlk    *pBlock;
1630
  SSubmitBlkIter blkIter;
1631
  STSRow        *pRow;
1632
  STSRowIter     rowIter;
1633
  SSubmitTbData *pTbData;
1634
  STSchema      *pTbSchema;
1635
  SArray        *pColValues;
1636
} SSubmitReqConvertCxt;
1637

1638
static int32_t vnodeResetTableCxt(SMeta *pMeta, SSubmitReqConvertCxt *pCxt) {
×
1639
  taosMemoryFreeClear(pCxt->pTbSchema);
×
1640
  int32_t code = metaGetTbTSchemaNotNull(pMeta, pCxt->msgIter.suid > 0 ? pCxt->msgIter.suid : pCxt->msgIter.uid,
×
1641
                                         pCxt->msgIter.sversion, 1, &pCxt->pTbSchema);
1642
  if (TSDB_CODE_SUCCESS != code) {
×
1643
    return code;
×
1644
  }
1645
  tdSTSRowIterInit(&pCxt->rowIter, pCxt->pTbSchema);
×
1646

1647
  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
×
1648
  if (NULL == pCxt->pTbData) {
×
1649
    pCxt->pTbData = taosMemoryCalloc(1, sizeof(SSubmitTbData));
×
1650
    if (NULL == pCxt->pTbData) {
×
1651
      return terrno;
×
1652
    }
1653
  }
1654
  pCxt->pTbData->flags = 0;
×
1655
  pCxt->pTbData->suid = pCxt->msgIter.suid;
×
1656
  pCxt->pTbData->uid = pCxt->msgIter.uid;
×
1657
  pCxt->pTbData->sver = pCxt->msgIter.sversion;
×
1658
  pCxt->pTbData->pCreateTbReq = NULL;
×
1659
  pCxt->pTbData->aRowP = taosArrayInit(128, POINTER_BYTES);
×
1660
  if (NULL == pCxt->pTbData->aRowP) {
×
1661
    return terrno;
×
1662
  }
1663

1664
  taosArrayDestroy(pCxt->pColValues);
×
1665
  pCxt->pColValues = taosArrayInit(pCxt->pTbSchema->numOfCols, sizeof(SColVal));
×
1666
  if (NULL == pCxt->pColValues) {
×
1667
    return terrno;
×
1668
  }
1669
  for (int32_t i = 0; i < pCxt->pTbSchema->numOfCols; ++i) {
×
1670
    SColVal val = COL_VAL_NONE(pCxt->pTbSchema->columns[i].colId, pCxt->pTbSchema->columns[i].type);
×
1671
    if (taosArrayPush(pCxt->pColValues, &val) == NULL) {
×
1672
      return terrno;
×
1673
    }
1674
  }
1675

1676
  return TSDB_CODE_SUCCESS;
×
1677
}
1678

1679
static void vnodeDestroySubmitReqConvertCxt(SSubmitReqConvertCxt *pCxt) {
×
1680
  taosMemoryFreeClear(pCxt->pTbSchema);
×
1681
  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
×
1682
  taosMemoryFreeClear(pCxt->pTbData);
×
1683
  taosArrayDestroy(pCxt->pColValues);
×
1684
}
×
1685

1686
static int32_t vnodeCellValConvertToColVal(STColumn *pCol, SCellVal *pCellVal, SColVal *pColVal) {
×
1687
  if (tdValTypeIsNone(pCellVal->valType)) {
×
1688
    pColVal->flag = CV_FLAG_NONE;
×
1689
    return TSDB_CODE_SUCCESS;
×
1690
  }
1691

1692
  if (tdValTypeIsNull(pCellVal->valType)) {
×
1693
    pColVal->flag = CV_FLAG_NULL;
×
1694
    return TSDB_CODE_SUCCESS;
×
1695
  }
1696

1697
  if (IS_VAR_DATA_TYPE(pCol->type)) {
×
1698
    pColVal->value.nData = varDataLen(pCellVal->val);
×
1699
    pColVal->value.pData = (uint8_t *)varDataVal(pCellVal->val);
×
1700
  } else if (TSDB_DATA_TYPE_FLOAT == pCol->type) {
×
1701
    float f = GET_FLOAT_VAL(pCellVal->val);
×
1702
    memcpy(&pColVal->value.val, &f, sizeof(f));
×
1703
  } else if (TSDB_DATA_TYPE_DOUBLE == pCol->type) {
×
1704
    pColVal->value.val = *(int64_t *)pCellVal->val;
×
1705
  } else {
1706
    GET_TYPED_DATA(pColVal->value.val, int64_t, pCol->type, pCellVal->val);
×
1707
  }
1708

1709
  pColVal->flag = CV_FLAG_VALUE;
×
1710
  return TSDB_CODE_SUCCESS;
×
1711
}
1712

1713
static int32_t vnodeTSRowConvertToColValArray(SSubmitReqConvertCxt *pCxt) {
×
1714
  int32_t code = TSDB_CODE_SUCCESS;
×
1715
  tdSTSRowIterReset(&pCxt->rowIter, pCxt->pRow);
×
1716
  for (int32_t i = 0; TSDB_CODE_SUCCESS == code && i < pCxt->pTbSchema->numOfCols; ++i) {
×
1717
    STColumn *pCol = pCxt->pTbSchema->columns + i;
×
1718
    SCellVal  cellVal = {0};
×
1719
    if (!tdSTSRowIterFetch(&pCxt->rowIter, pCol->colId, pCol->type, &cellVal)) {
×
1720
      break;
×
1721
    }
1722
    code = vnodeCellValConvertToColVal(pCol, &cellVal, (SColVal *)taosArrayGet(pCxt->pColValues, i));
×
1723
  }
1724
  return code;
×
1725
}
1726

1727
static int32_t vnodeDecodeCreateTbReq(SSubmitReqConvertCxt *pCxt) {
×
1728
  if (pCxt->msgIter.schemaLen <= 0) {
×
1729
    return TSDB_CODE_SUCCESS;
×
1730
  }
1731

1732
  pCxt->pTbData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
×
1733
  if (NULL == pCxt->pTbData->pCreateTbReq) {
×
1734
    return terrno;
×
1735
  }
1736

1737
  SDecoder decoder = {0};
×
1738
  tDecoderInit(&decoder, (uint8_t *)pCxt->pBlock->data, pCxt->msgIter.schemaLen);
×
1739
  int32_t code = tDecodeSVCreateTbReq(&decoder, pCxt->pTbData->pCreateTbReq);
×
1740
  tDecoderClear(&decoder);
×
1741

1742
  return code;
×
1743
}
1744

1745
static int32_t vnodeSubmitReqConvertToSubmitReq2(SVnode *pVnode, SSubmitReq *pReq, SSubmitReq2 *pReq2) {
×
1746
  pReq2->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData));
×
1747
  if (NULL == pReq2->aSubmitTbData) {
×
1748
    return terrno;
×
1749
  }
1750

1751
  SSubmitReqConvertCxt cxt = {0};
×
1752

1753
  int32_t code = tInitSubmitMsgIter(pReq, &cxt.msgIter);
×
1754
  while (TSDB_CODE_SUCCESS == code) {
×
1755
    code = tGetSubmitMsgNext(&cxt.msgIter, &cxt.pBlock);
×
1756
    if (TSDB_CODE_SUCCESS == code) {
×
1757
      if (NULL == cxt.pBlock) {
×
1758
        break;
×
1759
      }
1760
      code = vnodeResetTableCxt(pVnode->pMeta, &cxt);
×
1761
    }
1762
    if (TSDB_CODE_SUCCESS == code) {
×
1763
      code = tInitSubmitBlkIter(&cxt.msgIter, cxt.pBlock, &cxt.blkIter);
×
1764
    }
1765
    if (TSDB_CODE_SUCCESS == code) {
×
1766
      code = vnodeDecodeCreateTbReq(&cxt);
×
1767
    }
1768
    while (TSDB_CODE_SUCCESS == code && (cxt.pRow = tGetSubmitBlkNext(&cxt.blkIter)) != NULL) {
×
1769
      code = vnodeTSRowConvertToColValArray(&cxt);
×
1770
      if (TSDB_CODE_SUCCESS == code) {
×
1771
        SRow **pNewRow = taosArrayReserve(cxt.pTbData->aRowP, 1);
×
1772
        code = tRowBuild(cxt.pColValues, cxt.pTbSchema, pNewRow);
×
1773
      }
1774
    }
1775
    if (TSDB_CODE_SUCCESS == code) {
×
1776
      code = (NULL == taosArrayPush(pReq2->aSubmitTbData, cxt.pTbData) ? terrno : TSDB_CODE_SUCCESS);
×
1777
    }
1778
    if (TSDB_CODE_SUCCESS == code) {
×
1779
      taosMemoryFreeClear(cxt.pTbData);
×
1780
    }
1781
  }
1782

1783
  vnodeDestroySubmitReqConvertCxt(&cxt);
×
1784
  return code;
×
1785
}
1786

1787
static int32_t vnodeRebuildSubmitReqMsg(SSubmitReq2 *pSubmitReq, void **ppMsg) {
×
1788
  int32_t  code = TSDB_CODE_SUCCESS;
×
1789
  char    *pMsg = NULL;
×
1790
  uint32_t msglen = 0;
×
1791
  tEncodeSize(tEncodeSubmitReq, pSubmitReq, msglen, code);
×
1792
  if (TSDB_CODE_SUCCESS == code) {
×
1793
    pMsg = taosMemoryMalloc(msglen);
×
1794
    if (NULL == pMsg) {
×
1795
      code = terrno;
×
1796
    }
1797
  }
1798
  if (TSDB_CODE_SUCCESS == code) {
×
1799
    SEncoder encoder;
1800
    tEncoderInit(&encoder, (uint8_t *)pMsg, msglen);
×
1801
    code = tEncodeSubmitReq(&encoder, pSubmitReq);
×
1802
    tEncoderClear(&encoder);
×
1803
  }
1804
  if (TSDB_CODE_SUCCESS == code) {
×
1805
    *ppMsg = pMsg;
×
1806
  }
1807
  return code;
×
1808
}
1809

1810
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
12,465,434✔
1811
                                     SRpcMsg *pOriginalMsg) {
1812
  int32_t code = 0;
12,465,434✔
1813
  terrno = 0;
12,465,434✔
1814

1815
  SSubmitReq2 *pSubmitReq = &(SSubmitReq2){0};
12,465,552✔
1816
  SSubmitRsp2 *pSubmitRsp = &(SSubmitRsp2){0};
12,465,552✔
1817
  SArray      *newTbUids = NULL;
12,465,552✔
1818
  int32_t      ret;
1819
  SEncoder     ec = {0};
12,465,552✔
1820

1821
  pRsp->code = TSDB_CODE_SUCCESS;
12,465,552✔
1822

1823
  void           *pAllocMsg = NULL;
12,465,552✔
1824
  SSubmitReq2Msg *pMsg = (SSubmitReq2Msg *)pReq;
12,465,552✔
1825
  if (0 == pMsg->version) {
12,465,552!
1826
    code = vnodeSubmitReqConvertToSubmitReq2(pVnode, (SSubmitReq *)pMsg, pSubmitReq);
×
1827
    if (TSDB_CODE_SUCCESS == code) {
×
1828
      code = vnodeRebuildSubmitReqMsg(pSubmitReq, &pReq);
×
1829
    }
1830
    if (TSDB_CODE_SUCCESS == code) {
×
1831
      pAllocMsg = pReq;
×
1832
    }
1833
    if (TSDB_CODE_SUCCESS != code) {
×
1834
      goto _exit;
×
1835
    }
1836
  } else {
1837
    // decode
1838
    pReq = POINTER_SHIFT(pReq, sizeof(SSubmitReq2Msg));
12,465,552✔
1839
    len -= sizeof(SSubmitReq2Msg);
12,465,552✔
1840
    SDecoder dc = {0};
12,465,552✔
1841
    tDecoderInit(&dc, pReq, len);
12,465,552✔
1842
    if (tDecodeSubmitReq(&dc, pSubmitReq) < 0) {
12,465,476!
1843
      code = TSDB_CODE_INVALID_MSG;
×
1844
      goto _exit;
×
1845
    }
1846
    tDecoderClear(&dc);
12,465,420✔
1847
  }
1848

1849
  // scan
1850
  TSKEY now = taosGetTimestamp(pVnode->config.tsdbCfg.precision);
12,465,480✔
1851
  TSKEY minKey = now - tsTickPerMin[pVnode->config.tsdbCfg.precision] * pVnode->config.tsdbCfg.keep2;
12,465,484✔
1852
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
12,465,484✔
1853
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
25,638,234✔
1854
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
13,172,972✔
1855

1856
    if (pSubmitTbData->pCreateTbReq && pSubmitTbData->pCreateTbReq->uid == 0) {
13,172,973!
1857
      code = TSDB_CODE_INVALID_MSG;
×
1858
      goto _exit;
×
1859
    }
1860

1861
    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
13,172,973✔
1862
      if (TARRAY_SIZE(pSubmitTbData->aCol) <= 0) {
132!
1863
        code = TSDB_CODE_INVALID_MSG;
×
1864
        goto _exit;
×
1865
      }
1866

1867
      SColData *colDataArr = TARRAY_DATA(pSubmitTbData->aCol);
132✔
1868
      SRowKey   lastKey;
1869
      tColDataArrGetRowKey(colDataArr, TARRAY_SIZE(pSubmitTbData->aCol), 0, &lastKey);
132✔
1870
      for (int32_t iRow = 1; iRow < colDataArr[0].nVal; iRow++) {
222✔
1871
        SRowKey key;
1872
        tColDataArrGetRowKey(TARRAY_DATA(pSubmitTbData->aCol), TARRAY_SIZE(pSubmitTbData->aCol), iRow, &key);
90✔
1873
        if (tRowKeyCompare(&lastKey, &key) >= 0) {
90!
1874
          code = TSDB_CODE_INVALID_MSG;
×
1875
          vError("vgId:%d %s failed 1 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(terrno), ver);
×
1876
          goto _exit;
×
1877
        }
1878
      }
1879
    } else {
1880
      int32_t nRow = TARRAY_SIZE(pSubmitTbData->aRowP);
13,172,841✔
1881
      SRow  **aRow = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP);
13,172,841✔
1882
      SRowKey lastRowKey;
1883
      for (int32_t iRow = 0; iRow < nRow; ++iRow) {
287,322,152✔
1884
        if (aRow[iRow]->ts < minKey || aRow[iRow]->ts > maxKey) {
274,149,534!
1885
          code = TSDB_CODE_INVALID_MSG;
4,345✔
1886
          vError("vgId:%d %s failed 2 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code), ver);
4,345!
UNCOV
1887
          goto _exit;
×
1888
        }
1889
        if (iRow == 0) {
274,145,189✔
1890
          tRowGetKey(aRow[iRow], &lastRowKey);
13,172,855✔
1891
        } else {
1892
          SRowKey rowKey;
1893
          tRowGetKey(aRow[iRow], &rowKey);
260,972,334✔
1894

1895
          if (tRowKeyCompare(&lastRowKey, &rowKey) >= 0) {
260,971,543!
1896
            code = TSDB_CODE_INVALID_MSG;
×
1897
            vError("vgId:%d %s failed 3 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code), ver);
×
1898
            goto _exit;
×
1899
          }
1900
          lastRowKey = rowKey;
260,971,656✔
1901
        }
1902
      }
1903
    }
1904
  }
1905

1906
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
25,643,219✔
1907
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
13,177,486✔
1908

1909
    if (pSubmitTbData->pCreateTbReq) {
13,177,318✔
1910
      pSubmitTbData->uid = pSubmitTbData->pCreateTbReq->uid;
64,947✔
1911
    } else {
1912
      SMetaInfo info = {0};
13,112,371✔
1913

1914
      code = metaGetInfo(pVnode->pMeta, pSubmitTbData->uid, &info, NULL);
13,112,371✔
1915
      if (code) {
13,112,374!
UNCOV
1916
        code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
×
UNCOV
1917
        vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), pSubmitTbData->uid);
×
1918
        goto _exit;
4✔
1919
      }
1920

1921
      if (info.suid != pSubmitTbData->suid) {
13,112,375!
1922
        code = TSDB_CODE_INVALID_MSG;
×
1923
        goto _exit;
×
1924
      }
1925

1926
      if (info.suid) {
13,112,375✔
1927
        if (metaGetInfo(pVnode->pMeta, info.suid, &info, NULL) != 0) {
12,349,436!
1928
          vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), info.suid);
×
1929
        }
1930
      }
1931

1932
      if (pSubmitTbData->sver != info.skmVer) {
13,113,010!
1933
        code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER;
×
1934
        goto _exit;
×
1935
      }
1936
    }
1937

1938
    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
13,177,957✔
1939
      int32_t   nColData = TARRAY_SIZE(pSubmitTbData->aCol);
132✔
1940
      SColData *aColData = (SColData *)TARRAY_DATA(pSubmitTbData->aCol);
132✔
1941

1942
      if (nColData <= 0) {
132!
1943
        code = TSDB_CODE_INVALID_MSG;
×
1944
        goto _exit;
×
1945
      }
1946

1947
      if (aColData[0].cid != PRIMARYKEY_TIMESTAMP_COL_ID || aColData[0].type != TSDB_DATA_TYPE_TIMESTAMP ||
132!
1948
          aColData[0].nVal <= 0) {
132!
1949
        code = TSDB_CODE_INVALID_MSG;
×
1950
        goto _exit;
×
1951
      }
1952

1953
      for (int32_t j = 1; j < nColData; j++) {
564✔
1954
        if (aColData[j].nVal != aColData[0].nVal) {
432!
1955
          code = TSDB_CODE_INVALID_MSG;
×
1956
          goto _exit;
×
1957
        }
1958
      }
1959
    }
1960
  }
1961

1962
  vDebug("vgId:%d, submit block size %d", TD_VID(pVnode), (int32_t)taosArrayGetSize(pSubmitReq->aSubmitTbData));
12,465,733✔
1963

1964
  // loop to handle
1965
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
25,642,010✔
1966
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
13,175,767✔
1967

1968
    // create table
1969
    if (pSubmitTbData->pCreateTbReq) {
13,175,383✔
1970
      // alloc if need
1971
      if (pSubmitRsp->aCreateTbRsp == NULL &&
64,974✔
1972
          (pSubmitRsp->aCreateTbRsp = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(SVCreateTbRsp))) ==
45,018!
1973
              NULL) {
1974
        code = terrno;
×
1975
        goto _exit;
6✔
1976
      }
1977

1978
      SVCreateTbRsp *pCreateTbRsp = taosArrayReserve(pSubmitRsp->aCreateTbRsp, 1);
64,975✔
1979

1980
      // create table
1981
      if (metaCreateTable2(pVnode->pMeta, ver, pSubmitTbData->pCreateTbReq, &pCreateTbRsp->pMeta) == 0) {
64,976✔
1982
        // create table success
1983

1984
        if (newTbUids == NULL &&
65,342!
1985
            (newTbUids = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(int64_t))) == NULL) {
25,603✔
1986
          code = terrno;
×
1987
          goto _exit;
×
1988
        }
1989

1990
        if (taosArrayPush(newTbUids, &pSubmitTbData->uid) == NULL) {
79,478!
1991
          code = terrno;
×
1992
          goto _exit;
×
1993
        }
1994

1995
        if (pCreateTbRsp->pMeta) {
39,739!
1996
          vnodeUpdateMetaRsp(pVnode, pCreateTbRsp->pMeta);
39,739✔
1997
        }
1998
      } else {  // create table failed
1999
        if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
25,241✔
2000
          code = terrno;
6✔
2001
          vError("vgId:%d failed to create table:%s, code:%s", TD_VID(pVnode), pSubmitTbData->pCreateTbReq->name,
6!
2002
                 tstrerror(terrno));
2003
          goto _exit;
6✔
2004
        }
2005
        terrno = 0;
25,235✔
2006
        pSubmitTbData->uid = pSubmitTbData->pCreateTbReq->uid;  // update uid if table exist for using below
25,235✔
2007
      }
2008
    }
2009

2010
    // insert data
2011
    int32_t affectedRows;
2012
    code = tsdbInsertTableData(pVnode->pTsdb, ver, pSubmitTbData, &affectedRows);
13,175,383✔
2013
    if (code) goto _exit;
13,177,122!
2014

2015
    code = metaUpdateChangeTimeWithLock(pVnode->pMeta, pSubmitTbData->uid, pSubmitTbData->ctimeMs);
13,177,122✔
2016
    if (code) goto _exit;
13,176,482!
2017

2018
    pSubmitRsp->affectedRows += affectedRows;
13,176,482✔
2019
  }
2020

2021
  // update the affected table uid list
2022
  if (taosArrayGetSize(newTbUids) > 0) {
12,466,243✔
2023
    vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
25,603✔
2024
           (int32_t)taosArrayGetSize(newTbUids));
2025
    if (tqUpdateTbUidList(pVnode->pTq, newTbUids, true) != 0) {
25,603!
2026
      vError("vgId:%d, failed to update tbUid list", TD_VID(pVnode));
×
2027
    }
2028
  }
2029

2030
_exit:
12,465,518✔
2031
  // message
2032
  pRsp->code = code;
12,465,528✔
2033
  tEncodeSize(tEncodeSSubmitRsp2, pSubmitRsp, pRsp->contLen, ret);
12,465,528!
2034
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
12,465,468✔
2035
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
12,465,461✔
2036
  if (tEncodeSSubmitRsp2(&ec, pSubmitRsp) < 0) {
12,465,498!
2037
    vError("vgId:%d, failed to encode submit response", TD_VID(pVnode));
×
2038
  }
2039
  tEncoderClear(&ec);
12,465,511✔
2040

2041
  // update statistics
2042
  (void)atomic_add_fetch_64(&pVnode->statis.nInsert, pSubmitRsp->affectedRows);
12,465,523✔
2043
  (void)atomic_add_fetch_64(&pVnode->statis.nInsertSuccess, pSubmitRsp->affectedRows);
12,465,543✔
2044
  (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsert, 1);
12,465,537✔
2045

2046
  if (tsEnableMonitor && tsMonitorFqdn[0] != 0 && tsMonitorPort != 0 && pSubmitRsp->affectedRows > 0 &&
12,465,508!
2047
      strlen(pOriginalMsg->info.conn.user) > 0 && tsInsertCounter != NULL) {
×
2048
    const char *sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT_AFFECTED_ROWS,
×
2049
                                   pVnode->monitor.strClusterId,
×
2050
                                   pVnode->monitor.strDnodeId,
×
2051
                                   tsLocalEp,
2052
                                   pVnode->monitor.strVgId,
×
2053
                                   pOriginalMsg->info.conn.user,
×
2054
                                   "Success"};
2055
    int         tv = taos_counter_add(tsInsertCounter, pSubmitRsp->affectedRows, sample_labels);
×
2056
  }
2057

2058
  if (code == 0) {
12,465,508✔
2059
    (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
12,465,473✔
2060
    code = tdProcessRSmaSubmit(pVnode->pSma, ver, pSubmitReq, pReq, len);
12,465,499✔
2061
  }
2062
  /*
2063
  if (code == 0) {
2064
    atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
2065
    code = tdProcessRSmaSubmit(pVnode->pSma, ver, pSubmitReq, pReq, len);
2066

2067
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT, pVnode->monitor.strClusterId,
2068
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2069
                                          pOriginalMsg->info.conn.user, "Success"};
2070
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2071
  }
2072
  else{
2073
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT, pVnode->monitor.strClusterId,
2074
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2075
                                        pOriginalMsg->info.conn.user, "Failed"};
2076
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2077
  }
2078
  */
2079

2080
  // clear
2081
  taosArrayDestroy(newTbUids);
12,465,495✔
2082
  tDestroySubmitReq(pSubmitReq, 0 == pMsg->version ? TSDB_MSG_FLG_CMPT : TSDB_MSG_FLG_DECODE);
12,465,407!
2083
  tDestroySSubmitRsp2(pSubmitRsp, TSDB_MSG_FLG_ENCODE);
12,465,528✔
2084

2085
  if (code) terrno = code;
12,465,437✔
2086

2087
  taosMemoryFree(pAllocMsg);
12,465,437!
2088

2089
  return code;
12,465,495✔
2090
}
2091

2092
static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
27✔
2093
  SVCreateTSmaReq req = {0};
27✔
2094
  SDecoder        coder = {0};
27✔
2095

2096
  if (pRsp) {
27!
2097
    pRsp->msgType = TDMT_VND_CREATE_SMA_RSP;
27✔
2098
    pRsp->code = TSDB_CODE_SUCCESS;
27✔
2099
    pRsp->pCont = NULL;
27✔
2100
    pRsp->contLen = 0;
27✔
2101
  }
2102

2103
  // decode and process req
2104
  tDecoderInit(&coder, pReq, len);
27✔
2105

2106
  if (tDecodeSVCreateTSmaReq(&coder, &req) < 0) {
27!
2107
    terrno = TSDB_CODE_MSG_DECODE_ERROR;
×
2108
    if (pRsp) pRsp->code = terrno;
×
2109
    goto _err;
×
2110
  }
2111

2112
  if (tdProcessTSmaCreate(pVnode->pSma, ver, (const char *)&req) < 0) {
27!
2113
    if (pRsp) pRsp->code = terrno;
×
2114
    goto _err;
×
2115
  }
2116

2117
  tDecoderClear(&coder);
27✔
2118
  vDebug("vgId:%d, success to create tsma %s:%" PRIi64 " version %" PRIi64 " for table %" PRIi64, TD_VID(pVnode),
27!
2119
         req.indexName, req.indexUid, ver, req.tableUid);
2120
  return 0;
27✔
2121

2122
_err:
×
2123
  tDecoderClear(&coder);
×
2124
  vError("vgId:%d, failed to create tsma %s:%" PRIi64 " version %" PRIi64 "for table %" PRIi64 " since %s",
×
2125
         TD_VID(pVnode), req.indexName, req.indexUid, ver, req.tableUid, terrstr());
2126
  return terrno;
×
2127
}
2128

2129
/**
2130
 * @brief specific for smaDstVnode
2131
 *
2132
 * @param pVnode
2133
 * @param pCont
2134
 * @param contLen
2135
 * @return int32_t
2136
 */
2137
int32_t vnodeProcessCreateTSma(SVnode *pVnode, void *pCont, uint32_t contLen) {
×
2138
  return vnodeProcessCreateTSmaReq(pVnode, 1, pCont, contLen, NULL);
×
2139
}
2140

2141
static int32_t vnodeConsolidateAlterHashRange(SVnode *pVnode, int64_t ver) {
38✔
2142
  int32_t code = TSDB_CODE_SUCCESS;
38✔
2143

2144
  vInfo("vgId:%d, trim meta of tables per hash range [%" PRIu32 ", %" PRIu32 "]. apply-index:%" PRId64, TD_VID(pVnode),
38!
2145
        pVnode->config.hashBegin, pVnode->config.hashEnd, ver);
2146

2147
  // TODO: trim meta of tables from TDB per hash range [pVnode->config.hashBegin, pVnode->config.hashEnd]
2148
  code = metaTrimTables(pVnode->pMeta);
38✔
2149

2150
  return code;
38✔
2151
}
2152

2153
static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
7,895✔
2154
  vInfo("vgId:%d, vnode handle msgType:alter-confirm, alter confirm msg is processed", TD_VID(pVnode));
7,895!
2155
  int32_t code = TSDB_CODE_SUCCESS;
7,895✔
2156
  if (!pVnode->config.hashChange) {
7,895✔
2157
    goto _exit;
7,857✔
2158
  }
2159

2160
  code = vnodeConsolidateAlterHashRange(pVnode, ver);
38✔
2161
  if (code < 0) {
38!
2162
    vError("vgId:%d, failed to consolidate alter hashrange since %s. version:%" PRId64, TD_VID(pVnode), terrstr(), ver);
×
2163
    goto _exit;
×
2164
  }
2165
  pVnode->config.hashChange = false;
38✔
2166

2167
_exit:
7,895✔
2168
  pRsp->msgType = TDMT_VND_ALTER_CONFIRM_RSP;
7,895✔
2169
  pRsp->code = code;
7,895✔
2170
  pRsp->pCont = NULL;
7,895✔
2171
  pRsp->contLen = 0;
7,895✔
2172

2173
  return code;
7,895✔
2174
}
2175

2176
extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb);
2177
extern void    tsdbEnableBgTask(STsdb *pTsdb);
2178

2179
static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
360✔
2180
  bool walChanged = false;
360✔
2181
  bool tsdbChanged = false;
360✔
2182

2183
  SAlterVnodeConfigReq req = {0};
360✔
2184
  if (tDeserializeSAlterVnodeConfigReq(pReq, len, &req) != 0) {
360!
2185
    terrno = TSDB_CODE_INVALID_MSG;
×
2186
    return TSDB_CODE_INVALID_MSG;
×
2187
  }
2188

2189
  vInfo("vgId:%d, start to alter vnode config, page:%d pageSize:%d buffer:%d szPage:%d szBuf:%" PRIu64
360!
2190
        " cacheLast:%d cacheLastSize:%d days:%d keep0:%d keep1:%d keep2:%d keepTimeOffset:%d s3KeepLocal:%d "
2191
        "s3Compact:%d fsync:%d level:%d "
2192
        "walRetentionPeriod:%d walRetentionSize:%d",
2193
        TD_VID(pVnode), req.pages, req.pageSize, req.buffer, req.pageSize * 1024, (uint64_t)req.buffer * 1024 * 1024,
2194
        req.cacheLast, req.cacheLastSize, req.daysPerFile, req.daysToKeep0, req.daysToKeep1, req.daysToKeep2,
2195
        req.keepTimeOffset, req.s3KeepLocal, req.s3Compact, req.walFsyncPeriod, req.walLevel, req.walRetentionPeriod,
2196
        req.walRetentionSize);
2197

2198
  if (pVnode->config.cacheLastSize != req.cacheLastSize) {
362✔
2199
    pVnode->config.cacheLastSize = req.cacheLastSize;
2✔
2200
    tsdbCacheSetCapacity(pVnode, (size_t)pVnode->config.cacheLastSize * 1024 * 1024);
2✔
2201
  }
2202

2203
  if (pVnode->config.szBuf != req.buffer * 1024LL * 1024LL) {
362!
2204
    vInfo("vgId:%d, vnode buffer is changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pVnode->config.szBuf,
×
2205
          (uint64_t)(req.buffer * 1024LL * 1024LL));
2206
    pVnode->config.szBuf = req.buffer * 1024LL * 1024LL;
×
2207
  }
2208

2209
  if (pVnode->config.szCache != req.pages) {
362!
2210
    if (metaAlterCache(pVnode->pMeta, req.pages) < 0) {
×
2211
      vError("vgId:%d, failed to change vnode pages from %d to %d failed since %s", TD_VID(pVnode),
×
2212
             pVnode->config.szCache, req.pages, tstrerror(errno));
2213
      return errno;
×
2214
    } else {
2215
      vInfo("vgId:%d, vnode pages is changed from %d to %d", TD_VID(pVnode), pVnode->config.szCache, req.pages);
×
2216
      pVnode->config.szCache = req.pages;
×
2217
    }
2218
  }
2219

2220
  if (pVnode->config.cacheLast != req.cacheLast) {
362✔
2221
    pVnode->config.cacheLast = req.cacheLast;
95✔
2222
  }
2223

2224
  if (pVnode->config.walCfg.fsyncPeriod != req.walFsyncPeriod) {
362✔
2225
    pVnode->config.walCfg.fsyncPeriod = req.walFsyncPeriod;
54✔
2226
    walChanged = true;
54✔
2227
  }
2228

2229
  if (pVnode->config.walCfg.level != req.walLevel) {
362✔
2230
    if (pVnode->config.walCfg.level == 0) {
36!
2231
      pVnode->config.walCfg.clearFiles = 1;
×
2232
    }
2233
    pVnode->config.walCfg.level = req.walLevel;
36✔
2234
    walChanged = true;
36✔
2235
  }
2236

2237
  if (pVnode->config.walCfg.retentionPeriod != req.walRetentionPeriod) {
362✔
2238
    pVnode->config.walCfg.retentionPeriod = req.walRetentionPeriod;
129✔
2239
    walChanged = true;
129✔
2240
  }
2241

2242
  if (pVnode->config.walCfg.retentionSize != req.walRetentionSize) {
362!
2243
    pVnode->config.walCfg.retentionSize = req.walRetentionSize;
×
2244
    walChanged = true;
×
2245
  }
2246

2247
  if (pVnode->config.tsdbCfg.keep0 != req.daysToKeep0) {
362✔
2248
    pVnode->config.tsdbCfg.keep0 = req.daysToKeep0;
42✔
2249
    if (!VND_IS_RSMA(pVnode)) {
42!
2250
      tsdbChanged = true;
42✔
2251
    }
2252
  }
2253

2254
  if (pVnode->config.tsdbCfg.keep1 != req.daysToKeep1) {
362✔
2255
    pVnode->config.tsdbCfg.keep1 = req.daysToKeep1;
42✔
2256
    if (!VND_IS_RSMA(pVnode)) {
42!
2257
      tsdbChanged = true;
42✔
2258
    }
2259
  }
2260

2261
  if (pVnode->config.tsdbCfg.keep2 != req.daysToKeep2) {
362✔
2262
    pVnode->config.tsdbCfg.keep2 = req.daysToKeep2;
44✔
2263
    if (!VND_IS_RSMA(pVnode)) {
44!
2264
      tsdbChanged = true;
44✔
2265
    }
2266
  }
2267

2268
  if (pVnode->config.tsdbCfg.keepTimeOffset != req.keepTimeOffset) {
362✔
2269
    pVnode->config.tsdbCfg.keepTimeOffset = req.keepTimeOffset;
2✔
2270
    if (!VND_IS_RSMA(pVnode)) {
2!
2271
      tsdbChanged = true;
2✔
2272
    }
2273
  }
2274

2275
  if (req.sttTrigger != -1 && req.sttTrigger != pVnode->config.sttTrigger) {
362!
2276
    if (req.sttTrigger > 1 && pVnode->config.sttTrigger > 1) {
×
2277
      pVnode->config.sttTrigger = req.sttTrigger;
×
2278
    } else {
2279
      vnodeAWait(&pVnode->commitTask);
×
2280

2281
      int32_t ret = tsdbDisableAndCancelAllBgTask(pVnode->pTsdb);
×
2282
      if (ret != 0) {
×
2283
        vError("vgId:%d, failed to disable bg task since %s", TD_VID(pVnode), tstrerror(errno));
×
2284
      }
2285

2286
      pVnode->config.sttTrigger = req.sttTrigger;
×
2287
      tsdbEnableBgTask(pVnode->pTsdb);
×
2288
    }
2289
  }
2290

2291
  if (req.minRows != -1 && req.minRows != pVnode->config.tsdbCfg.minRows) {
362!
2292
    pVnode->config.tsdbCfg.minRows = req.minRows;
×
2293
  }
2294

2295
  if (req.s3KeepLocal != -1 && req.s3KeepLocal != pVnode->config.s3KeepLocal) {
362!
2296
    pVnode->config.s3KeepLocal = req.s3KeepLocal;
×
2297
  }
2298
  if (req.s3Compact != -1 && req.s3Compact != pVnode->config.s3Compact) {
362!
2299
    pVnode->config.s3Compact = req.s3Compact;
×
2300
  }
2301

2302
  if (walChanged) {
362✔
2303
    if (walAlter(pVnode->pWal, &pVnode->config.walCfg) != 0) {
219!
2304
      vError("vgId:%d, failed to alter wal config since %s", TD_VID(pVnode), tstrerror(errno));
×
2305
    }
2306
  }
2307

2308
  if (tsdbChanged) {
362✔
2309
    tsdbSetKeepCfg(pVnode->pTsdb, &pVnode->config.tsdbCfg);
46✔
2310
  }
2311

2312
  return 0;
362✔
2313
}
2314

2315
static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
2,896✔
2316
  SBatchDeleteReq deleteReq;
2317
  SDecoder        decoder;
2318
  tDecoderInit(&decoder, pReq, len);
2,896✔
2319
  if (tDecodeSBatchDeleteReq(&decoder, &deleteReq) < 0) {
2,896!
2320
    tDecoderClear(&decoder);
×
2321
    return terrno = TSDB_CODE_INVALID_MSG;
×
2322
  }
2323

2324
  SMetaReader mr = {0};
2,904✔
2325
  metaReaderDoInit(&mr, pVnode->pMeta, META_READER_NOLOCK);
2,904✔
2326
  STsdb *pTsdb = pVnode->pTsdb;
2,902✔
2327

2328
  if (deleteReq.level) {
2,902✔
2329
    pTsdb = deleteReq.level == 1 ? VND_RSMA1(pVnode) : VND_RSMA2(pVnode);
16✔
2330
  }
2331

2332
  int32_t sz = taosArrayGetSize(deleteReq.deleteReqs);
2,902✔
2333
  for (int32_t i = 0; i < sz; i++) {
6,595✔
2334
    SSingleDeleteReq *pOneReq = taosArrayGet(deleteReq.deleteReqs, i);
3,690✔
2335
    char             *name = pOneReq->tbname;
3,690✔
2336
    if (metaGetTableEntryByName(&mr, name) < 0) {
3,690✔
2337
      vDebug("vgId:%d, stream delete msg, skip since no table: %s", pVnode->config.vgId, name);
1,862✔
2338
      continue;
1,862✔
2339
    }
2340

2341
    int64_t uid = mr.me.uid;
1,831✔
2342

2343
    int32_t code = tsdbDeleteTableData(pTsdb, ver, deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
1,831✔
2344
    if (code < 0) {
1,835!
2345
      terrno = code;
×
2346
      vError("vgId:%d, delete error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64 ", end ts:%" PRId64,
×
2347
             TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
2348
    }
2349

2350
    if (deleteReq.level == 0) {
1,835✔
2351
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, deleteReq.ctimeMs);
1,219✔
2352
      if (code < 0) {
1,219!
2353
        terrno = code;
×
2354
        vError("vgId:%d, update change time error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64
×
2355
               ", end ts:%" PRId64,
2356
               TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
2357
      }
2358
    }
2359
    tDecoderClear(&mr.coder);
1,835✔
2360
  }
2361
  metaReaderClear(&mr);
2,905✔
2362
  taosArrayDestroy(deleteReq.deleteReqs);
2,904✔
2363
  return 0;
2,904✔
2364
}
2365

2366
static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
13,924✔
2367
                                     SRpcMsg *pOriginalMsg) {
2368
  int32_t     code = 0;
13,924✔
2369
  SDecoder   *pCoder = &(SDecoder){0};
13,924✔
2370
  SDeleteRes *pRes = &(SDeleteRes){0};
13,924✔
2371

2372
  pRsp->msgType = TDMT_VND_DELETE_RSP;
13,924✔
2373
  pRsp->pCont = NULL;
13,924✔
2374
  pRsp->contLen = 0;
13,924✔
2375
  pRsp->code = TSDB_CODE_SUCCESS;
13,924✔
2376

2377
  pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t));
13,924✔
2378
  if (pRes->uidList == NULL) {
13,924!
2379
    code = terrno;
×
2380
    goto _err;
×
2381
  }
2382

2383
  tDecoderInit(pCoder, pReq, len);
13,924✔
2384
  code = tDecodeDeleteRes(pCoder, pRes);
13,924✔
2385
  if (code) goto _err;
13,925!
2386

2387
  if (pRes->affectedRows > 0) {
13,925✔
2388
    for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) {
24,910✔
2389
      uint64_t uid = *(uint64_t *)taosArrayGet(pRes->uidList, iUid);
12,866✔
2390
      code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, uid, pRes->skey, pRes->ekey);
12,866✔
2391
      if (code) goto _err;
12,867!
2392
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, pRes->ctimeMs);
12,867✔
2393
      if (code) goto _err;
12,867!
2394
    }
2395
  }
2396

2397
  code = tdProcessRSmaDelete(pVnode->pSma, ver, pRes, pReq, len);
13,925✔
2398

2399
  tDecoderClear(pCoder);
13,925✔
2400
  taosArrayDestroy(pRes->uidList);
13,925✔
2401

2402
  SVDeleteRsp rsp = {.affectedRows = pRes->affectedRows};
13,925✔
2403
  int32_t     ret = 0;
13,925✔
2404
  tEncodeSize(tEncodeSVDeleteRsp, &rsp, pRsp->contLen, ret);
13,925!
2405
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
13,925✔
2406
  SEncoder ec = {0};
13,925✔
2407
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
13,925✔
2408
  code = tEncodeSVDeleteRsp(&ec, &rsp);
13,925✔
2409
  if (code) goto _err;
13,925!
2410
  tEncoderClear(&ec);
13,925✔
2411
  return code;
13,925✔
2412

2413
_err:
×
2414
  /*
2415
  if(code == TSDB_CODE_SUCCESS){
2416
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_DELETE, pVnode->monitor.strClusterId,
2417
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2418
                                        pOriginalMsg->info.conn.user, "Success"};
2419
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2420
  }
2421
  else{
2422
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_DELETE, pVnode->monitor.strClusterId,
2423
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2424
                                        pOriginalMsg->info.conn.user, "Failed"};
2425
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2426
  }
2427
  */
2428

2429
  return code;
×
2430
}
2431
static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
21✔
2432
  SVCreateStbReq req = {0};
21✔
2433
  SDecoder       dc = {0};
21✔
2434
  int32_t        code = 0;
21✔
2435

2436
  pRsp->msgType = TDMT_VND_CREATE_INDEX_RSP;
21✔
2437
  pRsp->code = TSDB_CODE_SUCCESS;
21✔
2438
  pRsp->pCont = NULL;
21✔
2439
  pRsp->contLen = 0;
21✔
2440

2441
  tDecoderInit(&dc, pReq, len);
21✔
2442
  // decode req
2443
  if (tDecodeSVCreateStbReq(&dc, &req) < 0) {
21!
2444
    tDecoderClear(&dc);
×
2445
    return terrno = TSDB_CODE_INVALID_MSG;
×
2446
  }
2447

2448
  code = metaAddIndexToSuperTable(pVnode->pMeta, ver, &req);
21✔
2449
  if (code) {
21!
2450
    pRsp->code = code;
×
2451
    goto _err;
×
2452
  }
2453
  tDecoderClear(&dc);
21✔
2454
  return 0;
21✔
2455

2456
_err:
×
2457
  tDecoderClear(&dc);
×
2458
  return code;
×
2459
}
2460
static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
8✔
2461
  SDropIndexReq req = {0};
8✔
2462
  int32_t       code = 0;
8✔
2463
  pRsp->msgType = TDMT_VND_DROP_INDEX_RSP;
8✔
2464
  pRsp->code = TSDB_CODE_SUCCESS;
8✔
2465
  pRsp->pCont = NULL;
8✔
2466
  pRsp->contLen = 0;
8✔
2467

2468
  if ((code = tDeserializeSDropIdxReq(pReq, len, &req))) {
8!
2469
    pRsp->code = code;
×
2470
    return code;
×
2471
  }
2472

2473
  code = metaDropIndexFromSuperTable(pVnode->pMeta, ver, &req);
8✔
2474
  if (code) {
8!
2475
    pRsp->code = code;
×
2476
    return code;
×
2477
  }
2478
  return TSDB_CODE_SUCCESS;
8✔
2479
}
2480

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

2483
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
5✔
2484
  if (!pVnode->restored) {
5✔
2485
    vInfo("vgId:%d, ignore compact req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
1!
2486
    return 0;
1✔
2487
  }
2488
  return vnodeAsyncCompact(pVnode, ver, pReq, len, pRsp);
4✔
2489
}
2490

2491
static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
2492
  if (syncCheckMember(pVnode->sync) != 0) {
×
2493
    vError("vgId:%d, failed to check member", TD_VID(pVnode));
×
2494
  }
2495

2496
  pRsp->msgType = TDMT_SYNC_CONFIG_CHANGE_RSP;
×
2497
  pRsp->code = TSDB_CODE_SUCCESS;
×
2498
  pRsp->pCont = NULL;
×
2499
  pRsp->contLen = 0;
×
2500

2501
  return 0;
×
2502
}
2503

2504
static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
2✔
2505
  SSyncState syncState = syncGetState(pVnode->sync);
2✔
2506
  if (syncState.state != TAOS_SYNC_STATE_LEADER) {
2!
2507
    return terrno = TSDB_CODE_SYN_NOT_LEADER;
×
2508
  }
2509

2510
  char token[TSDB_ARB_TOKEN_SIZE] = {0};
2✔
2511
  if (vnodeGetArbToken(pVnode, token) != 0) {
2!
2512
    return terrno = TSDB_CODE_NOT_FOUND;
×
2513
  }
2514

2515
  if (strncmp(token, member0Token, TSDB_ARB_TOKEN_SIZE) != 0 &&
2!
2516
      strncmp(token, member1Token, TSDB_ARB_TOKEN_SIZE) != 0) {
2!
2517
    return terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
2✔
2518
  }
2519

2520
  terrno = TSDB_CODE_SUCCESS;
×
2521
  return 0;
×
2522
}
2523

2524
static int32_t vnodeCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
×
2525
  int32_t code = vnodePreCheckAssignedLogSyncd(pVnode, member0Token, member1Token);
×
2526
  if (code != 0) {
×
2527
    return code;
×
2528
  }
2529

2530
  return syncGetAssignedLogSynced(pVnode->sync);
×
2531
}
2532

2533
static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
2534
  int32_t code = 0;
×
2535

2536
  SVArbCheckSyncReq syncReq = {0};
×
2537

2538
  code = tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq);
×
2539
  if (code) {
×
2540
    return terrno = code;
×
2541
  }
2542

2543
  pRsp->msgType = TDMT_VND_ARB_CHECK_SYNC_RSP;
×
2544
  pRsp->code = TSDB_CODE_SUCCESS;
×
2545
  pRsp->pCont = NULL;
×
2546
  pRsp->contLen = 0;
×
2547

2548
  SVArbCheckSyncRsp syncRsp = {0};
×
2549
  syncRsp.arbToken = syncReq.arbToken;
×
2550
  syncRsp.member0Token = syncReq.member0Token;
×
2551
  syncRsp.member1Token = syncReq.member1Token;
×
2552
  syncRsp.vgId = TD_VID(pVnode);
×
2553

2554
  if (vnodeCheckAssignedLogSyncd(pVnode, syncReq.member0Token, syncReq.member1Token) != 0) {
×
2555
    vError("vgId:%d, failed to check assigned log syncd", TD_VID(pVnode));
×
2556
  }
2557
  syncRsp.errCode = terrno;
×
2558

2559
  if (vnodeUpdateArbTerm(pVnode, syncReq.arbTerm) != 0) {
×
2560
    vError("vgId:%d, failed to update arb term", TD_VID(pVnode));
×
2561
    code = -1;
×
2562
    goto _OVER;
×
2563
  }
2564

2565
  int32_t contLen = tSerializeSVArbCheckSyncRsp(NULL, 0, &syncRsp);
×
2566
  if (contLen <= 0) {
×
2567
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2568
    code = -1;
×
2569
    goto _OVER;
×
2570
  }
2571
  void *pHead = rpcMallocCont(contLen);
×
2572
  if (!pHead) {
×
2573
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2574
    code = -1;
×
2575
    goto _OVER;
×
2576
  }
2577

2578
  if (tSerializeSVArbCheckSyncRsp(pHead, contLen, &syncRsp) <= 0) {
×
2579
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2580
    rpcFreeCont(pHead);
×
2581
    code = -1;
×
2582
    goto _OVER;
×
2583
  }
2584

2585
  pRsp->pCont = pHead;
×
2586
  pRsp->contLen = contLen;
×
2587

2588
  terrno = TSDB_CODE_SUCCESS;
×
2589

2590
_OVER:
×
2591
  tFreeSVArbCheckSyncReq(&syncReq);
×
2592
  return code;
×
2593
}
2594

2595
#ifndef TD_ENTERPRISE
2596
int32_t vnodeAsyncCompact(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) { return 0; }
2597
int32_t tsdbAsyncCompact(STsdb *tsdb, const STimeWindow *tw, bool sync) { return 0; }
2598
#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