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

taosdata / TDengine / #3570

30 Dec 2024 10:10AM UTC coverage: 62.94% (-0.02%) from 62.96%
#3570

push

travis-ci

web-flow
Merge pull request #29414 from taosdata/fix/keeper/3.0/gitinfo

[TD-33393] fix(keeper): add gitinfo

139195 of 284325 branches covered (48.96%)

Branch coverage included in aggregate %.

216954 of 281527 relevant lines covered (77.06%)

19045397.76 hits per line

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

60.46
/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) {
152,868✔
64
  int32_t code = 0;
152,868✔
65
  int32_t lino = 0;
152,868✔
66

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

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

78
  // name
79
  char *name = NULL;
152,896✔
80
  if (tDecodeCStr(pCoder, &name) < 0) {
152,873!
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);
152,873✔
87
  if (uid == 0) {
152,888✔
88
    uid = tGenIdPI64();
126,389✔
89
  }
90
  *(int64_t *)(pCoder->data + pCoder->pos) = uid;
152,868✔
91

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

95
  tEndDecode(pCoder);
152,868✔
96

97
_exit:
152,849✔
98
  if (code) {
152,849!
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);
152,849✔
102
    if (pUid) *pUid = uid;
152,849✔
103
  }
104
  return code;
152,840✔
105
}
106
static int32_t vnodePreProcessCreateTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
66,407✔
107
  int32_t code = 0;
66,407✔
108
  int32_t lino = 0;
66,407✔
109

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

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

120
  if (tDecodeI32v(&dc, &nReqs) < 0) {
66,422!
121
    code = TSDB_CODE_INVALID_MSG;
×
122
    TSDB_CHECK_CODE(code, lino, _exit);
×
123
  }
124
  for (int32_t iReq = 0; iReq < nReqs; iReq++) {
157,392✔
125
    code = vnodePreprocessCreateTableReq(pVnode, &dc, btime, NULL);
90,992✔
126
    TSDB_CHECK_CODE(code, lino, _exit);
90,970!
127
  }
128

129
  tEndDecode(&dc);
66,400✔
130

131
_exit:
66,415✔
132
  tDecoderClear(&dc);
66,415✔
133
  if (code) {
66,422!
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;
66,420✔
138
}
139

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

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

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

157
  code = 0;
936✔
158

159
_exit:
936✔
160
  tDecoderClear(&dc);
936✔
161
  if (code) {
936!
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,
936✔
165
           ctimeMs);
166
  }
167
  return code;
936✔
168
}
169

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

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

177
  SArray *tbUids = NULL;
95,366✔
178
  int64_t timestampMs = 0;
95,366✔
179

180
  SVDropTtlTableReq ttlReq = {0};
95,366✔
181
  if (tDeserializeSVDropTtlTableReq((char *)pContOld + sizeof(SMsgHead), reqLenOld, &ttlReq) != 0) {
95,366!
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));
95,707✔
188
    if (tbUids == NULL) {
95,751!
189
      code = terrno;
×
190
      TSDB_CHECK_CODE(code, lino, _exit);
×
191
    }
192

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

200
    ttlReq.nUids = taosArrayGetSize(tbUids);
95,526✔
201
    ttlReq.pTbUids = tbUids;
95,437✔
202
  }
203

204
  if (ttlReq.nUids == 0) {
95,437!
205
    code = TSDB_CODE_MSG_PREPROCESSED;
95,480✔
206
    TSDB_CHECK_CODE(code, lino, _exit);
95,480!
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:
95,515✔
233
  taosArrayDestroy(tbUids);
95,515✔
234

235
  if (code && code != TSDB_CODE_MSG_PREPROCESSED) {
95,514!
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);
95,514✔
240
  }
241

242
  return code;
95,541✔
243
}
244

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

250
  if (tStartDecode(pCoder) < 0) {
10,721,072!
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,734,872!
258
    code = TSDB_CODE_INVALID_MSG;
×
259
    TSDB_CHECK_CODE(code, lino, _exit);
×
260
  }
261
  version = (submitTbData.flags >> 8) & 0xff;
10,734,872✔
262
  submitTbData.flags = submitTbData.flags & 0xff;
10,734,872✔
263

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

270
  // submit data
271
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
10,724,398!
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,724,398✔
277
    *(int64_t *)(pCoder->data + pCoder->pos) = uid;
61,877✔
278
    pCoder->pos += sizeof(int64_t);
61,877✔
279
  } else {
280
    if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
10,656,477!
281
      code = TSDB_CODE_INVALID_MSG;
×
282
      TSDB_CHECK_CODE(code, lino, _exit);
×
283
    }
284
  }
285

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

291
  // scan and check
292
  TSKEY now = btimeMs;
10,712,795✔
293
  if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_MICRO) {
10,712,795✔
294
    now *= 1000;
22,369✔
295
  } else if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_NANO) {
10,690,426✔
296
    now *= 1000000;
3,557✔
297
  }
298

299
  int32_t keep = pVnode->config.tsdbCfg.keep2;
10,712,795✔
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,712,795✔
312
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
10,712,795✔
313
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,712,795✔
314
    uint64_t nColData;
315
    if (tDecodeU64v(pCoder, &nColData) < 0) {
135!
316
      code = TSDB_CODE_INVALID_MSG;
×
317
      goto _exit;
1✔
318
    }
319

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

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

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

344
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
753,951,509✔
345
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
743,233,624✔
346
      pCoder->pos += pRow->len;
743,233,624✔
347

348
      if (pRow->ts < minKey || pRow->ts > maxKey) {
743,233,624!
349
        code = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
1,698✔
350
        goto _exit;
1,698✔
351
      }
352
    }
353
  }
354

355
  if (!tDecodeIsEnd(pCoder)) {
10,718,019!
356
    *(int64_t *)(pCoder->data + pCoder->pos) = ctimeMs;
10,722,269✔
357
    pCoder->pos += sizeof(int64_t);
10,722,269✔
358
  }
359

360
  tEndDecode(pCoder);
10,718,019✔
361

362
_exit:
10,720,752✔
363
  return code;
10,720,752✔
364
}
365
static int32_t vnodePreProcessSubmitMsg(SVnode *pVnode, SRpcMsg *pMsg) {
10,043,175✔
366
  int32_t code = 0;
10,043,175✔
367
  int32_t lino = 0;
10,043,175✔
368

369
  if (tsBypassFlag & TSDB_BYPASS_RA_RPC_RECV_SUBMIT) {
10,043,175!
370
    return TSDB_CODE_MSG_PREPROCESSED;
×
371
  }
372

373
  SDecoder *pCoder = &(SDecoder){0};
10,043,175✔
374

375
  if (taosHton64(((SSubmitReq2Msg *)pMsg->pCont)->version) != 1) {
10,043,175!
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));
10,043,269✔
381

382
  if (tStartDecode(pCoder) < 0) {
10,043,156!
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) {
10,043,184!
389
    code = TSDB_CODE_INVALID_MSG;
×
390
    TSDB_CHECK_CODE(code, lino, _exit);
×
391
  }
392

393
  int64_t btimeMs = taosGetTimestampMs();
10,043,270✔
394
  int64_t ctimeMs = btimeMs;
10,043,270✔
395
  for (int32_t i = 0; i < nSubmitTbData; i++) {
20,762,230✔
396
    code = vnodePreProcessSubmitTbData(pVnode, pCoder, btimeMs, ctimeMs);
10,721,328✔
397
    TSDB_CHECK_CODE(code, lino, _exit);
10,720,659✔
398
  }
399

400
  tEndDecode(pCoder);
10,040,902✔
401

402
_exit:
10,043,245✔
403
  tDecoderClear(pCoder);
10,043,245✔
404
  if (code) {
10,043,229✔
405
    vError("vgId:%d, %s:%d failed to preprocess submit request since %s, msg type:%s", TD_VID(pVnode), __func__, lino,
1,699!
406
           tstrerror(code), TMSG_INFO(pMsg->msgType));
407
  }
408
  return code;
10,043,227✔
409
}
410

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

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

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

423
  code = qWorkerProcessDeleteMsg(&handle, pVnode->pQuery, pMsg, &res);
58,966✔
424
  if (code) goto _exit;
58,965!
425

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

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

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

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

444
  taosArrayDestroy(res.uidList);
58,966✔
445

446
_exit:
58,967✔
447
  return code;
58,967✔
448
}
449

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

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

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

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

464
  tDecoderClear(pCoder);
2,676✔
465
  taosArrayDestroy(pReq.deleteReqs);
2,675✔
466

467
  if (code) {
2,675!
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,675✔
471
  }
472
  return code;
2,675✔
473
}
474

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

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

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

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

491
  return code;
×
492
}
493

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

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

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

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

532
  tEncodeSize(tEncodeSVDropTbBatchReq, &sentBatchReqs, size, code);
2,491!
533
  tEncoderInit(&ec, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), size);
2,491✔
534
  code = tEncodeSVDropTbBatchReq(&ec, &sentBatchReqs);
2,491✔
535
  tEncoderClear(&ec);
2,491✔
536
  if (code != TSDB_CODE_SUCCESS) {
2,491!
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:
2,491✔
542
  tDecoderClear(&dc);
2,491✔
543
  if (sentBatchReqs.pArray) {
2,491!
544
    taosArrayDestroy(sentBatchReqs.pArray);
2,491✔
545
  }
546
  return code;
2,491✔
547
}
548

549
int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
10,375,566✔
550
  int32_t code = 0;
10,375,566✔
551

552
  switch (pMsg->msgType) {
10,375,566!
553
    case TDMT_VND_CREATE_TABLE: {
66,419✔
554
      code = vnodePreProcessCreateTableMsg(pVnode, pMsg);
66,419✔
555
    } break;
66,418✔
556
    case TDMT_VND_ALTER_TABLE: {
936✔
557
      code = vnodePreProcessAlterTableMsg(pVnode, pMsg);
936✔
558
    } break;
936✔
559
    case TDMT_VND_FETCH_TTL_EXPIRED_TBS:
95,755✔
560
    case TDMT_VND_DROP_TTL_TABLE: {
561
      code = vnodePreProcessDropTtlMsg(pVnode, pMsg);
95,755✔
562
    } break;
95,473✔
563
    case TDMT_VND_SUBMIT: {
10,043,261✔
564
      code = vnodePreProcessSubmitMsg(pVnode, pMsg);
10,043,261✔
565
    } break;
10,043,209✔
566
    case TDMT_VND_DELETE: {
58,963✔
567
      code = vnodePreProcessDeleteMsg(pVnode, pMsg);
58,963✔
568
    } break;
58,964✔
569
    case TDMT_VND_BATCH_DEL: {
2,673✔
570
      code = vnodePreProcessBatchDeleteMsg(pVnode, pMsg);
2,673✔
571
    } break;
2,675✔
572
    case TDMT_VND_ARB_CHECK_SYNC: {
×
573
      code = vnodePreProcessArbCheckSyncMsg(pVnode, pMsg);
×
574
    } break;
×
575
    case TDMT_VND_DROP_TABLE: {
2,491✔
576
      code = vnodePreProcessDropTbMsg(pVnode, pMsg);
2,491✔
577
    } break;
2,491✔
578
    default:
105,068✔
579
      break;
105,068✔
580
  }
581

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

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

595
  (void)taosThreadMutexLock(&pVnode->mutex);
13,775,767✔
596
  if (pVnode->disableWrite) {
13,776,211!
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);
13,776,211✔
602

603
  if (ver <= pVnode->state.applied) {
13,776,210!
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
13,776,210!
610
         ", conn.applyTerm:%" PRId64 ", contLen:%d",
611
         TD_VID(pVnode), TMSG_INFO(pMsg->msgType), ver, pVnode->state.applied, pVnode->state.applyTerm,
612
         pMsg->info.conn.applyTerm, pMsg->contLen);
613

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

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

622
  atomic_store_64(&pVnode->state.applied, ver);
13,775,975✔
623
  atomic_store_64(&pVnode->state.applyTerm, pMsg->info.conn.applyTerm);
13,776,256✔
624

625
  if (!syncUtilUserCommit(pMsg->msgType)) goto _exit;
13,776,258✔
626

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

632
  switch (pMsg->msgType) {
13,750,993!
633
    /* META */
634
    case TDMT_VND_CREATE_STB:
26,312✔
635
      if (vnodeProcessCreateStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
26,312✔
636
      break;
26,379✔
637
    case TDMT_VND_ALTER_STB:
6,545✔
638
      if (vnodeProcessAlterStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
6,545!
639
      break;
6,551✔
640
    case TDMT_VND_DROP_STB:
2,331✔
641
      if (vnodeProcessDropStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
2,331!
642
      break;
2,334✔
643
    case TDMT_VND_CREATE_TABLE:
74,688✔
644
      if (vnodeProcessCreateTbReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
74,688!
645
      break;
74,722✔
646
    case TDMT_VND_ALTER_TABLE:
943✔
647
      if (vnodeProcessAlterTbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
943!
648
      break;
943✔
649
    case TDMT_VND_DROP_TABLE:
2,533✔
650
      if (vnodeProcessDropTbReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
2,533!
651
      break;
2,533✔
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:
242✔
659
      if (vnodeProcessTrimReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
242!
660
      break;
243✔
661
    case TDMT_VND_S3MIGRATE:
×
662
      if (vnodeProcessS3MigrateReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
×
663
      break;
×
664
    case TDMT_VND_CREATE_SMA:
28✔
665
      if (vnodeProcessCreateTSmaReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
28!
666
      break;
28✔
667
    /* TSDB */
668
    case TDMT_VND_SUBMIT:
13,476,607✔
669
      if (vnodeProcessSubmitReq(pVnode, ver, pMsg->pCont, pMsg->contLen, pRsp, pMsg) < 0) goto _err;
13,476,607✔
670
      break;
13,476,500✔
671
    case TDMT_VND_DELETE:
62,936✔
672
      if (vnodeProcessDeleteReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
62,936!
673
      break;
62,938✔
674
    case TDMT_VND_BATCH_DEL:
3,002✔
675
      if (vnodeProcessBatchDeleteReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
3,002!
676
      break;
3,005✔
677
    /* TQ */
678
    case TDMT_VND_TMQ_SUBSCRIBE:
3,108✔
679
      if (tqProcessSubscribeReq(pVnode->pTq, ver, pReq, len) < 0) {
3,108✔
680
        goto _err;
1✔
681
      }
682
      break;
3,116✔
683
    case TDMT_VND_TMQ_DELETE_SUB:
865✔
684
      if (tqProcessDeleteSubReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen) < 0) {
865!
685
        goto _err;
×
686
      }
687
      break;
866✔
688
    case TDMT_VND_TMQ_COMMIT_OFFSET:
11,525✔
689
      if (tqProcessOffsetCommitReq(pVnode->pTq, ver, pReq, len) < 0) {
11,525!
690
        goto _err;
×
691
      }
692
      break;
11,529✔
693
    case TDMT_VND_TMQ_ADD_CHECKINFO:
120✔
694
      if (tqProcessAddCheckInfoReq(pVnode->pTq, ver, pReq, len) < 0) {
120!
695
        goto _err;
×
696
      }
697
      break;
121✔
698
    case TDMT_VND_TMQ_DEL_CHECKINFO:
13✔
699
      if (tqProcessDelCheckInfoReq(pVnode->pTq, ver, pReq, len) < 0) {
13✔
700
        goto _err;
2✔
701
      }
702
      break;
12✔
703
    case TDMT_STREAM_TASK_DEPLOY: {
14,256✔
704
      if ((code = tqProcessTaskDeployReq(pVnode->pTq, ver, pReq, len)) != TSDB_CODE_SUCCESS) {
14,256!
705
        goto _err;
×
706
      }
707
    } break;
14,270✔
708
    case TDMT_STREAM_TASK_DROP: {
6,970✔
709
      if ((code = tqProcessTaskDropReq(pVnode->pTq, pMsg->pCont, pMsg->contLen)) < 0) {
6,970!
710
        goto _err;
×
711
      }
712
    } break;
6,989✔
713
    case TDMT_STREAM_TASK_UPDATE_CHKPT: {
6,781✔
714
      if ((code = tqProcessTaskUpdateCheckpointReq(pVnode->pTq, pMsg->pCont, pMsg->contLen)) < 0) {
6,781!
715
        goto _err;
×
716
      }
717
    } break;
6,741✔
718
    case TDMT_STREAM_CONSEN_CHKPT: {
197✔
719
      if (pVnode->restored && (code = tqProcessTaskConsenChkptIdReq(pVnode->pTq, pMsg)) < 0) {
197!
720
        goto _err;
×
721
      }
722

723
    } break;
197✔
724
    case TDMT_STREAM_TASK_PAUSE: {
2,079✔
725
      if (pVnode->restored && vnodeIsLeader(pVnode) &&
3,478!
726
          (code = tqProcessTaskPauseReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen)) < 0) {
1,398✔
727
        goto _err;
×
728
      }
729
    } break;
2,080✔
730
    case TDMT_STREAM_TASK_RESUME: {
3,705✔
731
      if (pVnode->restored && vnodeIsLeader(pVnode) &&
6,273!
732
          (code = tqProcessTaskResumeReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen)) < 0) {
2,564✔
733
        goto _err;
×
734
      }
735
    } break;
3,710✔
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:
8,066✔
743
      needCommit = pVnode->config.hashChange;
8,066✔
744
      if (vnodeProcessAlterConfirmReq(pVnode, ver, pReq, len, pRsp) < 0) {
8,066!
745
        goto _err;
×
746
      }
747
      break;
8,066✔
748
    case TDMT_VND_ALTER_CONFIG:
627✔
749
      vnodeProcessAlterConfigReq(pVnode, ver, pReq, len, pRsp);
627✔
750
      break;
627✔
751
    case TDMT_VND_COMMIT:
29,147✔
752
      needCommit = true;
29,147✔
753
      break;
29,147✔
754
    case TDMT_VND_CREATE_INDEX:
939✔
755
      vnodeProcessCreateIndexReq(pVnode, ver, pReq, len, pRsp);
939✔
756
      break;
939✔
757
    case TDMT_VND_DROP_INDEX:
2,114✔
758
      vnodeProcessDropIndexReq(pVnode, ver, pReq, len, pRsp);
2,114✔
759
      break;
2,114✔
760
    case TDMT_VND_STREAM_CHECK_POINT_SOURCE:  // always return true
4,016✔
761
      tqProcessTaskCheckPointSourceReq(pVnode->pTq, pMsg, pRsp);
4,016✔
762
      break;
4,015✔
763
    case TDMT_VND_STREAM_TASK_UPDATE:  // always return true
90✔
764
      tqProcessTaskUpdateReq(pVnode->pTq, pMsg);
90✔
765
      break;
90✔
766
    case TDMT_VND_COMPACT:
202✔
767
      vnodeProcessCompactVnodeReq(pVnode, ver, pReq, len, pRsp);
202✔
768
      goto _exit;
203✔
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:
1✔
779
      vnodeProcessArbCheckSyncReq(pVnode, pReq, len, pRsp);
1✔
780
      break;
1✔
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,
13,750,811!
787
         ver);
788

789
  walApplyVer(pVnode->pWal, ver);
13,750,811✔
790

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

797
  // commit if need
798
  if (needCommit) {
13,750,319✔
799
    vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), ver);
28,683!
800
    code = vnodeAsyncCommit(pVnode);
28,692✔
801
    if (code) {
28,704!
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);
28,704✔
808
    if (code) {
28,700✔
809
      vError("vgId:%d, failed to begin vnode since %s.", TD_VID(pVnode), tstrerror(terrno));
49!
810
      goto _err;
×
811
    }
812
  }
813

814
_exit:
13,750,287✔
815
  return 0;
13,775,277✔
816

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

823
int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
8,027,955✔
824
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) {
8,027,955✔
825
    return 0;
575,341✔
826
  }
827

828
  return qWorkerPreprocessQueryMsg(pVnode->pQuery, pMsg, TDMT_SCH_QUERY == pMsg->msgType);
7,452,614✔
829
}
830

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

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

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

848
  switch (pMsg->msgType) {
8,038,682✔
849
    case TDMT_SCH_QUERY:
5,700,906✔
850
      if (!syncIsReadyForRead(pVnode->sync)) {
5,700,906✔
851
        pMsg->code = (terrno) ? terrno : TSDB_CODE_SYN_NOT_LEADER;
1,745!
852
        redirected = true;
1,745✔
853
      }
854
      code = qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
5,700,865✔
855
      if (redirected) {
5,699,303✔
856
        vnodeRedirectRpcMsg(pVnode, pMsg, pMsg->code);
756✔
857
        return 0;
1,745✔
858
      }
859
      return code;
5,698,547✔
860
    case TDMT_SCH_MERGE_QUERY:
1,763,303✔
861
      return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
1,763,303✔
862
    case TDMT_SCH_QUERY_CONTINUE:
475,758✔
863
      return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
475,758✔
864
    case TDMT_VND_TMQ_CONSUME:
72,969✔
865
      return tqProcessPollReq(pVnode->pTq, pMsg);
72,969✔
866
    case TDMT_VND_TMQ_CONSUME_PUSH:
25,312✔
867
      return tqProcessPollPush(pVnode->pTq, pMsg);
25,312✔
868
    default:
434✔
869
      vError("unknown msg type:%d in query queue", pMsg->msgType);
434!
870
      return TSDB_CODE_APP_ERROR;
×
871
  }
872
}
873

874
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
19,852,599✔
875
  vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg);
19,852,599✔
876
  if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
19,852,600!
877
       pMsg->msgType == TDMT_VND_BATCH_META || pMsg->msgType == TDMT_VND_TABLE_NAME) &&
13,728,597✔
878
      !syncIsReadyForRead(pVnode->sync)) {
7,237,518✔
879
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
5,395✔
880
    return 0;
5,395✔
881
  }
882

883
  switch (pMsg->msgType) {
19,851,641!
884
    case TDMT_SCH_FETCH:
9,461,804✔
885
    case TDMT_SCH_MERGE_FETCH:
886
      return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg, 0);
9,461,804✔
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:
7,454,680✔
892
      return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg, 0);
7,454,680✔
893
    case TDMT_SCH_TASK_NOTIFY:
45✔
894
      return qWorkerProcessNotifyMsg(pVnode, pVnode->pQuery, pMsg, 0);
45✔
895
    case TDMT_SCH_QUERY_HEARTBEAT:
1,827,503✔
896
      return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg, 0);
1,827,503✔
897
    case TDMT_VND_TABLE_META:
1,774✔
898
    case TDMT_VND_TABLE_NAME:
899
      return vnodeGetTableMeta(pVnode, pMsg, true);
1,774✔
900
    case TDMT_VND_TABLE_CFG:
×
901
      return vnodeGetTableCfg(pVnode, pMsg, true);
×
902
    case TDMT_VND_BATCH_META:
1,105,747✔
903
      return vnodeGetBatchMeta(pVnode, pMsg);
1,105,747✔
904
#ifdef TD_ENTERPRISE
905
    case TDMT_VND_QUERY_COMPACT_PROGRESS:
48✔
906
      return vnodeQueryCompactProgress(pVnode, pMsg);
48✔
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:
3✔
913
      return tqProcessVgCommittedInfoReq(pVnode->pTq, pMsg);
3✔
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) {
365,151✔
924
  vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg);
365,151✔
925
  if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
365,151!
926
       pMsg->msgType == TDMT_VND_BATCH_META) &&
365,176!
927
      !syncIsReadyForRead(pVnode->sync)) {
×
928
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
×
929
    return 0;
×
930
  }
931

932
  switch (pMsg->msgType) {
365,186!
933
    case TDMT_STREAM_TASK_RUN:
169,641✔
934
      return tqProcessTaskRunReq(pVnode->pTq, pMsg);
169,641✔
935
    case TDMT_STREAM_TASK_DISPATCH:
49,477✔
936
      return tqProcessTaskDispatchReq(pVnode->pTq, pMsg);
49,477✔
937
    case TDMT_STREAM_TASK_DISPATCH_RSP:
49,439✔
938
      return tqProcessTaskDispatchRsp(pVnode->pTq, pMsg);
49,439✔
939
    case TDMT_VND_STREAM_TASK_CHECK:
21,843✔
940
      return tqProcessTaskCheckReq(pVnode->pTq, pMsg);
21,843✔
941
    case TDMT_VND_STREAM_TASK_CHECK_RSP:
22,360✔
942
      return tqProcessTaskCheckRsp(pVnode->pTq, pMsg);
22,360✔
943
    case TDMT_STREAM_RETRIEVE:
579✔
944
      return tqProcessTaskRetrieveReq(pVnode->pTq, pMsg);
579✔
945
    case TDMT_STREAM_RETRIEVE_RSP:
462✔
946
      return tqProcessTaskRetrieveRsp(pVnode->pTq, pMsg);
462✔
947
    case TDMT_VND_STREAM_SCAN_HISTORY:
2,640✔
948
      return tqProcessTaskScanHistory(pVnode->pTq, pMsg);
2,640✔
949
    case TDMT_STREAM_TASK_CHECKPOINT_READY:
7,592✔
950
      return tqProcessTaskCheckpointReadyMsg(pVnode->pTq, pMsg);
7,592✔
951
    case TDMT_STREAM_TASK_CHECKPOINT_READY_RSP:
7,586✔
952
      return tqProcessTaskCheckpointReadyRsp(pVnode->pTq, pMsg);
7,586✔
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:
23,316✔
958
      return tqProcessStreamHbRsp(pVnode->pTq, pMsg);
23,316✔
959
    case TDMT_MND_STREAM_REQ_CHKPT_RSP:
4,426✔
960
      return tqProcessStreamReqCheckpointRsp(pVnode->pTq, pMsg);
4,426✔
961
    case TDMT_VND_GET_STREAM_PROGRESS:
×
962
      return tqStreamProgressRetrieveReq(pVnode->pTq, pMsg);
×
963
    case TDMT_MND_STREAM_CHKPT_REPORT_RSP:
5,825✔
964
      return tqProcessTaskChkptReportRsp(pVnode->pTq, pMsg);
5,825✔
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) {
3✔
972
  int32_t code = tdProcessTSmaInsert(((SVnode *)pVnode)->pSma, smaId, (const char *)data);
3✔
973
  if (code) {
3!
974
    vError("failed to process sma result since %s", tstrerror(code));
×
975
  }
976
}
3✔
977

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

983
  tstrncpy(pMetaRsp->dbFName, pVnode->config.dbname, TSDB_DB_FNAME_LEN);
153,375✔
984
  pMetaRsp->dbId = pVnode->config.dbId;
153,375✔
985
  pMetaRsp->vgId = TD_VID(pVnode);
153,375✔
986
  pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
153,375✔
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) {
242✔
992
  if (!pVnode->restored) {
242✔
993
    vInfo("vgId:%d, ignore trim req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
35!
994
    return 0;
35✔
995
  }
996

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

1000
  // decode
1001
  if (tDeserializeSVTrimDbReq(pReq, len, &trimReq) != 0) {
207!
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);
208!
1007

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

1010
_exit:
208✔
1011
  return code;
208✔
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) {
26,309✔
1147
  int32_t        code = 0;
26,309✔
1148
  SVCreateStbReq req = {0};
26,309✔
1149
  SDecoder       coder;
1150

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

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

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

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

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

1176
  tDecoderClear(&coder);
26,384✔
1177
  return 0;
26,361✔
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,
74,686✔
1185
                                       SRpcMsg *pOriginRpc) {
1186
  SDecoder           decoder = {0};
74,686✔
1187
  SEncoder           encoder = {0};
74,686✔
1188
  int32_t            rcode = 0;
74,686✔
1189
  SVCreateTbBatchReq req = {0};
74,686✔
1190
  SVCreateTbReq     *pCreateReq;
1191
  SVCreateTbBatchRsp rsp = {0};
74,686✔
1192
  SVCreateTbRsp      cRsp = {0};
74,686✔
1193
  char               tbName[TSDB_TABLE_FNAME_LEN];
1194
  STbUidStore       *pStore = NULL;
74,686✔
1195
  SArray            *tbUids = NULL;
74,686✔
1196
  SArray            *tbNames = NULL;
74,686✔
1197
  pRsp->msgType = TDMT_VND_CREATE_TABLE_RSP;
74,686✔
1198
  pRsp->code = TSDB_CODE_SUCCESS;
74,686✔
1199
  pRsp->pCont = NULL;
74,686✔
1200
  pRsp->contLen = 0;
74,686✔
1201

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

1210
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(cRsp));
74,714✔
1211
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
74,720✔
1212
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
74,721✔
1213
  if (rsp.pArray == NULL || tbUids == NULL || tbNames == NULL) {
74,722!
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++) {
190,232✔
1221
    pCreateReq = req.pReqs + iReq;
115,500✔
1222
    memset(&cRsp, 0, sizeof(cRsp));
115,500✔
1223

1224
    if (tsEnableAudit && tsEnableAuditCreateTable) {
115,500!
1225
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
115,504!
1226
      if (str == NULL) {
115,510!
1227
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1228
        rcode = -1;
×
1229
        goto _exit;
×
1230
      }
1231
      tstrncpy(str, pCreateReq->name, TSDB_TABLE_FNAME_LEN);
115,510✔
1232
      if (taosArrayPush(tbNames, &str) == NULL) {
115,506!
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);
115,502✔
1241
    if (vnodeValidateTableHash(pVnode, tbName) < 0) {
115,511✔
1242
      cRsp.code = TSDB_CODE_VND_HASH_MISMATCH;
19✔
1243
      if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
38!
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);
19!
1249
      continue;
19✔
1250
    }
1251

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

1272
    if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
230,983!
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));
74,732✔
1280
  if (tqUpdateTbUidList(pVnode->pTq, tbUids, true) < 0) {
74,732!
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) {
74,722!
1284
    goto _exit;
×
1285
  }
1286
  pStore = tdUidStoreFree(pStore);
74,722✔
1287

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

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

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

1310
    SStringBuilder sb = {0};
74,718✔
1311
    for (int32_t i = 0; i < tbNames->size; i++) {
190,212✔
1312
      char **key = (char **)taosArrayGet(tbNames, i);
115,495✔
1313
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
115,496✔
1314
      if (i < tbNames->size - 1) {
115,493✔
1315
        taosStringBuilderAppendChar(&sb, ',');
40,778✔
1316
      }
1317
      // taosMemoryFreeClear(*key);
1318
    }
1319

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

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

1327
    taosStringBuilderDestroy(&sb);
74,719✔
1328
  }
1329

1330
_exit:
1✔
1331
  tDeleteSVCreateTbBatchReq(&req);
74,721✔
1332
  taosArrayDestroyEx(rsp.pArray, tFreeSVCreateTbRsp);
74,724✔
1333
  taosArrayDestroy(tbUids);
74,723✔
1334
  tDecoderClear(&decoder);
74,722✔
1335
  tEncoderClear(&encoder);
74,722✔
1336
  taosArrayDestroyP(tbNames, NULL);
74,722✔
1337
  return rcode;
74,723✔
1338
}
1339

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

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

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

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

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

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

1368
  return 0;
6,551✔
1369
}
1370

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

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

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

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

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

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

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

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

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

1429
  tDecoderInit(&dc, pReq, len);
943✔
1430

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

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

1446
  if (NULL != vMetaRsp.pSchemas) {
905✔
1447
    vnodeUpdateMetaRsp(pVnode, &vMetaRsp);
182✔
1448
    vAlterTbRsp.pMeta = &vMetaRsp;
182✔
1449
  }
1450

1451
  if (vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL || vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL) {
905✔
1452
    int64_t uid = metaGetTableEntryUidByName(pVnode->pMeta, vAlterTbReq.tbName);
653✔
1453
    if (uid == 0) {
653!
1454
      vError("vgId:%d, %s failed at %s:%d since table %s not found", TD_VID(pVnode), __func__, __FILE__, __LINE__,
×
1455
             vAlterTbReq.tbName);
1456
      goto _exit;
×
1457
    }
1458

1459
    SArray* tbUids = taosArrayInit(4, sizeof(int64_t));
653✔
1460
    void* p = taosArrayPush(tbUids, &uid);
653✔
1461
    TSDB_CHECK_NULL(p, code, lino, _exit, terrno);
653!
1462

1463
    vDebug("vgId:%d, remove tags value altered table:%s from query table list", TD_VID(pVnode), vAlterTbReq.tbName);
653✔
1464
    if ((code = tqUpdateTbUidList(pVnode->pTq, tbUids, false)) < 0) {
653!
1465
      vError("vgId:%d, failed to remove tbUid list since %s", TD_VID(pVnode), tstrerror(code));
×
1466
    }
1467

1468
    vDebug("vgId:%d, try to add table:%s in query table list", TD_VID(pVnode), vAlterTbReq.tbName);
653✔
1469
    if ((code = tqUpdateTbUidList(pVnode->pTq, tbUids, true)) < 0) {
653!
1470
      vError("vgId:%d, failed to add tbUid list since %s", TD_VID(pVnode), tstrerror(code));
×
1471
    }
1472

1473
    taosArrayDestroy(tbUids);
653✔
1474
  }
1475

1476
_exit:
252✔
1477
  taosArrayDestroy(vAlterTbReq.pMultiTag);
943✔
1478
  tEncodeSize(tEncodeSVAlterTbRsp, &vAlterTbRsp, pRsp->contLen, ret);
943!
1479
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
943✔
1480
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
943✔
1481
  if (tEncodeSVAlterTbRsp(&ec, &vAlterTbRsp) != 0) {
943!
1482
    vError("vgId:%d, failed to encode alter table response", TD_VID(pVnode));
×
1483
  }
1484

1485
  tEncoderClear(&ec);
943✔
1486
  if (vMetaRsp.pSchemas) {
943✔
1487
    taosMemoryFree(vMetaRsp.pSchemas);
182!
1488
    taosMemoryFree(vMetaRsp.pSchemaExt);
182!
1489
  }
1490
  return 0;
943✔
1491
}
1492

1493
static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
2,533✔
1494
                                     SRpcMsg *pOriginRpc) {
1495
  SVDropTbBatchReq req = {0};
2,533✔
1496
  SVDropTbBatchRsp rsp = {0};
2,533✔
1497
  SDecoder         decoder = {0};
2,533✔
1498
  SEncoder         encoder = {0};
2,533✔
1499
  int32_t          ret;
1500
  SArray          *tbUids = NULL;
2,533✔
1501
  STbUidStore     *pStore = NULL;
2,533✔
1502
  SArray          *tbNames = NULL;
2,533✔
1503

1504
  pRsp->msgType = TDMT_VND_DROP_TABLE_RSP;
2,533✔
1505
  pRsp->pCont = NULL;
2,533✔
1506
  pRsp->contLen = 0;
2,533✔
1507
  pRsp->code = TSDB_CODE_SUCCESS;
2,533✔
1508

1509
  // decode req
1510
  tDecoderInit(&decoder, pReq, len);
2,533✔
1511
  ret = tDecodeSVDropTbBatchReq(&decoder, &req);
2,533✔
1512
  if (ret < 0) {
2,533!
1513
    terrno = TSDB_CODE_INVALID_MSG;
×
1514
    pRsp->code = terrno;
×
1515
    goto _exit;
×
1516
  }
1517

1518
  // process req
1519
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
2,533✔
1520
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(SVDropTbRsp));
2,533✔
1521
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
2,533✔
1522
  if (tbUids == NULL || rsp.pArray == NULL || tbNames == NULL) goto _exit;
2,533!
1523

1524
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
5,091✔
1525
    SVDropTbReq *pDropTbReq = req.pReqs + iReq;
2,558✔
1526
    SVDropTbRsp  dropTbRsp = {0};
2,558✔
1527
    tb_uid_t     tbUid = 0;
2,558✔
1528

1529
    /* code */
1530
    ret = metaDropTable2(pVnode->pMeta, ver, pDropTbReq);
2,558✔
1531
    if (ret < 0) {
2,558!
1532
      if (pDropTbReq->igNotExists && terrno == TSDB_CODE_TDB_TABLE_NOT_EXIST) {
×
1533
        dropTbRsp.code = TSDB_CODE_SUCCESS;
×
1534
      } else {
1535
        dropTbRsp.code = terrno;
×
1536
      }
1537
    } else {
1538
      dropTbRsp.code = TSDB_CODE_SUCCESS;
2,558✔
1539
      if (tbUid > 0) {
2,558!
1540
        if (tdFetchTbUidList(pVnode->pSma, &pStore, pDropTbReq->suid, tbUid) < 0) {
×
1541
          vError("vgId:%d, failed to fetch tbUid list", TD_VID(pVnode));
×
1542
        }
1543
      }
1544
    }
1545

1546
    if (taosArrayPush(rsp.pArray, &dropTbRsp) == NULL) {
5,116!
1547
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1548
      pRsp->code = terrno;
×
1549
      goto _exit;
×
1550
    }
1551

1552
    if (tsEnableAuditCreateTable) {
2,558!
1553
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
2,558!
1554
      if (str == NULL) {
2,558!
1555
        pRsp->code = terrno;
×
1556
        goto _exit;
×
1557
      }
1558
      tstrncpy(str, pDropTbReq->name, TSDB_TABLE_FNAME_LEN);
2,558✔
1559
      if (taosArrayPush(tbNames, &str) == NULL) {
2,558!
1560
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1561
        pRsp->code = terrno;
×
1562
        goto _exit;
×
1563
      }
1564
    }
1565
  }
1566

1567
  if (tqUpdateTbUidList(pVnode->pTq, tbUids, false) < 0) {
2,533!
1568
    vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(terrno));
×
1569
  }
1570

1571
  if (tdUpdateTbUidList(pVnode->pSma, pStore, false) < 0) {
2,533!
1572
    goto _exit;
×
1573
  }
1574

1575
  if (tsEnableAuditCreateTable) {
2,533!
1576
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
2,533✔
1577

1578
    SName name = {0};
2,533✔
1579
    if (tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB) != 0) {
2,533!
1580
      vError("vgId:%d, failed to get name from string", TD_VID(pVnode));
×
1581
    }
1582

1583
    SStringBuilder sb = {0};
2,533✔
1584
    for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
5,091✔
1585
      char **key = (char **)taosArrayGet(tbNames, iReq);
2,558✔
1586
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
2,558✔
1587
      if (iReq < req.nReqs - 1) {
2,558✔
1588
        taosStringBuilderAppendChar(&sb, ',');
25✔
1589
      }
1590
      taosMemoryFreeClear(*key);
2,558!
1591
    }
1592

1593
    size_t len = 0;
2,533✔
1594
    char  *keyJoined = taosStringBuilderGetResult(&sb, &len);
2,533✔
1595

1596
    if (pOriginRpc->info.conn.user != NULL && strlen(pOriginRpc->info.conn.user) > 0) {
2,533!
1597
      auditAddRecord(pOriginRpc, clusterId, "dropTable", name.dbname, "", keyJoined, len);
2,436✔
1598
    }
1599

1600
    taosStringBuilderDestroy(&sb);
2,533✔
1601
  }
1602

1603
_exit:
×
1604
  taosArrayDestroy(tbUids);
2,533✔
1605
  pStore = tdUidStoreFree(pStore);
2,533✔
1606
  tDecoderClear(&decoder);
2,533✔
1607
  tEncodeSize(tEncodeSVDropTbBatchRsp, &rsp, pRsp->contLen, ret);
2,533!
1608
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
2,533✔
1609
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
2,533✔
1610
  if (tEncodeSVDropTbBatchRsp(&encoder, &rsp) != 0) {
2,533!
1611
    vError("vgId:%d, failed to encode drop table batch response", TD_VID(pVnode));
×
1612
  }
1613
  tEncoderClear(&encoder);
2,533✔
1614
  taosArrayDestroy(rsp.pArray);
2,533✔
1615
  taosArrayDestroy(tbNames);
2,533✔
1616
  return 0;
2,533✔
1617
}
1618

1619
#ifdef BUILD_NO_CALL
1620
static int32_t vnodeDebugPrintSingleSubmitMsg(SMeta *pMeta, SSubmitBlk *pBlock, SSubmitMsgIter *msgIter,
1621
                                              const char *tags) {
1622
  SSubmitBlkIter blkIter = {0};
1623
  STSchema      *pSchema = NULL;
1624
  tb_uid_t       suid = 0;
1625
  STSRow        *row = NULL;
1626
  int32_t        rv = -1;
1627

1628
  tInitSubmitBlkIter(msgIter, pBlock, &blkIter);
1629
  if (blkIter.row == NULL) return 0;
1630

1631
  int32_t code = metaGetTbTSchemaNotNull(pMeta, msgIter->suid, TD_ROW_SVER(blkIter.row), 1,
1632
                                         &pSchema);  // TODO: use the real schema
1633
  if (TSDB_CODE_SUCCESS != code) {
1634
    printf("%s:%d no valid schema\n", tags, __LINE__);
1635
    return code;
1636
  }
1637

1638
  suid = msgIter->suid;
1639
  rv = TD_ROW_SVER(blkIter.row);
1640

1641
  char __tags[128] = {0};
1642
  snprintf(__tags, 128, "%s: uid %" PRIi64 " ", tags, msgIter->uid);
1643
  while ((row = tGetSubmitBlkNext(&blkIter))) {
1644
    tdSRowPrint(row, pSchema, __tags);
1645
  }
1646

1647
  taosMemoryFreeClear(pSchema);
1648

1649
  return TSDB_CODE_SUCCESS;
1650
}
1651
#endif
1652
typedef struct SSubmitReqConvertCxt {
1653
  SSubmitMsgIter msgIter;
1654
  SSubmitBlk    *pBlock;
1655
  SSubmitBlkIter blkIter;
1656
  STSRow        *pRow;
1657
  STSRowIter     rowIter;
1658
  SSubmitTbData *pTbData;
1659
  STSchema      *pTbSchema;
1660
  SArray        *pColValues;
1661
} SSubmitReqConvertCxt;
1662

1663
static int32_t vnodeResetTableCxt(SMeta *pMeta, SSubmitReqConvertCxt *pCxt) {
×
1664
  taosMemoryFreeClear(pCxt->pTbSchema);
×
1665
  int32_t code = metaGetTbTSchemaNotNull(pMeta, pCxt->msgIter.suid > 0 ? pCxt->msgIter.suid : pCxt->msgIter.uid,
×
1666
                                         pCxt->msgIter.sversion, 1, &pCxt->pTbSchema);
1667
  if (TSDB_CODE_SUCCESS != code) {
×
1668
    return code;
×
1669
  }
1670
  tdSTSRowIterInit(&pCxt->rowIter, pCxt->pTbSchema);
×
1671

1672
  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
×
1673
  if (NULL == pCxt->pTbData) {
×
1674
    pCxt->pTbData = taosMemoryCalloc(1, sizeof(SSubmitTbData));
×
1675
    if (NULL == pCxt->pTbData) {
×
1676
      return terrno;
×
1677
    }
1678
  }
1679
  pCxt->pTbData->flags = 0;
×
1680
  pCxt->pTbData->suid = pCxt->msgIter.suid;
×
1681
  pCxt->pTbData->uid = pCxt->msgIter.uid;
×
1682
  pCxt->pTbData->sver = pCxt->msgIter.sversion;
×
1683
  pCxt->pTbData->pCreateTbReq = NULL;
×
1684
  pCxt->pTbData->aRowP = taosArrayInit(128, POINTER_BYTES);
×
1685
  if (NULL == pCxt->pTbData->aRowP) {
×
1686
    return terrno;
×
1687
  }
1688

1689
  taosArrayDestroy(pCxt->pColValues);
×
1690
  pCxt->pColValues = taosArrayInit(pCxt->pTbSchema->numOfCols, sizeof(SColVal));
×
1691
  if (NULL == pCxt->pColValues) {
×
1692
    return terrno;
×
1693
  }
1694
  for (int32_t i = 0; i < pCxt->pTbSchema->numOfCols; ++i) {
×
1695
    SColVal val = COL_VAL_NONE(pCxt->pTbSchema->columns[i].colId, pCxt->pTbSchema->columns[i].type);
×
1696
    if (taosArrayPush(pCxt->pColValues, &val) == NULL) {
×
1697
      return terrno;
×
1698
    }
1699
  }
1700

1701
  return TSDB_CODE_SUCCESS;
×
1702
}
1703

1704
static void vnodeDestroySubmitReqConvertCxt(SSubmitReqConvertCxt *pCxt) {
×
1705
  taosMemoryFreeClear(pCxt->pTbSchema);
×
1706
  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
×
1707
  taosMemoryFreeClear(pCxt->pTbData);
×
1708
  taosArrayDestroy(pCxt->pColValues);
×
1709
}
×
1710

1711
static int32_t vnodeCellValConvertToColVal(STColumn *pCol, SCellVal *pCellVal, SColVal *pColVal) {
×
1712
  if (tdValTypeIsNone(pCellVal->valType)) {
×
1713
    pColVal->flag = CV_FLAG_NONE;
×
1714
    return TSDB_CODE_SUCCESS;
×
1715
  }
1716

1717
  if (tdValTypeIsNull(pCellVal->valType)) {
×
1718
    pColVal->flag = CV_FLAG_NULL;
×
1719
    return TSDB_CODE_SUCCESS;
×
1720
  }
1721

1722
  if (IS_VAR_DATA_TYPE(pCol->type)) {
×
1723
    pColVal->value.nData = varDataLen(pCellVal->val);
×
1724
    pColVal->value.pData = (uint8_t *)varDataVal(pCellVal->val);
×
1725
  } else if (TSDB_DATA_TYPE_FLOAT == pCol->type) {
×
1726
    float f = GET_FLOAT_VAL(pCellVal->val);
×
1727
    memcpy(&pColVal->value.val, &f, sizeof(f));
×
1728
  } else if (TSDB_DATA_TYPE_DOUBLE == pCol->type) {
×
1729
    pColVal->value.val = *(int64_t *)pCellVal->val;
×
1730
  } else {
1731
    GET_TYPED_DATA(pColVal->value.val, int64_t, pCol->type, pCellVal->val);
×
1732
  }
1733

1734
  pColVal->flag = CV_FLAG_VALUE;
×
1735
  return TSDB_CODE_SUCCESS;
×
1736
}
1737

1738
static int32_t vnodeTSRowConvertToColValArray(SSubmitReqConvertCxt *pCxt) {
×
1739
  int32_t code = TSDB_CODE_SUCCESS;
×
1740
  tdSTSRowIterReset(&pCxt->rowIter, pCxt->pRow);
×
1741
  for (int32_t i = 0; TSDB_CODE_SUCCESS == code && i < pCxt->pTbSchema->numOfCols; ++i) {
×
1742
    STColumn *pCol = pCxt->pTbSchema->columns + i;
×
1743
    SCellVal  cellVal = {0};
×
1744
    if (!tdSTSRowIterFetch(&pCxt->rowIter, pCol->colId, pCol->type, &cellVal)) {
×
1745
      break;
×
1746
    }
1747
    code = vnodeCellValConvertToColVal(pCol, &cellVal, (SColVal *)taosArrayGet(pCxt->pColValues, i));
×
1748
  }
1749
  return code;
×
1750
}
1751

1752
static int32_t vnodeDecodeCreateTbReq(SSubmitReqConvertCxt *pCxt) {
×
1753
  if (pCxt->msgIter.schemaLen <= 0) {
×
1754
    return TSDB_CODE_SUCCESS;
×
1755
  }
1756

1757
  pCxt->pTbData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
×
1758
  if (NULL == pCxt->pTbData->pCreateTbReq) {
×
1759
    return terrno;
×
1760
  }
1761

1762
  SDecoder decoder = {0};
×
1763
  tDecoderInit(&decoder, (uint8_t *)pCxt->pBlock->data, pCxt->msgIter.schemaLen);
×
1764
  int32_t code = tDecodeSVCreateTbReq(&decoder, pCxt->pTbData->pCreateTbReq);
×
1765
  tDecoderClear(&decoder);
×
1766

1767
  return code;
×
1768
}
1769

1770
static int32_t vnodeSubmitReqConvertToSubmitReq2(SVnode *pVnode, SSubmitReq *pReq, SSubmitReq2 *pReq2) {
×
1771
  pReq2->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData));
×
1772
  if (NULL == pReq2->aSubmitTbData) {
×
1773
    return terrno;
×
1774
  }
1775

1776
  SSubmitReqConvertCxt cxt = {0};
×
1777

1778
  int32_t code = tInitSubmitMsgIter(pReq, &cxt.msgIter);
×
1779
  while (TSDB_CODE_SUCCESS == code) {
×
1780
    code = tGetSubmitMsgNext(&cxt.msgIter, &cxt.pBlock);
×
1781
    if (TSDB_CODE_SUCCESS == code) {
×
1782
      if (NULL == cxt.pBlock) {
×
1783
        break;
×
1784
      }
1785
      code = vnodeResetTableCxt(pVnode->pMeta, &cxt);
×
1786
    }
1787
    if (TSDB_CODE_SUCCESS == code) {
×
1788
      code = tInitSubmitBlkIter(&cxt.msgIter, cxt.pBlock, &cxt.blkIter);
×
1789
    }
1790
    if (TSDB_CODE_SUCCESS == code) {
×
1791
      code = vnodeDecodeCreateTbReq(&cxt);
×
1792
    }
1793
    while (TSDB_CODE_SUCCESS == code && (cxt.pRow = tGetSubmitBlkNext(&cxt.blkIter)) != NULL) {
×
1794
      code = vnodeTSRowConvertToColValArray(&cxt);
×
1795
      if (TSDB_CODE_SUCCESS == code) {
×
1796
        SRow **pNewRow = taosArrayReserve(cxt.pTbData->aRowP, 1);
×
1797
        code = tRowBuild(cxt.pColValues, cxt.pTbSchema, pNewRow);
×
1798
      }
1799
    }
1800
    if (TSDB_CODE_SUCCESS == code) {
×
1801
      code = (NULL == taosArrayPush(pReq2->aSubmitTbData, cxt.pTbData) ? terrno : TSDB_CODE_SUCCESS);
×
1802
    }
1803
    if (TSDB_CODE_SUCCESS == code) {
×
1804
      taosMemoryFreeClear(cxt.pTbData);
×
1805
    }
1806
  }
1807

1808
  vnodeDestroySubmitReqConvertCxt(&cxt);
×
1809
  return code;
×
1810
}
1811

1812
static int32_t vnodeRebuildSubmitReqMsg(SSubmitReq2 *pSubmitReq, void **ppMsg) {
×
1813
  int32_t  code = TSDB_CODE_SUCCESS;
×
1814
  char    *pMsg = NULL;
×
1815
  uint32_t msglen = 0;
×
1816
  tEncodeSize(tEncodeSubmitReq, pSubmitReq, msglen, code);
×
1817
  if (TSDB_CODE_SUCCESS == code) {
×
1818
    pMsg = taosMemoryMalloc(msglen);
×
1819
    if (NULL == pMsg) {
×
1820
      code = terrno;
×
1821
    }
1822
  }
1823
  if (TSDB_CODE_SUCCESS == code) {
×
1824
    SEncoder encoder;
1825
    tEncoderInit(&encoder, (uint8_t *)pMsg, msglen);
×
1826
    code = tEncodeSubmitReq(&encoder, pSubmitReq);
×
1827
    tEncoderClear(&encoder);
×
1828
  }
1829
  if (TSDB_CODE_SUCCESS == code) {
×
1830
    *ppMsg = pMsg;
×
1831
  }
1832
  return code;
×
1833
}
1834

1835
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
13,476,587✔
1836
                                     SRpcMsg *pOriginalMsg) {
1837
  int32_t code = 0;
13,476,587✔
1838
  terrno = 0;
13,476,587✔
1839

1840
  SSubmitReq2 *pSubmitReq = &(SSubmitReq2){0};
13,476,760✔
1841
  SSubmitRsp2 *pSubmitRsp = &(SSubmitRsp2){0};
13,476,760✔
1842
  SArray      *newTbUids = NULL;
13,476,760✔
1843
  int32_t      ret;
1844
  SEncoder     ec = {0};
13,476,760✔
1845

1846
  pRsp->code = TSDB_CODE_SUCCESS;
13,476,760✔
1847

1848
  void           *pAllocMsg = NULL;
13,476,760✔
1849
  SSubmitReq2Msg *pMsg = (SSubmitReq2Msg *)pReq;
13,476,760✔
1850
  if (0 == pMsg->version) {
13,476,760!
1851
    code = vnodeSubmitReqConvertToSubmitReq2(pVnode, (SSubmitReq *)pMsg, pSubmitReq);
×
1852
    if (TSDB_CODE_SUCCESS == code) {
×
1853
      code = vnodeRebuildSubmitReqMsg(pSubmitReq, &pReq);
×
1854
    }
1855
    if (TSDB_CODE_SUCCESS == code) {
×
1856
      pAllocMsg = pReq;
×
1857
    }
1858
    if (TSDB_CODE_SUCCESS != code) {
×
1859
      goto _exit;
×
1860
    }
1861
  } else {
1862
    // decode
1863
    pReq = POINTER_SHIFT(pReq, sizeof(SSubmitReq2Msg));
13,476,760✔
1864
    len -= sizeof(SSubmitReq2Msg);
13,476,760✔
1865
    SDecoder dc = {0};
13,476,760✔
1866
    tDecoderInit(&dc, pReq, len);
13,476,760✔
1867
    if (tDecodeSubmitReq(&dc, pSubmitReq) < 0) {
13,476,685!
1868
      code = TSDB_CODE_INVALID_MSG;
×
1869
      goto _exit;
×
1870
    }
1871
    tDecoderClear(&dc);
13,476,691✔
1872
  }
1873

1874
  // scan
1875
  TSKEY now = taosGetTimestamp(pVnode->config.tsdbCfg.precision);
13,476,648✔
1876
  TSKEY minKey = now - tsTickPerMin[pVnode->config.tsdbCfg.precision] * pVnode->config.tsdbCfg.keep2;
13,476,668✔
1877
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
13,476,668✔
1878
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
27,658,937✔
1879
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
14,182,215✔
1880

1881
    if (pSubmitTbData->pCreateTbReq && pSubmitTbData->pCreateTbReq->uid == 0) {
14,182,240!
1882
      code = TSDB_CODE_INVALID_MSG;
×
1883
      goto _exit;
×
1884
    }
1885

1886
    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
14,182,240✔
1887
      if (TARRAY_SIZE(pSubmitTbData->aCol) <= 0) {
133!
1888
        code = TSDB_CODE_INVALID_MSG;
×
1889
        goto _exit;
×
1890
      }
1891

1892
      SColData *colDataArr = TARRAY_DATA(pSubmitTbData->aCol);
133✔
1893
      SRowKey   lastKey;
1894
      tColDataArrGetRowKey(colDataArr, TARRAY_SIZE(pSubmitTbData->aCol), 0, &lastKey);
133✔
1895
      for (int32_t iRow = 1; iRow < colDataArr[0].nVal; iRow++) {
223✔
1896
        SRowKey key;
1897
        tColDataArrGetRowKey(TARRAY_DATA(pSubmitTbData->aCol), TARRAY_SIZE(pSubmitTbData->aCol), iRow, &key);
90✔
1898
        if (tRowKeyCompare(&lastKey, &key) >= 0) {
90!
1899
          code = TSDB_CODE_INVALID_MSG;
×
1900
          vError("vgId:%d %s failed 1 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(terrno), ver);
×
1901
          goto _exit;
×
1902
        }
1903
      }
1904
    } else {
1905
      int32_t nRow = TARRAY_SIZE(pSubmitTbData->aRowP);
14,182,107✔
1906
      SRow  **aRow = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP);
14,182,107✔
1907
      SRowKey lastRowKey;
1908
      for (int32_t iRow = 0; iRow < nRow; ++iRow) {
810,919,590✔
1909
        if (aRow[iRow]->ts < minKey || aRow[iRow]->ts > maxKey) {
796,737,454!
1910
          code = TSDB_CODE_INVALID_MSG;
14,184✔
1911
          vError("vgId:%d %s failed 2 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code), ver);
14,184✔
1912
          goto _exit;
9✔
1913
        }
1914
        if (iRow == 0) {
796,723,270✔
1915
          tRowGetKey(aRow[iRow], &lastRowKey);
14,182,008✔
1916
        } else {
1917
          SRowKey rowKey;
1918
          tRowGetKey(aRow[iRow], &rowKey);
782,541,262✔
1919

1920
          if (tRowKeyCompare(&lastRowKey, &rowKey) >= 0) {
782,538,365!
1921
            code = TSDB_CODE_INVALID_MSG;
×
1922
            vError("vgId:%d %s failed 3 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code), ver);
×
1923
            goto _exit;
×
1924
          }
1925
          lastRowKey = rowKey;
782,549,387✔
1926
        }
1927
      }
1928
    }
1929
  }
1930

1931
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
27,661,869✔
1932
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
14,184,797✔
1933

1934
    if (pSubmitTbData->pCreateTbReq) {
14,184,728✔
1935
      pSubmitTbData->uid = pSubmitTbData->pCreateTbReq->uid;
64,832✔
1936
    } else {
1937
      SMetaInfo info = {0};
14,119,896✔
1938

1939
      code = metaGetInfo(pVnode->pMeta, pSubmitTbData->uid, &info, NULL);
14,119,896✔
1940
      if (code) {
14,120,146!
1941
        code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
×
1942
        vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), pSubmitTbData->uid);
×
1943
        goto _exit;
5✔
1944
      }
1945

1946
      if (info.suid != pSubmitTbData->suid) {
14,120,149!
1947
        code = TSDB_CODE_INVALID_MSG;
×
1948
        goto _exit;
×
1949
      }
1950

1951
      if (info.suid) {
14,120,149✔
1952
        if (metaGetInfo(pVnode->pMeta, info.suid, &info, NULL) != 0) {
13,191,538!
1953
          vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), info.suid);
×
1954
        }
1955
      }
1956

1957
      if (pSubmitTbData->sver != info.skmVer) {
14,120,315!
1958
        code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER;
×
1959
        goto _exit;
×
1960
      }
1961
    }
1962

1963
    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
14,185,147✔
1964
      int32_t   nColData = TARRAY_SIZE(pSubmitTbData->aCol);
134✔
1965
      SColData *aColData = (SColData *)TARRAY_DATA(pSubmitTbData->aCol);
134✔
1966

1967
      if (nColData <= 0) {
134!
1968
        code = TSDB_CODE_INVALID_MSG;
×
1969
        goto _exit;
×
1970
      }
1971

1972
      if (aColData[0].cid != PRIMARYKEY_TIMESTAMP_COL_ID || aColData[0].type != TSDB_DATA_TYPE_TIMESTAMP ||
134!
1973
          aColData[0].nVal <= 0) {
134!
1974
        code = TSDB_CODE_INVALID_MSG;
×
1975
        goto _exit;
×
1976
      }
1977

1978
      for (int32_t j = 1; j < nColData; j++) {
584✔
1979
        if (aColData[j].nVal != aColData[0].nVal) {
450!
1980
          code = TSDB_CODE_INVALID_MSG;
×
1981
          goto _exit;
×
1982
        }
1983
      }
1984
    }
1985
  }
1986

1987
  vDebug("vgId:%d, submit block size %d", TD_VID(pVnode), (int32_t)taosArrayGetSize(pSubmitReq->aSubmitTbData));
13,477,072✔
1988

1989
  // loop to handle
1990
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
27,659,150✔
1991
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
14,182,350✔
1992

1993
    // create table
1994
    if (pSubmitTbData->pCreateTbReq) {
14,181,971✔
1995
      // alloc if need
1996
      if (pSubmitRsp->aCreateTbRsp == NULL &&
64,858✔
1997
          (pSubmitRsp->aCreateTbRsp = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(SVCreateTbRsp))) ==
45,940!
1998
              NULL) {
1999
        code = terrno;
×
2000
        goto _exit;
8✔
2001
      }
2002

2003
      SVCreateTbRsp *pCreateTbRsp = taosArrayReserve(pSubmitRsp->aCreateTbRsp, 1);
64,858✔
2004

2005
      // create table
2006
      if (metaCreateTable2(pVnode->pMeta, ver, pSubmitTbData->pCreateTbReq, &pCreateTbRsp->pMeta) == 0) {
64,857✔
2007
        // create table success
2008

2009
        if (newTbUids == NULL &&
65,114!
2010
            (newTbUids = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(int64_t))) == NULL) {
26,014✔
2011
          code = terrno;
×
2012
          goto _exit;
×
2013
        }
2014

2015
        if (taosArrayPush(newTbUids, &pSubmitTbData->uid) == NULL) {
78,200!
2016
          code = terrno;
×
2017
          goto _exit;
×
2018
        }
2019

2020
        if (pCreateTbRsp->pMeta) {
39,100!
2021
          vnodeUpdateMetaRsp(pVnode, pCreateTbRsp->pMeta);
39,100✔
2022
        }
2023
      } else {  // create table failed
2024
        if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
25,760✔
2025
          code = terrno;
8✔
2026
          vError("vgId:%d failed to create table:%s, code:%s", TD_VID(pVnode), pSubmitTbData->pCreateTbReq->name,
8!
2027
                 tstrerror(terrno));
2028
          goto _exit;
8✔
2029
        }
2030
        terrno = 0;
25,752✔
2031
        pSubmitTbData->uid = pSubmitTbData->pCreateTbReq->uid;  // update uid if table exist for using below
25,752✔
2032
      }
2033
    }
2034

2035
    // insert data
2036
    int32_t affectedRows;
2037
    code = tsdbInsertTableData(pVnode->pTsdb, ver, pSubmitTbData, &affectedRows);
14,181,965✔
2038
    if (code) goto _exit;
14,182,639!
2039

2040
    code = metaUpdateChangeTimeWithLock(pVnode->pMeta, pSubmitTbData->uid, pSubmitTbData->ctimeMs);
14,182,639✔
2041
    if (code) goto _exit;
14,182,393!
2042

2043
    pSubmitRsp->affectedRows += affectedRows;
14,182,393✔
2044
  }
2045

2046
  // update the affected table uid list
2047
  if (taosArrayGetSize(newTbUids) > 0) {
13,476,800✔
2048
    vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
26,014✔
2049
           (int32_t)taosArrayGetSize(newTbUids));
2050
    if (tqUpdateTbUidList(pVnode->pTq, newTbUids, true) != 0) {
26,014!
2051
      vError("vgId:%d, failed to update tbUid list", TD_VID(pVnode));
×
2052
    }
2053
  }
2054

2055
_exit:
13,476,740✔
2056
  // message
2057
  pRsp->code = code;
13,476,762✔
2058
  tEncodeSize(tEncodeSSubmitRsp2, pSubmitRsp, pRsp->contLen, ret);
13,476,762!
2059
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
13,476,581✔
2060
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
13,476,636✔
2061
  if (tEncodeSSubmitRsp2(&ec, pSubmitRsp) < 0) {
13,476,706!
2062
    vError("vgId:%d, failed to encode submit response", TD_VID(pVnode));
×
2063
  }
2064
  tEncoderClear(&ec);
13,476,691✔
2065

2066
  // update statistics
2067
  (void)atomic_add_fetch_64(&pVnode->statis.nInsert, pSubmitRsp->affectedRows);
13,476,772✔
2068
  (void)atomic_add_fetch_64(&pVnode->statis.nInsertSuccess, pSubmitRsp->affectedRows);
13,476,826✔
2069
  (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsert, 1);
13,476,829✔
2070

2071
  if (tsEnableMonitor && tsMonitorFqdn[0] != 0 && tsMonitorPort != 0 && pSubmitRsp->affectedRows > 0 &&
13,476,824!
2072
      strlen(pOriginalMsg->info.conn.user) > 0 && tsInsertCounter != NULL) {
×
2073
    const char *sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT_AFFECTED_ROWS,
×
2074
                                   pVnode->monitor.strClusterId,
×
2075
                                   pVnode->monitor.strDnodeId,
×
2076
                                   tsLocalEp,
2077
                                   pVnode->monitor.strVgId,
×
2078
                                   pOriginalMsg->info.conn.user,
×
2079
                                   "Success"};
2080
    int         tv = taos_counter_add(tsInsertCounter, pSubmitRsp->affectedRows, sample_labels);
×
2081
  }
2082

2083
  if (code == 0) {
13,476,824✔
2084
    (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
13,476,765✔
2085
    code = tdProcessRSmaSubmit(pVnode->pSma, ver, pSubmitReq, pReq, len);
13,476,802✔
2086
  }
2087
  /*
2088
  if (code == 0) {
2089
    atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
2090
    code = tdProcessRSmaSubmit(pVnode->pSma, ver, pSubmitReq, pReq, len);
2091

2092
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT, pVnode->monitor.strClusterId,
2093
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2094
                                          pOriginalMsg->info.conn.user, "Success"};
2095
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2096
  }
2097
  else{
2098
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT, pVnode->monitor.strClusterId,
2099
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2100
                                        pOriginalMsg->info.conn.user, "Failed"};
2101
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2102
  }
2103
  */
2104

2105
  // clear
2106
  taosArrayDestroy(newTbUids);
13,476,755✔
2107
  tDestroySubmitReq(pSubmitReq, 0 == pMsg->version ? TSDB_MSG_FLG_CMPT : TSDB_MSG_FLG_DECODE);
13,476,651!
2108
  tDestroySSubmitRsp2(pSubmitRsp, TSDB_MSG_FLG_ENCODE);
13,476,774✔
2109

2110
  if (code) terrno = code;
13,476,694✔
2111

2112
  taosMemoryFree(pAllocMsg);
13,476,694!
2113

2114
  return code;
13,476,681✔
2115
}
2116

2117
static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
28✔
2118
  SVCreateTSmaReq req = {0};
28✔
2119
  SDecoder        coder = {0};
28✔
2120

2121
  if (pRsp) {
28!
2122
    pRsp->msgType = TDMT_VND_CREATE_SMA_RSP;
28✔
2123
    pRsp->code = TSDB_CODE_SUCCESS;
28✔
2124
    pRsp->pCont = NULL;
28✔
2125
    pRsp->contLen = 0;
28✔
2126
  }
2127

2128
  // decode and process req
2129
  tDecoderInit(&coder, pReq, len);
28✔
2130

2131
  if (tDecodeSVCreateTSmaReq(&coder, &req) < 0) {
28!
2132
    terrno = TSDB_CODE_MSG_DECODE_ERROR;
×
2133
    if (pRsp) pRsp->code = terrno;
×
2134
    goto _err;
×
2135
  }
2136

2137
  if (tdProcessTSmaCreate(pVnode->pSma, ver, (const char *)&req) < 0) {
28!
2138
    if (pRsp) pRsp->code = terrno;
×
2139
    goto _err;
×
2140
  }
2141

2142
  tDecoderClear(&coder);
28✔
2143
  vDebug("vgId:%d, success to create tsma %s:%" PRIi64 " version %" PRIi64 " for table %" PRIi64, TD_VID(pVnode),
28!
2144
         req.indexName, req.indexUid, ver, req.tableUid);
2145
  return 0;
28✔
2146

2147
_err:
×
2148
  tDecoderClear(&coder);
×
2149
  vError("vgId:%d, failed to create tsma %s:%" PRIi64 " version %" PRIi64 "for table %" PRIi64 " since %s",
×
2150
         TD_VID(pVnode), req.indexName, req.indexUid, ver, req.tableUid, terrstr());
2151
  return terrno;
×
2152
}
2153

2154
/**
2155
 * @brief specific for smaDstVnode
2156
 *
2157
 * @param pVnode
2158
 * @param pCont
2159
 * @param contLen
2160
 * @return int32_t
2161
 */
2162
int32_t vnodeProcessCreateTSma(SVnode *pVnode, void *pCont, uint32_t contLen) {
×
2163
  return vnodeProcessCreateTSmaReq(pVnode, 1, pCont, contLen, NULL);
×
2164
}
2165

2166
static int32_t vnodeConsolidateAlterHashRange(SVnode *pVnode, int64_t ver) {
42✔
2167
  int32_t code = TSDB_CODE_SUCCESS;
42✔
2168

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

2172
  // TODO: trim meta of tables from TDB per hash range [pVnode->config.hashBegin, pVnode->config.hashEnd]
2173
  code = metaTrimTables(pVnode->pMeta, ver);
42✔
2174

2175
  return code;
42✔
2176
}
2177

2178
static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
8,066✔
2179
  vInfo("vgId:%d, vnode handle msgType:alter-confirm, alter confirm msg is processed", TD_VID(pVnode));
8,066!
2180
  int32_t code = TSDB_CODE_SUCCESS;
8,066✔
2181
  if (!pVnode->config.hashChange) {
8,066✔
2182
    goto _exit;
8,024✔
2183
  }
2184

2185
  code = vnodeConsolidateAlterHashRange(pVnode, ver);
42✔
2186
  if (code < 0) {
42!
2187
    vError("vgId:%d, failed to consolidate alter hashrange since %s. version:%" PRId64, TD_VID(pVnode), terrstr(), ver);
×
2188
    goto _exit;
×
2189
  }
2190
  pVnode->config.hashChange = false;
42✔
2191

2192
_exit:
8,066✔
2193
  pRsp->msgType = TDMT_VND_ALTER_CONFIRM_RSP;
8,066✔
2194
  pRsp->code = code;
8,066✔
2195
  pRsp->pCont = NULL;
8,066✔
2196
  pRsp->contLen = 0;
8,066✔
2197

2198
  return code;
8,066✔
2199
}
2200

2201
extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb);
2202
extern void    tsdbEnableBgTask(STsdb *pTsdb);
2203

2204
static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
627✔
2205
  bool walChanged = false;
627✔
2206
  bool tsdbChanged = false;
627✔
2207

2208
  SAlterVnodeConfigReq req = {0};
627✔
2209
  if (tDeserializeSAlterVnodeConfigReq(pReq, len, &req) != 0) {
627!
2210
    terrno = TSDB_CODE_INVALID_MSG;
×
2211
    return TSDB_CODE_INVALID_MSG;
×
2212
  }
2213

2214
  vInfo("vgId:%d, start to alter vnode config, page:%d pageSize:%d buffer:%d szPage:%d szBuf:%" PRIu64
627!
2215
        " cacheLast:%d cacheLastSize:%d days:%d keep0:%d keep1:%d keep2:%d keepTimeOffset:%d s3KeepLocal:%d "
2216
        "s3Compact:%d fsync:%d level:%d "
2217
        "walRetentionPeriod:%d walRetentionSize:%d",
2218
        TD_VID(pVnode), req.pages, req.pageSize, req.buffer, req.pageSize * 1024, (uint64_t)req.buffer * 1024 * 1024,
2219
        req.cacheLast, req.cacheLastSize, req.daysPerFile, req.daysToKeep0, req.daysToKeep1, req.daysToKeep2,
2220
        req.keepTimeOffset, req.s3KeepLocal, req.s3Compact, req.walFsyncPeriod, req.walLevel, req.walRetentionPeriod,
2221
        req.walRetentionSize);
2222

2223
  if (pVnode->config.cacheLastSize != req.cacheLastSize) {
627✔
2224
    pVnode->config.cacheLastSize = req.cacheLastSize;
232✔
2225
    tsdbCacheSetCapacity(pVnode, (size_t)pVnode->config.cacheLastSize * 1024 * 1024);
232✔
2226
  }
2227

2228
  if (pVnode->config.szBuf != req.buffer * 1024LL * 1024LL) {
627!
2229
    vInfo("vgId:%d, vnode buffer is changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pVnode->config.szBuf,
×
2230
          (uint64_t)(req.buffer * 1024LL * 1024LL));
2231
    pVnode->config.szBuf = req.buffer * 1024LL * 1024LL;
×
2232
  }
2233

2234
  if (pVnode->config.szCache != req.pages) {
627!
2235
    if (metaAlterCache(pVnode->pMeta, req.pages) < 0) {
×
2236
      vError("vgId:%d, failed to change vnode pages from %d to %d failed since %s", TD_VID(pVnode),
×
2237
             pVnode->config.szCache, req.pages, tstrerror(errno));
2238
      return errno;
×
2239
    } else {
2240
      vInfo("vgId:%d, vnode pages is changed from %d to %d", TD_VID(pVnode), pVnode->config.szCache, req.pages);
×
2241
      pVnode->config.szCache = req.pages;
×
2242
    }
2243
  }
2244

2245
  if (pVnode->config.cacheLast != req.cacheLast) {
627✔
2246
    pVnode->config.cacheLast = req.cacheLast;
345✔
2247
  }
2248

2249
  if (pVnode->config.walCfg.fsyncPeriod != req.walFsyncPeriod) {
627✔
2250
    pVnode->config.walCfg.fsyncPeriod = req.walFsyncPeriod;
54✔
2251
    walChanged = true;
54✔
2252
  }
2253

2254
  if (pVnode->config.walCfg.level != req.walLevel) {
627✔
2255
    if (pVnode->config.walCfg.level == 0) {
36!
2256
      pVnode->config.walCfg.clearFiles = 1;
×
2257
    }
2258
    pVnode->config.walCfg.level = req.walLevel;
36✔
2259
    walChanged = true;
36✔
2260
  }
2261

2262
  if (pVnode->config.walCfg.retentionPeriod != req.walRetentionPeriod) {
627✔
2263
    pVnode->config.walCfg.retentionPeriod = req.walRetentionPeriod;
132✔
2264
    walChanged = true;
132✔
2265
  }
2266

2267
  if (pVnode->config.walCfg.retentionSize != req.walRetentionSize) {
627!
2268
    pVnode->config.walCfg.retentionSize = req.walRetentionSize;
×
2269
    walChanged = true;
×
2270
  }
2271

2272
  if (pVnode->config.tsdbCfg.keep0 != req.daysToKeep0) {
627✔
2273
    pVnode->config.tsdbCfg.keep0 = req.daysToKeep0;
54✔
2274
    if (!VND_IS_RSMA(pVnode)) {
54!
2275
      tsdbChanged = true;
54✔
2276
    }
2277
  }
2278

2279
  if (pVnode->config.tsdbCfg.keep1 != req.daysToKeep1) {
627✔
2280
    pVnode->config.tsdbCfg.keep1 = req.daysToKeep1;
54✔
2281
    if (!VND_IS_RSMA(pVnode)) {
54!
2282
      tsdbChanged = true;
54✔
2283
    }
2284
  }
2285

2286
  if (pVnode->config.tsdbCfg.keep2 != req.daysToKeep2) {
627✔
2287
    pVnode->config.tsdbCfg.keep2 = req.daysToKeep2;
56✔
2288
    if (!VND_IS_RSMA(pVnode)) {
56!
2289
      tsdbChanged = true;
56✔
2290
    }
2291
  }
2292

2293
  if (pVnode->config.tsdbCfg.keepTimeOffset != req.keepTimeOffset) {
627✔
2294
    pVnode->config.tsdbCfg.keepTimeOffset = req.keepTimeOffset;
2✔
2295
    if (!VND_IS_RSMA(pVnode)) {
2!
2296
      tsdbChanged = true;
2✔
2297
    }
2298
  }
2299

2300
  if (req.sttTrigger != -1 && req.sttTrigger != pVnode->config.sttTrigger) {
627!
2301
    if (req.sttTrigger > 1 && pVnode->config.sttTrigger > 1) {
×
2302
      pVnode->config.sttTrigger = req.sttTrigger;
×
2303
    } else {
2304
      vnodeAWait(&pVnode->commitTask);
×
2305

2306
      int32_t ret = tsdbDisableAndCancelAllBgTask(pVnode->pTsdb);
×
2307
      if (ret != 0) {
×
2308
        vError("vgId:%d, failed to disable bg task since %s", TD_VID(pVnode), tstrerror(errno));
×
2309
      }
2310

2311
      pVnode->config.sttTrigger = req.sttTrigger;
×
2312
      tsdbEnableBgTask(pVnode->pTsdb);
×
2313
    }
2314
  }
2315

2316
  if (req.minRows != -1 && req.minRows != pVnode->config.tsdbCfg.minRows) {
627!
2317
    pVnode->config.tsdbCfg.minRows = req.minRows;
×
2318
  }
2319

2320
  if (req.s3KeepLocal != -1 && req.s3KeepLocal != pVnode->config.s3KeepLocal) {
627!
2321
    pVnode->config.s3KeepLocal = req.s3KeepLocal;
×
2322
  }
2323
  if (req.s3Compact != -1 && req.s3Compact != pVnode->config.s3Compact) {
627!
2324
    pVnode->config.s3Compact = req.s3Compact;
×
2325
  }
2326

2327
  if (walChanged) {
627✔
2328
    if (walAlter(pVnode->pWal, &pVnode->config.walCfg) != 0) {
222!
2329
      vError("vgId:%d, failed to alter wal config since %s", TD_VID(pVnode), tstrerror(errno));
×
2330
    }
2331
  }
2332

2333
  if (tsdbChanged) {
627✔
2334
    tsdbSetKeepCfg(pVnode->pTsdb, &pVnode->config.tsdbCfg);
58✔
2335
  }
2336

2337
  return 0;
627✔
2338
}
2339

2340
static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
3,002✔
2341
  SBatchDeleteReq deleteReq;
2342
  SDecoder        decoder;
2343
  tDecoderInit(&decoder, pReq, len);
3,002✔
2344
  if (tDecodeSBatchDeleteReq(&decoder, &deleteReq) < 0) {
3,002!
2345
    tDecoderClear(&decoder);
×
2346
    return terrno = TSDB_CODE_INVALID_MSG;
×
2347
  }
2348

2349
  SMetaReader mr = {0};
3,001✔
2350
  metaReaderDoInit(&mr, pVnode->pMeta, META_READER_NOLOCK);
3,001✔
2351
  STsdb *pTsdb = pVnode->pTsdb;
3,003✔
2352

2353
  if (deleteReq.level) {
3,003✔
2354
    pTsdb = deleteReq.level == 1 ? VND_RSMA1(pVnode) : VND_RSMA2(pVnode);
16✔
2355
  }
2356

2357
  int32_t sz = taosArrayGetSize(deleteReq.deleteReqs);
3,003✔
2358
  for (int32_t i = 0; i < sz; i++) {
6,830✔
2359
    SSingleDeleteReq *pOneReq = taosArrayGet(deleteReq.deleteReqs, i);
3,827✔
2360
    char             *name = pOneReq->tbname;
3,826✔
2361
    if (metaGetTableEntryByName(&mr, name) < 0) {
3,826✔
2362
      vDebug("vgId:%d, stream delete msg, skip since no table: %s", pVnode->config.vgId, name);
1,944✔
2363
      continue;
1,944✔
2364
    }
2365

2366
    int64_t uid = mr.me.uid;
1,884✔
2367

2368
    int32_t code = tsdbDeleteTableData(pTsdb, ver, deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
1,884✔
2369
    if (code < 0) {
1,885!
2370
      terrno = code;
×
2371
      vError("vgId:%d, delete error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64 ", end ts:%" PRId64,
×
2372
             TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
2373
    }
2374

2375
    if (deleteReq.level == 0) {
1,885✔
2376
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, deleteReq.ctimeMs);
1,269✔
2377
      if (code < 0) {
1,269!
2378
        terrno = code;
×
2379
        vError("vgId:%d, update change time error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64
×
2380
               ", end ts:%" PRId64,
2381
               TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
2382
      }
2383
    }
2384
    tDecoderClear(&mr.coder);
1,885✔
2385
  }
2386
  metaReaderClear(&mr);
3,003✔
2387
  taosArrayDestroy(deleteReq.deleteReqs);
3,004✔
2388
  return 0;
3,005✔
2389
}
2390

2391
static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
62,936✔
2392
                                     SRpcMsg *pOriginalMsg) {
2393
  int32_t     code = 0;
62,936✔
2394
  SDecoder   *pCoder = &(SDecoder){0};
62,936✔
2395
  SDeleteRes *pRes = &(SDeleteRes){0};
62,936✔
2396

2397
  pRsp->msgType = TDMT_VND_DELETE_RSP;
62,936✔
2398
  pRsp->pCont = NULL;
62,936✔
2399
  pRsp->contLen = 0;
62,936✔
2400
  pRsp->code = TSDB_CODE_SUCCESS;
62,936✔
2401

2402
  pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t));
62,936✔
2403
  if (pRes->uidList == NULL) {
62,938!
2404
    code = terrno;
×
2405
    goto _err;
×
2406
  }
2407

2408
  tDecoderInit(pCoder, pReq, len);
62,938✔
2409
  code = tDecodeDeleteRes(pCoder, pRes);
62,937✔
2410
  if (code) goto _err;
62,941!
2411

2412
  if (pRes->affectedRows > 0) {
62,941✔
2413
    for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) {
118,261✔
2414
      uint64_t uid = *(uint64_t *)taosArrayGet(pRes->uidList, iUid);
59,948✔
2415
      code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, uid, pRes->skey, pRes->ekey);
59,949✔
2416
      if (code) goto _err;
59,952!
2417
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, pRes->ctimeMs);
59,952✔
2418
      if (code) goto _err;
59,951!
2419
    }
2420
  }
2421

2422
  code = tdProcessRSmaDelete(pVnode->pSma, ver, pRes, pReq, len);
62,940✔
2423

2424
  tDecoderClear(pCoder);
62,942✔
2425
  taosArrayDestroy(pRes->uidList);
62,942✔
2426

2427
  SVDeleteRsp rsp = {.affectedRows = pRes->affectedRows};
62,945✔
2428
  int32_t     ret = 0;
62,945✔
2429
  tEncodeSize(tEncodeSVDeleteRsp, &rsp, pRsp->contLen, ret);
62,945!
2430
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
62,941✔
2431
  SEncoder ec = {0};
62,945✔
2432
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
62,945✔
2433
  code = tEncodeSVDeleteRsp(&ec, &rsp);
62,945✔
2434
  if (code) goto _err;
62,942!
2435
  tEncoderClear(&ec);
62,942✔
2436
  return code;
62,943✔
2437

2438
_err:
×
2439
  /*
2440
  if(code == TSDB_CODE_SUCCESS){
2441
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_DELETE, pVnode->monitor.strClusterId,
2442
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2443
                                        pOriginalMsg->info.conn.user, "Success"};
2444
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2445
  }
2446
  else{
2447
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_DELETE, pVnode->monitor.strClusterId,
2448
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2449
                                        pOriginalMsg->info.conn.user, "Failed"};
2450
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2451
  }
2452
  */
2453

2454
  return code;
×
2455
}
2456
static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
939✔
2457
  SVCreateStbReq req = {0};
939✔
2458
  SDecoder       dc = {0};
939✔
2459
  int32_t        code = 0;
939✔
2460

2461
  pRsp->msgType = TDMT_VND_CREATE_INDEX_RSP;
939✔
2462
  pRsp->code = TSDB_CODE_SUCCESS;
939✔
2463
  pRsp->pCont = NULL;
939✔
2464
  pRsp->contLen = 0;
939✔
2465

2466
  tDecoderInit(&dc, pReq, len);
939✔
2467
  // decode req
2468
  if (tDecodeSVCreateStbReq(&dc, &req) < 0) {
939!
2469
    tDecoderClear(&dc);
×
2470
    return terrno = TSDB_CODE_INVALID_MSG;
×
2471
  }
2472

2473
  code = metaAddIndexToSuperTable(pVnode->pMeta, ver, &req);
939✔
2474
  if (code) {
939!
2475
    pRsp->code = code;
×
2476
    goto _err;
×
2477
  }
2478
  tDecoderClear(&dc);
939✔
2479
  return 0;
939✔
2480

2481
_err:
×
2482
  tDecoderClear(&dc);
×
2483
  return code;
×
2484
}
2485
static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
2,114✔
2486
  SDropIndexReq req = {0};
2,114✔
2487
  int32_t       code = 0;
2,114✔
2488
  pRsp->msgType = TDMT_VND_DROP_INDEX_RSP;
2,114✔
2489
  pRsp->code = TSDB_CODE_SUCCESS;
2,114✔
2490
  pRsp->pCont = NULL;
2,114✔
2491
  pRsp->contLen = 0;
2,114✔
2492

2493
  if ((code = tDeserializeSDropIdxReq(pReq, len, &req))) {
2,114!
2494
    pRsp->code = code;
×
2495
    return code;
×
2496
  }
2497

2498
  code = metaDropIndexFromSuperTable(pVnode->pMeta, ver, &req);
2,114✔
2499
  if (code) {
2,114!
2500
    pRsp->code = code;
×
2501
    return code;
×
2502
  }
2503
  return TSDB_CODE_SUCCESS;
2,114✔
2504
}
2505

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

2508
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
202✔
2509
  if (!pVnode->restored) {
202✔
2510
    vInfo("vgId:%d, ignore compact req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
173!
2511
    return 0;
173✔
2512
  }
2513
  return vnodeAsyncCompact(pVnode, ver, pReq, len, pRsp);
29✔
2514
}
2515

2516
static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
2517
  if (syncCheckMember(pVnode->sync) != 0) {
×
2518
    vError("vgId:%d, failed to check member", TD_VID(pVnode));
×
2519
  }
2520

2521
  pRsp->msgType = TDMT_SYNC_CONFIG_CHANGE_RSP;
×
2522
  pRsp->code = TSDB_CODE_SUCCESS;
×
2523
  pRsp->pCont = NULL;
×
2524
  pRsp->contLen = 0;
×
2525

2526
  return 0;
×
2527
}
2528

2529
static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
1✔
2530
  SSyncState syncState = syncGetState(pVnode->sync);
1✔
2531
  if (syncState.state != TAOS_SYNC_STATE_LEADER) {
1!
2532
    return terrno = TSDB_CODE_SYN_NOT_LEADER;
1✔
2533
  }
2534

2535
  char token[TSDB_ARB_TOKEN_SIZE] = {0};
×
2536
  if (vnodeGetArbToken(pVnode, token) != 0) {
×
2537
    return terrno = TSDB_CODE_NOT_FOUND;
×
2538
  }
2539

2540
  if (strncmp(token, member0Token, TSDB_ARB_TOKEN_SIZE) != 0 &&
×
2541
      strncmp(token, member1Token, TSDB_ARB_TOKEN_SIZE) != 0) {
×
2542
    return terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
×
2543
  }
2544

2545
  terrno = TSDB_CODE_SUCCESS;
×
2546
  return 0;
×
2547
}
2548

2549
static int32_t vnodeCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
1✔
2550
  int32_t code = vnodePreCheckAssignedLogSyncd(pVnode, member0Token, member1Token);
1✔
2551
  if (code != 0) {
1!
2552
    return code;
1✔
2553
  }
2554

2555
  return syncGetAssignedLogSynced(pVnode->sync);
×
2556
}
2557

2558
static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) {
1✔
2559
  int32_t code = 0;
1✔
2560

2561
  SVArbCheckSyncReq syncReq = {0};
1✔
2562

2563
  code = tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq);
1✔
2564
  if (code) {
1!
2565
    return terrno = code;
×
2566
  }
2567

2568
  pRsp->msgType = TDMT_VND_ARB_CHECK_SYNC_RSP;
1✔
2569
  pRsp->code = TSDB_CODE_SUCCESS;
1✔
2570
  pRsp->pCont = NULL;
1✔
2571
  pRsp->contLen = 0;
1✔
2572

2573
  SVArbCheckSyncRsp syncRsp = {0};
1✔
2574
  syncRsp.arbToken = syncReq.arbToken;
1✔
2575
  syncRsp.member0Token = syncReq.member0Token;
1✔
2576
  syncRsp.member1Token = syncReq.member1Token;
1✔
2577
  syncRsp.vgId = TD_VID(pVnode);
1✔
2578

2579
  if (vnodeCheckAssignedLogSyncd(pVnode, syncReq.member0Token, syncReq.member1Token) != 0) {
1!
2580
    vError("vgId:%d, failed to check assigned log syncd", TD_VID(pVnode));
1!
2581
  }
2582
  syncRsp.errCode = terrno;
1✔
2583

2584
  if (vnodeUpdateArbTerm(pVnode, syncReq.arbTerm) != 0) {
1!
2585
    vError("vgId:%d, failed to update arb term", TD_VID(pVnode));
×
2586
    code = -1;
×
2587
    goto _OVER;
×
2588
  }
2589

2590
  int32_t contLen = tSerializeSVArbCheckSyncRsp(NULL, 0, &syncRsp);
1✔
2591
  if (contLen <= 0) {
1!
2592
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2593
    code = -1;
×
2594
    goto _OVER;
×
2595
  }
2596
  void *pHead = rpcMallocCont(contLen);
1✔
2597
  if (!pHead) {
1!
2598
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2599
    code = -1;
×
2600
    goto _OVER;
×
2601
  }
2602

2603
  if (tSerializeSVArbCheckSyncRsp(pHead, contLen, &syncRsp) <= 0) {
1!
2604
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2605
    rpcFreeCont(pHead);
×
2606
    code = -1;
×
2607
    goto _OVER;
×
2608
  }
2609

2610
  pRsp->pCont = pHead;
1✔
2611
  pRsp->contLen = contLen;
1✔
2612

2613
  terrno = TSDB_CODE_SUCCESS;
1✔
2614

2615
_OVER:
1✔
2616
  tFreeSVArbCheckSyncReq(&syncReq);
1✔
2617
  return code;
1✔
2618
}
2619

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