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

taosdata / TDengine / #3543

29 Nov 2024 02:58AM UTC coverage: 60.842% (+0.02%) from 60.819%
#3543

push

travis-ci

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

merge: from main to 3.0

120460 of 253224 branches covered (47.57%)

Branch coverage included in aggregate %.

706 of 908 new or added lines in 18 files covered. (77.75%)

2401 existing lines in 137 files now uncovered.

201633 of 276172 relevant lines covered (73.01%)

19045673.23 hits per line

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

59.49
/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) {
175,760✔
64
  int32_t code = 0;
175,760✔
65
  int32_t lino = 0;
175,760✔
66

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

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

78
  // name
79
  char *name = NULL;
175,818✔
80
  if (tDecodeCStr(pCoder, &name) < 0) {
175,773!
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);
175,773✔
87
  if (uid == 0) {
175,772✔
88
    uid = tGenIdPI64();
149,069✔
89
  }
90
  *(int64_t *)(pCoder->data + pCoder->pos) = uid;
175,785✔
91

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

95
  tEndDecode(pCoder);
175,785✔
96

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

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

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

120
  if (tDecodeI32v(&dc, &nReqs) < 0) {
78,116!
121
    code = TSDB_CODE_INVALID_MSG;
×
122
    TSDB_CHECK_CODE(code, lino, _exit);
×
123
  }
124
  for (int32_t iReq = 0; iReq < nReqs; iReq++) {
181,610✔
125
    code = vnodePreprocessCreateTableReq(pVnode, &dc, btime, NULL);
103,516✔
126
    TSDB_CHECK_CODE(code, lino, _exit);
103,494!
127
  }
128

129
  tEndDecode(&dc);
78,094✔
130

131
_exit:
78,112✔
132
  tDecoderClear(&dc);
78,112✔
133
  if (code) {
78,118!
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;
78,111✔
138
}
139

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

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

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

157
  code = 0;
5,188✔
158

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

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

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

177
  SArray *tbUids = NULL;
92,406✔
178
  int64_t timestampMs = 0;
92,406✔
179

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

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

200
    ttlReq.nUids = taosArrayGetSize(tbUids);
92,555✔
201
    ttlReq.pTbUids = tbUids;
92,381✔
202
  }
203

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

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

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

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

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

230
  code = 0;
38✔
231

232
_exit:
92,472✔
233
  taosArrayDestroy(tbUids);
92,472✔
234

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

242
  return code;
92,546✔
243
}
244

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

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

264
  int64_t uid;
265
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
10,880,378✔
266
    code = vnodePreprocessCreateTableReq(pVnode, pCoder, btimeMs, &uid);
72,250✔
267
    TSDB_CHECK_CODE(code, lino, _exit);
72,259!
268
  }
269

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

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

291
  // scan and check
292
  TSKEY now = btimeMs;
10,856,971✔
293
  if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_MICRO) {
10,856,971✔
294
    now *= 1000;
23,163✔
295
  } else if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_NANO) {
10,833,808✔
296
    now *= 1000000;
3,763✔
297
  }
298

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

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

327
    for (int32_t iRow = 0; iRow < colData.nVal; iRow++) {
424✔
328
      if (((TSKEY *)colData.pData)[iRow] < minKey || ((TSKEY *)colData.pData)[iRow] > maxKey) {
270!
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++) {
686✔
335
      pCoder->pos += tGetColData(version, pCoder->data + pCoder->pos, &colData);
532✔
336
    }
337
  } else {
338
    uint64_t nRow;
339
    if (tDecodeU64v(pCoder, &nRow) < 0) {
10,861,135!
340
      code = TSDB_CODE_INVALID_MSG;
×
341
      goto _exit;
494✔
342
    }
343

344
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
765,846,962✔
345
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
754,986,321✔
346
      pCoder->pos += pRow->len;
754,986,321✔
347

348
      if (pRow->ts < minKey || pRow->ts > maxKey) {
754,986,321!
349
        code = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
494✔
350
        goto _exit;
494✔
351
      }
352
    }
353
  }
354

355
  if (!tDecodeIsEnd(pCoder)) {
10,860,795!
356
    *(int64_t *)(pCoder->data + pCoder->pos) = ctimeMs;
10,862,728✔
357
    pCoder->pos += sizeof(int64_t);
10,862,728✔
358
  }
359

360
  tEndDecode(pCoder);
10,860,795✔
361

362
_exit:
10,859,865✔
363
  return code;
10,859,865✔
364
}
365
static int32_t vnodePreProcessSubmitMsg(SVnode *pVnode, SRpcMsg *pMsg) {
10,156,557✔
366
  int32_t code = 0;
10,156,557✔
367
  int32_t lino = 0;
10,156,557✔
368

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

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

375
  if (taosHton64(((SSubmitReq2Msg *)pMsg->pCont)->version) != 1) {
10,156,557!
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,156,638✔
381

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

393
  int64_t btimeMs = taosGetTimestampMs();
10,156,642✔
394
  int64_t ctimeMs = btimeMs;
10,156,642✔
395
  for (int32_t i = 0; i < nSubmitTbData; i++) {
21,015,846✔
396
    code = vnodePreProcessSubmitTbData(pVnode, pCoder, btimeMs, ctimeMs);
10,860,429✔
397
    TSDB_CHECK_CODE(code, lino, _exit);
10,859,699✔
398
  }
399

400
  tEndDecode(pCoder);
10,155,417✔
401

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

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

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

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

423
  code = qWorkerProcessDeleteMsg(&handle, pVnode->pQuery, pMsg, &res);
60,125✔
424
  if (code) goto _exit;
60,130!
425

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

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

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

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

444
  taosArrayDestroy(res.uidList);
60,129✔
445

446
_exit:
60,130✔
447
  return code;
60,130✔
448
}
449

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

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

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

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

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

467
  if (code) {
2,894!
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,894✔
471
  }
472
  return code;
2,892✔
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) {
16,046✔
495
  int32_t          code = TSDB_CODE_SUCCESS;
16,046✔
496
  int32_t          lino = 0;
16,046✔
497
  int32_t          size = 0;
16,046✔
498
  SDecoder         dc = {0};
16,046✔
499
  SEncoder         ec = {0};
16,046✔
500
  SVDropTbBatchReq receivedBatchReqs = {0};
16,046✔
501
  SVDropTbBatchReq sentBatchReqs = {0};
16,046✔
502

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

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

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

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

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

552
  switch (pMsg->msgType) {
10,522,047!
553
    case TDMT_VND_CREATE_TABLE: {
78,115✔
554
      code = vnodePreProcessCreateTableMsg(pVnode, pMsg);
78,115✔
555
    } break;
78,110✔
556
    case TDMT_VND_ALTER_TABLE: {
5,188✔
557
      code = vnodePreProcessAlterTableMsg(pVnode, pMsg);
5,188✔
558
    } break;
5,188✔
559
    case TDMT_VND_FETCH_TTL_EXPIRED_TBS:
92,789✔
560
    case TDMT_VND_DROP_TTL_TABLE: {
561
      code = vnodePreProcessDropTtlMsg(pVnode, pMsg);
92,789✔
562
    } break;
92,510✔
563
    case TDMT_VND_SUBMIT: {
10,156,658✔
564
      code = vnodePreProcessSubmitMsg(pVnode, pMsg);
10,156,658✔
565
    } break;
10,156,591✔
566
    case TDMT_VND_DELETE: {
60,126✔
567
      code = vnodePreProcessDeleteMsg(pVnode, pMsg);
60,126✔
568
    } break;
60,128✔
569
    case TDMT_VND_BATCH_DEL: {
2,893✔
570
      code = vnodePreProcessBatchDeleteMsg(pVnode, pMsg);
2,893✔
571
    } break;
2,889✔
572
    case TDMT_VND_ARB_CHECK_SYNC: {
×
573
      code = vnodePreProcessArbCheckSyncMsg(pVnode, pMsg);
×
574
    } break;
×
575
    case TDMT_VND_DROP_TABLE: {
16,046✔
576
      code = vnodePreProcessDropTbMsg(pVnode, pMsg);
16,046✔
577
    } break;
16,046✔
578
    default:
110,232✔
579
      break;
110,232✔
580
  }
581

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

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

595
  (void)taosThreadMutexLock(&pVnode->mutex);
13,408,136✔
596
  if (pVnode->disableWrite) {
13,408,624!
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,408,624✔
602

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

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

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

622
  atomic_store_64(&pVnode->state.applied, ver);
13,408,348✔
623
  atomic_store_64(&pVnode->state.applyTerm, pMsg->info.conn.applyTerm);
13,408,619✔
624

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

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

632
  switch (pMsg->msgType) {
13,380,567!
633
    /* META */
634
    case TDMT_VND_CREATE_STB:
30,828✔
635
      if (vnodeProcessCreateStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
30,828✔
636
      break;
30,833✔
637
    case TDMT_VND_ALTER_STB:
4,940✔
638
      if (vnodeProcessAlterStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
4,940!
639
      break;
4,951✔
640
    case TDMT_VND_DROP_STB:
3,460✔
641
      if (vnodeProcessDropStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
3,460!
642
      break;
3,462✔
643
    case TDMT_VND_CREATE_TABLE:
86,423✔
644
      if (vnodeProcessCreateTbReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
86,423!
645
      break;
86,445✔
646
    case TDMT_VND_ALTER_TABLE:
5,192✔
647
      if (vnodeProcessAlterTbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
5,192!
648
      break;
5,192✔
649
    case TDMT_VND_DROP_TABLE:
16,088✔
650
      if (vnodeProcessDropTbReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
16,088!
651
      break;
16,088✔
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:
38✔
656
      if (vnodeProcessFetchTtlExpiredTbs(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
38!
657
      break;
38✔
658
    case TDMT_VND_TRIM:
230✔
659
      if (vnodeProcessTrimReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
230!
660
      break;
230✔
661
    case TDMT_VND_S3MIGRATE:
×
662
      if (vnodeProcessS3MigrateReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
×
663
      break;
×
664
    case TDMT_VND_CREATE_SMA:
33✔
665
      if (vnodeProcessCreateTSmaReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
33!
666
      break;
33✔
667
    /* TSDB */
668
    case TDMT_VND_SUBMIT:
13,071,283✔
669
      if (vnodeProcessSubmitReq(pVnode, ver, pMsg->pCont, pMsg->contLen, pRsp, pMsg) < 0) goto _err;
13,071,283✔
670
      break;
13,071,290✔
671
    case TDMT_VND_DELETE:
63,516✔
672
      if (vnodeProcessDeleteReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
63,516!
673
      break;
63,516✔
674
    case TDMT_VND_BATCH_DEL:
3,257✔
675
      if (vnodeProcessBatchDeleteReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
3,257!
676
      break;
3,260✔
677
    /* TQ */
678
    case TDMT_VND_TMQ_SUBSCRIBE:
4,226✔
679
      if (tqProcessSubscribeReq(pVnode->pTq, ver, pReq, len) < 0) {
4,226✔
680
        goto _err;
1✔
681
      }
682
      break;
4,229✔
683
    case TDMT_VND_TMQ_DELETE_SUB:
883✔
684
      if (tqProcessDeleteSubReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen) < 0) {
883!
685
        goto _err;
×
686
      }
687
      break;
885✔
688
    case TDMT_VND_TMQ_COMMIT_OFFSET:
9,187✔
689
      if (tqProcessOffsetCommitReq(pVnode->pTq, ver, pReq, len) < 0) {
9,187!
690
        goto _err;
×
691
      }
692
      break;
9,192✔
693
    case TDMT_VND_TMQ_ADD_CHECKINFO:
131✔
694
      if (tqProcessAddCheckInfoReq(pVnode->pTq, ver, pReq, len) < 0) {
131!
695
        goto _err;
×
696
      }
697
      break;
133✔
698
    case TDMT_VND_TMQ_DEL_CHECKINFO:
26✔
699
      if (tqProcessDelCheckInfoReq(pVnode->pTq, ver, pReq, len) < 0) {
26✔
700
        goto _err;
2✔
701
      }
702
      break;
24✔
703
    case TDMT_STREAM_TASK_DEPLOY: {
13,744✔
704
      if ((code = tqProcessTaskDeployReq(pVnode->pTq, ver, pReq, len)) != TSDB_CODE_SUCCESS) {
13,744!
705
        goto _err;
×
706
      }
707
    } break;
13,766✔
708
    case TDMT_STREAM_TASK_DROP: {
6,926✔
709
      if ((code = tqProcessTaskDropReq(pVnode->pTq, pMsg->pCont, pMsg->contLen)) < 0) {
6,926!
710
        goto _err;
×
711
      }
712
    } break;
6,945✔
713
    case TDMT_STREAM_TASK_UPDATE_CHKPT: {
6,877✔
714
      if ((code = tqProcessTaskUpdateCheckpointReq(pVnode->pTq, pMsg->pCont, pMsg->contLen)) < 0) {
6,877!
715
        goto _err;
×
716
      }
717
    } break;
6,890✔
718
    case TDMT_STREAM_CONSEN_CHKPT: {
154✔
719
      if (pVnode->restored && (code = tqProcessTaskConsenChkptIdReq(pVnode->pTq, pMsg)) < 0) {
154!
720
        goto _err;
×
721
      }
722

723
    } break;
154✔
724
    case TDMT_STREAM_TASK_PAUSE: {
2,065✔
725
      if (pVnode->restored && vnodeIsLeader(pVnode) &&
3,448!
726
          (code = tqProcessTaskPauseReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen)) < 0) {
1,382✔
727
        goto _err;
×
728
      }
729
    } break;
2,066✔
730
    case TDMT_STREAM_TASK_RESUME: {
2,060✔
731
      if (pVnode->restored && vnodeIsLeader(pVnode) &&
3,436!
732
          (code = tqProcessTaskResumeReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen)) < 0) {
1,375✔
733
        goto _err;
×
734
      }
735
    } break;
2,060✔
736
    case TDMT_VND_STREAM_TASK_RESET: {
×
NEW
737
      if (pVnode->restored && vnodeIsLeader(pVnode) && (code = tqProcessTaskResetReq(pVnode->pTq, pMsg)) < 0) {
×
NEW
738
        goto _err;
×
739
      }
740

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

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

789
  walApplyVer(pVnode->pWal, ver);
13,380,456✔
790

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

797
  // commit if need
798
  if (needCommit) {
13,380,038✔
799
    vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), ver);
31,628!
800
    code = vnodeAsyncCommit(pVnode);
31,644✔
801
    if (code) {
31,648!
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);
31,648✔
808
    if (code) {
31,640✔
809
      vError("vgId:%d, failed to begin vnode since %s.", TD_VID(pVnode), tstrerror(terrno));
69!
810
      goto _err;
×
811
    }
812
  }
813

814
_exit:
13,379,981✔
815
  return 0;
13,407,717✔
816

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

823
int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
8,275,473✔
824
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) {
8,275,473✔
825
    return 0;
572,756✔
826
  }
827

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

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

838
  if (pMsg->msgType == TDMT_VND_TMQ_CONSUME && !pVnode->restored) {
8,286,004!
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,286,004✔
844
  initStorageAPI(&handle.api);
8,286,004✔
845

846
  switch (pMsg->msgType) {
8,283,557!
847
    case TDMT_SCH_QUERY:
7,712,599✔
848
    case TDMT_SCH_MERGE_QUERY:
849
      return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
7,712,599✔
850
    case TDMT_SCH_QUERY_CONTINUE:
461,829✔
851
      return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
461,829✔
852
    case TDMT_VND_TMQ_CONSUME:
79,547✔
853
      return tqProcessPollReq(pVnode->pTq, pMsg);
79,547✔
854
    case TDMT_VND_TMQ_CONSUME_PUSH:
30,000✔
855
      return tqProcessPollPush(pVnode->pTq, pMsg);
30,000✔
856
    default:
×
857
      vError("unknown msg type:%d in query queue", pMsg->msgType);
×
858
      return TSDB_CODE_APP_ERROR;
×
859
  }
860
}
861

862
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
20,801,301✔
863
  vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg);
20,801,301✔
864
  if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
20,801,301!
865
       pMsg->msgType == TDMT_VND_BATCH_META || pMsg->msgType == TDMT_VND_TABLE_NAME) &&
14,413,619✔
866
      !syncIsReadyForRead(pVnode->sync)) {
7,512,124✔
867
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
3,999✔
868
    return 0;
3,999✔
869
  }
870

871
  switch (pMsg->msgType) {
20,799,995!
872
    case TDMT_SCH_FETCH:
9,961,105✔
873
    case TDMT_SCH_MERGE_FETCH:
874
      return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg, 0);
9,961,105✔
875
    case TDMT_SCH_FETCH_RSP:
×
876
      return qWorkerProcessRspMsg(pVnode, pVnode->pQuery, pMsg, 0);
×
877
    // case TDMT_SCH_CANCEL_TASK:
878
    //   return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg, 0);
879
    case TDMT_SCH_DROP_TASK:
7,709,345✔
880
      return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg, 0);
7,709,345✔
881
    case TDMT_SCH_TASK_NOTIFY:
219✔
882
      return qWorkerProcessNotifyMsg(pVnode, pVnode->pQuery, pMsg, 0);
219✔
883
    case TDMT_SCH_QUERY_HEARTBEAT:
2,007,652✔
884
      return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg, 0);
2,007,652✔
885
    case TDMT_VND_TABLE_META:
3,101✔
886
    case TDMT_VND_TABLE_NAME:
887
      return vnodeGetTableMeta(pVnode, pMsg, true);
3,101✔
888
    case TDMT_VND_TABLE_CFG:
×
889
      return vnodeGetTableCfg(pVnode, pMsg, true);
×
890
    case TDMT_VND_BATCH_META:
1,118,475✔
891
      return vnodeGetBatchMeta(pVnode, pMsg);
1,118,475✔
892
#ifdef TD_ENTERPRISE
893
    case TDMT_VND_QUERY_COMPACT_PROGRESS:
60✔
894
      return vnodeQueryCompactProgress(pVnode, pMsg);
60✔
895
#endif
896
      //    case TDMT_VND_TMQ_CONSUME:
897
      //      return tqProcessPollReq(pVnode->pTq, pMsg);
898
    case TDMT_VND_TMQ_VG_WALINFO:
12✔
899
      return tqProcessVgWalInfoReq(pVnode->pTq, pMsg);
12✔
900
    case TDMT_VND_TMQ_VG_COMMITTEDINFO:
2✔
901
      return tqProcessVgCommittedInfoReq(pVnode->pTq, pMsg);
2✔
902
    case TDMT_VND_TMQ_SEEK:
24✔
903
      return tqProcessSeekReq(pVnode->pTq, pMsg);
24✔
904

905
    default:
×
906
      vError("unknown msg type:%d in fetch queue", pMsg->msgType);
×
907
      return TSDB_CODE_APP_ERROR;
×
908
  }
909
}
910

911
int32_t vnodeProcessStreamMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
416,284✔
912
  vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg);
416,284✔
913
  if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
416,284!
914
       pMsg->msgType == TDMT_VND_BATCH_META) &&
416,306!
UNCOV
915
      !syncIsReadyForRead(pVnode->sync)) {
×
916
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
×
917
    return 0;
×
918
  }
919

920
  switch (pMsg->msgType) {
416,338!
921
    case TDMT_STREAM_TASK_RUN:
215,648✔
922
      return tqProcessTaskRunReq(pVnode->pTq, pMsg);
215,648✔
923
    case TDMT_STREAM_TASK_DISPATCH:
52,193✔
924
      return tqProcessTaskDispatchReq(pVnode->pTq, pMsg);
52,193✔
925
    case TDMT_STREAM_TASK_DISPATCH_RSP:
52,440✔
926
      return tqProcessTaskDispatchRsp(pVnode->pTq, pMsg);
52,440✔
927
    case TDMT_VND_STREAM_TASK_CHECK:
21,411✔
928
      return tqProcessTaskCheckReq(pVnode->pTq, pMsg);
21,411✔
929
    case TDMT_VND_STREAM_TASK_CHECK_RSP:
21,515✔
930
      return tqProcessTaskCheckRsp(pVnode->pTq, pMsg);
21,515✔
931
    case TDMT_STREAM_RETRIEVE:
541✔
932
      return tqProcessTaskRetrieveReq(pVnode->pTq, pMsg);
541✔
933
    case TDMT_STREAM_RETRIEVE_RSP:
430✔
934
      return tqProcessTaskRetrieveRsp(pVnode->pTq, pMsg);
430✔
935
    case TDMT_VND_STREAM_SCAN_HISTORY:
2,583✔
936
      return tqProcessTaskScanHistory(pVnode->pTq, pMsg);
2,583✔
937
    case TDMT_STREAM_TASK_CHECKPOINT_READY:
8,148✔
938
      return tqProcessTaskCheckpointReadyMsg(pVnode->pTq, pMsg);
8,148✔
939
    case TDMT_STREAM_TASK_CHECKPOINT_READY_RSP:
8,145✔
940
      return tqProcessTaskCheckpointReadyRsp(pVnode->pTq, pMsg);
8,145✔
941
    case TDMT_STREAM_RETRIEVE_TRIGGER:
×
942
      return tqProcessTaskRetrieveTriggerReq(pVnode->pTq, pMsg);
×
943
    case TDMT_STREAM_RETRIEVE_TRIGGER_RSP:
×
944
      return tqProcessTaskRetrieveTriggerRsp(pVnode->pTq, pMsg);
×
945
    case TDMT_MND_STREAM_HEARTBEAT_RSP:
22,343✔
946
      return tqProcessStreamHbRsp(pVnode->pTq, pMsg);
22,343✔
947
    case TDMT_MND_STREAM_REQ_CHKPT_RSP:
4,702✔
948
      return tqProcessStreamReqCheckpointRsp(pVnode->pTq, pMsg);
4,702✔
949
    case TDMT_VND_GET_STREAM_PROGRESS:
×
950
      return tqStreamProgressRetrieveReq(pVnode->pTq, pMsg);
×
951
    case TDMT_MND_STREAM_CHKPT_REPORT_RSP:
6,239✔
952
      return tqProcessTaskChkptReportRsp(pVnode->pTq, pMsg);
6,239✔
953
    default:
×
954
      vError("unknown msg type:%d in stream queue", pMsg->msgType);
×
955
      return TSDB_CODE_APP_ERROR;
×
956
  }
957
}
958

959
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
5✔
960
  int32_t code = tdProcessTSmaInsert(((SVnode *)pVnode)->pSma, smaId, (const char *)data);
5✔
961
  if (code) {
5!
962
    vError("failed to process sma result since %s", tstrerror(code));
×
963
  }
964
}
5✔
965

966
void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) {
181,094✔
967
  if (NULL == pMetaRsp) {
181,094!
968
    return;
×
969
  }
970

971
  strcpy(pMetaRsp->dbFName, pVnode->config.dbname);
181,094✔
972
  pMetaRsp->dbId = pVnode->config.dbId;
181,094✔
973
  pMetaRsp->vgId = TD_VID(pVnode);
181,094✔
974
  pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
181,094✔
975
}
976

977
extern int32_t vnodeAsyncRetention(SVnode *pVnode, int64_t now);
978

979
static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
230✔
980
  int32_t     code = 0;
230✔
981
  SVTrimDbReq trimReq = {0};
230✔
982

983
  // decode
984
  if (tDeserializeSVTrimDbReq(pReq, len, &trimReq) != 0) {
230!
985
    code = TSDB_CODE_INVALID_MSG;
×
986
    goto _exit;
×
987
  }
988

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

991
  code = vnodeAsyncRetention(pVnode, trimReq.timestamp);
230✔
992

993
_exit:
230✔
994
  return code;
230✔
995
}
996

997
extern int32_t vnodeAsyncS3Migrate(SVnode *pVnode, int64_t now);
998

999
static int32_t vnodeProcessS3MigrateReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
1000
  int32_t          code = 0;
×
1001
  SVS3MigrateDbReq s3migrateReq = {0};
×
1002

1003
  // decode
1004
  if (tDeserializeSVS3MigrateDbReq(pReq, len, &s3migrateReq) != 0) {
×
1005
    code = TSDB_CODE_INVALID_MSG;
×
1006
    goto _exit;
×
1007
  }
1008

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

1011
  code = vnodeAsyncS3Migrate(pVnode, s3migrateReq.timestamp);
×
1012

1013
_exit:
×
1014
  return code;
×
1015
}
1016

1017
static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
1018
  int               ret = 0;
×
1019
  SVDropTtlTableReq ttlReq = {0};
×
1020
  if (tDeserializeSVDropTtlTableReq(pReq, len, &ttlReq) != 0) {
×
1021
    ret = TSDB_CODE_INVALID_MSG;
×
1022
    goto end;
×
1023
  }
1024

1025
  if (ttlReq.nUids != taosArrayGetSize(ttlReq.pTbUids)) {
×
1026
    ret = TSDB_CODE_INVALID_MSG;
×
1027
    goto end;
×
1028
  }
1029

1030
  if (ttlReq.nUids != 0) {
×
1031
    vInfo("vgId:%d, drop ttl table req will be processed, time:%d, ntbUids:%d", pVnode->config.vgId,
×
1032
          ttlReq.timestampSec, ttlReq.nUids);
1033
  }
1034

1035
  if (ttlReq.nUids > 0) {
×
1036
    int32_t code = metaDropTables(pVnode->pMeta, ttlReq.pTbUids);
×
1037
    if (code) return code;
×
1038

1039
    code = tqUpdateTbUidList(pVnode->pTq, ttlReq.pTbUids, false);
×
1040
    if (code) {
×
1041
      vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(code));
×
1042
    }
1043
  }
1044

1045
end:
×
1046
  taosArrayDestroy(ttlReq.pTbUids);
×
1047
  return ret;
×
1048
}
1049

1050
static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
38✔
1051
  int32_t                 code = -1;
38✔
1052
  SMetaReader             mr = {0};
38✔
1053
  SVDropTtlTableReq       ttlReq = {0};
38✔
1054
  SVFetchTtlExpiredTbsRsp rsp = {0};
38✔
1055
  SEncoder                encoder = {0};
38✔
1056
  SArray                 *pNames = NULL;
38✔
1057
  pRsp->msgType = TDMT_VND_FETCH_TTL_EXPIRED_TBS_RSP;
38✔
1058
  pRsp->code = TSDB_CODE_SUCCESS;
38✔
1059
  pRsp->pCont = NULL;
38✔
1060
  pRsp->contLen = 0;
38✔
1061

1062
  if (tDeserializeSVDropTtlTableReq(pReq, len, &ttlReq) != 0) {
38!
1063
    terrno = TSDB_CODE_INVALID_MSG;
×
1064
    goto _end;
×
1065
  }
1066

1067
  if (!(ttlReq.nUids == taosArrayGetSize(ttlReq.pTbUids))) {
38!
1068
    terrno = TSDB_CODE_INVALID_MSG;
×
1069
    goto _end;
×
1070
  }
1071

1072
  tb_uid_t    suid;
1073
  char        ctbName[TSDB_TABLE_NAME_LEN];
1074
  SVDropTbReq expiredTb = {.igNotExists = true};
38✔
1075
  metaReaderDoInit(&mr, pVnode->pMeta, 0);
38✔
1076
  rsp.vgId = TD_VID(pVnode);
38✔
1077
  rsp.pExpiredTbs = taosArrayInit(ttlReq.nUids, sizeof(SVDropTbReq));
38✔
1078
  if (!rsp.pExpiredTbs) goto _end;
38!
1079

1080
  pNames = taosArrayInit(ttlReq.nUids, TSDB_TABLE_NAME_LEN);
38✔
1081
  if (!pNames) {
38!
1082
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1083
    goto _end;
×
1084
  }
1085
  char buf[TSDB_TABLE_NAME_LEN];
1086
  for (int32_t i = 0; i < ttlReq.nUids; ++i) {
177✔
1087
    tb_uid_t *uid = taosArrayGet(ttlReq.pTbUids, i);
139✔
1088
    expiredTb.suid = *uid;
139✔
1089
    terrno = metaReaderGetTableEntryByUid(&mr, *uid);
139✔
1090
    if (terrno < 0) goto _end;
139!
1091
    strncpy(buf, mr.me.name, TSDB_TABLE_NAME_LEN);
139✔
1092
    void *p = taosArrayPush(pNames, buf);
140✔
1093
    if (p == NULL) {
140!
1094
      goto _end;
×
1095
    }
1096

1097
    expiredTb.name = p;
140✔
1098
    if (mr.me.type == TSDB_CHILD_TABLE) {
140✔
1099
      expiredTb.suid = mr.me.ctbEntry.suid;
90✔
1100
    }
1101

1102
    if (taosArrayPush(rsp.pExpiredTbs, &expiredTb) == NULL) {
279!
1103
      goto _end;
×
1104
    }
1105
  }
1106

1107
  int32_t ret = 0;
38✔
1108
  tEncodeSize(tEncodeVFetchTtlExpiredTbsRsp, &rsp, pRsp->contLen, ret);
38!
1109
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
38✔
1110
  if (pRsp->pCont == NULL) {
38!
1111
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1112
    code = -1;
×
1113
    goto _end;
×
1114
  }
1115
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
38✔
1116
  terrno = tEncodeVFetchTtlExpiredTbsRsp(&encoder, &rsp);
38✔
1117
  tEncoderClear(&encoder);
38✔
1118

1119
  if (terrno == 0) code = 0;
38!
1120
_end:
×
1121
  metaReaderClear(&mr);
38✔
1122
  tFreeFetchTtlExpiredTbsRsp(&rsp);
38✔
1123
  taosArrayDestroy(ttlReq.pTbUids);
38✔
1124
  if (pNames) taosArrayDestroy(pNames);
38!
1125
  pRsp->code = terrno;
38✔
1126
  return code;
38✔
1127
}
1128

1129
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
30,821✔
1130
  int32_t        code = 0;
30,821✔
1131
  SVCreateStbReq req = {0};
30,821✔
1132
  SDecoder       coder;
1133

1134
  pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
30,821✔
1135
  pRsp->code = TSDB_CODE_SUCCESS;
30,821✔
1136
  pRsp->pCont = NULL;
30,821✔
1137
  pRsp->contLen = 0;
30,821✔
1138

1139
  // decode and process req
1140
  tDecoderInit(&coder, pReq, len);
30,821✔
1141

1142
  code = tDecodeSVCreateStbReq(&coder, &req);
30,821✔
1143
  if (code) {
30,861!
1144
    pRsp->code = code;
×
1145
    goto _err;
×
1146
  }
1147

1148
  code = metaCreateSTable(pVnode->pMeta, ver, &req);
30,861✔
1149
  if (code) {
30,831✔
1150
    pRsp->code = code;
4✔
1151
    goto _err;
4✔
1152
  }
1153

1154
  if ((code = tdProcessRSmaCreate(pVnode->pSma, &req)) < 0) {
30,827!
1155
    pRsp->code = code;
×
1156
    goto _err;
×
1157
  }
1158

1159
  tDecoderClear(&coder);
30,914✔
1160
  return 0;
30,868✔
1161

1162
_err:
4✔
1163
  tDecoderClear(&coder);
4✔
1164
  return code;
4✔
1165
}
1166

1167
static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
86,420✔
1168
                                       SRpcMsg *pOriginRpc) {
1169
  SDecoder           decoder = {0};
86,420✔
1170
  SEncoder           encoder = {0};
86,420✔
1171
  int32_t            rcode = 0;
86,420✔
1172
  SVCreateTbBatchReq req = {0};
86,420✔
1173
  SVCreateTbReq     *pCreateReq;
1174
  SVCreateTbBatchRsp rsp = {0};
86,420✔
1175
  SVCreateTbRsp      cRsp = {0};
86,420✔
1176
  char               tbName[TSDB_TABLE_FNAME_LEN];
1177
  STbUidStore       *pStore = NULL;
86,420✔
1178
  SArray            *tbUids = NULL;
86,420✔
1179
  SArray            *tbNames = NULL;
86,420✔
1180
  pRsp->msgType = TDMT_VND_CREATE_TABLE_RSP;
86,420✔
1181
  pRsp->code = TSDB_CODE_SUCCESS;
86,420✔
1182
  pRsp->pCont = NULL;
86,420✔
1183
  pRsp->contLen = 0;
86,420✔
1184

1185
  // decode
1186
  tDecoderInit(&decoder, pReq, len);
86,420✔
1187
  if (tDecodeSVCreateTbBatchReq(&decoder, &req) < 0) {
86,413!
1188
    rcode = -1;
×
1189
    terrno = TSDB_CODE_INVALID_MSG;
×
1190
    goto _exit;
×
1191
  }
1192

1193
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(cRsp));
86,441✔
1194
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
86,447✔
1195
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
86,451✔
1196
  if (rsp.pArray == NULL || tbUids == NULL || tbNames == NULL) {
86,456!
UNCOV
1197
    rcode = -1;
×
UNCOV
1198
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1199
    goto _exit;
×
1200
  }
1201

1202
  // loop to create table
1203
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
214,475✔
1204
    pCreateReq = req.pReqs + iReq;
128,044✔
1205
    memset(&cRsp, 0, sizeof(cRsp));
128,044✔
1206

1207
    if (tsEnableAudit && tsEnableAuditCreateTable) {
128,044!
1208
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
128,048✔
1209
      if (str == NULL) {
128,071!
1210
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1211
        rcode = -1;
×
1212
        goto _exit;
×
1213
      }
1214
      strcpy(str, pCreateReq->name);
128,071✔
1215
      if (taosArrayPush(tbNames, &str) == NULL) {
128,062!
1216
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1217
        rcode = -1;
×
1218
        goto _exit;
×
1219
      }
1220
    }
1221

1222
    // validate hash
1223
    sprintf(tbName, "%s.%s", pVnode->config.dbname, pCreateReq->name);
128,058✔
1224
    if (vnodeValidateTableHash(pVnode, tbName) < 0) {
128,058✔
1225
      cRsp.code = TSDB_CODE_VND_HASH_MISMATCH;
20✔
1226
      if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
40!
1227
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1228
        rcode = -1;
×
1229
        goto _exit;
×
1230
      }
1231
      vError("vgId:%d create-table:%s failed due to hash value mismatch", TD_VID(pVnode), tbName);
20!
1232
      continue;
20✔
1233
    }
1234

1235
    // do create table
1236
    if (metaCreateTable(pVnode->pMeta, ver, pCreateReq, &cRsp.pMeta) < 0) {
128,053✔
1237
      if (pCreateReq->flags & TD_CREATE_IF_NOT_EXISTS && terrno == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
1,322!
1238
        cRsp.code = TSDB_CODE_SUCCESS;
3✔
1239
      } else {
1240
        cRsp.code = terrno;
1,319✔
1241
      }
1242
    } else {
1243
      cRsp.code = TSDB_CODE_SUCCESS;
126,723✔
1244
      if (tdFetchTbUidList(pVnode->pSma, &pStore, pCreateReq->ctb.suid, pCreateReq->uid) < 0) {
126,723!
1245
        vError("vgId:%d, failed to fetch tbUid list", TD_VID(pVnode));
×
1246
      }
1247
      if (taosArrayPush(tbUids, &pCreateReq->uid) == NULL) {
253,428!
1248
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1249
        rcode = -1;
×
1250
        goto _exit;
×
1251
      }
1252
      vnodeUpdateMetaRsp(pVnode, cRsp.pMeta);
126,705✔
1253
    }
1254

1255
    if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
256,011!
1256
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1257
      rcode = -1;
×
1258
      goto _exit;
×
1259
    }
1260
  }
1261

1262
  vDebug("vgId:%d, add %d new created tables into query table list", TD_VID(pVnode), (int32_t)taosArrayGetSize(tbUids));
86,431✔
1263
  if (tqUpdateTbUidList(pVnode->pTq, tbUids, true) < 0) {
86,431!
1264
    vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(terrno));
×
1265
  }
1266
  if (tdUpdateTbUidList(pVnode->pSma, pStore, true) < 0) {
86,452!
1267
    goto _exit;
×
1268
  }
1269
  pStore = tdUidStoreFree(pStore);
86,449✔
1270

1271
  // prepare rsp
1272
  int32_t ret = 0;
86,449✔
1273
  tEncodeSize(tEncodeSVCreateTbBatchRsp, &rsp, pRsp->contLen, ret);
86,449!
1274
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
86,442✔
1275
  if (pRsp->pCont == NULL) {
86,453!
1276
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1277
    rcode = -1;
×
1278
    goto _exit;
×
1279
  }
1280
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
86,453✔
1281
  if (tEncodeSVCreateTbBatchRsp(&encoder, &rsp) != 0) {
86,452!
1282
    vError("vgId:%d, failed to encode create table batch response", TD_VID(pVnode));
×
1283
  }
1284

1285
  if (tsEnableAudit && tsEnableAuditCreateTable) {
86,450!
1286
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
86,450✔
1287

1288
    SName name = {0};
86,450✔
1289
    if (tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB) < 0) {
86,450!
1290
      vError("vgId:%d, failed to get name from string", TD_VID(pVnode));
×
1291
    }
1292

1293
    SStringBuilder sb = {0};
86,448✔
1294
    for (int32_t i = 0; i < tbNames->size; i++) {
214,511✔
1295
      char **key = (char **)taosArrayGet(tbNames, i);
128,080✔
1296
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
128,072✔
1297
      if (i < tbNames->size - 1) {
128,061✔
1298
        taosStringBuilderAppendChar(&sb, ',');
41,634✔
1299
      }
1300
      // taosMemoryFreeClear(*key);
1301
    }
1302

1303
    size_t len = 0;
86,431✔
1304
    char  *keyJoined = taosStringBuilderGetResult(&sb, &len);
86,431✔
1305

1306
    if (pOriginRpc->info.conn.user != NULL && strlen(pOriginRpc->info.conn.user) > 0) {
86,429!
1307
      auditAddRecord(pOriginRpc, clusterId, "createTable", name.dbname, "", keyJoined, len);
71,351✔
1308
    }
1309

1310
    taosStringBuilderDestroy(&sb);
86,426✔
1311
  }
1312

1313
_exit:
×
1314
  tDeleteSVCreateTbBatchReq(&req);
86,422✔
1315
  taosArrayDestroyEx(rsp.pArray, tFreeSVCreateTbRsp);
86,450✔
1316
  taosArrayDestroy(tbUids);
86,455✔
1317
  tDecoderClear(&decoder);
86,453✔
1318
  tEncoderClear(&encoder);
86,454✔
1319
  taosArrayDestroyP(tbNames, taosMemoryFree);
86,455✔
1320
  return rcode;
86,454✔
1321
}
1322

1323
static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
4,940✔
1324
  int32_t        code = 0;
4,940✔
1325
  SVCreateStbReq req = {0};
4,940✔
1326
  SDecoder       dc = {0};
4,940✔
1327

1328
  pRsp->msgType = TDMT_VND_ALTER_STB_RSP;
4,940✔
1329
  pRsp->code = TSDB_CODE_SUCCESS;
4,940✔
1330
  pRsp->pCont = NULL;
4,940✔
1331
  pRsp->contLen = 0;
4,940✔
1332

1333
  tDecoderInit(&dc, pReq, len);
4,940✔
1334

1335
  // decode req
1336
  code = tDecodeSVCreateStbReq(&dc, &req);
4,943✔
1337
  if (code) {
4,954!
1338
    tDecoderClear(&dc);
×
1339
    return code;
×
1340
  }
1341

1342
  code = metaAlterSTable(pVnode->pMeta, ver, &req);
4,954✔
1343
  if (code) {
4,951!
1344
    pRsp->code = code;
×
1345
    tDecoderClear(&dc);
×
1346
    return code;
×
1347
  }
1348

1349
  tDecoderClear(&dc);
4,951✔
1350

1351
  return 0;
4,954✔
1352
}
1353

1354
static int32_t vnodeProcessDropStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
3,460✔
1355
  SVDropStbReq req = {0};
3,460✔
1356
  int32_t      rcode = TSDB_CODE_SUCCESS;
3,460✔
1357
  SDecoder     decoder = {0};
3,460✔
1358
  SArray      *tbUidList = NULL;
3,460✔
1359

1360
  pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
3,460✔
1361
  pRsp->pCont = NULL;
3,460✔
1362
  pRsp->contLen = 0;
3,460✔
1363

1364
  // decode request
1365
  tDecoderInit(&decoder, pReq, len);
3,460✔
1366
  if (tDecodeSVDropStbReq(&decoder, &req) < 0) {
3,460!
1367
    rcode = TSDB_CODE_INVALID_MSG;
×
1368
    goto _exit;
×
1369
  }
1370

1371
  // process request
1372
  tbUidList = taosArrayInit(8, sizeof(int64_t));
3,460✔
1373
  if (tbUidList == NULL) goto _exit;
3,461!
1374
  if (metaDropSTable(pVnode->pMeta, ver, &req, tbUidList) < 0) {
3,461✔
1375
    rcode = terrno;
8✔
1376
    goto _exit;
8✔
1377
  }
1378

1379
  if (tqUpdateTbUidList(pVnode->pTq, tbUidList, false) < 0) {
3,454!
1380
    rcode = terrno;
×
1381
    goto _exit;
×
1382
  }
1383

1384
  if (tdProcessRSmaDrop(pVnode->pSma, &req) < 0) {
3,455!
1385
    rcode = terrno;
×
1386
    goto _exit;
×
1387
  }
1388

1389
  // return rsp
1390
_exit:
3,453✔
1391
  if (tbUidList) taosArrayDestroy(tbUidList);
3,461!
1392
  pRsp->code = rcode;
3,461✔
1393
  tDecoderClear(&decoder);
3,461✔
1394
  return 0;
3,463✔
1395
}
1396

1397
static int32_t vnodeProcessAlterTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
5,192✔
1398
  SVAlterTbReq  vAlterTbReq = {0};
5,192✔
1399
  SVAlterTbRsp  vAlterTbRsp = {0};
5,192✔
1400
  SDecoder      dc = {0};
5,192✔
1401
  int32_t       rcode = 0;
5,192✔
1402
  int32_t       ret;
1403
  SEncoder      ec = {0};
5,192✔
1404
  STableMetaRsp vMetaRsp = {0};
5,192✔
1405

1406
  pRsp->msgType = TDMT_VND_ALTER_TABLE_RSP;
5,192✔
1407
  pRsp->pCont = NULL;
5,192✔
1408
  pRsp->contLen = 0;
5,192✔
1409
  pRsp->code = TSDB_CODE_SUCCESS;
5,192✔
1410

1411
  tDecoderInit(&dc, pReq, len);
5,192✔
1412

1413
  // decode
1414
  if (tDecodeSVAlterTbReq(&dc, &vAlterTbReq) < 0) {
5,192!
1415
    vAlterTbRsp.code = TSDB_CODE_INVALID_MSG;
×
1416
    tDecoderClear(&dc);
×
1417
    rcode = -1;
×
1418
    goto _exit;
×
1419
  }
1420

1421
  // process
1422
  if (metaAlterTable(pVnode->pMeta, ver, &vAlterTbReq, &vMetaRsp) < 0) {
5,192✔
1423
    vAlterTbRsp.code = terrno;
923✔
1424
    tDecoderClear(&dc);
923✔
1425
    rcode = -1;
923✔
1426
    goto _exit;
923✔
1427
  }
1428
  tDecoderClear(&dc);
4,269✔
1429

1430
  if (NULL != vMetaRsp.pSchemas) {
4,269✔
1431
    vnodeUpdateMetaRsp(pVnode, &vMetaRsp);
1,042✔
1432
    vAlterTbRsp.pMeta = &vMetaRsp;
1,042✔
1433
  }
1434

1435
_exit:
3,227✔
1436
  taosArrayDestroy(vAlterTbReq.pMultiTag);
5,192✔
1437
  tEncodeSize(tEncodeSVAlterTbRsp, &vAlterTbRsp, pRsp->contLen, ret);
5,192!
1438
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
5,192✔
1439
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
5,192✔
1440
  if (tEncodeSVAlterTbRsp(&ec, &vAlterTbRsp) != 0) {
5,192!
1441
    vError("vgId:%d, failed to encode alter table response", TD_VID(pVnode));
×
1442
  }
1443
  tEncoderClear(&ec);
5,192✔
1444
  if (vMetaRsp.pSchemas) {
5,192✔
1445
    taosMemoryFree(vMetaRsp.pSchemas);
1,042✔
1446
    taosMemoryFree(vMetaRsp.pSchemaExt);
1,042✔
1447
  }
1448
  return 0;
5,192✔
1449
}
1450

1451
static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
16,088✔
1452
                                     SRpcMsg *pOriginRpc) {
1453
  SVDropTbBatchReq req = {0};
16,088✔
1454
  SVDropTbBatchRsp rsp = {0};
16,088✔
1455
  SDecoder         decoder = {0};
16,088✔
1456
  SEncoder         encoder = {0};
16,088✔
1457
  int32_t          ret;
1458
  SArray          *tbUids = NULL;
16,088✔
1459
  STbUidStore     *pStore = NULL;
16,088✔
1460
  SArray          *tbNames = NULL;
16,088✔
1461

1462
  pRsp->msgType = TDMT_VND_DROP_TABLE_RSP;
16,088✔
1463
  pRsp->pCont = NULL;
16,088✔
1464
  pRsp->contLen = 0;
16,088✔
1465
  pRsp->code = TSDB_CODE_SUCCESS;
16,088✔
1466

1467
  // decode req
1468
  tDecoderInit(&decoder, pReq, len);
16,088✔
1469
  ret = tDecodeSVDropTbBatchReq(&decoder, &req);
16,088✔
1470
  if (ret < 0) {
16,088!
1471
    terrno = TSDB_CODE_INVALID_MSG;
×
1472
    pRsp->code = terrno;
×
1473
    goto _exit;
×
1474
  }
1475

1476
  // process req
1477
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
16,088✔
1478
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(SVDropTbRsp));
16,088✔
1479
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
16,088✔
1480
  if (tbUids == NULL || rsp.pArray == NULL || tbNames == NULL) goto _exit;
16,088!
1481

1482
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
32,201✔
1483
    SVDropTbReq *pDropTbReq = req.pReqs + iReq;
16,113✔
1484
    SVDropTbRsp  dropTbRsp = {0};
16,113✔
1485
    tb_uid_t     tbUid = 0;
16,113✔
1486

1487
    /* code */
1488
    ret = metaDropTable(pVnode->pMeta, ver, pDropTbReq, tbUids, &tbUid);
16,113✔
1489
    if (ret < 0) {
16,113!
1490
      if (pDropTbReq->igNotExists && terrno == TSDB_CODE_TDB_TABLE_NOT_EXIST) {
×
1491
        dropTbRsp.code = TSDB_CODE_SUCCESS;
×
1492
      } else {
1493
        dropTbRsp.code = terrno;
×
1494
      }
1495
    } else {
1496
      dropTbRsp.code = TSDB_CODE_SUCCESS;
16,113✔
1497
      if (tbUid > 0) {
16,113✔
1498
        if (tdFetchTbUidList(pVnode->pSma, &pStore, pDropTbReq->suid, tbUid) < 0) {
13,750!
1499
          vError("vgId:%d, failed to fetch tbUid list", TD_VID(pVnode));
×
1500
        }
1501
      }
1502
    }
1503

1504
    if (taosArrayPush(rsp.pArray, &dropTbRsp) == NULL) {
32,226!
1505
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1506
      pRsp->code = terrno;
×
1507
      goto _exit;
×
1508
    }
1509

1510
    if (tsEnableAuditCreateTable) {
16,113!
1511
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
16,113✔
1512
      if (str == NULL) {
16,113!
1513
        pRsp->code = terrno;
×
1514
        goto _exit;
×
1515
      }
1516
      strcpy(str, pDropTbReq->name);
16,113✔
1517
      if (taosArrayPush(tbNames, &str) == NULL) {
16,113!
1518
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1519
        pRsp->code = terrno;
×
1520
        goto _exit;
×
1521
      }
1522
    }
1523
  }
1524

1525
  if (tqUpdateTbUidList(pVnode->pTq, tbUids, false) < 0) {
16,088!
1526
    vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(terrno));
×
1527
  }
1528

1529
  if (tdUpdateTbUidList(pVnode->pSma, pStore, false) < 0) {
16,088!
1530
    goto _exit;
×
1531
  }
1532

1533
  if (tsEnableAuditCreateTable) {
16,088!
1534
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
16,088✔
1535

1536
    SName name = {0};
16,088✔
1537
    if (tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB) != 0) {
16,088!
1538
      vError("vgId:%d, failed to get name from string", TD_VID(pVnode));
×
1539
    }
1540

1541
    SStringBuilder sb = {0};
16,088✔
1542
    for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
32,201✔
1543
      char **key = (char **)taosArrayGet(tbNames, iReq);
16,113✔
1544
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
16,113✔
1545
      if (iReq < req.nReqs - 1) {
16,113✔
1546
        taosStringBuilderAppendChar(&sb, ',');
25✔
1547
      }
1548
      taosMemoryFreeClear(*key);
16,113!
1549
    }
1550

1551
    size_t len = 0;
16,088✔
1552
    char  *keyJoined = taosStringBuilderGetResult(&sb, &len);
16,088✔
1553

1554
    if (pOriginRpc->info.conn.user != NULL && strlen(pOriginRpc->info.conn.user) > 0) {
16,088!
1555
      auditAddRecord(pOriginRpc, clusterId, "dropTable", name.dbname, "", keyJoined, len);
15,991✔
1556
    }
1557

1558
    taosStringBuilderDestroy(&sb);
16,088✔
1559
  }
1560

1561
_exit:
×
1562
  taosArrayDestroy(tbUids);
16,088✔
1563
  pStore = tdUidStoreFree(pStore);
16,088✔
1564
  tDecoderClear(&decoder);
16,088✔
1565
  tEncodeSize(tEncodeSVDropTbBatchRsp, &rsp, pRsp->contLen, ret);
16,088!
1566
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
16,088✔
1567
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
16,088✔
1568
  if (tEncodeSVDropTbBatchRsp(&encoder, &rsp) != 0) {
16,088!
1569
    vError("vgId:%d, failed to encode drop table batch response", TD_VID(pVnode));
×
1570
  }
1571
  tEncoderClear(&encoder);
16,088✔
1572
  taosArrayDestroy(rsp.pArray);
16,088✔
1573
  taosArrayDestroy(tbNames);
16,088✔
1574
  return 0;
16,088✔
1575
}
1576

1577
#ifdef BUILD_NO_CALL
1578
static int32_t vnodeDebugPrintSingleSubmitMsg(SMeta *pMeta, SSubmitBlk *pBlock, SSubmitMsgIter *msgIter,
1579
                                              const char *tags) {
1580
  SSubmitBlkIter blkIter = {0};
1581
  STSchema      *pSchema = NULL;
1582
  tb_uid_t       suid = 0;
1583
  STSRow        *row = NULL;
1584
  int32_t        rv = -1;
1585

1586
  tInitSubmitBlkIter(msgIter, pBlock, &blkIter);
1587
  if (blkIter.row == NULL) return 0;
1588

1589
  int32_t code = metaGetTbTSchemaNotNull(pMeta, msgIter->suid, TD_ROW_SVER(blkIter.row), 1,
1590
                                         &pSchema);  // TODO: use the real schema
1591
  if (TSDB_CODE_SUCCESS != code) {
1592
    printf("%s:%d no valid schema\n", tags, __LINE__);
1593
    return code;
1594
  }
1595

1596
  suid = msgIter->suid;
1597
  rv = TD_ROW_SVER(blkIter.row);
1598

1599
  char __tags[128] = {0};
1600
  snprintf(__tags, 128, "%s: uid %" PRIi64 " ", tags, msgIter->uid);
1601
  while ((row = tGetSubmitBlkNext(&blkIter))) {
1602
    tdSRowPrint(row, pSchema, __tags);
1603
  }
1604

1605
  taosMemoryFreeClear(pSchema);
1606

1607
  return TSDB_CODE_SUCCESS;
1608
}
1609
#endif
1610
typedef struct SSubmitReqConvertCxt {
1611
  SSubmitMsgIter msgIter;
1612
  SSubmitBlk    *pBlock;
1613
  SSubmitBlkIter blkIter;
1614
  STSRow        *pRow;
1615
  STSRowIter     rowIter;
1616
  SSubmitTbData *pTbData;
1617
  STSchema      *pTbSchema;
1618
  SArray        *pColValues;
1619
} SSubmitReqConvertCxt;
1620

1621
static int32_t vnodeResetTableCxt(SMeta *pMeta, SSubmitReqConvertCxt *pCxt) {
×
1622
  taosMemoryFreeClear(pCxt->pTbSchema);
×
1623
  int32_t code = metaGetTbTSchemaNotNull(pMeta, pCxt->msgIter.suid > 0 ? pCxt->msgIter.suid : pCxt->msgIter.uid,
×
1624
                                         pCxt->msgIter.sversion, 1, &pCxt->pTbSchema);
1625
  if (TSDB_CODE_SUCCESS != code) {
×
1626
    return code;
×
1627
  }
1628
  tdSTSRowIterInit(&pCxt->rowIter, pCxt->pTbSchema);
×
1629

1630
  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
×
1631
  if (NULL == pCxt->pTbData) {
×
1632
    pCxt->pTbData = taosMemoryCalloc(1, sizeof(SSubmitTbData));
×
1633
    if (NULL == pCxt->pTbData) {
×
1634
      return terrno;
×
1635
    }
1636
  }
1637
  pCxt->pTbData->flags = 0;
×
1638
  pCxt->pTbData->suid = pCxt->msgIter.suid;
×
1639
  pCxt->pTbData->uid = pCxt->msgIter.uid;
×
1640
  pCxt->pTbData->sver = pCxt->msgIter.sversion;
×
1641
  pCxt->pTbData->pCreateTbReq = NULL;
×
1642
  pCxt->pTbData->aRowP = taosArrayInit(128, POINTER_BYTES);
×
1643
  if (NULL == pCxt->pTbData->aRowP) {
×
1644
    return terrno;
×
1645
  }
1646

1647
  taosArrayDestroy(pCxt->pColValues);
×
1648
  pCxt->pColValues = taosArrayInit(pCxt->pTbSchema->numOfCols, sizeof(SColVal));
×
1649
  if (NULL == pCxt->pColValues) {
×
1650
    return terrno;
×
1651
  }
1652
  for (int32_t i = 0; i < pCxt->pTbSchema->numOfCols; ++i) {
×
1653
    SColVal val = COL_VAL_NONE(pCxt->pTbSchema->columns[i].colId, pCxt->pTbSchema->columns[i].type);
×
1654
    if (taosArrayPush(pCxt->pColValues, &val) == NULL) {
×
1655
      return terrno;
×
1656
    }
1657
  }
1658

1659
  return TSDB_CODE_SUCCESS;
×
1660
}
1661

1662
static void vnodeDestroySubmitReqConvertCxt(SSubmitReqConvertCxt *pCxt) {
×
1663
  taosMemoryFreeClear(pCxt->pTbSchema);
×
1664
  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
×
1665
  taosMemoryFreeClear(pCxt->pTbData);
×
1666
  taosArrayDestroy(pCxt->pColValues);
×
1667
}
×
1668

1669
static int32_t vnodeCellValConvertToColVal(STColumn *pCol, SCellVal *pCellVal, SColVal *pColVal) {
×
1670
  if (tdValTypeIsNone(pCellVal->valType)) {
×
1671
    pColVal->flag = CV_FLAG_NONE;
×
1672
    return TSDB_CODE_SUCCESS;
×
1673
  }
1674

1675
  if (tdValTypeIsNull(pCellVal->valType)) {
×
1676
    pColVal->flag = CV_FLAG_NULL;
×
1677
    return TSDB_CODE_SUCCESS;
×
1678
  }
1679

1680
  if (IS_VAR_DATA_TYPE(pCol->type)) {
×
1681
    pColVal->value.nData = varDataLen(pCellVal->val);
×
1682
    pColVal->value.pData = (uint8_t *)varDataVal(pCellVal->val);
×
1683
  } else if (TSDB_DATA_TYPE_FLOAT == pCol->type) {
×
1684
    float f = GET_FLOAT_VAL(pCellVal->val);
×
1685
    memcpy(&pColVal->value.val, &f, sizeof(f));
×
1686
  } else if (TSDB_DATA_TYPE_DOUBLE == pCol->type) {
×
1687
    pColVal->value.val = *(int64_t *)pCellVal->val;
×
1688
  } else {
1689
    GET_TYPED_DATA(pColVal->value.val, int64_t, pCol->type, pCellVal->val);
×
1690
  }
1691

1692
  pColVal->flag = CV_FLAG_VALUE;
×
1693
  return TSDB_CODE_SUCCESS;
×
1694
}
1695

1696
static int32_t vnodeTSRowConvertToColValArray(SSubmitReqConvertCxt *pCxt) {
×
1697
  int32_t code = TSDB_CODE_SUCCESS;
×
1698
  tdSTSRowIterReset(&pCxt->rowIter, pCxt->pRow);
×
1699
  for (int32_t i = 0; TSDB_CODE_SUCCESS == code && i < pCxt->pTbSchema->numOfCols; ++i) {
×
1700
    STColumn *pCol = pCxt->pTbSchema->columns + i;
×
1701
    SCellVal  cellVal = {0};
×
1702
    if (!tdSTSRowIterFetch(&pCxt->rowIter, pCol->colId, pCol->type, &cellVal)) {
×
1703
      break;
×
1704
    }
1705
    code = vnodeCellValConvertToColVal(pCol, &cellVal, (SColVal *)taosArrayGet(pCxt->pColValues, i));
×
1706
  }
1707
  return code;
×
1708
}
1709

1710
static int32_t vnodeDecodeCreateTbReq(SSubmitReqConvertCxt *pCxt) {
×
1711
  if (pCxt->msgIter.schemaLen <= 0) {
×
1712
    return TSDB_CODE_SUCCESS;
×
1713
  }
1714

1715
  pCxt->pTbData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
×
1716
  if (NULL == pCxt->pTbData->pCreateTbReq) {
×
1717
    return terrno;
×
1718
  }
1719

1720
  SDecoder decoder = {0};
×
1721
  tDecoderInit(&decoder, (uint8_t *)pCxt->pBlock->data, pCxt->msgIter.schemaLen);
×
1722
  int32_t code = tDecodeSVCreateTbReq(&decoder, pCxt->pTbData->pCreateTbReq);
×
1723
  tDecoderClear(&decoder);
×
1724

1725
  return code;
×
1726
}
1727

1728
static int32_t vnodeSubmitReqConvertToSubmitReq2(SVnode *pVnode, SSubmitReq *pReq, SSubmitReq2 *pReq2) {
×
1729
  pReq2->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData));
×
1730
  if (NULL == pReq2->aSubmitTbData) {
×
1731
    return terrno;
×
1732
  }
1733

1734
  SSubmitReqConvertCxt cxt = {0};
×
1735

1736
  int32_t code = tInitSubmitMsgIter(pReq, &cxt.msgIter);
×
1737
  while (TSDB_CODE_SUCCESS == code) {
×
1738
    code = tGetSubmitMsgNext(&cxt.msgIter, &cxt.pBlock);
×
1739
    if (TSDB_CODE_SUCCESS == code) {
×
1740
      if (NULL == cxt.pBlock) {
×
1741
        break;
×
1742
      }
1743
      code = vnodeResetTableCxt(pVnode->pMeta, &cxt);
×
1744
    }
1745
    if (TSDB_CODE_SUCCESS == code) {
×
1746
      code = tInitSubmitBlkIter(&cxt.msgIter, cxt.pBlock, &cxt.blkIter);
×
1747
    }
1748
    if (TSDB_CODE_SUCCESS == code) {
×
1749
      code = vnodeDecodeCreateTbReq(&cxt);
×
1750
    }
1751
    while (TSDB_CODE_SUCCESS == code && (cxt.pRow = tGetSubmitBlkNext(&cxt.blkIter)) != NULL) {
×
1752
      code = vnodeTSRowConvertToColValArray(&cxt);
×
1753
      if (TSDB_CODE_SUCCESS == code) {
×
1754
        SRow **pNewRow = taosArrayReserve(cxt.pTbData->aRowP, 1);
×
1755
        code = tRowBuild(cxt.pColValues, cxt.pTbSchema, pNewRow);
×
1756
      }
1757
    }
1758
    if (TSDB_CODE_SUCCESS == code) {
×
1759
      code = (NULL == taosArrayPush(pReq2->aSubmitTbData, cxt.pTbData) ? terrno : TSDB_CODE_SUCCESS);
×
1760
    }
1761
    if (TSDB_CODE_SUCCESS == code) {
×
1762
      taosMemoryFreeClear(cxt.pTbData);
×
1763
    }
1764
  }
1765

1766
  vnodeDestroySubmitReqConvertCxt(&cxt);
×
1767
  return code;
×
1768
}
1769

1770
static int32_t vnodeRebuildSubmitReqMsg(SSubmitReq2 *pSubmitReq, void **ppMsg) {
×
1771
  int32_t  code = TSDB_CODE_SUCCESS;
×
1772
  char    *pMsg = NULL;
×
1773
  uint32_t msglen = 0;
×
1774
  tEncodeSize(tEncodeSubmitReq, pSubmitReq, msglen, code);
×
1775
  if (TSDB_CODE_SUCCESS == code) {
×
1776
    pMsg = taosMemoryMalloc(msglen);
×
1777
    if (NULL == pMsg) {
×
1778
      code = terrno;
×
1779
    }
1780
  }
1781
  if (TSDB_CODE_SUCCESS == code) {
×
1782
    SEncoder encoder;
1783
    tEncoderInit(&encoder, (uint8_t *)pMsg, msglen);
×
1784
    code = tEncodeSubmitReq(&encoder, pSubmitReq);
×
1785
    tEncoderClear(&encoder);
×
1786
  }
1787
  if (TSDB_CODE_SUCCESS == code) {
×
1788
    *ppMsg = pMsg;
×
1789
  }
1790
  return code;
×
1791
}
1792

1793
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
13,071,258✔
1794
                                     SRpcMsg *pOriginalMsg) {
1795
  int32_t code = 0;
13,071,258✔
1796
  terrno = 0;
13,071,258✔
1797

1798
  SSubmitReq2 *pSubmitReq = &(SSubmitReq2){0};
13,071,393✔
1799
  SSubmitRsp2 *pSubmitRsp = &(SSubmitRsp2){0};
13,071,393✔
1800
  SArray      *newTbUids = NULL;
13,071,393✔
1801
  int32_t      ret;
1802
  SEncoder     ec = {0};
13,071,393✔
1803

1804
  pRsp->code = TSDB_CODE_SUCCESS;
13,071,393✔
1805

1806
  void           *pAllocMsg = NULL;
13,071,393✔
1807
  SSubmitReq2Msg *pMsg = (SSubmitReq2Msg *)pReq;
13,071,393✔
1808
  if (0 == pMsg->version) {
13,071,393!
1809
    code = vnodeSubmitReqConvertToSubmitReq2(pVnode, (SSubmitReq *)pMsg, pSubmitReq);
×
1810
    if (TSDB_CODE_SUCCESS == code) {
×
1811
      code = vnodeRebuildSubmitReqMsg(pSubmitReq, &pReq);
×
1812
    }
1813
    if (TSDB_CODE_SUCCESS == code) {
×
1814
      pAllocMsg = pReq;
×
1815
    }
1816
    if (TSDB_CODE_SUCCESS != code) {
×
1817
      goto _exit;
×
1818
    }
1819
  } else {
1820
    // decode
1821
    pReq = POINTER_SHIFT(pReq, sizeof(SSubmitReq2Msg));
13,071,393✔
1822
    len -= sizeof(SSubmitReq2Msg);
13,071,393✔
1823
    SDecoder dc = {0};
13,071,393✔
1824
    tDecoderInit(&dc, pReq, len);
13,071,393✔
1825
    if (tDecodeSubmitReq(&dc, pSubmitReq) < 0) {
13,071,290!
1826
      code = TSDB_CODE_INVALID_MSG;
×
1827
      goto _exit;
×
1828
    }
1829
    tDecoderClear(&dc);
13,071,354✔
1830
  }
1831

1832
  // scan
1833
  TSKEY now = taosGetTimestamp(pVnode->config.tsdbCfg.precision);
13,071,335✔
1834
  TSKEY minKey = now - tsTickPerMin[pVnode->config.tsdbCfg.precision] * pVnode->config.tsdbCfg.keep2;
13,071,315✔
1835
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
13,071,315✔
1836
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
26,884,657✔
1837
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
13,814,507✔
1838

1839
    if (pSubmitTbData->pCreateTbReq && pSubmitTbData->pCreateTbReq->uid == 0) {
13,814,472!
1840
      code = TSDB_CODE_INVALID_MSG;
×
1841
      goto _exit;
×
1842
    }
1843

1844
    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
13,814,472✔
1845
      if (TARRAY_SIZE(pSubmitTbData->aCol) <= 0) {
155!
1846
        code = TSDB_CODE_INVALID_MSG;
×
1847
        goto _exit;
×
1848
      }
1849

1850
      SColData *colDataArr = TARRAY_DATA(pSubmitTbData->aCol);
155✔
1851
      SRowKey   lastKey;
1852
      tColDataArrGetRowKey(colDataArr, TARRAY_SIZE(pSubmitTbData->aCol), 0, &lastKey);
155✔
1853
      for (int32_t iRow = 1; iRow < colDataArr[0].nVal; iRow++) {
269✔
1854
        SRowKey key;
1855
        tColDataArrGetRowKey(TARRAY_DATA(pSubmitTbData->aCol), TARRAY_SIZE(pSubmitTbData->aCol), iRow, &key);
115✔
1856
        if (tRowKeyCompare(&lastKey, &key) >= 0) {
115!
1857
          code = TSDB_CODE_INVALID_MSG;
×
1858
          vError("vgId:%d %s failed 1 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(terrno), ver);
×
1859
          goto _exit;
×
1860
        }
1861
      }
1862
    } else {
1863
      int32_t nRow = TARRAY_SIZE(pSubmitTbData->aRowP);
13,814,317✔
1864
      SRow  **aRow = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP);
13,814,317✔
1865
      SRowKey lastRowKey;
1866
      for (int32_t iRow = 0; iRow < nRow; ++iRow) {
831,868,207✔
1867
        if (aRow[iRow]->ts < minKey || aRow[iRow]->ts > maxKey) {
818,055,019!
1868
          code = TSDB_CODE_INVALID_MSG;
11,670✔
1869
          vError("vgId:%d %s failed 2 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code), ver);
11,670!
1870
          goto _exit;
×
1871
        }
1872
        if (iRow == 0) {
818,043,349✔
1873
          tRowGetKey(aRow[iRow], &lastRowKey);
13,814,417✔
1874
        } else {
1875
          SRowKey rowKey;
1876
          tRowGetKey(aRow[iRow], &rowKey);
804,228,932✔
1877

1878
          if (tRowKeyCompare(&lastRowKey, &rowKey) >= 0) {
804,229,729!
1879
            code = TSDB_CODE_INVALID_MSG;
×
1880
            vError("vgId:%d %s failed 3 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code), ver);
×
1881
            goto _exit;
×
1882
          }
1883
          lastRowKey = rowKey;
804,226,523✔
1884
        }
1885
      }
1886
    }
1887
  }
1888

1889
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
26,887,992✔
1890
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
13,817,433✔
1891

1892
    if (pSubmitTbData->pCreateTbReq) {
13,817,169✔
1893
      pSubmitTbData->uid = pSubmitTbData->pCreateTbReq->uid;
79,409✔
1894
    } else {
1895
      SMetaInfo info = {0};
13,737,760✔
1896

1897
      code = metaGetInfo(pVnode->pMeta, pSubmitTbData->uid, &info, NULL);
13,737,760✔
1898
      if (code) {
13,738,473✔
1899
        code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
7✔
1900
        vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), pSubmitTbData->uid);
7!
1901
        goto _exit;
8✔
1902
      }
1903

1904
      if (info.suid != pSubmitTbData->suid) {
13,738,466!
1905
        code = TSDB_CODE_INVALID_MSG;
×
1906
        goto _exit;
×
1907
      }
1908

1909
      if (info.suid) {
13,738,466✔
1910
        if (metaGetInfo(pVnode->pMeta, info.suid, &info, NULL) != 0) {
12,864,608!
1911
          vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), info.suid);
×
1912
        }
1913
      }
1914

1915
      if (pSubmitTbData->sver != info.skmVer) {
13,738,433!
1916
        code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER;
×
1917
        goto _exit;
×
1918
      }
1919
    }
1920

1921
    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
13,817,842✔
1922
      int32_t   nColData = TARRAY_SIZE(pSubmitTbData->aCol);
155✔
1923
      SColData *aColData = (SColData *)TARRAY_DATA(pSubmitTbData->aCol);
155✔
1924

1925
      if (nColData <= 0) {
155!
1926
        code = TSDB_CODE_INVALID_MSG;
×
1927
        goto _exit;
×
1928
      }
1929

1930
      if (aColData[0].cid != PRIMARYKEY_TIMESTAMP_COL_ID || aColData[0].type != TSDB_DATA_TYPE_TIMESTAMP ||
155!
1931
          aColData[0].nVal <= 0) {
155!
1932
        code = TSDB_CODE_INVALID_MSG;
×
1933
        goto _exit;
×
1934
      }
1935

1936
      for (int32_t j = 1; j < nColData; j++) {
690✔
1937
        if (aColData[j].nVal != aColData[0].nVal) {
535!
1938
          code = TSDB_CODE_INVALID_MSG;
×
1939
          goto _exit;
×
1940
        }
1941
      }
1942
    }
1943
  }
1944

1945
  vDebug("vgId:%d, submit block size %d", TD_VID(pVnode), (int32_t)taosArrayGetSize(pSubmitReq->aSubmitTbData));
13,070,559✔
1946

1947
  // loop to handle
1948
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
26,886,016✔
1949
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
13,813,799✔
1950

1951
    // create table
1952
    if (pSubmitTbData->pCreateTbReq) {
13,813,479✔
1953
      // alloc if need
1954
      if (pSubmitRsp->aCreateTbRsp == NULL &&
79,398✔
1955
          (pSubmitRsp->aCreateTbRsp = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(SVCreateTbRsp))) ==
56,074!
1956
              NULL) {
1957
        code = terrno;
×
1958
        goto _exit;
8✔
1959
      }
1960

1961
      SVCreateTbRsp *pCreateTbRsp = taosArrayReserve(pSubmitRsp->aCreateTbRsp, 1);
79,399✔
1962

1963
      // create table
1964
      if (metaCreateTable(pVnode->pMeta, ver, pSubmitTbData->pCreateTbReq, &pCreateTbRsp->pMeta) == 0) {
79,397✔
1965
        // create table success
1966

1967
        if (newTbUids == NULL &&
89,230!
1968
            (newTbUids = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(int64_t))) == NULL) {
35,872✔
1969
          code = terrno;
×
1970
          goto _exit;
×
1971
        }
1972

1973
        if (taosArrayPush(newTbUids, &pSubmitTbData->uid) == NULL) {
106,716!
1974
          code = terrno;
×
1975
          goto _exit;
×
1976
        }
1977

1978
        if (pCreateTbRsp->pMeta) {
53,358!
1979
          vnodeUpdateMetaRsp(pVnode, pCreateTbRsp->pMeta);
53,358✔
1980
        }
1981
      } else {  // create table failed
1982
        if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
26,045✔
1983
          code = terrno;
8✔
1984
          vError("vgId:%d failed to create table:%s, code:%s", TD_VID(pVnode), pSubmitTbData->pCreateTbReq->name,
8!
1985
                 tstrerror(terrno));
1986
          goto _exit;
8✔
1987
        }
1988
        terrno = 0;
26,037✔
1989
        pSubmitTbData->uid = pSubmitTbData->pCreateTbReq->uid;  // update uid if table exist for using below
26,037✔
1990
      }
1991
    }
1992

1993
    // insert data
1994
    int32_t affectedRows;
1995
    code = tsdbInsertTableData(pVnode->pTsdb, ver, pSubmitTbData, &affectedRows);
13,813,476✔
1996
    if (code) goto _exit;
13,815,234!
1997

1998
    code = metaUpdateChangeTimeWithLock(pVnode->pMeta, pSubmitTbData->uid, pSubmitTbData->ctimeMs);
13,815,234✔
1999
    if (code) goto _exit;
13,814,544!
2000

2001
    pSubmitRsp->affectedRows += affectedRows;
13,814,544✔
2002
  }
2003

2004
  // update the affected table uid list
2005
  if (taosArrayGetSize(newTbUids) > 0) {
13,072,217✔
2006
    vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
35,872✔
2007
           (int32_t)taosArrayGetSize(newTbUids));
2008
    if (tqUpdateTbUidList(pVnode->pTq, newTbUids, true) != 0) {
35,872!
2009
      vError("vgId:%d, failed to update tbUid list", TD_VID(pVnode));
×
2010
    }
2011
  }
2012

2013
_exit:
13,071,426✔
2014
  // message
2015
  pRsp->code = code;
13,071,442✔
2016
  tEncodeSize(tEncodeSSubmitRsp2, pSubmitRsp, pRsp->contLen, ret);
13,071,442!
2017
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
13,071,386✔
2018
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
13,071,348✔
2019
  if (tEncodeSSubmitRsp2(&ec, pSubmitRsp) < 0) {
13,071,365!
2020
    vError("vgId:%d, failed to encode submit response", TD_VID(pVnode));
×
2021
  }
2022
  tEncoderClear(&ec);
13,071,420✔
2023

2024
  // update statistics
2025
  (void)atomic_add_fetch_64(&pVnode->statis.nInsert, pSubmitRsp->affectedRows);
13,071,482✔
2026
  (void)atomic_add_fetch_64(&pVnode->statis.nInsertSuccess, pSubmitRsp->affectedRows);
13,071,500✔
2027
  (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsert, 1);
13,071,535✔
2028

2029
  if (tsEnableMonitor && tsMonitorFqdn[0] != 0 && tsMonitorPort != 0 && pSubmitRsp->affectedRows > 0 &&
13,071,530!
2030
      strlen(pOriginalMsg->info.conn.user) > 0 && tsInsertCounter != NULL) {
×
2031
    const char *sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT_AFFECTED_ROWS,
×
2032
                                   pVnode->monitor.strClusterId,
×
2033
                                   pVnode->monitor.strDnodeId,
×
2034
                                   tsLocalEp,
2035
                                   pVnode->monitor.strVgId,
×
2036
                                   pOriginalMsg->info.conn.user,
×
2037
                                   "Success"};
2038
    int         tv = taos_counter_add(tsInsertCounter, pSubmitRsp->affectedRows, sample_labels);
×
2039
  }
2040

2041
  if (code == 0) {
13,071,530✔
2042
    (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
13,071,488✔
2043
    code = tdProcessRSmaSubmit(pVnode->pSma, ver, pSubmitReq, pReq, len);
13,071,502✔
2044
  }
2045
  /*
2046
  if (code == 0) {
2047
    atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
2048
    code = tdProcessRSmaSubmit(pVnode->pSma, ver, pSubmitReq, pReq, len);
2049

2050
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT, pVnode->monitor.strClusterId,
2051
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2052
                                          pOriginalMsg->info.conn.user, "Success"};
2053
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2054
  }
2055
  else{
2056
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT, pVnode->monitor.strClusterId,
2057
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2058
                                        pOriginalMsg->info.conn.user, "Failed"};
2059
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2060
  }
2061
  */
2062

2063
  // clear
2064
  taosArrayDestroy(newTbUids);
13,071,495✔
2065
  tDestroySubmitReq(pSubmitReq, 0 == pMsg->version ? TSDB_MSG_FLG_CMPT : TSDB_MSG_FLG_DECODE);
13,071,450!
2066
  tDestroySSubmitRsp2(pSubmitRsp, TSDB_MSG_FLG_ENCODE);
13,071,421✔
2067

2068
  if (code) terrno = code;
13,071,371✔
2069

2070
  taosMemoryFree(pAllocMsg);
13,071,371✔
2071

2072
  return code;
13,071,371✔
2073
}
2074

2075
static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
33✔
2076
  SVCreateTSmaReq req = {0};
33✔
2077
  SDecoder        coder = {0};
33✔
2078

2079
  if (pRsp) {
33!
2080
    pRsp->msgType = TDMT_VND_CREATE_SMA_RSP;
33✔
2081
    pRsp->code = TSDB_CODE_SUCCESS;
33✔
2082
    pRsp->pCont = NULL;
33✔
2083
    pRsp->contLen = 0;
33✔
2084
  }
2085

2086
  // decode and process req
2087
  tDecoderInit(&coder, pReq, len);
33✔
2088

2089
  if (tDecodeSVCreateTSmaReq(&coder, &req) < 0) {
33!
2090
    terrno = TSDB_CODE_MSG_DECODE_ERROR;
×
2091
    if (pRsp) pRsp->code = terrno;
×
2092
    goto _err;
×
2093
  }
2094

2095
  if (tdProcessTSmaCreate(pVnode->pSma, ver, (const char *)&req) < 0) {
33!
2096
    if (pRsp) pRsp->code = terrno;
×
2097
    goto _err;
×
2098
  }
2099

2100
  tDecoderClear(&coder);
33✔
2101
  vDebug("vgId:%d, success to create tsma %s:%" PRIi64 " version %" PRIi64 " for table %" PRIi64, TD_VID(pVnode),
33✔
2102
         req.indexName, req.indexUid, ver, req.tableUid);
2103
  return 0;
33✔
2104

2105
_err:
×
2106
  tDecoderClear(&coder);
×
2107
  vError("vgId:%d, failed to create tsma %s:%" PRIi64 " version %" PRIi64 "for table %" PRIi64 " since %s",
×
2108
         TD_VID(pVnode), req.indexName, req.indexUid, ver, req.tableUid, terrstr());
2109
  return terrno;
×
2110
}
2111

2112
/**
2113
 * @brief specific for smaDstVnode
2114
 *
2115
 * @param pVnode
2116
 * @param pCont
2117
 * @param contLen
2118
 * @return int32_t
2119
 */
2120
int32_t vnodeProcessCreateTSma(SVnode *pVnode, void *pCont, uint32_t contLen) {
×
2121
  return vnodeProcessCreateTSmaReq(pVnode, 1, pCont, contLen, NULL);
×
2122
}
2123

2124
static int32_t vnodeConsolidateAlterHashRange(SVnode *pVnode, int64_t ver) {
88✔
2125
  int32_t code = TSDB_CODE_SUCCESS;
88✔
2126

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

2130
  // TODO: trim meta of tables from TDB per hash range [pVnode->config.hashBegin, pVnode->config.hashEnd]
2131
  code = metaTrimTables(pVnode->pMeta);
88✔
2132

2133
  return code;
88✔
2134
}
2135

2136
static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
8,319✔
2137
  vInfo("vgId:%d, vnode handle msgType:alter-confirm, alter confirm msg is processed", TD_VID(pVnode));
8,319!
2138
  int32_t code = TSDB_CODE_SUCCESS;
8,319✔
2139
  if (!pVnode->config.hashChange) {
8,319✔
2140
    goto _exit;
8,231✔
2141
  }
2142

2143
  code = vnodeConsolidateAlterHashRange(pVnode, ver);
88✔
2144
  if (code < 0) {
88!
2145
    vError("vgId:%d, failed to consolidate alter hashrange since %s. version:%" PRId64, TD_VID(pVnode), terrstr(), ver);
×
2146
    goto _exit;
×
2147
  }
2148
  pVnode->config.hashChange = false;
88✔
2149

2150
_exit:
8,319✔
2151
  pRsp->msgType = TDMT_VND_ALTER_CONFIRM_RSP;
8,319✔
2152
  pRsp->code = code;
8,319✔
2153
  pRsp->pCont = NULL;
8,319✔
2154
  pRsp->contLen = 0;
8,319✔
2155

2156
  return code;
8,319✔
2157
}
2158

2159
extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb);
2160
extern void    tsdbEnableBgTask(STsdb *pTsdb);
2161

2162
static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
898✔
2163
  bool walChanged = false;
898✔
2164
  bool tsdbChanged = false;
898✔
2165

2166
  SAlterVnodeConfigReq req = {0};
898✔
2167
  if (tDeserializeSAlterVnodeConfigReq(pReq, len, &req) != 0) {
898!
2168
    terrno = TSDB_CODE_INVALID_MSG;
×
2169
    return TSDB_CODE_INVALID_MSG;
×
2170
  }
2171

2172
  vInfo("vgId:%d, start to alter vnode config, page:%d pageSize:%d buffer:%d szPage:%d szBuf:%" PRIu64
902!
2173
        " cacheLast:%d cacheLastSize:%d days:%d keep0:%d keep1:%d keep2:%d keepTimeOffset:%d s3KeepLocal:%d "
2174
        "s3Compact:%d fsync:%d level:%d "
2175
        "walRetentionPeriod:%d walRetentionSize:%d",
2176
        TD_VID(pVnode), req.pages, req.pageSize, req.buffer, req.pageSize * 1024, (uint64_t)req.buffer * 1024 * 1024,
2177
        req.cacheLast, req.cacheLastSize, req.daysPerFile, req.daysToKeep0, req.daysToKeep1, req.daysToKeep2,
2178
        req.keepTimeOffset, req.s3KeepLocal, req.s3Compact, req.walFsyncPeriod, req.walLevel, req.walRetentionPeriod,
2179
        req.walRetentionSize);
2180

2181
  if (pVnode->config.cacheLastSize != req.cacheLastSize) {
902✔
2182
    pVnode->config.cacheLastSize = req.cacheLastSize;
394✔
2183
    tsdbCacheSetCapacity(pVnode, (size_t)pVnode->config.cacheLastSize * 1024 * 1024);
394✔
2184
  }
2185

2186
  if (pVnode->config.szBuf != req.buffer * 1024LL * 1024LL) {
902✔
2187
    vInfo("vgId:%d, vnode buffer is changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pVnode->config.szBuf,
10!
2188
          (uint64_t)(req.buffer * 1024LL * 1024LL));
2189
    pVnode->config.szBuf = req.buffer * 1024LL * 1024LL;
10✔
2190
  }
2191

2192
  if (pVnode->config.szCache != req.pages) {
902✔
2193
    if (metaAlterCache(pVnode->pMeta, req.pages) < 0) {
6!
2194
      vError("vgId:%d, failed to change vnode pages from %d to %d failed since %s", TD_VID(pVnode),
×
2195
             pVnode->config.szCache, req.pages, tstrerror(errno));
2196
      return errno;
×
2197
    } else {
2198
      vInfo("vgId:%d, vnode pages is changed from %d to %d", TD_VID(pVnode), pVnode->config.szCache, req.pages);
6!
2199
      pVnode->config.szCache = req.pages;
6✔
2200
    }
2201
  }
2202

2203
  if (pVnode->config.cacheLast != req.cacheLast) {
902✔
2204
    pVnode->config.cacheLast = req.cacheLast;
575✔
2205
  }
2206

2207
  if (pVnode->config.walCfg.fsyncPeriod != req.walFsyncPeriod) {
902✔
2208
    pVnode->config.walCfg.fsyncPeriod = req.walFsyncPeriod;
70✔
2209
    walChanged = true;
70✔
2210
  }
2211

2212
  if (pVnode->config.walCfg.level != req.walLevel) {
902✔
2213
    if (pVnode->config.walCfg.level == 0) {
51✔
2214
      pVnode->config.walCfg.clearFiles = 1;
3✔
2215
    }
2216
    pVnode->config.walCfg.level = req.walLevel;
51✔
2217
    walChanged = true;
51✔
2218
  }
2219

2220
  if (pVnode->config.walCfg.retentionPeriod != req.walRetentionPeriod) {
902✔
2221
    pVnode->config.walCfg.retentionPeriod = req.walRetentionPeriod;
132✔
2222
    walChanged = true;
132✔
2223
  }
2224

2225
  if (pVnode->config.walCfg.retentionSize != req.walRetentionSize) {
902!
2226
    pVnode->config.walCfg.retentionSize = req.walRetentionSize;
×
2227
    walChanged = true;
×
2228
  }
2229

2230
  if (pVnode->config.tsdbCfg.keep0 != req.daysToKeep0) {
902✔
2231
    pVnode->config.tsdbCfg.keep0 = req.daysToKeep0;
56✔
2232
    if (!VND_IS_RSMA(pVnode)) {
56!
2233
      tsdbChanged = true;
56✔
2234
    }
2235
  }
2236

2237
  if (pVnode->config.tsdbCfg.keep1 != req.daysToKeep1) {
902✔
2238
    pVnode->config.tsdbCfg.keep1 = req.daysToKeep1;
56✔
2239
    if (!VND_IS_RSMA(pVnode)) {
56!
2240
      tsdbChanged = true;
56✔
2241
    }
2242
  }
2243

2244
  if (pVnode->config.tsdbCfg.keep2 != req.daysToKeep2) {
902✔
2245
    pVnode->config.tsdbCfg.keep2 = req.daysToKeep2;
56✔
2246
    if (!VND_IS_RSMA(pVnode)) {
56!
2247
      tsdbChanged = true;
56✔
2248
    }
2249
  }
2250

2251
  if (pVnode->config.tsdbCfg.keepTimeOffset != req.keepTimeOffset) {
902✔
2252
    pVnode->config.tsdbCfg.keepTimeOffset = req.keepTimeOffset;
2✔
2253
    if (!VND_IS_RSMA(pVnode)) {
2!
2254
      tsdbChanged = true;
2✔
2255
    }
2256
  }
2257

2258
  if (req.sttTrigger != -1 && req.sttTrigger != pVnode->config.sttTrigger) {
902!
2259
    if (req.sttTrigger > 1 && pVnode->config.sttTrigger > 1) {
×
2260
      pVnode->config.sttTrigger = req.sttTrigger;
×
2261
    } else {
2262
      vnodeAWait(&pVnode->commitTask);
×
2263

2264
      int32_t ret = tsdbDisableAndCancelAllBgTask(pVnode->pTsdb);
×
2265
      if (ret != 0) {
×
2266
        vError("vgId:%d, failed to disable bg task since %s", TD_VID(pVnode), tstrerror(errno));
×
2267
      }
2268

2269
      pVnode->config.sttTrigger = req.sttTrigger;
×
2270
      tsdbEnableBgTask(pVnode->pTsdb);
×
2271
    }
2272
  }
2273

2274
  if (req.minRows != -1 && req.minRows != pVnode->config.tsdbCfg.minRows) {
902!
2275
    pVnode->config.tsdbCfg.minRows = req.minRows;
×
2276
  }
2277

2278
  if (req.s3KeepLocal != -1 && req.s3KeepLocal != pVnode->config.s3KeepLocal) {
902!
2279
    pVnode->config.s3KeepLocal = req.s3KeepLocal;
×
2280
  }
2281
  if (req.s3Compact != -1 && req.s3Compact != pVnode->config.s3Compact) {
902!
2282
    pVnode->config.s3Compact = req.s3Compact;
×
2283
  }
2284

2285
  if (walChanged) {
902✔
2286
    if (walAlter(pVnode->pWal, &pVnode->config.walCfg) != 0) {
249!
2287
      vError("vgId:%d, failed to alter wal config since %s", TD_VID(pVnode), tstrerror(errno));
×
2288
    }
2289
  }
2290

2291
  if (tsdbChanged) {
902✔
2292
    tsdbSetKeepCfg(pVnode->pTsdb, &pVnode->config.tsdbCfg);
60✔
2293
  }
2294

2295
  return 0;
902✔
2296
}
2297

2298
static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
3,256✔
2299
  SBatchDeleteReq deleteReq;
2300
  SDecoder        decoder;
2301
  tDecoderInit(&decoder, pReq, len);
3,256✔
2302
  if (tDecodeSBatchDeleteReq(&decoder, &deleteReq) < 0) {
3,256!
2303
    tDecoderClear(&decoder);
×
2304
    return terrno = TSDB_CODE_INVALID_MSG;
×
2305
  }
2306

2307
  SMetaReader mr = {0};
3,259✔
2308
  metaReaderDoInit(&mr, pVnode->pMeta, META_READER_NOLOCK);
3,259✔
2309
  STsdb *pTsdb = pVnode->pTsdb;
3,262✔
2310

2311
  if (deleteReq.level) {
3,262✔
2312
    pTsdb = deleteReq.level == 1 ? VND_RSMA1(pVnode) : VND_RSMA2(pVnode);
16✔
2313
  }
2314

2315
  int32_t sz = taosArrayGetSize(deleteReq.deleteReqs);
3,262✔
2316
  for (int32_t i = 0; i < sz; i++) {
7,351✔
2317
    SSingleDeleteReq *pOneReq = taosArrayGet(deleteReq.deleteReqs, i);
4,091✔
2318
    char             *name = pOneReq->tbname;
4,091✔
2319
    if (metaGetTableEntryByName(&mr, name) < 0) {
4,091✔
2320
      vDebug("vgId:%d, stream delete msg, skip since no table: %s", pVnode->config.vgId, name);
2,121✔
2321
      continue;
2,121✔
2322
    }
2323

2324
    int64_t uid = mr.me.uid;
1,971✔
2325

2326
    int32_t code = tsdbDeleteTableData(pTsdb, ver, deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
1,971✔
2327
    if (code < 0) {
1,971!
2328
      terrno = code;
×
2329
      vError("vgId:%d, delete error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64 ", end ts:%" PRId64,
×
2330
             TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
2331
    }
2332

2333
    if (deleteReq.level == 0) {
1,971✔
2334
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, deleteReq.ctimeMs);
1,355✔
2335
      if (code < 0) {
1,355!
2336
        terrno = code;
×
2337
        vError("vgId:%d, update change time error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64
×
2338
               ", end ts:%" PRId64,
2339
               TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
2340
      }
2341
    }
2342
    tDecoderClear(&mr.coder);
1,971✔
2343
  }
2344
  metaReaderClear(&mr);
3,260✔
2345
  taosArrayDestroy(deleteReq.deleteReqs);
3,260✔
2346
  return 0;
3,262✔
2347
}
2348

2349
static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
63,515✔
2350
                                     SRpcMsg *pOriginalMsg) {
2351
  int32_t     code = 0;
63,515✔
2352
  SDecoder   *pCoder = &(SDecoder){0};
63,515✔
2353
  SDeleteRes *pRes = &(SDeleteRes){0};
63,515✔
2354

2355
  pRsp->msgType = TDMT_VND_DELETE_RSP;
63,515✔
2356
  pRsp->pCont = NULL;
63,515✔
2357
  pRsp->contLen = 0;
63,515✔
2358
  pRsp->code = TSDB_CODE_SUCCESS;
63,515✔
2359

2360
  pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t));
63,515✔
2361
  if (pRes->uidList == NULL) {
63,519!
2362
    code = terrno;
×
2363
    goto _err;
×
2364
  }
2365

2366
  tDecoderInit(pCoder, pReq, len);
63,519✔
2367
  code = tDecodeDeleteRes(pCoder, pRes);
63,516✔
2368
  if (code) goto _err;
63,519!
2369

2370
  if (pRes->affectedRows > 0) {
63,519✔
2371
    for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) {
119,325✔
2372
      uint64_t uid = *(uint64_t *)taosArrayGet(pRes->uidList, iUid);
60,514✔
2373
      code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, uid, pRes->skey, pRes->ekey);
60,514✔
2374
      if (code) goto _err;
60,516!
2375
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, pRes->ctimeMs);
60,516✔
2376
      if (code) goto _err;
60,515!
2377
    }
2378
  }
2379

2380
  code = tdProcessRSmaDelete(pVnode->pSma, ver, pRes, pReq, len);
63,518✔
2381

2382
  tDecoderClear(pCoder);
63,517✔
2383
  taosArrayDestroy(pRes->uidList);
63,518✔
2384

2385
  SVDeleteRsp rsp = {.affectedRows = pRes->affectedRows};
63,518✔
2386
  int32_t     ret = 0;
63,518✔
2387
  tEncodeSize(tEncodeSVDeleteRsp, &rsp, pRsp->contLen, ret);
63,518!
2388
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
63,516✔
2389
  SEncoder ec = {0};
63,521✔
2390
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
63,521✔
2391
  code = tEncodeSVDeleteRsp(&ec, &rsp);
63,522✔
2392
  if (code) goto _err;
63,521!
2393
  tEncoderClear(&ec);
63,521✔
2394
  return code;
63,522✔
2395

2396
_err:
×
2397
  /*
2398
  if(code == TSDB_CODE_SUCCESS){
2399
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_DELETE, pVnode->monitor.strClusterId,
2400
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2401
                                        pOriginalMsg->info.conn.user, "Success"};
2402
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2403
  }
2404
  else{
2405
    const char *batch_sample_labels[] = {VNODE_METRIC_TAG_VALUE_DELETE, pVnode->monitor.strClusterId,
2406
                                        pVnode->monitor.strDnodeId, tsLocalEp, pVnode->monitor.strVgId,
2407
                                        pOriginalMsg->info.conn.user, "Failed"};
2408
    taos_counter_inc(pVnode->monitor.insertCounter, batch_sample_labels);
2409
  }
2410
  */
2411

2412
  return code;
×
2413
}
2414
static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
979✔
2415
  SVCreateStbReq req = {0};
979✔
2416
  SDecoder       dc = {0};
979✔
2417
  int32_t        code = 0;
979✔
2418

2419
  pRsp->msgType = TDMT_VND_CREATE_INDEX_RSP;
979✔
2420
  pRsp->code = TSDB_CODE_SUCCESS;
979✔
2421
  pRsp->pCont = NULL;
979✔
2422
  pRsp->contLen = 0;
979✔
2423

2424
  tDecoderInit(&dc, pReq, len);
979✔
2425
  // decode req
2426
  if (tDecodeSVCreateStbReq(&dc, &req) < 0) {
979!
2427
    tDecoderClear(&dc);
×
2428
    return terrno = TSDB_CODE_INVALID_MSG;
×
2429
  }
2430

2431
  code = metaAddIndexToSTable(pVnode->pMeta, ver, &req);
979✔
2432
  if (code) {
979!
2433
    pRsp->code = code;
×
2434
    goto _err;
×
2435
  }
2436
  tDecoderClear(&dc);
979✔
2437
  return 0;
979✔
2438

2439
_err:
×
2440
  tDecoderClear(&dc);
×
2441
  return code;
×
2442
}
2443
static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
2,154✔
2444
  SDropIndexReq req = {0};
2,154✔
2445
  int32_t       code = 0;
2,154✔
2446
  pRsp->msgType = TDMT_VND_DROP_INDEX_RSP;
2,154✔
2447
  pRsp->code = TSDB_CODE_SUCCESS;
2,154✔
2448
  pRsp->pCont = NULL;
2,154✔
2449
  pRsp->contLen = 0;
2,154✔
2450

2451
  if ((code = tDeserializeSDropIdxReq(pReq, len, &req))) {
2,154!
2452
    pRsp->code = code;
×
2453
    return code;
×
2454
  }
2455

2456
  code = metaDropIndexFromSTable(pVnode->pMeta, ver, &req);
2,154✔
2457
  if (code) {
2,154!
2458
    pRsp->code = code;
×
2459
    return code;
×
2460
  }
2461
  return TSDB_CODE_SUCCESS;
2,154✔
2462
}
2463

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

2466
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
241✔
2467
  if (!pVnode->restored) {
241✔
2468
    vInfo("vgId:%d, ignore compact req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
173!
2469
    return 0;
173✔
2470
  }
2471
  return vnodeAsyncCompact(pVnode, ver, pReq, len, pRsp);
68✔
2472
}
2473

2474
static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
2475
  if (syncCheckMember(pVnode->sync) != 0) {
×
2476
    vError("vgId:%d, failed to check member", TD_VID(pVnode));
×
2477
  }
2478

2479
  pRsp->msgType = TDMT_SYNC_CONFIG_CHANGE_RSP;
×
2480
  pRsp->code = TSDB_CODE_SUCCESS;
×
2481
  pRsp->pCont = NULL;
×
2482
  pRsp->contLen = 0;
×
2483

2484
  return 0;
×
2485
}
2486

2487
static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
×
2488
  SSyncState syncState = syncGetState(pVnode->sync);
×
2489
  if (syncState.state != TAOS_SYNC_STATE_LEADER) {
×
2490
    return terrno = TSDB_CODE_SYN_NOT_LEADER;
×
2491
  }
2492

2493
  char token[TSDB_ARB_TOKEN_SIZE] = {0};
×
2494
  if (vnodeGetArbToken(pVnode, token) != 0) {
×
2495
    return terrno = TSDB_CODE_NOT_FOUND;
×
2496
  }
2497

2498
  if (strncmp(token, member0Token, TSDB_ARB_TOKEN_SIZE) != 0 &&
×
2499
      strncmp(token, member1Token, TSDB_ARB_TOKEN_SIZE) != 0) {
×
2500
    return terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
×
2501
  }
2502

2503
  terrno = TSDB_CODE_SUCCESS;
×
2504
  return 0;
×
2505
}
2506

2507
static int32_t vnodeCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
×
2508
  int32_t code = vnodePreCheckAssignedLogSyncd(pVnode, member0Token, member1Token);
×
2509
  if (code != 0) {
×
2510
    return code;
×
2511
  }
2512

2513
  return syncGetAssignedLogSynced(pVnode->sync);
×
2514
}
2515

2516
static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
2517
  int32_t code = 0;
×
2518

2519
  SVArbCheckSyncReq syncReq = {0};
×
2520

2521
  code = tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq);
×
2522
  if (code) {
×
2523
    return terrno = code;
×
2524
  }
2525

2526
  pRsp->msgType = TDMT_VND_ARB_CHECK_SYNC_RSP;
×
2527
  pRsp->code = TSDB_CODE_SUCCESS;
×
2528
  pRsp->pCont = NULL;
×
2529
  pRsp->contLen = 0;
×
2530

2531
  SVArbCheckSyncRsp syncRsp = {0};
×
2532
  syncRsp.arbToken = syncReq.arbToken;
×
2533
  syncRsp.member0Token = syncReq.member0Token;
×
2534
  syncRsp.member1Token = syncReq.member1Token;
×
2535
  syncRsp.vgId = TD_VID(pVnode);
×
2536

2537
  if (vnodeCheckAssignedLogSyncd(pVnode, syncReq.member0Token, syncReq.member1Token) != 0) {
×
2538
    vError("vgId:%d, failed to check assigned log syncd", TD_VID(pVnode));
×
2539
  }
2540
  syncRsp.errCode = terrno;
×
2541

2542
  if (vnodeUpdateArbTerm(pVnode, syncReq.arbTerm) != 0) {
×
2543
    vError("vgId:%d, failed to update arb term", TD_VID(pVnode));
×
2544
    code = -1;
×
2545
    goto _OVER;
×
2546
  }
2547

2548
  int32_t contLen = tSerializeSVArbCheckSyncRsp(NULL, 0, &syncRsp);
×
2549
  if (contLen <= 0) {
×
2550
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2551
    code = -1;
×
2552
    goto _OVER;
×
2553
  }
2554
  void *pHead = rpcMallocCont(contLen);
×
2555
  if (!pHead) {
×
2556
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2557
    code = -1;
×
2558
    goto _OVER;
×
2559
  }
2560

2561
  if (tSerializeSVArbCheckSyncRsp(pHead, contLen, &syncRsp) <= 0) {
×
2562
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2563
    rpcFreeCont(pHead);
×
2564
    code = -1;
×
2565
    goto _OVER;
×
2566
  }
2567

2568
  pRsp->pCont = pHead;
×
2569
  pRsp->contLen = contLen;
×
2570

2571
  terrno = TSDB_CODE_SUCCESS;
×
2572

2573
_OVER:
×
2574
  tFreeSVArbCheckSyncReq(&syncReq);
×
2575
  return code;
×
2576
}
2577

2578
#ifndef TD_ENTERPRISE
2579
int32_t vnodeAsyncCompact(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) { return 0; }
2580
int32_t tsdbAsyncCompact(STsdb *tsdb, const STimeWindow *tw, bool sync) { return 0; }
2581
#endif
2582

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

© 2025 Coveralls, Inc