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

taosdata / TDengine / #3552

11 Dec 2024 06:08AM UTC coverage: 62.526% (+0.7%) from 61.798%
#3552

push

travis-ci

web-flow
Merge pull request #29092 from taosdata/fix/3.0/TD-33146

fix:[TD-33146] stmt_get_tag_fields return error code

124833 of 255773 branches covered (48.81%)

Branch coverage included in aggregate %.

209830 of 279467 relevant lines covered (75.08%)

19111707.6 hits per line

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

59.6
/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,359✔
64
  int32_t code = 0;
175,359✔
65
  int32_t lino = 0;
175,359✔
66

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

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

78
  // name
79
  char *name = NULL;
175,399✔
80
  if (tDecodeCStr(pCoder, &name) < 0) {
175,380!
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,380✔
87
  if (uid == 0) {
175,371✔
88
    uid = tGenIdPI64();
148,609✔
89
  }
90
  *(int64_t *)(pCoder->data + pCoder->pos) = uid;
175,386✔
91

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

95
  tEndDecode(pCoder);
175,386✔
96

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

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

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

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

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

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

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

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

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

157
  code = 0;
5,195✔
158

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

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

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

177
  SArray *tbUids = NULL;
90,368✔
178
  int64_t timestampMs = 0;
90,368✔
179

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

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

200
    ttlReq.nUids = taosArrayGetSize(tbUids);
90,414✔
201
    ttlReq.pTbUids = tbUids;
90,324✔
202
  }
203

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

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

213
    SMsgHead *pContNew = rpcMallocCont(contLenNew);
38✔
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:
90,345✔
233
  taosArrayDestroy(tbUids);
90,345✔
234

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

242
  return code;
90,307✔
243
}
244

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

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

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

270
  // submit data
271
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
10,866,444!
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,866,444✔
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,788,841!
281
      code = TSDB_CODE_INVALID_MSG;
×
282
      TSDB_CHECK_CODE(code, lino, _exit);
×
283
    }
284
  }
285

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

291
  // scan and check
292
  TSKEY now = btimeMs;
10,848,799✔
293
  if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_MICRO) {
10,848,799✔
294
    now *= 1000;
23,186✔
295
  } else if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_NANO) {
10,825,613✔
296
    now *= 1000000;
3,760✔
297
  }
298

299
  int32_t keep = pVnode->config.tsdbCfg.keep2;
10,848,799✔
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,848,799✔
312
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
10,848,799✔
313
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,848,799✔
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) {
156!
323
      code = TSDB_CODE_INVALID_MSG;
×
324
      goto _exit;
×
325
    }
326

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

344
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
762,964,061✔
345
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
752,111,803✔
346
      pCoder->pos += pRow->len;
752,111,803✔
347

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

355
  if (!tDecodeIsEnd(pCoder)) {
10,852,412!
356
    *(int64_t *)(pCoder->data + pCoder->pos) = ctimeMs;
10,854,092✔
357
    pCoder->pos += sizeof(int64_t);
10,854,092✔
358
  }
359

360
  tEndDecode(pCoder);
10,852,412✔
361

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

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

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

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

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

393
  int64_t btimeMs = taosGetTimestampMs();
10,175,578✔
394
  int64_t ctimeMs = btimeMs;
10,175,578✔
395
  for (int32_t i = 0; i < nSubmitTbData; i++) {
21,031,443✔
396
    code = vnodePreProcessSubmitTbData(pVnode, pCoder, btimeMs, ctimeMs);
10,857,035✔
397
    TSDB_CHECK_CODE(code, lino, _exit);
10,856,360✔
398
  }
399

400
  tEndDecode(pCoder);
10,174,408✔
401

402
_exit:
10,175,598✔
403
  tDecoderClear(pCoder);
10,175,598✔
404
  if (code) {
10,175,564✔
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,175,563✔
409
}
410

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

552
  switch (pMsg->msgType) {
10,542,080!
553
    case TDMT_VND_CREATE_TABLE: {
78,089✔
554
      code = vnodePreProcessCreateTableMsg(pVnode, pMsg);
78,089✔
555
    } break;
78,078✔
556
    case TDMT_VND_ALTER_TABLE: {
5,195✔
557
      code = vnodePreProcessAlterTableMsg(pVnode, pMsg);
5,195✔
558
    } break;
5,195✔
559
    case TDMT_VND_FETCH_TTL_EXPIRED_TBS:
90,566✔
560
    case TDMT_VND_DROP_TTL_TABLE: {
561
      code = vnodePreProcessDropTtlMsg(pVnode, pMsg);
90,566✔
562
    } break;
90,323✔
563
    case TDMT_VND_SUBMIT: {
10,175,607✔
564
      code = vnodePreProcessSubmitMsg(pVnode, pMsg);
10,175,607✔
565
    } break;
10,175,552✔
566
    case TDMT_VND_DELETE: {
60,140✔
567
      code = vnodePreProcessDeleteMsg(pVnode, pMsg);
60,140✔
568
    } break;
60,144✔
569
    case TDMT_VND_BATCH_DEL: {
2,525✔
570
      code = vnodePreProcessBatchDeleteMsg(pVnode, pMsg);
2,525✔
571
    } break;
2,524✔
572
    case TDMT_VND_ARB_CHECK_SYNC: {
×
573
      code = vnodePreProcessArbCheckSyncMsg(pVnode, pMsg);
×
574
    } break;
×
575
    case TDMT_VND_DROP_TABLE: {
15,968✔
576
      code = vnodePreProcessDropTbMsg(pVnode, pMsg);
15,968✔
577
    } break;
15,968✔
578
    default:
113,990✔
579
      break;
113,990✔
580
  }
581

582
  if (code && code != TSDB_CODE_MSG_PREPROCESSED) {
10,541,774✔
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,541,632✔
587
}
588

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

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

603
  if (ver <= pVnode->state.applied) {
13,579,717!
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,579,717!
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,579,513!
615
    return terrno = TSDB_CODE_INTERNAL_ERROR;
×
616
  }
617

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

622
  atomic_store_64(&pVnode->state.applied, ver);
13,579,513✔
623
  atomic_store_64(&pVnode->state.applyTerm, pMsg->info.conn.applyTerm);
13,579,802✔
624

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

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

632
  switch (pMsg->msgType) {
13,551,704!
633
    /* META */
634
    case TDMT_VND_CREATE_STB:
31,344✔
635
      if (vnodeProcessCreateStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
31,344✔
636
      break;
31,297✔
637
    case TDMT_VND_ALTER_STB:
9,050✔
638
      if (vnodeProcessAlterStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
9,050!
639
      break;
9,051✔
640
    case TDMT_VND_DROP_STB:
3,460✔
641
      if (vnodeProcessDropStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
3,460!
642
      break;
3,484✔
643
    case TDMT_VND_CREATE_TABLE:
85,952✔
644
      if (vnodeProcessCreateTbReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
85,952!
645
      break;
85,984✔
646
    case TDMT_VND_ALTER_TABLE:
5,201✔
647
      if (vnodeProcessAlterTbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
5,201!
648
      break;
5,201✔
649
    case TDMT_VND_DROP_TABLE:
16,010✔
650
      if (vnodeProcessDropTbReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
16,010!
651
      break;
16,010✔
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:
210✔
659
      if (vnodeProcessTrimReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
210!
660
      break;
210✔
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,241,018✔
669
      if (vnodeProcessSubmitReq(pVnode, ver, pMsg->pCont, pMsg->contLen, pRsp, pMsg) < 0) goto _err;
13,241,018✔
670
      break;
13,241,007✔
671
    case TDMT_VND_DELETE:
63,488✔
672
      if (vnodeProcessDeleteReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
63,488!
673
      break;
63,487✔
674
    case TDMT_VND_BATCH_DEL:
2,737✔
675
      if (vnodeProcessBatchDeleteReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
2,737!
676
      break;
2,737✔
677
    /* TQ */
678
    case TDMT_VND_TMQ_SUBSCRIBE:
4,198✔
679
      if (tqProcessSubscribeReq(pVnode->pTq, ver, pReq, len) < 0) {
4,198✔
680
        goto _err;
2✔
681
      }
682
      break;
4,203✔
683
    case TDMT_VND_TMQ_DELETE_SUB:
869✔
684
      if (tqProcessDeleteSubReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen) < 0) {
869!
685
        goto _err;
×
686
      }
687
      break;
869✔
688
    case TDMT_VND_TMQ_COMMIT_OFFSET:
10,030✔
689
      if (tqProcessOffsetCommitReq(pVnode->pTq, ver, pReq, len) < 0) {
10,030!
690
        goto _err;
×
691
      }
692
      break;
10,036✔
693
    case TDMT_VND_TMQ_ADD_CHECKINFO:
133✔
694
      if (tqProcessAddCheckInfoReq(pVnode->pTq, ver, pReq, len) < 0) {
133!
695
        goto _err;
×
696
      }
697
      break;
134✔
698
    case TDMT_VND_TMQ_DEL_CHECKINFO:
28✔
699
      if (tqProcessDelCheckInfoReq(pVnode->pTq, ver, pReq, len) < 0) {
28✔
700
        goto _err;
2✔
701
      }
702
      break;
26✔
703
    case TDMT_STREAM_TASK_DEPLOY: {
13,728✔
704
      if ((code = tqProcessTaskDeployReq(pVnode->pTq, ver, pReq, len)) != TSDB_CODE_SUCCESS) {
13,728!
705
        goto _err;
×
706
      }
707
    } break;
13,751✔
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,949✔
713
    case TDMT_STREAM_TASK_UPDATE_CHKPT: {
5,886✔
714
      if ((code = tqProcessTaskUpdateCheckpointReq(pVnode->pTq, pMsg->pCont, pMsg->contLen)) < 0) {
5,886!
715
        goto _err;
×
716
      }
717
    } break;
5,901✔
718
    case TDMT_STREAM_CONSEN_CHKPT: {
172✔
719
      if (pVnode->restored && (code = tqProcessTaskConsenChkptIdReq(pVnode->pTq, pMsg)) < 0) {
172!
720
        goto _err;
×
721
      }
722

723
    } break;
172✔
724
    case TDMT_STREAM_TASK_PAUSE: {
1,862✔
725
      if (pVnode->restored && vnodeIsLeader(pVnode) &&
3,255!
726
          (code = tqProcessTaskPauseReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen)) < 0) {
1,388✔
727
        goto _err;
×
728
      }
729
    } break;
1,865✔
730
    case TDMT_STREAM_TASK_RESUME: {
1,857✔
731
      if (pVnode->restored && vnodeIsLeader(pVnode) &&
3,243!
732
          (code = tqProcessTaskResumeReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen)) < 0) {
1,385✔
733
        goto _err;
×
734
      }
735
    } break;
1,858✔
736
    case TDMT_VND_STREAM_TASK_RESET: {
×
737
      if (pVnode->restored && vnodeIsLeader(pVnode) && (code = tqProcessTaskResetReq(pVnode->pTq, pMsg)) < 0) {
×
738
        goto _err;
×
739
      }
740

741
    } break;
×
742
    case TDMT_VND_ALTER_CONFIRM:
8,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:
881✔
749
      vnodeProcessAlterConfigReq(pVnode, ver, pReq, len, pRsp);
881✔
750
      break;
882✔
751
    case TDMT_VND_COMMIT:
31,327✔
752
      needCommit = true;
31,327✔
753
      break;
31,327✔
754
    case TDMT_VND_CREATE_INDEX:
983✔
755
      vnodeProcessCreateIndexReq(pVnode, ver, pReq, len, pRsp);
983✔
756
      break;
983✔
757
    case TDMT_VND_DROP_INDEX:
2,166✔
758
      vnodeProcessDropIndexReq(pVnode, ver, pReq, len, pRsp);
2,166✔
759
      break;
2,166✔
760
    case TDMT_VND_STREAM_CHECK_POINT_SOURCE:  // always return true
3,477✔
761
      tqProcessTaskCheckPointSourceReq(pVnode->pTq, pMsg, pRsp);
3,477✔
762
      break;
3,477✔
763
    case TDMT_VND_STREAM_TASK_UPDATE:  // always return true
80✔
764
      tqProcessTaskUpdateReq(pVnode->pTq, pMsg);
80✔
765
      break;
80✔
766
    case TDMT_VND_COMPACT:
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,551,537!
787
         ver);
788

789
  walApplyVer(pVnode->pWal, ver);
13,551,537✔
790

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

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

814
_exit:
13,551,199✔
815
  return 0;
13,578,953✔
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,480,843✔
824
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) {
8,480,843✔
825
    return 0;
533,399✔
826
  }
827

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

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

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

846
  switch (pMsg->msgType) {
8,487,285!
847
    case TDMT_SCH_QUERY:
7,955,595✔
848
    case TDMT_SCH_MERGE_QUERY:
849
      return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
7,955,595✔
850
    case TDMT_SCH_QUERY_CONTINUE:
440,957✔
851
      return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
440,957✔
852
    case TDMT_VND_TMQ_CONSUME:
67,815✔
853
      return tqProcessPollReq(pVnode->pTq, pMsg);
67,815✔
854
    case TDMT_VND_TMQ_CONSUME_PUSH:
23,370✔
855
      return tqProcessPollPush(pVnode->pTq, pMsg);
23,370✔
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,999,757✔
863
  vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg);
20,999,757✔
864
  if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
20,999,757✔
865
       pMsg->msgType == TDMT_VND_BATCH_META || pMsg->msgType == TDMT_VND_TABLE_NAME) &&
14,516,699✔
866
      !syncIsReadyForRead(pVnode->sync)) {
7,565,406✔
867
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
4,928✔
868
    return 0;
4,928✔
869
  }
870

871
  switch (pMsg->msgType) {
20,996,258!
872
    case TDMT_SCH_FETCH:
9,760,152✔
873
    case TDMT_SCH_MERGE_FETCH:
874
      return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg, 0);
9,760,152✔
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,950,517✔
880
      return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg, 0);
7,950,517✔
881
    case TDMT_SCH_TASK_NOTIFY:
181✔
882
      return qWorkerProcessNotifyMsg(pVnode, pVnode->pQuery, pMsg, 0);
181✔
883
    case TDMT_SCH_QUERY_HEARTBEAT:
2,211,907✔
884
      return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg, 0);
2,211,907✔
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,070,301✔
891
      return vnodeGetBatchMeta(pVnode, pMsg);
1,070,301✔
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:
13✔
899
      return tqProcessVgWalInfoReq(pVnode->pTq, pMsg);
13✔
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) {
368,061✔
912
  vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg);
368,061✔
913
  if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
368,061!
914
       pMsg->msgType == TDMT_VND_BATCH_META) &&
368,125!
915
      !syncIsReadyForRead(pVnode->sync)) {
×
916
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
×
917
    return 0;
×
918
  }
919

920
  switch (pMsg->msgType) {
368,130!
921
    case TDMT_STREAM_TASK_RUN:
164,805✔
922
      return tqProcessTaskRunReq(pVnode->pTq, pMsg);
164,805✔
923
    case TDMT_STREAM_TASK_DISPATCH:
54,870✔
924
      return tqProcessTaskDispatchReq(pVnode->pTq, pMsg);
54,870✔
925
    case TDMT_STREAM_TASK_DISPATCH_RSP:
54,833✔
926
      return tqProcessTaskDispatchRsp(pVnode->pTq, pMsg);
54,833✔
927
    case TDMT_VND_STREAM_TASK_CHECK:
21,350✔
928
      return tqProcessTaskCheckReq(pVnode->pTq, pMsg);
21,350✔
929
    case TDMT_VND_STREAM_TASK_CHECK_RSP:
21,459✔
930
      return tqProcessTaskCheckRsp(pVnode->pTq, pMsg);
21,459✔
931
    case TDMT_STREAM_RETRIEVE:
552✔
932
      return tqProcessTaskRetrieveReq(pVnode->pTq, pMsg);
552✔
933
    case TDMT_STREAM_RETRIEVE_RSP:
432✔
934
      return tqProcessTaskRetrieveRsp(pVnode->pTq, pMsg);
432✔
935
    case TDMT_VND_STREAM_SCAN_HISTORY:
2,578✔
936
      return tqProcessTaskScanHistory(pVnode->pTq, pMsg);
2,578✔
937
    case TDMT_STREAM_TASK_CHECKPOINT_READY:
7,534✔
938
      return tqProcessTaskCheckpointReadyMsg(pVnode->pTq, pMsg);
7,534✔
939
    case TDMT_STREAM_TASK_CHECKPOINT_READY_RSP:
7,528✔
940
      return tqProcessTaskCheckpointReadyRsp(pVnode->pTq, pMsg);
7,528✔
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,006✔
946
      return tqProcessStreamHbRsp(pVnode->pTq, pMsg);
22,006✔
947
    case TDMT_MND_STREAM_REQ_CHKPT_RSP:
4,399✔
948
      return tqProcessStreamReqCheckpointRsp(pVnode->pTq, pMsg);
4,399✔
949
    case TDMT_VND_GET_STREAM_PROGRESS:
×
950
      return tqStreamProgressRetrieveReq(pVnode->pTq, pMsg);
×
951
    case TDMT_MND_STREAM_CHKPT_REPORT_RSP:
5,784✔
952
      return tqProcessTaskChkptReportRsp(pVnode->pTq, pMsg);
5,784✔
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) {
7✔
960
  int32_t code = tdProcessTSmaInsert(((SVnode *)pVnode)->pSma, smaId, (const char *)data);
7✔
961
  if (code) {
7!
962
    vError("failed to process sma result since %s", tstrerror(code));
×
963
  }
964
}
7✔
965

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

971
  strcpy(pMetaRsp->dbFName, pVnode->config.dbname);
177,226✔
972
  pMetaRsp->dbId = pVnode->config.dbId;
177,226✔
973
  pMetaRsp->vgId = TD_VID(pVnode);
177,226✔
974
  pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
177,226✔
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) {
210✔
980
  if (!pVnode->restored) {
210✔
981
    vInfo("vgId:%d, ignore trim req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
23!
982
    return 0;
23✔
983
  }
984

985
  int32_t     code = 0;
187✔
986
  SVTrimDbReq trimReq = {0};
187✔
987

988
  // decode
989
  if (tDeserializeSVTrimDbReq(pReq, len, &trimReq) != 0) {
187!
990
    code = TSDB_CODE_INVALID_MSG;
×
991
    goto _exit;
×
992
  }
993

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

996
  code = vnodeAsyncRetention(pVnode, trimReq.timestamp);
187✔
997

998
_exit:
187✔
999
  return code;
187✔
1000
}
1001

1002
extern int32_t vnodeAsyncS3Migrate(SVnode *pVnode, int64_t now);
1003

1004
static int32_t vnodeProcessS3MigrateReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
1005
  int32_t          code = 0;
×
1006
  SVS3MigrateDbReq s3migrateReq = {0};
×
1007

1008
  // decode
1009
  if (tDeserializeSVS3MigrateDbReq(pReq, len, &s3migrateReq) != 0) {
×
1010
    code = TSDB_CODE_INVALID_MSG;
×
1011
    goto _exit;
×
1012
  }
1013

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

1016
  code = vnodeAsyncS3Migrate(pVnode, s3migrateReq.timestamp);
×
1017

1018
_exit:
×
1019
  return code;
×
1020
}
1021

1022
static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
1023
  int               ret = 0;
×
1024
  SVDropTtlTableReq ttlReq = {0};
×
1025
  if (tDeserializeSVDropTtlTableReq(pReq, len, &ttlReq) != 0) {
×
1026
    ret = TSDB_CODE_INVALID_MSG;
×
1027
    goto end;
×
1028
  }
1029

1030
  if (ttlReq.nUids != taosArrayGetSize(ttlReq.pTbUids)) {
×
1031
    ret = TSDB_CODE_INVALID_MSG;
×
1032
    goto end;
×
1033
  }
1034

1035
  if (ttlReq.nUids != 0) {
×
1036
    vInfo("vgId:%d, drop ttl table req will be processed, time:%d, ntbUids:%d", pVnode->config.vgId,
×
1037
          ttlReq.timestampSec, ttlReq.nUids);
1038
  }
1039

1040
  if (ttlReq.nUids > 0) {
×
1041
    int32_t code = metaDropTables(pVnode->pMeta, ttlReq.pTbUids);
×
1042
    if (code) return code;
×
1043

1044
    code = tqUpdateTbUidList(pVnode->pTq, ttlReq.pTbUids, false);
×
1045
    if (code) {
×
1046
      vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(code));
×
1047
    }
1048
  }
1049

1050
end:
×
1051
  taosArrayDestroy(ttlReq.pTbUids);
×
1052
  return ret;
×
1053
}
1054

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

1067
  if (tDeserializeSVDropTtlTableReq(pReq, len, &ttlReq) != 0) {
38!
1068
    terrno = TSDB_CODE_INVALID_MSG;
×
1069
    goto _end;
×
1070
  }
1071

1072
  if (!(ttlReq.nUids == taosArrayGetSize(ttlReq.pTbUids))) {
38!
1073
    terrno = TSDB_CODE_INVALID_MSG;
×
1074
    goto _end;
×
1075
  }
1076

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

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

1102
    expiredTb.name = p;
140✔
1103
    if (mr.me.type == TSDB_CHILD_TABLE) {
140✔
1104
      expiredTb.suid = mr.me.ctbEntry.suid;
90✔
1105
    }
1106

1107
    if (taosArrayPush(rsp.pExpiredTbs, &expiredTb) == NULL) {
281!
1108
      goto _end;
×
1109
    }
1110
  }
1111

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

1124
  if (terrno == 0) code = 0;
38!
1125
_end:
×
1126
  metaReaderClear(&mr);
38✔
1127
  tFreeFetchTtlExpiredTbsRsp(&rsp);
38✔
1128
  taosArrayDestroy(ttlReq.pTbUids);
38✔
1129
  if (pNames) taosArrayDestroy(pNames);
38!
1130
  pRsp->code = terrno;
38✔
1131
  return code;
38✔
1132
}
1133

1134
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
31,337✔
1135
  int32_t        code = 0;
31,337✔
1136
  SVCreateStbReq req = {0};
31,337✔
1137
  SDecoder       coder;
1138

1139
  pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
31,337✔
1140
  pRsp->code = TSDB_CODE_SUCCESS;
31,337✔
1141
  pRsp->pCont = NULL;
31,337✔
1142
  pRsp->contLen = 0;
31,337✔
1143

1144
  // decode and process req
1145
  tDecoderInit(&coder, pReq, len);
31,337✔
1146

1147
  code = tDecodeSVCreateStbReq(&coder, &req);
31,349✔
1148
  if (code) {
31,360!
1149
    pRsp->code = code;
×
1150
    goto _err;
×
1151
  }
1152

1153
  code = metaCreateSTable(pVnode->pMeta, ver, &req);
31,360✔
1154
  if (code) {
31,331✔
1155
    pRsp->code = code;
3✔
1156
    goto _err;
3✔
1157
  }
1158

1159
  if ((code = tdProcessRSmaCreate(pVnode->pSma, &req)) < 0) {
31,328!
1160
    pRsp->code = code;
×
1161
    goto _err;
×
1162
  }
1163

1164
  tDecoderClear(&coder);
31,404✔
1165
  return 0;
31,336✔
1166

1167
_err:
3✔
1168
  tDecoderClear(&coder);
3✔
1169
  return code;
3✔
1170
}
1171

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

1190
  // decode
1191
  tDecoderInit(&decoder, pReq, len);
85,949✔
1192
  if (tDecodeSVCreateTbBatchReq(&decoder, &req) < 0) {
85,946!
1193
    rcode = -1;
×
1194
    terrno = TSDB_CODE_INVALID_MSG;
×
1195
    goto _exit;
×
1196
  }
1197

1198
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(cRsp));
85,967✔
1199
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
85,979✔
1200
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
85,985✔
1201
  if (rsp.pArray == NULL || tbUids == NULL || tbNames == NULL) {
85,985!
1202
    rcode = -1;
×
1203
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1204
    goto _exit;
×
1205
  }
1206

1207
  // loop to create table
1208
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
212,557✔
1209
    pCreateReq = req.pReqs + iReq;
126,604✔
1210
    memset(&cRsp, 0, sizeof(cRsp));
126,604✔
1211

1212
    if (tsEnableAudit && tsEnableAuditCreateTable) {
126,604!
1213
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
126,606✔
1214
      if (str == NULL) {
126,630!
1215
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1216
        rcode = -1;
×
1217
        goto _exit;
×
1218
      }
1219
      strcpy(str, pCreateReq->name);
126,630✔
1220
      if (taosArrayPush(tbNames, &str) == NULL) {
126,624!
1221
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1222
        rcode = -1;
×
1223
        goto _exit;
×
1224
      }
1225
    }
1226

1227
    // validate hash
1228
    sprintf(tbName, "%s.%s", pVnode->config.dbname, pCreateReq->name);
126,622✔
1229
    if (vnodeValidateTableHash(pVnode, tbName) < 0) {
126,622✔
1230
      cRsp.code = TSDB_CODE_VND_HASH_MISMATCH;
31✔
1231
      if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
62!
1232
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1233
        rcode = -1;
×
1234
        goto _exit;
×
1235
      }
1236
      vError("vgId:%d create-table:%s failed due to hash value mismatch", TD_VID(pVnode), tbName);
31!
1237
      continue;
31✔
1238
    }
1239

1240
    // do create table
1241
    if (metaCreateTable(pVnode->pMeta, ver, pCreateReq, &cRsp.pMeta) < 0) {
126,599✔
1242
      if (pCreateReq->flags & TD_CREATE_IF_NOT_EXISTS && terrno == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
1,361!
1243
        cRsp.code = TSDB_CODE_SUCCESS;
3✔
1244
      } else {
1245
        cRsp.code = terrno;
1,358✔
1246
      }
1247
    } else {
1248
      cRsp.code = TSDB_CODE_SUCCESS;
125,228✔
1249
      if (tdFetchTbUidList(pVnode->pSma, &pStore, pCreateReq->ctb.suid, pCreateReq->uid) < 0) {
125,228!
1250
        vError("vgId:%d, failed to fetch tbUid list", TD_VID(pVnode));
×
1251
      }
1252
      if (taosArrayPush(tbUids, &pCreateReq->uid) == NULL) {
250,430!
1253
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1254
        rcode = -1;
×
1255
        goto _exit;
×
1256
      }
1257
      vnodeUpdateMetaRsp(pVnode, cRsp.pMeta);
125,206✔
1258
    }
1259

1260
    if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
253,102!
1261
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1262
      rcode = -1;
×
1263
      goto _exit;
×
1264
    }
1265
  }
1266

1267
  vDebug("vgId:%d, add %d new created tables into query table list", TD_VID(pVnode), (int32_t)taosArrayGetSize(tbUids));
85,953✔
1268
  if (tqUpdateTbUidList(pVnode->pTq, tbUids, true) < 0) {
85,954!
1269
    vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(terrno));
×
1270
  }
1271
  if (tdUpdateTbUidList(pVnode->pSma, pStore, true) < 0) {
85,988!
1272
    goto _exit;
×
1273
  }
1274
  pStore = tdUidStoreFree(pStore);
85,986✔
1275

1276
  // prepare rsp
1277
  int32_t ret = 0;
85,987✔
1278
  tEncodeSize(tEncodeSVCreateTbBatchRsp, &rsp, pRsp->contLen, ret);
85,987!
1279
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
85,982✔
1280
  if (pRsp->pCont == NULL) {
85,984!
1281
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1282
    rcode = -1;
×
1283
    goto _exit;
×
1284
  }
1285
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
85,984✔
1286
  if (tEncodeSVCreateTbBatchRsp(&encoder, &rsp) != 0) {
85,980!
1287
    vError("vgId:%d, failed to encode create table batch response", TD_VID(pVnode));
×
1288
  }
1289

1290
  if (tsEnableAudit && tsEnableAuditCreateTable) {
85,979!
1291
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
85,979✔
1292

1293
    SName name = {0};
85,979✔
1294
    if (tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB) < 0) {
85,979!
1295
      vError("vgId:%d, failed to get name from string", TD_VID(pVnode));
×
1296
    }
1297

1298
    SStringBuilder sb = {0};
85,984✔
1299
    for (int32_t i = 0; i < tbNames->size; i++) {
212,612✔
1300
      char **key = (char **)taosArrayGet(tbNames, i);
126,638✔
1301
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
126,636✔
1302
      if (i < tbNames->size - 1) {
126,634✔
1303
        taosStringBuilderAppendChar(&sb, ',');
40,660✔
1304
      }
1305
      // taosMemoryFreeClear(*key);
1306
    }
1307

1308
    size_t len = 0;
85,974✔
1309
    char  *keyJoined = taosStringBuilderGetResult(&sb, &len);
85,974✔
1310

1311
    if (pOriginRpc->info.conn.user != NULL && strlen(pOriginRpc->info.conn.user) > 0) {
85,979!
1312
      auditAddRecord(pOriginRpc, clusterId, "createTable", name.dbname, "", keyJoined, len);
71,260✔
1313
    }
1314

1315
    taosStringBuilderDestroy(&sb);
85,977✔
1316
  }
1317

1318
_exit:
×
1319
  tDeleteSVCreateTbBatchReq(&req);
85,975✔
1320
  taosArrayDestroyEx(rsp.pArray, tFreeSVCreateTbRsp);
85,983✔
1321
  taosArrayDestroy(tbUids);
85,982✔
1322
  tDecoderClear(&decoder);
85,982✔
1323
  tEncoderClear(&encoder);
85,983✔
1324
  taosArrayDestroyP(tbNames, taosMemoryFree);
85,986✔
1325
  return rcode;
85,987✔
1326
}
1327

1328
static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
9,049✔
1329
  int32_t        code = 0;
9,049✔
1330
  SVCreateStbReq req = {0};
9,049✔
1331
  SDecoder       dc = {0};
9,049✔
1332

1333
  pRsp->msgType = TDMT_VND_ALTER_STB_RSP;
9,049✔
1334
  pRsp->code = TSDB_CODE_SUCCESS;
9,049✔
1335
  pRsp->pCont = NULL;
9,049✔
1336
  pRsp->contLen = 0;
9,049✔
1337

1338
  tDecoderInit(&dc, pReq, len);
9,049✔
1339

1340
  // decode req
1341
  code = tDecodeSVCreateStbReq(&dc, &req);
9,049✔
1342
  if (code) {
9,055!
1343
    tDecoderClear(&dc);
×
1344
    return code;
×
1345
  }
1346

1347
  code = metaAlterSTable(pVnode->pMeta, ver, &req);
9,055✔
1348
  if (code) {
9,050!
1349
    pRsp->code = code;
×
1350
    tDecoderClear(&dc);
×
1351
    return code;
×
1352
  }
1353

1354
  tDecoderClear(&dc);
9,050✔
1355

1356
  return 0;
9,052✔
1357
}
1358

1359
static int32_t vnodeProcessDropStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
3,460✔
1360
  SVDropStbReq req = {0};
3,460✔
1361
  int32_t      rcode = TSDB_CODE_SUCCESS;
3,460✔
1362
  SDecoder     decoder = {0};
3,460✔
1363
  SArray      *tbUidList = NULL;
3,460✔
1364

1365
  pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
3,460✔
1366
  pRsp->pCont = NULL;
3,460✔
1367
  pRsp->contLen = 0;
3,460✔
1368

1369
  // decode request
1370
  tDecoderInit(&decoder, pReq, len);
3,460✔
1371
  if (tDecodeSVDropStbReq(&decoder, &req) < 0) {
3,463!
1372
    rcode = TSDB_CODE_INVALID_MSG;
×
1373
    goto _exit;
×
1374
  }
1375

1376
  // process request
1377
  tbUidList = taosArrayInit(8, sizeof(int64_t));
3,475✔
1378
  if (tbUidList == NULL) goto _exit;
3,479!
1379
  if (metaDropSTable(pVnode->pMeta, ver, &req, tbUidList) < 0) {
3,479✔
1380
    rcode = terrno;
51✔
1381
    goto _exit;
51✔
1382
  }
1383

1384
  if (tqUpdateTbUidList(pVnode->pTq, tbUidList, false) < 0) {
3,432!
1385
    rcode = terrno;
×
1386
    goto _exit;
×
1387
  }
1388

1389
  if (tdProcessRSmaDrop(pVnode->pSma, &req) < 0) {
3,433!
1390
    rcode = terrno;
×
1391
    goto _exit;
×
1392
  }
1393

1394
  // return rsp
1395
_exit:
3,433✔
1396
  if (tbUidList) taosArrayDestroy(tbUidList);
3,484!
1397
  pRsp->code = rcode;
3,484✔
1398
  tDecoderClear(&decoder);
3,484✔
1399
  return 0;
3,484✔
1400
}
1401

1402
static int32_t vnodeProcessAlterTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
5,201✔
1403
  SVAlterTbReq  vAlterTbReq = {0};
5,201✔
1404
  SVAlterTbRsp  vAlterTbRsp = {0};
5,201✔
1405
  SDecoder      dc = {0};
5,201✔
1406
  int32_t       rcode = 0;
5,201✔
1407
  int32_t       ret;
1408
  SEncoder      ec = {0};
5,201✔
1409
  STableMetaRsp vMetaRsp = {0};
5,201✔
1410

1411
  pRsp->msgType = TDMT_VND_ALTER_TABLE_RSP;
5,201✔
1412
  pRsp->pCont = NULL;
5,201✔
1413
  pRsp->contLen = 0;
5,201✔
1414
  pRsp->code = TSDB_CODE_SUCCESS;
5,201✔
1415

1416
  tDecoderInit(&dc, pReq, len);
5,201✔
1417

1418
  // decode
1419
  if (tDecodeSVAlterTbReq(&dc, &vAlterTbReq) < 0) {
5,201!
1420
    vAlterTbRsp.code = TSDB_CODE_INVALID_MSG;
×
1421
    tDecoderClear(&dc);
×
1422
    rcode = -1;
×
1423
    goto _exit;
×
1424
  }
1425

1426
  // process
1427
  if (metaAlterTable(pVnode->pMeta, ver, &vAlterTbReq, &vMetaRsp) < 0) {
5,201✔
1428
    vAlterTbRsp.code = terrno;
932✔
1429
    tDecoderClear(&dc);
932✔
1430
    rcode = -1;
932✔
1431
    goto _exit;
932✔
1432
  }
1433
  tDecoderClear(&dc);
4,269✔
1434

1435
  if (NULL != vMetaRsp.pSchemas) {
4,269✔
1436
    vnodeUpdateMetaRsp(pVnode, &vMetaRsp);
1,042✔
1437
    vAlterTbRsp.pMeta = &vMetaRsp;
1,042✔
1438
  }
1439

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

1456
static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
16,010✔
1457
                                     SRpcMsg *pOriginRpc) {
1458
  SVDropTbBatchReq req = {0};
16,010✔
1459
  SVDropTbBatchRsp rsp = {0};
16,010✔
1460
  SDecoder         decoder = {0};
16,010✔
1461
  SEncoder         encoder = {0};
16,010✔
1462
  int32_t          ret;
1463
  SArray          *tbUids = NULL;
16,010✔
1464
  STbUidStore     *pStore = NULL;
16,010✔
1465
  SArray          *tbNames = NULL;
16,010✔
1466

1467
  pRsp->msgType = TDMT_VND_DROP_TABLE_RSP;
16,010✔
1468
  pRsp->pCont = NULL;
16,010✔
1469
  pRsp->contLen = 0;
16,010✔
1470
  pRsp->code = TSDB_CODE_SUCCESS;
16,010✔
1471

1472
  // decode req
1473
  tDecoderInit(&decoder, pReq, len);
16,010✔
1474
  ret = tDecodeSVDropTbBatchReq(&decoder, &req);
16,010✔
1475
  if (ret < 0) {
16,010!
1476
    terrno = TSDB_CODE_INVALID_MSG;
×
1477
    pRsp->code = terrno;
×
1478
    goto _exit;
×
1479
  }
1480

1481
  // process req
1482
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
16,010✔
1483
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(SVDropTbRsp));
16,010✔
1484
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
16,010✔
1485
  if (tbUids == NULL || rsp.pArray == NULL || tbNames == NULL) goto _exit;
16,010!
1486

1487
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
32,045✔
1488
    SVDropTbReq *pDropTbReq = req.pReqs + iReq;
16,035✔
1489
    SVDropTbRsp  dropTbRsp = {0};
16,035✔
1490
    tb_uid_t     tbUid = 0;
16,035✔
1491

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

1509
    if (taosArrayPush(rsp.pArray, &dropTbRsp) == NULL) {
32,070!
1510
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1511
      pRsp->code = terrno;
×
1512
      goto _exit;
×
1513
    }
1514

1515
    if (tsEnableAuditCreateTable) {
16,035!
1516
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
16,035✔
1517
      if (str == NULL) {
16,035!
1518
        pRsp->code = terrno;
×
1519
        goto _exit;
×
1520
      }
1521
      strcpy(str, pDropTbReq->name);
16,035✔
1522
      if (taosArrayPush(tbNames, &str) == NULL) {
16,035!
1523
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1524
        pRsp->code = terrno;
×
1525
        goto _exit;
×
1526
      }
1527
    }
1528
  }
1529

1530
  if (tqUpdateTbUidList(pVnode->pTq, tbUids, false) < 0) {
16,010!
1531
    vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(terrno));
×
1532
  }
1533

1534
  if (tdUpdateTbUidList(pVnode->pSma, pStore, false) < 0) {
16,010!
1535
    goto _exit;
×
1536
  }
1537

1538
  if (tsEnableAuditCreateTable) {
16,010!
1539
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
16,010✔
1540

1541
    SName name = {0};
16,010✔
1542
    if (tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB) != 0) {
16,010!
1543
      vError("vgId:%d, failed to get name from string", TD_VID(pVnode));
×
1544
    }
1545

1546
    SStringBuilder sb = {0};
16,010✔
1547
    for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
32,045✔
1548
      char **key = (char **)taosArrayGet(tbNames, iReq);
16,035✔
1549
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
16,035✔
1550
      if (iReq < req.nReqs - 1) {
16,035✔
1551
        taosStringBuilderAppendChar(&sb, ',');
25✔
1552
      }
1553
      taosMemoryFreeClear(*key);
16,035!
1554
    }
1555

1556
    size_t len = 0;
16,010✔
1557
    char  *keyJoined = taosStringBuilderGetResult(&sb, &len);
16,010✔
1558

1559
    if (pOriginRpc->info.conn.user != NULL && strlen(pOriginRpc->info.conn.user) > 0) {
16,010!
1560
      auditAddRecord(pOriginRpc, clusterId, "dropTable", name.dbname, "", keyJoined, len);
15,913✔
1561
    }
1562

1563
    taosStringBuilderDestroy(&sb);
16,010✔
1564
  }
1565

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

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

1591
  tInitSubmitBlkIter(msgIter, pBlock, &blkIter);
1592
  if (blkIter.row == NULL) return 0;
1593

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

1601
  suid = msgIter->suid;
1602
  rv = TD_ROW_SVER(blkIter.row);
1603

1604
  char __tags[128] = {0};
1605
  snprintf(__tags, 128, "%s: uid %" PRIi64 " ", tags, msgIter->uid);
1606
  while ((row = tGetSubmitBlkNext(&blkIter))) {
1607
    tdSRowPrint(row, pSchema, __tags);
1608
  }
1609

1610
  taosMemoryFreeClear(pSchema);
1611

1612
  return TSDB_CODE_SUCCESS;
1613
}
1614
#endif
1615
typedef struct SSubmitReqConvertCxt {
1616
  SSubmitMsgIter msgIter;
1617
  SSubmitBlk    *pBlock;
1618
  SSubmitBlkIter blkIter;
1619
  STSRow        *pRow;
1620
  STSRowIter     rowIter;
1621
  SSubmitTbData *pTbData;
1622
  STSchema      *pTbSchema;
1623
  SArray        *pColValues;
1624
} SSubmitReqConvertCxt;
1625

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

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

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

1664
  return TSDB_CODE_SUCCESS;
×
1665
}
1666

1667
static void vnodeDestroySubmitReqConvertCxt(SSubmitReqConvertCxt *pCxt) {
×
1668
  taosMemoryFreeClear(pCxt->pTbSchema);
×
1669
  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
×
1670
  taosMemoryFreeClear(pCxt->pTbData);
×
1671
  taosArrayDestroy(pCxt->pColValues);
×
1672
}
×
1673

1674
static int32_t vnodeCellValConvertToColVal(STColumn *pCol, SCellVal *pCellVal, SColVal *pColVal) {
×
1675
  if (tdValTypeIsNone(pCellVal->valType)) {
×
1676
    pColVal->flag = CV_FLAG_NONE;
×
1677
    return TSDB_CODE_SUCCESS;
×
1678
  }
1679

1680
  if (tdValTypeIsNull(pCellVal->valType)) {
×
1681
    pColVal->flag = CV_FLAG_NULL;
×
1682
    return TSDB_CODE_SUCCESS;
×
1683
  }
1684

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

1697
  pColVal->flag = CV_FLAG_VALUE;
×
1698
  return TSDB_CODE_SUCCESS;
×
1699
}
1700

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

1715
static int32_t vnodeDecodeCreateTbReq(SSubmitReqConvertCxt *pCxt) {
×
1716
  if (pCxt->msgIter.schemaLen <= 0) {
×
1717
    return TSDB_CODE_SUCCESS;
×
1718
  }
1719

1720
  pCxt->pTbData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
×
1721
  if (NULL == pCxt->pTbData->pCreateTbReq) {
×
1722
    return terrno;
×
1723
  }
1724

1725
  SDecoder decoder = {0};
×
1726
  tDecoderInit(&decoder, (uint8_t *)pCxt->pBlock->data, pCxt->msgIter.schemaLen);
×
1727
  int32_t code = tDecodeSVCreateTbReq(&decoder, pCxt->pTbData->pCreateTbReq);
×
1728
  tDecoderClear(&decoder);
×
1729

1730
  return code;
×
1731
}
1732

1733
static int32_t vnodeSubmitReqConvertToSubmitReq2(SVnode *pVnode, SSubmitReq *pReq, SSubmitReq2 *pReq2) {
×
1734
  pReq2->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData));
×
1735
  if (NULL == pReq2->aSubmitTbData) {
×
1736
    return terrno;
×
1737
  }
1738

1739
  SSubmitReqConvertCxt cxt = {0};
×
1740

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

1771
  vnodeDestroySubmitReqConvertCxt(&cxt);
×
1772
  return code;
×
1773
}
1774

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

1798
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
13,240,996✔
1799
                                     SRpcMsg *pOriginalMsg) {
1800
  int32_t code = 0;
13,240,996✔
1801
  terrno = 0;
13,240,996✔
1802

1803
  SSubmitReq2 *pSubmitReq = &(SSubmitReq2){0};
13,241,150✔
1804
  SSubmitRsp2 *pSubmitRsp = &(SSubmitRsp2){0};
13,241,150✔
1805
  SArray      *newTbUids = NULL;
13,241,150✔
1806
  int32_t      ret;
1807
  SEncoder     ec = {0};
13,241,150✔
1808

1809
  pRsp->code = TSDB_CODE_SUCCESS;
13,241,150✔
1810

1811
  void           *pAllocMsg = NULL;
13,241,150✔
1812
  SSubmitReq2Msg *pMsg = (SSubmitReq2Msg *)pReq;
13,241,150✔
1813
  if (0 == pMsg->version) {
13,241,150!
1814
    code = vnodeSubmitReqConvertToSubmitReq2(pVnode, (SSubmitReq *)pMsg, pSubmitReq);
×
1815
    if (TSDB_CODE_SUCCESS == code) {
×
1816
      code = vnodeRebuildSubmitReqMsg(pSubmitReq, &pReq);
×
1817
    }
1818
    if (TSDB_CODE_SUCCESS == code) {
×
1819
      pAllocMsg = pReq;
×
1820
    }
1821
    if (TSDB_CODE_SUCCESS != code) {
×
1822
      goto _exit;
×
1823
    }
1824
  } else {
1825
    // decode
1826
    pReq = POINTER_SHIFT(pReq, sizeof(SSubmitReq2Msg));
13,241,150✔
1827
    len -= sizeof(SSubmitReq2Msg);
13,241,150✔
1828
    SDecoder dc = {0};
13,241,150✔
1829
    tDecoderInit(&dc, pReq, len);
13,241,150✔
1830
    if (tDecodeSubmitReq(&dc, pSubmitReq) < 0) {
13,241,023!
1831
      code = TSDB_CODE_INVALID_MSG;
×
1832
      goto _exit;
×
1833
    }
1834
    tDecoderClear(&dc);
13,241,130✔
1835
  }
1836

1837
  // scan
1838
  TSKEY now = taosGetTimestamp(pVnode->config.tsdbCfg.precision);
13,241,110✔
1839
  TSKEY minKey = now - tsTickPerMin[pVnode->config.tsdbCfg.precision] * pVnode->config.tsdbCfg.keep2;
13,241,150✔
1840
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
13,241,150✔
1841
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
27,201,594✔
1842
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
13,960,212✔
1843

1844
    if (pSubmitTbData->pCreateTbReq && pSubmitTbData->pCreateTbReq->uid == 0) {
13,960,151!
1845
      code = TSDB_CODE_INVALID_MSG;
×
1846
      goto _exit;
×
1847
    }
1848

1849
    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
13,960,151✔
1850
      if (TARRAY_SIZE(pSubmitTbData->aCol) <= 0) {
154!
1851
        code = TSDB_CODE_INVALID_MSG;
×
1852
        goto _exit;
×
1853
      }
1854

1855
      SColData *colDataArr = TARRAY_DATA(pSubmitTbData->aCol);
154✔
1856
      SRowKey   lastKey;
1857
      tColDataArrGetRowKey(colDataArr, TARRAY_SIZE(pSubmitTbData->aCol), 0, &lastKey);
154✔
1858
      for (int32_t iRow = 1; iRow < colDataArr[0].nVal; iRow++) {
269✔
1859
        SRowKey key;
1860
        tColDataArrGetRowKey(TARRAY_DATA(pSubmitTbData->aCol), TARRAY_SIZE(pSubmitTbData->aCol), iRow, &key);
115✔
1861
        if (tRowKeyCompare(&lastKey, &key) >= 0) {
115!
1862
          code = TSDB_CODE_INVALID_MSG;
×
1863
          vError("vgId:%d %s failed 1 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(terrno), ver);
×
1864
          goto _exit;
×
1865
        }
1866
      }
1867
    } else {
1868
      int32_t nRow = TARRAY_SIZE(pSubmitTbData->aRowP);
13,959,997✔
1869
      SRow  **aRow = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP);
13,959,997✔
1870
      SRowKey lastRowKey;
1871
      for (int32_t iRow = 0; iRow < nRow; ++iRow) {
826,273,559✔
1872
        if (aRow[iRow]->ts < minKey || aRow[iRow]->ts > maxKey) {
812,313,269!
1873
          code = TSDB_CODE_INVALID_MSG;
17,239✔
1874
          vError("vgId:%d %s failed 2 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code), ver);
17,239!
1875
          goto _exit;
×
1876
        }
1877
        if (iRow == 0) {
812,296,030✔
1878
          tRowGetKey(aRow[iRow], &lastRowKey);
13,960,052✔
1879
        } else {
1880
          SRowKey rowKey;
1881
          tRowGetKey(aRow[iRow], &rowKey);
798,335,978✔
1882

1883
          if (tRowKeyCompare(&lastRowKey, &rowKey) >= 0) {
798,333,072!
1884
            code = TSDB_CODE_INVALID_MSG;
×
1885
            vError("vgId:%d %s failed 3 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code), ver);
×
1886
            goto _exit;
×
1887
          }
1888
          lastRowKey = rowKey;
798,350,037✔
1889
        }
1890
      }
1891
    }
1892
  }
1893

1894
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
27,204,630✔
1895
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
13,962,745✔
1896

1897
    if (pSubmitTbData->pCreateTbReq) {
13,962,597✔
1898
      pSubmitTbData->uid = pSubmitTbData->pCreateTbReq->uid;
77,040✔
1899
    } else {
1900
      SMetaInfo info = {0};
13,885,557✔
1901

1902
      code = metaGetInfo(pVnode->pMeta, pSubmitTbData->uid, &info, NULL);
13,885,557✔
1903
      if (code) {
13,886,285!
1904
        code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
×
1905
        vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), pSubmitTbData->uid);
×
1906
        goto _exit;
8✔
1907
      }
1908

1909
      if (info.suid != pSubmitTbData->suid) {
13,886,295!
1910
        code = TSDB_CODE_INVALID_MSG;
×
1911
        goto _exit;
×
1912
      }
1913

1914
      if (info.suid) {
13,886,295✔
1915
        if (metaGetInfo(pVnode->pMeta, info.suid, &info, NULL) != 0) {
12,948,598!
1916
          vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), info.suid);
×
1917
        }
1918
      }
1919

1920
      if (pSubmitTbData->sver != info.skmVer) {
13,886,208!
1921
        code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER;
×
1922
        goto _exit;
×
1923
      }
1924
    }
1925

1926
    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
13,963,248✔
1927
      int32_t   nColData = TARRAY_SIZE(pSubmitTbData->aCol);
155✔
1928
      SColData *aColData = (SColData *)TARRAY_DATA(pSubmitTbData->aCol);
155✔
1929

1930
      if (nColData <= 0) {
155!
1931
        code = TSDB_CODE_INVALID_MSG;
×
1932
        goto _exit;
×
1933
      }
1934

1935
      if (aColData[0].cid != PRIMARYKEY_TIMESTAMP_COL_ID || aColData[0].type != TSDB_DATA_TYPE_TIMESTAMP ||
155!
1936
          aColData[0].nVal <= 0) {
155!
1937
        code = TSDB_CODE_INVALID_MSG;
×
1938
        goto _exit;
×
1939
      }
1940

1941
      for (int32_t j = 1; j < nColData; j++) {
691✔
1942
        if (aColData[j].nVal != aColData[0].nVal) {
536!
1943
          code = TSDB_CODE_INVALID_MSG;
×
1944
          goto _exit;
×
1945
        }
1946
      }
1947
    }
1948
  }
1949

1950
  vDebug("vgId:%d, submit block size %d", TD_VID(pVnode), (int32_t)taosArrayGetSize(pSubmitReq->aSubmitTbData));
13,241,885✔
1951

1952
  // loop to handle
1953
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
27,200,663✔
1954
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
13,959,445✔
1955

1956
    // create table
1957
    if (pSubmitTbData->pCreateTbReq) {
13,959,196✔
1958
      // alloc if need
1959
      if (pSubmitRsp->aCreateTbRsp == NULL &&
77,034✔
1960
          (pSubmitRsp->aCreateTbRsp = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(SVCreateTbRsp))) ==
55,917!
1961
              NULL) {
1962
        code = terrno;
×
1963
        goto _exit;
8✔
1964
      }
1965

1966
      SVCreateTbRsp *pCreateTbRsp = taosArrayReserve(pSubmitRsp->aCreateTbRsp, 1);
77,034✔
1967

1968
      // create table
1969
      if (metaCreateTable(pVnode->pMeta, ver, pSubmitTbData->pCreateTbReq, &pCreateTbRsp->pMeta) == 0) {
77,032✔
1970
        // create table success
1971

1972
        if (newTbUids == NULL &&
86,690!
1973
            (newTbUids = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(int64_t))) == NULL) {
35,708✔
1974
          code = terrno;
×
1975
          goto _exit;
×
1976
        }
1977

1978
        if (taosArrayPush(newTbUids, &pSubmitTbData->uid) == NULL) {
101,965!
1979
          code = terrno;
×
1980
          goto _exit;
×
1981
        }
1982

1983
        if (pCreateTbRsp->pMeta) {
50,983!
1984
          vnodeUpdateMetaRsp(pVnode, pCreateTbRsp->pMeta);
50,983✔
1985
        }
1986
      } else {  // create table failed
1987
        if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
26,052✔
1988
          code = terrno;
8✔
1989
          vError("vgId:%d failed to create table:%s, code:%s", TD_VID(pVnode), pSubmitTbData->pCreateTbReq->name,
8!
1990
                 tstrerror(terrno));
1991
          goto _exit;
8✔
1992
        }
1993
        terrno = 0;
26,044✔
1994
        pSubmitTbData->uid = pSubmitTbData->pCreateTbReq->uid;  // update uid if table exist for using below
26,044✔
1995
      }
1996
    }
1997

1998
    // insert data
1999
    int32_t affectedRows;
2000
    code = tsdbInsertTableData(pVnode->pTsdb, ver, pSubmitTbData, &affectedRows);
13,959,190✔
2001
    if (code) goto _exit;
13,959,746!
2002

2003
    code = metaUpdateChangeTimeWithLock(pVnode->pMeta, pSubmitTbData->uid, pSubmitTbData->ctimeMs);
13,959,746✔
2004
    if (code) goto _exit;
13,959,438!
2005

2006
    pSubmitRsp->affectedRows += affectedRows;
13,959,438✔
2007
  }
2008

2009
  // update the affected table uid list
2010
  if (taosArrayGetSize(newTbUids) > 0) {
13,241,218✔
2011
    vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
35,708✔
2012
           (int32_t)taosArrayGetSize(newTbUids));
2013
    if (tqUpdateTbUidList(pVnode->pTq, newTbUids, true) != 0) {
35,708!
2014
      vError("vgId:%d, failed to update tbUid list", TD_VID(pVnode));
×
2015
    }
2016
  }
2017

2018
_exit:
13,241,153✔
2019
  // message
2020
  pRsp->code = code;
13,241,169✔
2021
  tEncodeSize(tEncodeSSubmitRsp2, pSubmitRsp, pRsp->contLen, ret);
13,241,169!
2022
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
13,241,118✔
2023
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
13,241,095✔
2024
  if (tEncodeSSubmitRsp2(&ec, pSubmitRsp) < 0) {
13,241,154!
2025
    vError("vgId:%d, failed to encode submit response", TD_VID(pVnode));
×
2026
  }
2027
  tEncoderClear(&ec);
13,241,185✔
2028

2029
  // update statistics
2030
  (void)atomic_add_fetch_64(&pVnode->statis.nInsert, pSubmitRsp->affectedRows);
13,241,223✔
2031
  (void)atomic_add_fetch_64(&pVnode->statis.nInsertSuccess, pSubmitRsp->affectedRows);
13,241,232✔
2032
  (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsert, 1);
13,241,241✔
2033

2034
  if (tsEnableMonitor && tsMonitorFqdn[0] != 0 && tsMonitorPort != 0 && pSubmitRsp->affectedRows > 0 &&
13,241,239!
2035
      strlen(pOriginalMsg->info.conn.user) > 0 && tsInsertCounter != NULL) {
×
2036
    const char *sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT_AFFECTED_ROWS,
×
2037
                                   pVnode->monitor.strClusterId,
×
2038
                                   pVnode->monitor.strDnodeId,
×
2039
                                   tsLocalEp,
2040
                                   pVnode->monitor.strVgId,
×
2041
                                   pOriginalMsg->info.conn.user,
×
2042
                                   "Success"};
2043
    int         tv = taos_counter_add(tsInsertCounter, pSubmitRsp->affectedRows, sample_labels);
×
2044
  }
2045

2046
  if (code == 0) {
13,241,239✔
2047
    (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
13,241,210✔
2048
    code = tdProcessRSmaSubmit(pVnode->pSma, ver, pSubmitReq, pReq, len);
13,241,236✔
2049
  }
2050
  /*
2051
  if (code == 0) {
2052
    atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
2053
    code = tdProcessRSmaSubmit(pVnode->pSma, ver, pSubmitReq, pReq, len);
2054

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

2068
  // clear
2069
  taosArrayDestroy(newTbUids);
13,241,199✔
2070
  tDestroySubmitReq(pSubmitReq, 0 == pMsg->version ? TSDB_MSG_FLG_CMPT : TSDB_MSG_FLG_DECODE);
13,241,149!
2071
  tDestroySSubmitRsp2(pSubmitRsp, TSDB_MSG_FLG_ENCODE);
13,241,179✔
2072

2073
  if (code) terrno = code;
13,241,130✔
2074

2075
  taosMemoryFree(pAllocMsg);
13,241,130✔
2076

2077
  return code;
13,241,115✔
2078
}
2079

2080
static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
33✔
2081
  SVCreateTSmaReq req = {0};
33✔
2082
  SDecoder        coder = {0};
33✔
2083

2084
  if (pRsp) {
33!
2085
    pRsp->msgType = TDMT_VND_CREATE_SMA_RSP;
33✔
2086
    pRsp->code = TSDB_CODE_SUCCESS;
33✔
2087
    pRsp->pCont = NULL;
33✔
2088
    pRsp->contLen = 0;
33✔
2089
  }
2090

2091
  // decode and process req
2092
  tDecoderInit(&coder, pReq, len);
33✔
2093

2094
  if (tDecodeSVCreateTSmaReq(&coder, &req) < 0) {
33!
2095
    terrno = TSDB_CODE_MSG_DECODE_ERROR;
×
2096
    if (pRsp) pRsp->code = terrno;
×
2097
    goto _err;
×
2098
  }
2099

2100
  if (tdProcessTSmaCreate(pVnode->pSma, ver, (const char *)&req) < 0) {
33!
2101
    if (pRsp) pRsp->code = terrno;
×
2102
    goto _err;
×
2103
  }
2104

2105
  tDecoderClear(&coder);
33✔
2106
  vDebug("vgId:%d, success to create tsma %s:%" PRIi64 " version %" PRIi64 " for table %" PRIi64, TD_VID(pVnode),
33✔
2107
         req.indexName, req.indexUid, ver, req.tableUid);
2108
  return 0;
33✔
2109

2110
_err:
×
2111
  tDecoderClear(&coder);
×
2112
  vError("vgId:%d, failed to create tsma %s:%" PRIi64 " version %" PRIi64 "for table %" PRIi64 " since %s",
×
2113
         TD_VID(pVnode), req.indexName, req.indexUid, ver, req.tableUid, terrstr());
2114
  return terrno;
×
2115
}
2116

2117
/**
2118
 * @brief specific for smaDstVnode
2119
 *
2120
 * @param pVnode
2121
 * @param pCont
2122
 * @param contLen
2123
 * @return int32_t
2124
 */
2125
int32_t vnodeProcessCreateTSma(SVnode *pVnode, void *pCont, uint32_t contLen) {
×
2126
  return vnodeProcessCreateTSmaReq(pVnode, 1, pCont, contLen, NULL);
×
2127
}
2128

2129
static int32_t vnodeConsolidateAlterHashRange(SVnode *pVnode, int64_t ver) {
88✔
2130
  int32_t code = TSDB_CODE_SUCCESS;
88✔
2131

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

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

2138
  return code;
88✔
2139
}
2140

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

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

2155
_exit:
8,319✔
2156
  pRsp->msgType = TDMT_VND_ALTER_CONFIRM_RSP;
8,319✔
2157
  pRsp->code = code;
8,319✔
2158
  pRsp->pCont = NULL;
8,319✔
2159
  pRsp->contLen = 0;
8,319✔
2160

2161
  return code;
8,319✔
2162
}
2163

2164
extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb);
2165
extern void    tsdbEnableBgTask(STsdb *pTsdb);
2166

2167
static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
880✔
2168
  bool walChanged = false;
880✔
2169
  bool tsdbChanged = false;
880✔
2170

2171
  SAlterVnodeConfigReq req = {0};
880✔
2172
  if (tDeserializeSAlterVnodeConfigReq(pReq, len, &req) != 0) {
880!
2173
    terrno = TSDB_CODE_INVALID_MSG;
×
2174
    return TSDB_CODE_INVALID_MSG;
×
2175
  }
2176

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

2186
  if (pVnode->config.cacheLastSize != req.cacheLastSize) {
881✔
2187
    pVnode->config.cacheLastSize = req.cacheLastSize;
374✔
2188
    tsdbCacheSetCapacity(pVnode, (size_t)pVnode->config.cacheLastSize * 1024 * 1024);
374✔
2189
  }
2190

2191
  if (pVnode->config.szBuf != req.buffer * 1024LL * 1024LL) {
881✔
2192
    vInfo("vgId:%d, vnode buffer is changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pVnode->config.szBuf,
10!
2193
          (uint64_t)(req.buffer * 1024LL * 1024LL));
2194
    pVnode->config.szBuf = req.buffer * 1024LL * 1024LL;
10✔
2195
  }
2196

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

2208
  if (pVnode->config.cacheLast != req.cacheLast) {
881✔
2209
    pVnode->config.cacheLast = req.cacheLast;
555✔
2210
  }
2211

2212
  if (pVnode->config.walCfg.fsyncPeriod != req.walFsyncPeriod) {
881✔
2213
    pVnode->config.walCfg.fsyncPeriod = req.walFsyncPeriod;
70✔
2214
    walChanged = true;
70✔
2215
  }
2216

2217
  if (pVnode->config.walCfg.level != req.walLevel) {
881✔
2218
    if (pVnode->config.walCfg.level == 0) {
51✔
2219
      pVnode->config.walCfg.clearFiles = 1;
3✔
2220
    }
2221
    pVnode->config.walCfg.level = req.walLevel;
51✔
2222
    walChanged = true;
51✔
2223
  }
2224

2225
  if (pVnode->config.walCfg.retentionPeriod != req.walRetentionPeriod) {
881✔
2226
    pVnode->config.walCfg.retentionPeriod = req.walRetentionPeriod;
132✔
2227
    walChanged = true;
132✔
2228
  }
2229

2230
  if (pVnode->config.walCfg.retentionSize != req.walRetentionSize) {
881!
2231
    pVnode->config.walCfg.retentionSize = req.walRetentionSize;
×
2232
    walChanged = true;
×
2233
  }
2234

2235
  if (pVnode->config.tsdbCfg.keep0 != req.daysToKeep0) {
881✔
2236
    pVnode->config.tsdbCfg.keep0 = req.daysToKeep0;
56✔
2237
    if (!VND_IS_RSMA(pVnode)) {
56!
2238
      tsdbChanged = true;
56✔
2239
    }
2240
  }
2241

2242
  if (pVnode->config.tsdbCfg.keep1 != req.daysToKeep1) {
881✔
2243
    pVnode->config.tsdbCfg.keep1 = req.daysToKeep1;
56✔
2244
    if (!VND_IS_RSMA(pVnode)) {
56!
2245
      tsdbChanged = true;
56✔
2246
    }
2247
  }
2248

2249
  if (pVnode->config.tsdbCfg.keep2 != req.daysToKeep2) {
881✔
2250
    pVnode->config.tsdbCfg.keep2 = req.daysToKeep2;
56✔
2251
    if (!VND_IS_RSMA(pVnode)) {
56!
2252
      tsdbChanged = true;
56✔
2253
    }
2254
  }
2255

2256
  if (pVnode->config.tsdbCfg.keepTimeOffset != req.keepTimeOffset) {
881✔
2257
    pVnode->config.tsdbCfg.keepTimeOffset = req.keepTimeOffset;
2✔
2258
    if (!VND_IS_RSMA(pVnode)) {
2!
2259
      tsdbChanged = true;
2✔
2260
    }
2261
  }
2262

2263
  if (req.sttTrigger != -1 && req.sttTrigger != pVnode->config.sttTrigger) {
881!
2264
    if (req.sttTrigger > 1 && pVnode->config.sttTrigger > 1) {
×
2265
      pVnode->config.sttTrigger = req.sttTrigger;
×
2266
    } else {
2267
      vnodeAWait(&pVnode->commitTask);
×
2268

2269
      int32_t ret = tsdbDisableAndCancelAllBgTask(pVnode->pTsdb);
×
2270
      if (ret != 0) {
×
2271
        vError("vgId:%d, failed to disable bg task since %s", TD_VID(pVnode), tstrerror(errno));
×
2272
      }
2273

2274
      pVnode->config.sttTrigger = req.sttTrigger;
×
2275
      tsdbEnableBgTask(pVnode->pTsdb);
×
2276
    }
2277
  }
2278

2279
  if (req.minRows != -1 && req.minRows != pVnode->config.tsdbCfg.minRows) {
881!
2280
    pVnode->config.tsdbCfg.minRows = req.minRows;
×
2281
  }
2282

2283
  if (req.s3KeepLocal != -1 && req.s3KeepLocal != pVnode->config.s3KeepLocal) {
881!
2284
    pVnode->config.s3KeepLocal = req.s3KeepLocal;
×
2285
  }
2286
  if (req.s3Compact != -1 && req.s3Compact != pVnode->config.s3Compact) {
881!
2287
    pVnode->config.s3Compact = req.s3Compact;
×
2288
  }
2289

2290
  if (walChanged) {
881✔
2291
    if (walAlter(pVnode->pWal, &pVnode->config.walCfg) != 0) {
249!
2292
      vError("vgId:%d, failed to alter wal config since %s", TD_VID(pVnode), tstrerror(errno));
×
2293
    }
2294
  }
2295

2296
  if (tsdbChanged) {
882✔
2297
    tsdbSetKeepCfg(pVnode->pTsdb, &pVnode->config.tsdbCfg);
60✔
2298
  }
2299

2300
  return 0;
882✔
2301
}
2302

2303
static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
2,735✔
2304
  SBatchDeleteReq deleteReq;
2305
  SDecoder        decoder;
2306
  tDecoderInit(&decoder, pReq, len);
2,735✔
2307
  if (tDecodeSBatchDeleteReq(&decoder, &deleteReq) < 0) {
2,734!
2308
    tDecoderClear(&decoder);
×
2309
    return terrno = TSDB_CODE_INVALID_MSG;
×
2310
  }
2311

2312
  SMetaReader mr = {0};
2,737✔
2313
  metaReaderDoInit(&mr, pVnode->pMeta, META_READER_NOLOCK);
2,737✔
2314
  STsdb *pTsdb = pVnode->pTsdb;
2,739✔
2315

2316
  if (deleteReq.level) {
2,739✔
2317
    pTsdb = deleteReq.level == 1 ? VND_RSMA1(pVnode) : VND_RSMA2(pVnode);
16✔
2318
  }
2319

2320
  int32_t sz = taosArrayGetSize(deleteReq.deleteReqs);
2,739✔
2321
  for (int32_t i = 0; i < sz; i++) {
6,263✔
2322
    SSingleDeleteReq *pOneReq = taosArrayGet(deleteReq.deleteReqs, i);
3,524✔
2323
    char             *name = pOneReq->tbname;
3,523✔
2324
    if (metaGetTableEntryByName(&mr, name) < 0) {
3,523✔
2325
      vDebug("vgId:%d, stream delete msg, skip since no table: %s", pVnode->config.vgId, name);
1,752✔
2326
      continue;
1,752✔
2327
    }
2328

2329
    int64_t uid = mr.me.uid;
1,774✔
2330

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

2338
    if (deleteReq.level == 0) {
1,774✔
2339
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, deleteReq.ctimeMs);
1,158✔
2340
      if (code < 0) {
1,158!
2341
        terrno = code;
×
2342
        vError("vgId:%d, update change time error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64
×
2343
               ", end ts:%" PRId64,
2344
               TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
2345
      }
2346
    }
2347
    tDecoderClear(&mr.coder);
1,774✔
2348
  }
2349
  metaReaderClear(&mr);
2,739✔
2350
  taosArrayDestroy(deleteReq.deleteReqs);
2,738✔
2351
  return 0;
2,738✔
2352
}
2353

2354
static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
63,487✔
2355
                                     SRpcMsg *pOriginalMsg) {
2356
  int32_t     code = 0;
63,487✔
2357
  SDecoder   *pCoder = &(SDecoder){0};
63,487✔
2358
  SDeleteRes *pRes = &(SDeleteRes){0};
63,487✔
2359

2360
  pRsp->msgType = TDMT_VND_DELETE_RSP;
63,487✔
2361
  pRsp->pCont = NULL;
63,487✔
2362
  pRsp->contLen = 0;
63,487✔
2363
  pRsp->code = TSDB_CODE_SUCCESS;
63,487✔
2364

2365
  pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t));
63,487✔
2366
  if (pRes->uidList == NULL) {
63,491!
2367
    code = terrno;
×
2368
    goto _err;
×
2369
  }
2370

2371
  tDecoderInit(pCoder, pReq, len);
63,491✔
2372
  code = tDecodeDeleteRes(pCoder, pRes);
63,488✔
2373
  if (code) goto _err;
63,490!
2374

2375
  if (pRes->affectedRows > 0) {
63,490✔
2376
    for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) {
119,297✔
2377
      uint64_t uid = *(uint64_t *)taosArrayGet(pRes->uidList, iUid);
60,497✔
2378
      code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, uid, pRes->skey, pRes->ekey);
60,497✔
2379
      if (code) goto _err;
60,496!
2380
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, pRes->ctimeMs);
60,496✔
2381
      if (code) goto _err;
60,496!
2382
    }
2383
  }
2384

2385
  code = tdProcessRSmaDelete(pVnode->pSma, ver, pRes, pReq, len);
63,490✔
2386

2387
  tDecoderClear(pCoder);
63,486✔
2388
  taosArrayDestroy(pRes->uidList);
63,490✔
2389

2390
  SVDeleteRsp rsp = {.affectedRows = pRes->affectedRows};
63,492✔
2391
  int32_t     ret = 0;
63,492✔
2392
  tEncodeSize(tEncodeSVDeleteRsp, &rsp, pRsp->contLen, ret);
63,492!
2393
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
63,489✔
2394
  SEncoder ec = {0};
63,491✔
2395
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
63,491✔
2396
  code = tEncodeSVDeleteRsp(&ec, &rsp);
63,492✔
2397
  if (code) goto _err;
63,493!
2398
  tEncoderClear(&ec);
63,493✔
2399
  return code;
63,492✔
2400

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

2417
  return code;
×
2418
}
2419
static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
983✔
2420
  SVCreateStbReq req = {0};
983✔
2421
  SDecoder       dc = {0};
983✔
2422
  int32_t        code = 0;
983✔
2423

2424
  pRsp->msgType = TDMT_VND_CREATE_INDEX_RSP;
983✔
2425
  pRsp->code = TSDB_CODE_SUCCESS;
983✔
2426
  pRsp->pCont = NULL;
983✔
2427
  pRsp->contLen = 0;
983✔
2428

2429
  tDecoderInit(&dc, pReq, len);
983✔
2430
  // decode req
2431
  if (tDecodeSVCreateStbReq(&dc, &req) < 0) {
983!
2432
    tDecoderClear(&dc);
×
2433
    return terrno = TSDB_CODE_INVALID_MSG;
×
2434
  }
2435

2436
  code = metaAddIndexToSTable(pVnode->pMeta, ver, &req);
983✔
2437
  if (code) {
983!
2438
    pRsp->code = code;
×
2439
    goto _err;
×
2440
  }
2441
  tDecoderClear(&dc);
983✔
2442
  return 0;
983✔
2443

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

2456
  if ((code = tDeserializeSDropIdxReq(pReq, len, &req))) {
2,166!
2457
    pRsp->code = code;
×
2458
    return code;
×
2459
  }
2460

2461
  code = metaDropIndexFromSTable(pVnode->pMeta, ver, &req);
2,166✔
2462
  if (code) {
2,166!
2463
    pRsp->code = code;
×
2464
    return code;
×
2465
  }
2466
  return TSDB_CODE_SUCCESS;
2,166✔
2467
}
2468

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

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

2479
static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
2480
  if (syncCheckMember(pVnode->sync) != 0) {
×
2481
    vError("vgId:%d, failed to check member", TD_VID(pVnode));
×
2482
  }
2483

2484
  pRsp->msgType = TDMT_SYNC_CONFIG_CHANGE_RSP;
×
2485
  pRsp->code = TSDB_CODE_SUCCESS;
×
2486
  pRsp->pCont = NULL;
×
2487
  pRsp->contLen = 0;
×
2488

2489
  return 0;
×
2490
}
2491

2492
static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
×
2493
  SSyncState syncState = syncGetState(pVnode->sync);
×
2494
  if (syncState.state != TAOS_SYNC_STATE_LEADER) {
×
2495
    return terrno = TSDB_CODE_SYN_NOT_LEADER;
×
2496
  }
2497

2498
  char token[TSDB_ARB_TOKEN_SIZE] = {0};
×
2499
  if (vnodeGetArbToken(pVnode, token) != 0) {
×
2500
    return terrno = TSDB_CODE_NOT_FOUND;
×
2501
  }
2502

2503
  if (strncmp(token, member0Token, TSDB_ARB_TOKEN_SIZE) != 0 &&
×
2504
      strncmp(token, member1Token, TSDB_ARB_TOKEN_SIZE) != 0) {
×
2505
    return terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
×
2506
  }
2507

2508
  terrno = TSDB_CODE_SUCCESS;
×
2509
  return 0;
×
2510
}
2511

2512
static int32_t vnodeCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
×
2513
  int32_t code = vnodePreCheckAssignedLogSyncd(pVnode, member0Token, member1Token);
×
2514
  if (code != 0) {
×
2515
    return code;
×
2516
  }
2517

2518
  return syncGetAssignedLogSynced(pVnode->sync);
×
2519
}
2520

2521
static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
2522
  int32_t code = 0;
×
2523

2524
  SVArbCheckSyncReq syncReq = {0};
×
2525

2526
  code = tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq);
×
2527
  if (code) {
×
2528
    return terrno = code;
×
2529
  }
2530

2531
  pRsp->msgType = TDMT_VND_ARB_CHECK_SYNC_RSP;
×
2532
  pRsp->code = TSDB_CODE_SUCCESS;
×
2533
  pRsp->pCont = NULL;
×
2534
  pRsp->contLen = 0;
×
2535

2536
  SVArbCheckSyncRsp syncRsp = {0};
×
2537
  syncRsp.arbToken = syncReq.arbToken;
×
2538
  syncRsp.member0Token = syncReq.member0Token;
×
2539
  syncRsp.member1Token = syncReq.member1Token;
×
2540
  syncRsp.vgId = TD_VID(pVnode);
×
2541

2542
  if (vnodeCheckAssignedLogSyncd(pVnode, syncReq.member0Token, syncReq.member1Token) != 0) {
×
2543
    vError("vgId:%d, failed to check assigned log syncd", TD_VID(pVnode));
×
2544
  }
2545
  syncRsp.errCode = terrno;
×
2546

2547
  if (vnodeUpdateArbTerm(pVnode, syncReq.arbTerm) != 0) {
×
2548
    vError("vgId:%d, failed to update arb term", TD_VID(pVnode));
×
2549
    code = -1;
×
2550
    goto _OVER;
×
2551
  }
2552

2553
  int32_t contLen = tSerializeSVArbCheckSyncRsp(NULL, 0, &syncRsp);
×
2554
  if (contLen <= 0) {
×
2555
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2556
    code = -1;
×
2557
    goto _OVER;
×
2558
  }
2559
  void *pHead = rpcMallocCont(contLen);
×
2560
  if (!pHead) {
×
2561
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2562
    code = -1;
×
2563
    goto _OVER;
×
2564
  }
2565

2566
  if (tSerializeSVArbCheckSyncRsp(pHead, contLen, &syncRsp) <= 0) {
×
2567
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2568
    rpcFreeCont(pHead);
×
2569
    code = -1;
×
2570
    goto _OVER;
×
2571
  }
2572

2573
  pRsp->pCont = pHead;
×
2574
  pRsp->contLen = contLen;
×
2575

2576
  terrno = TSDB_CODE_SUCCESS;
×
2577

2578
_OVER:
×
2579
  tFreeSVArbCheckSyncReq(&syncReq);
×
2580
  return code;
×
2581
}
2582

2583
#ifndef TD_ENTERPRISE
2584
int32_t vnodeAsyncCompact(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) { return 0; }
2585
int32_t tsdbAsyncCompact(STsdb *tsdb, const STimeWindow *tw, bool sync) { return 0; }
2586
#endif
2587

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc