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

taosdata / TDengine / #3541

26 Nov 2024 03:56AM UTC coverage: 60.776% (-0.07%) from 60.846%
#3541

push

travis-ci

web-flow
Merge pull request #28920 from taosdata/fix/TD-33008-3.0

fix(query)[TD-33008]. fix error handling in tsdbCacheRead

120076 of 252763 branches covered (47.51%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

1395 existing lines in 154 files now uncovered.

200995 of 275526 relevant lines covered (72.95%)

19612328.37 hits per line

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

59.58
/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) {
173,380✔
64
  int32_t code = 0;
173,380✔
65
  int32_t lino = 0;
173,380✔
66

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

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

78
  // name
79
  char *name = NULL;
173,426✔
80
  if (tDecodeCStr(pCoder, &name) < 0) {
173,415!
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);
173,415✔
87
  if (uid == 0) {
173,404✔
88
    uid = tGenIdPI64();
146,678✔
89
  }
90
  *(int64_t *)(pCoder->data + pCoder->pos) = uid;
173,421✔
91

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

95
  tEndDecode(pCoder);
173,421✔
96

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

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

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

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

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

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

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

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

147
  SVAlterTbReq vAlterTbReq = {0};
5,231✔
148
  int64_t      ctimeMs = taosGetTimestampMs();
5,231✔
149
  if (tDecodeSVAlterTbReqSetCtime(&dc, &vAlterTbReq, ctimeMs) < 0) {
5,231!
150
    goto _exit;
×
151
  }
152

153
  code = 0;
5,231✔
154

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

166
static int32_t vnodePreProcessDropTtlMsg(SVnode *pVnode, SRpcMsg *pMsg) {
90,543✔
167
  int32_t code = TSDB_CODE_INVALID_MSG;
90,543✔
168
  int32_t lino = 0;
90,543✔
169

170
  SMsgHead *pContOld = pMsg->pCont;
90,543✔
171
  int32_t   reqLenOld = pMsg->contLen - sizeof(SMsgHead);
90,543✔
172

173
  SArray *tbUids = NULL;
90,543✔
174
  int64_t timestampMs = 0;
90,543✔
175

176
  SVDropTtlTableReq ttlReq = {0};
90,543✔
177
  if (tDeserializeSVDropTtlTableReq((char *)pContOld + sizeof(SMsgHead), reqLenOld, &ttlReq) != 0) {
90,543!
178
    code = TSDB_CODE_INVALID_MSG;
×
179
    TSDB_CHECK_CODE(code, lino, _exit);
×
180
  }
181

182
  {  // find expired uids
183
    tbUids = taosArrayInit(8, sizeof(tb_uid_t));
90,785✔
184
    if (tbUids == NULL) {
90,707!
185
      code = terrno;
×
186
      TSDB_CHECK_CODE(code, lino, _exit);
×
187
    }
188

189
    timestampMs = (int64_t)ttlReq.timestampSec * 1000;
90,707✔
190
    code = metaTtlFindExpired(pVnode->pMeta, timestampMs, tbUids, ttlReq.ttlDropMaxCount);
90,707✔
191
    if (code != 0) {
90,637!
192
      code = TSDB_CODE_INVALID_MSG;
×
193
      TSDB_CHECK_CODE(code, lino, _exit);
×
194
    }
195

196
    ttlReq.nUids = taosArrayGetSize(tbUids);
90,637✔
197
    ttlReq.pTbUids = tbUids;
90,568✔
198
  }
199

200
  if (ttlReq.nUids == 0) {
90,568!
201
    code = TSDB_CODE_MSG_PREPROCESSED;
90,573✔
202
    TSDB_CHECK_CODE(code, lino, _exit);
90,573!
203
  }
204

205
  {  // prepare new content
UNCOV
206
    int32_t reqLenNew = tSerializeSVDropTtlTableReq(NULL, 0, &ttlReq);
×
207
    int32_t contLenNew = reqLenNew + sizeof(SMsgHead);
38✔
208

209
    SMsgHead *pContNew = rpcMallocCont(contLenNew);
38✔
210
    if (pContNew == NULL) {
38!
211
      code = terrno;
×
212
      TSDB_CHECK_CODE(code, lino, _exit);
×
213
    }
214

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

221
    rpcFreeCont(pContOld);
38✔
222
    pMsg->pCont = pContNew;
38✔
223
    pMsg->contLen = contLenNew;
38✔
224
  }
225

226
  code = 0;
38✔
227

228
_exit:
90,644✔
229
  taosArrayDestroy(tbUids);
90,644✔
230

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

238
  return code;
90,612✔
239
}
240

241
extern int64_t tsMaxKeyByPrecision[];
242
static int32_t vnodePreProcessSubmitTbData(SVnode *pVnode, SDecoder *pCoder, int64_t btimeMs, int64_t ctimeMs) {
10,821,772✔
243
  int32_t code = 0;
10,821,772✔
244
  int32_t lino = 0;
10,821,772✔
245

246
  if (tStartDecode(pCoder) < 0) {
10,821,772!
247
    code = TSDB_CODE_INVALID_MSG;
×
248
    TSDB_CHECK_CODE(code, lino, _exit);
×
249
  }
250

251
  SSubmitTbData submitTbData;
252
  uint8_t       version;
253
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
10,827,310!
254
    code = TSDB_CODE_INVALID_MSG;
×
255
    TSDB_CHECK_CODE(code, lino, _exit);
×
256
  }
257
  version = (submitTbData.flags >> 8) & 0xff;
10,827,310✔
258
  submitTbData.flags = submitTbData.flags & 0xff;
10,827,310✔
259

260
  int64_t uid;
261
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
10,827,310✔
262
    code = vnodePreprocessCreateTableReq(pVnode, pCoder, btimeMs, &uid);
69,889✔
263
    TSDB_CHECK_CODE(code, lino, _exit);
69,902!
264
  }
265

266
  // submit data
267
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
10,821,019!
268
    code = TSDB_CODE_INVALID_MSG;
×
269
    TSDB_CHECK_CODE(code, lino, _exit);
×
270
  }
271

272
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
10,821,019✔
273
    *(int64_t *)(pCoder->data + pCoder->pos) = uid;
69,899✔
274
    pCoder->pos += sizeof(int64_t);
69,899✔
275
  } else {
276
    if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
10,748,921!
277
      code = TSDB_CODE_INVALID_MSG;
×
278
      TSDB_CHECK_CODE(code, lino, _exit);
×
279
    }
280
  }
281

282
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
10,817,108!
283
    code = TSDB_CODE_INVALID_MSG;
×
284
    TSDB_CHECK_CODE(code, lino, _exit);
×
285
  }
286

287
  // scan and check
288
  TSKEY now = btimeMs;
10,817,108✔
289
  if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_MICRO) {
10,817,108✔
290
    now *= 1000;
23,170✔
291
  } else if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_NANO) {
10,793,938✔
292
    now *= 1000000;
3,745✔
293
  }
294

295
  int32_t keep = pVnode->config.tsdbCfg.keep2;
10,817,108✔
296
  /*
297
  int32_t nlevel = tfsGetLevel(pVnode->pTfs);
298
  if (nlevel > 1 && tsS3Enabled) {
299
    if (nlevel == 3) {
300
      keep = pVnode->config.tsdbCfg.keep1;
301
    } else if (nlevel == 2) {
302
      keep = pVnode->config.tsdbCfg.keep0;
303
    }
304
  }
305
  */
306

307
  TSKEY minKey = now - tsTickPerMin[pVnode->config.tsdbCfg.precision] * keep;
10,817,108✔
308
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
10,817,108✔
309
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,817,108✔
310
    uint64_t nColData;
311
    if (tDecodeU64v(pCoder, &nColData) < 0) {
156!
312
      code = TSDB_CODE_INVALID_MSG;
×
313
      goto _exit;
1✔
314
    }
315

316
    SColData colData = {0};
156✔
317
    pCoder->pos += tGetColData(version, pCoder->data + pCoder->pos, &colData);
156✔
318
    if (colData.flag != HAS_VALUE) {
156!
319
      code = TSDB_CODE_INVALID_MSG;
×
320
      goto _exit;
×
321
    }
322

323
    for (int32_t iRow = 0; iRow < colData.nVal; iRow++) {
426✔
324
      if (((TSKEY *)colData.pData)[iRow] < minKey || ((TSKEY *)colData.pData)[iRow] > maxKey) {
271!
325
        code = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
1✔
326
        goto _exit;
1✔
327
      }
328
    }
329

330
    for (uint64_t i = 1; i < nColData; i++) {
691✔
331
      pCoder->pos += tGetColData(version, pCoder->data + pCoder->pos, &colData);
536✔
332
    }
333
  } else {
334
    uint64_t nRow;
335
    if (tDecodeU64v(pCoder, &nRow) < 0) {
10,820,726!
336
      code = TSDB_CODE_INVALID_MSG;
×
337
      goto _exit;
495✔
338
    }
339

340
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
686,629,257✔
341
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
675,809,026✔
342
      pCoder->pos += pRow->len;
675,809,026✔
343

344
      if (pRow->ts < minKey || pRow->ts > maxKey) {
675,809,026!
345
        code = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
495✔
346
        goto _exit;
495✔
347
      }
348
    }
349
  }
350

351
  if (!tDecodeIsEnd(pCoder)) {
10,820,386!
352
    *(int64_t *)(pCoder->data + pCoder->pos) = ctimeMs;
10,822,970✔
353
    pCoder->pos += sizeof(int64_t);
10,822,970✔
354
  }
355

356
  tEndDecode(pCoder);
10,820,386✔
357

358
_exit:
10,821,880✔
359
  return code;
10,821,880✔
360
}
361
static int32_t vnodePreProcessSubmitMsg(SVnode *pVnode, SRpcMsg *pMsg) {
10,155,586✔
362
  int32_t code = 0;
10,155,586✔
363
  int32_t lino = 0;
10,155,586✔
364

365
  if (tsBypassFlag & TSDB_BYPASS_RA_RPC_RECV_SUBMIT) {
10,155,586!
366
    return TSDB_CODE_MSG_PREPROCESSED;
×
367
  }
368

369
  SDecoder *pCoder = &(SDecoder){0};
10,155,586✔
370

371
  if (taosHton64(((SSubmitReq2Msg *)pMsg->pCont)->version) != 1) {
10,155,586!
372
    code = TSDB_CODE_INVALID_MSG;
×
373
    TSDB_CHECK_CODE(code, lino, _exit);
×
374
  }
375

376
  tDecoderInit(pCoder, (uint8_t *)pMsg->pCont + sizeof(SSubmitReq2Msg), pMsg->contLen - sizeof(SSubmitReq2Msg));
10,155,615✔
377

378
  if (tStartDecode(pCoder) < 0) {
10,155,540!
379
    code = TSDB_CODE_INVALID_MSG;
×
380
    TSDB_CHECK_CODE(code, lino, _exit);
×
381
  }
382

383
  uint64_t nSubmitTbData;
384
  if (tDecodeU64v(pCoder, &nSubmitTbData) < 0) {
10,155,530!
385
    code = TSDB_CODE_INVALID_MSG;
×
386
    TSDB_CHECK_CODE(code, lino, _exit);
×
387
  }
388

389
  int64_t btimeMs = taosGetTimestampMs();
10,155,649✔
390
  int64_t ctimeMs = btimeMs;
10,155,649✔
391
  for (int32_t i = 0; i < nSubmitTbData; i++) {
20,976,888✔
392
    code = vnodePreProcessSubmitTbData(pVnode, pCoder, btimeMs, ctimeMs);
10,822,015✔
393
    TSDB_CHECK_CODE(code, lino, _exit);
10,821,735✔
394
  }
395

396
  tEndDecode(pCoder);
10,154,873✔
397

398
_exit:
10,155,613✔
399
  tDecoderClear(pCoder);
10,155,613✔
400
  if (code) {
10,155,577✔
401
    vError("vgId:%d, %s:%d failed to preprocess submit request since %s, msg type:%s", TD_VID(pVnode), __func__, lino,
496!
402
           tstrerror(code), TMSG_INFO(pMsg->msgType));
403
  }
404
  return code;
10,155,582✔
405
}
406

407
static int32_t vnodePreProcessDeleteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
60,134✔
408
  int32_t code = 0;
60,134✔
409

410
  int32_t    size;
411
  int32_t    ret;
412
  uint8_t   *pCont;
413
  SEncoder  *pCoder = &(SEncoder){0};
60,134✔
414
  SDeleteRes res = {0};
60,134✔
415

416
  SReadHandle handle = {.vnode = pVnode, .pMsgCb = &pVnode->msgCb, .skipRollup = 1};
60,134✔
417
  initStorageAPI(&handle.api);
60,134✔
418

419
  code = qWorkerProcessDeleteMsg(&handle, pVnode->pQuery, pMsg, &res);
60,134✔
420
  if (code) goto _exit;
60,135!
421

422
  res.ctimeMs = taosGetTimestampMs();
60,135✔
423
  // malloc and encode
424
  tEncodeSize(tEncodeDeleteRes, &res, size, ret);
60,135!
425
  pCont = rpcMallocCont(size + sizeof(SMsgHead));
60,134✔
426

427
  ((SMsgHead *)pCont)->contLen = size + sizeof(SMsgHead);
60,136✔
428
  ((SMsgHead *)pCont)->vgId = TD_VID(pVnode);
60,136✔
429

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

436
  rpcFreeCont(pMsg->pCont);
60,136✔
437
  pMsg->pCont = pCont;
60,136✔
438
  pMsg->contLen = size + sizeof(SMsgHead);
60,136✔
439

440
  taosArrayDestroy(res.uidList);
60,136✔
441

442
_exit:
60,136✔
443
  return code;
60,136✔
444
}
445

446
static int32_t vnodePreProcessBatchDeleteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
3,191✔
447
  int32_t code = 0;
3,191✔
448
  int32_t lino = 0;
3,191✔
449

450
  int64_t         ctimeMs = taosGetTimestampMs();
3,191✔
451
  SBatchDeleteReq pReq = {0};
3,191✔
452
  SDecoder       *pCoder = &(SDecoder){0};
3,191✔
453

454
  tDecoderInit(pCoder, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead));
3,191✔
455

456
  if (tDecodeSBatchDeleteReqSetCtime(pCoder, &pReq, ctimeMs) < 0) {
3,190!
457
    code = TSDB_CODE_INVALID_MSG;
×
458
  }
459

460
  tDecoderClear(pCoder);
3,191✔
461
  taosArrayDestroy(pReq.deleteReqs);
3,189✔
462

463
  if (code) {
3,191!
464
    vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
×
465
  } else {
466
    vTrace("vgId:%d %s done, ctimeMs generated:%" PRId64, TD_VID(pVnode), __func__, ctimeMs);
3,191✔
467
  }
468
  return code;
3,190✔
469
}
470

UNCOV
471
static int32_t vnodePreProcessArbCheckSyncMsg(SVnode *pVnode, SRpcMsg *pMsg) {
×
UNCOV
472
  SVArbCheckSyncReq syncReq = {0};
×
473

UNCOV
474
  if (tDeserializeSVArbCheckSyncReq((char *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead),
×
475
                                    &syncReq) != 0) {
476
    return TSDB_CODE_INVALID_MSG;
×
477
  }
478

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

UNCOV
484
  int32_t code = terrno;
×
UNCOV
485
  tFreeSVArbCheckSyncReq(&syncReq);
×
486

UNCOV
487
  return code;
×
488
}
489

490
int32_t vnodePreProcessDropTbMsg(SVnode* pVnode, SRpcMsg* pMsg) {
16,386✔
491
  int32_t          code = TSDB_CODE_SUCCESS;
16,386✔
492
  int32_t          lino = 0;
16,386✔
493
  int32_t          size = 0;
16,386✔
494
  SDecoder         dc = {0};
16,386✔
495
  SEncoder         ec = {0};
16,386✔
496
  SVDropTbBatchReq receivedBatchReqs = {0};
16,386✔
497
  SVDropTbBatchReq sentBatchReqs = {0};
16,386✔
498

499
  tDecoderInit(&dc, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead));
16,386✔
500

501
  code = tDecodeSVDropTbBatchReq(&dc, &receivedBatchReqs);
16,386✔
502
  if (code < 0) {
16,386!
503
    terrno = code;
×
504
    TSDB_CHECK_CODE(code, lino, _exit);
×
505
  }
506
  sentBatchReqs.pArray = taosArrayInit(receivedBatchReqs.nReqs, sizeof(SVDropTbReq));
16,386✔
507
  if (!sentBatchReqs.pArray) {
16,386!
508
    code = terrno;
×
509
    goto _exit;
×
510
  }
511

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

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

537
_exit:
16,386✔
538
  tDecoderClear(&dc);
16,386✔
539
  if (sentBatchReqs.pArray) {
16,386!
540
    taosArrayDestroy(sentBatchReqs.pArray);
16,386✔
541
  }
542
  return code;
16,386✔
543
}
544

545
int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
10,519,840✔
546
  int32_t code = 0;
10,519,840✔
547

548
  switch (pMsg->msgType) {
10,519,840!
549
    case TDMT_VND_CREATE_TABLE: {
78,099✔
550
      code = vnodePreProcessCreateTableMsg(pVnode, pMsg);
78,099✔
551
    } break;
78,093✔
552
    case TDMT_VND_ALTER_TABLE: {
5,231✔
553
      code = vnodePreProcessAlterTableMsg(pVnode, pMsg);
5,231✔
554
    } break;
5,231✔
555
    case TDMT_VND_FETCH_TTL_EXPIRED_TBS:
90,778✔
556
    case TDMT_VND_DROP_TTL_TABLE: {
557
      code = vnodePreProcessDropTtlMsg(pVnode, pMsg);
90,778✔
558
    } break;
90,620✔
559
    case TDMT_VND_SUBMIT: {
10,155,625✔
560
      code = vnodePreProcessSubmitMsg(pVnode, pMsg);
10,155,625✔
561
    } break;
10,155,568✔
562
    case TDMT_VND_DELETE: {
60,133✔
563
      code = vnodePreProcessDeleteMsg(pVnode, pMsg);
60,133✔
564
    } break;
60,136✔
565
    case TDMT_VND_BATCH_DEL: {
3,190✔
566
      code = vnodePreProcessBatchDeleteMsg(pVnode, pMsg);
3,190✔
567
    } break;
3,191✔
UNCOV
568
    case TDMT_VND_ARB_CHECK_SYNC: {
×
UNCOV
569
      code = vnodePreProcessArbCheckSyncMsg(pVnode, pMsg);
×
UNCOV
570
    } break;
×
571
    case TDMT_VND_DROP_TABLE: {
16,386✔
572
      code = vnodePreProcessDropTbMsg(pVnode, pMsg);
16,386✔
573
    } break;
16,386✔
574
    default:
110,398✔
575
      break;
110,398✔
576
  }
577

578
  if (code && code != TSDB_CODE_MSG_PREPROCESSED) {
10,519,623✔
579
    vError("vgId:%d, failed to preprocess write request since %s, msg type:%s", TD_VID(pVnode), tstrerror(code),
496!
580
           TMSG_INFO(pMsg->msgType));
581
  }
582
  return code;
10,519,566✔
583
}
584

585
int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg *pRsp) {
14,995,909✔
586
  int32_t code = 0;
14,995,909✔
587
  void   *ptr = NULL;
14,995,909✔
588
  void   *pReq;
589
  int32_t len;
590

591
  (void)taosThreadMutexLock(&pVnode->mutex);
14,995,909✔
592
  if (pVnode->disableWrite) {
14,996,343!
593
    (void)taosThreadMutexUnlock(&pVnode->mutex);
×
594
    vError("vgId:%d write is disabled for snapshot, version:%" PRId64, TD_VID(pVnode), ver);
×
595
    return TSDB_CODE_VND_WRITE_DISABLED;
×
596
  }
597
  (void)taosThreadMutexUnlock(&pVnode->mutex);
14,996,343✔
598

599
  if (ver <= pVnode->state.applied) {
14,996,327!
600
    vError("vgId:%d, duplicate write request. ver: %" PRId64 ", applied: %" PRId64 "", TD_VID(pVnode), ver,
×
601
           pVnode->state.applied);
602
    return terrno = TSDB_CODE_VND_DUP_REQUEST;
×
603
  }
604

605
  vDebug("vgId:%d, start to process write request %s, index:%" PRId64 ", applied:%" PRId64 ", state.applyTerm:%" PRId64
14,996,327✔
606
         ", conn.applyTerm:%" PRId64,
607
         TD_VID(pVnode), TMSG_INFO(pMsg->msgType), ver, pVnode->state.applied, pVnode->state.applyTerm,
608
         pMsg->info.conn.applyTerm);
609

610
  if (!(pVnode->state.applyTerm <= pMsg->info.conn.applyTerm)) {
14,996,004!
611
    return terrno = TSDB_CODE_INTERNAL_ERROR;
×
612
  }
613

614
  if (!(pVnode->state.applied + 1 == ver)) {
14,996,004!
615
    return terrno = TSDB_CODE_INTERNAL_ERROR;
×
616
  }
617

618
  atomic_store_64(&pVnode->state.applied, ver);
14,996,004✔
619
  atomic_store_64(&pVnode->state.applyTerm, pMsg->info.conn.applyTerm);
14,996,340✔
620

621
  if (!syncUtilUserCommit(pMsg->msgType)) goto _exit;
14,996,329✔
622

623
  // skip header
624
  pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
14,968,481✔
625
  len = pMsg->contLen - sizeof(SMsgHead);
14,968,481✔
626
  bool needCommit = false;
14,968,481✔
627

628
  switch (pMsg->msgType) {
14,968,481!
629
    /* META */
630
    case TDMT_VND_CREATE_STB:
31,762✔
631
      if (vnodeProcessCreateStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
31,762✔
632
      break;
31,742✔
633
    case TDMT_VND_ALTER_STB:
4,910✔
634
      if (vnodeProcessAlterStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
4,910!
635
      break;
4,907✔
636
    case TDMT_VND_DROP_STB:
3,380✔
637
      if (vnodeProcessDropStbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
3,380!
638
      break;
3,385✔
639
    case TDMT_VND_CREATE_TABLE:
91,309✔
640
      if (vnodeProcessCreateTbReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
91,309!
641
      break;
91,326✔
642
    case TDMT_VND_ALTER_TABLE:
5,184✔
643
      if (vnodeProcessAlterTbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
5,184!
644
      break;
5,184✔
645
    case TDMT_VND_DROP_TABLE:
16,428✔
646
      if (vnodeProcessDropTbReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
16,428!
647
      break;
16,428✔
648
    case TDMT_VND_DROP_TTL_TABLE:
×
649
      if (vnodeProcessDropTtlTbReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
×
650
      break;
×
651
    case TDMT_VND_FETCH_TTL_EXPIRED_TBS:
35✔
652
      if (vnodeProcessFetchTtlExpiredTbs(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
35!
653
      break;
37✔
654
    case TDMT_VND_TRIM:
216✔
655
      if (vnodeProcessTrimReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
216!
656
      break;
216✔
657
    case TDMT_VND_S3MIGRATE:
×
658
      if (vnodeProcessS3MigrateReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
×
659
      break;
×
660
    case TDMT_VND_CREATE_SMA:
33✔
661
      if (vnodeProcessCreateTSmaReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
33!
662
      break;
33✔
663
    /* TSDB */
664
    case TDMT_VND_SUBMIT:
14,650,821✔
665
      if (vnodeProcessSubmitReq(pVnode, ver, pMsg->pCont, pMsg->contLen, pRsp, pMsg) < 0) goto _err;
14,650,821✔
666
      break;
14,650,801✔
667
    case TDMT_VND_DELETE:
64,851✔
668
      if (vnodeProcessDeleteReq(pVnode, ver, pReq, len, pRsp, pMsg) < 0) goto _err;
64,851!
669
      break;
64,852✔
670
    case TDMT_VND_BATCH_DEL:
3,537✔
671
      if (vnodeProcessBatchDeleteReq(pVnode, ver, pReq, len, pRsp) < 0) goto _err;
3,537!
672
      break;
3,544✔
673
    /* TQ */
674
    case TDMT_VND_TMQ_SUBSCRIBE:
4,279✔
675
      if (tqProcessSubscribeReq(pVnode->pTq, ver, pReq, len) < 0) {
4,279✔
676
        goto _err;
1✔
677
      }
678
      break;
4,278✔
679
    case TDMT_VND_TMQ_DELETE_SUB:
883✔
680
      if (tqProcessDeleteSubReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen) < 0) {
883!
681
        goto _err;
×
682
      }
683
      break;
884✔
684
    case TDMT_VND_TMQ_COMMIT_OFFSET:
9,805✔
685
      if (tqProcessOffsetCommitReq(pVnode->pTq, ver, pReq, len) < 0) {
9,805!
686
        goto _err;
×
687
      }
688
      break;
9,811✔
689
    case TDMT_VND_TMQ_ADD_CHECKINFO:
137✔
690
      if (tqProcessAddCheckInfoReq(pVnode->pTq, ver, pReq, len) < 0) {
137!
691
        goto _err;
×
692
      }
693
      break;
137✔
694
    case TDMT_VND_TMQ_DEL_CHECKINFO:
30✔
695
      if (tqProcessDelCheckInfoReq(pVnode->pTq, ver, pReq, len) < 0) {
30✔
696
        goto _err;
2✔
697
      }
698
      break;
28✔
699
    case TDMT_STREAM_TASK_DEPLOY: {
13,666✔
700
      if ((code = tqProcessTaskDeployReq(pVnode->pTq, ver, pReq, len)) != TSDB_CODE_SUCCESS) {
13,666!
701
        goto _err;
×
702
      }
703
    } break;
13,680✔
704
    case TDMT_STREAM_TASK_DROP: {
6,978✔
705
      if ((code = tqProcessTaskDropReq(pVnode->pTq, pMsg->pCont, pMsg->contLen)) < 0) {
6,978!
706
        goto _err;
×
707
      }
708
    } break;
7,005✔
709
    case TDMT_STREAM_TASK_UPDATE_CHKPT: {
6,987✔
710
      if ((code = tqProcessTaskUpdateCheckpointReq(pVnode->pTq, pMsg->pCont, pMsg->contLen)) < 0) {
6,987!
711
        goto _err;
×
712
      }
713
    } break;
6,991✔
714
    case TDMT_STREAM_CONSEN_CHKPT: {
124✔
715
      if (pVnode->restored && (code = tqProcessTaskConsenChkptIdReq(pVnode->pTq, pMsg)) < 0) {
124!
716
        goto _err;
×
717
      }
718

719
    } break;
124✔
720
    case TDMT_STREAM_TASK_PAUSE: {
1,964✔
721
      if (pVnode->restored && vnodeIsLeader(pVnode) &&
3,297!
722
          (code = tqProcessTaskPauseReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen)) < 0) {
1,332✔
723
        goto _err;
×
724
      }
725
    } break;
1,967✔
726
    case TDMT_STREAM_TASK_RESUME: {
1,957✔
727
      if (pVnode->restored && vnodeIsLeader(pVnode) &&
3,283!
728
          (code = tqProcessTaskResumeReq(pVnode->pTq, ver, pMsg->pCont, pMsg->contLen)) < 0) {
1,324✔
729
        goto _err;
×
730
      }
731
    } break;
1,960✔
732
    case TDMT_VND_STREAM_TASK_RESET: {
×
733
      if (pVnode->restored && vnodeIsLeader(pVnode) &&
×
734
           (code = tqProcessTaskResetReq(pVnode->pTq, pMsg)) < 0) {
×
735
          goto _err;
×
736
        }
737

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

783
  vTrace("vgId:%d, process %s request, code:0x%x index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), pRsp->code,
14,968,488✔
784
         ver);
785

786
  walApplyVer(pVnode->pWal, ver);
14,968,488✔
787

788
  code = tqPushMsg(pVnode->pTq, pMsg->msgType);
14,968,427✔
789
  if (code) {
14,968,594✔
790
    vError("vgId:%d, failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno));
540!
791
    return code;
540✔
792
  }
793

794
  // commit if need
795
  if (needCommit) {
14,968,054✔
796
    vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), ver);
32,071!
797
    code = vnodeAsyncCommit(pVnode);
32,090✔
798
    if (code) {
32,093!
799
      vError("vgId:%d, failed to vnode async commit since %s.", TD_VID(pVnode), tstrerror(terrno));
×
800
      goto _err;
×
801
    }
802

803
    // start a new one
804
    code = vnodeBegin(pVnode);
32,093✔
805
    if (code) {
32,090✔
806
      vError("vgId:%d, failed to begin vnode since %s.", TD_VID(pVnode), tstrerror(terrno));
88!
807
      goto _err;
×
808
    }
809
  }
810

811
_exit:
14,967,985✔
812
  return 0;
14,995,333✔
813

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

820
int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
8,423,586✔
821
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) {
8,423,586✔
822
    return 0;
540,526✔
823
  }
824

825
  return qWorkerPreprocessQueryMsg(pVnode->pQuery, pMsg, TDMT_SCH_QUERY == pMsg->msgType);
7,883,060✔
826
}
827

828
int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
8,430,521✔
829
  vTrace("message in vnode query queue is processing");
8,430,521✔
830
  if ((pMsg->msgType == TDMT_SCH_QUERY || pMsg->msgType == TDMT_VND_TMQ_CONSUME) && !syncIsReadyForRead(pVnode->sync)) {
8,430,522✔
831
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
1,498✔
832
    return 0;
1,498✔
833
  }
834

835
  if (pMsg->msgType == TDMT_VND_TMQ_CONSUME && !pVnode->restored) {
8,428,154!
836
    vnodeRedirectRpcMsg(pVnode, pMsg, TSDB_CODE_SYN_RESTORING);
×
837
    return 0;
×
838
  }
839

840
  SReadHandle handle = {.vnode = pVnode, .pMsgCb = &pVnode->msgCb, .pWorkerCb = pInfo->workerCb};
8,428,154✔
841
  initStorageAPI(&handle.api);
8,428,154✔
842

843
  switch (pMsg->msgType) {
8,426,745!
844
    case TDMT_SCH_QUERY:
7,887,649✔
845
    case TDMT_SCH_MERGE_QUERY:
846
      return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
7,887,649✔
847
    case TDMT_SCH_QUERY_CONTINUE:
441,011✔
848
      return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
441,011✔
849
    case TDMT_VND_TMQ_CONSUME:
72,500✔
850
      return tqProcessPollReq(pVnode->pTq, pMsg);
72,500✔
851
    case TDMT_VND_TMQ_CONSUME_PUSH:
25,842✔
852
      return tqProcessPollPush(pVnode->pTq, pMsg);
25,842✔
853
    default:
×
854
      vError("unknown msg type:%d in query queue", pMsg->msgType);
×
855
      return TSDB_CODE_APP_ERROR;
×
856
  }
857
}
858

859
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
21,077,548✔
860
  vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg);
21,077,548✔
861
  if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
21,077,550!
862
       pMsg->msgType == TDMT_VND_BATCH_META || pMsg->msgType == TDMT_VND_TABLE_NAME) &&
14,607,479✔
863
      !syncIsReadyForRead(pVnode->sync)) {
7,586,226✔
864
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
1,973✔
865
    return 0;
1,973✔
866
  }
867

868
  switch (pMsg->msgType) {
21,078,872!
869
    case TDMT_SCH_FETCH:
9,975,854✔
870
    case TDMT_SCH_MERGE_FETCH:
871
      return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg, 0);
9,975,854✔
872
    case TDMT_SCH_FETCH_RSP:
×
873
      return qWorkerProcessRspMsg(pVnode, pVnode->pQuery, pMsg, 0);
×
874
    // case TDMT_SCH_CANCEL_TASK:
875
    //   return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg, 0);
876
    case TDMT_SCH_DROP_TASK:
7,886,132✔
877
      return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg, 0);
7,886,132✔
878
    case TDMT_SCH_TASK_NOTIFY:
424✔
879
      return qWorkerProcessNotifyMsg(pVnode, pVnode->pQuery, pMsg, 0);
424✔
880
    case TDMT_SCH_QUERY_HEARTBEAT:
2,100,155✔
881
      return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg, 0);
2,100,155✔
882
    case TDMT_VND_TABLE_META:
3,072✔
883
    case TDMT_VND_TABLE_NAME:
884
      return vnodeGetTableMeta(pVnode, pMsg, true);
3,072✔
885
    case TDMT_VND_TABLE_CFG:
×
886
      return vnodeGetTableCfg(pVnode, pMsg, true);
×
887
    case TDMT_VND_BATCH_META:
1,113,174✔
888
      return vnodeGetBatchMeta(pVnode, pMsg);
1,113,174✔
889
#ifdef TD_ENTERPRISE
890
    case TDMT_VND_QUERY_COMPACT_PROGRESS:
22✔
891
      return vnodeQueryCompactProgress(pVnode, pMsg);
22✔
892
#endif
893
      //    case TDMT_VND_TMQ_CONSUME:
894
      //      return tqProcessPollReq(pVnode->pTq, pMsg);
895
    case TDMT_VND_TMQ_VG_WALINFO:
13✔
896
      return tqProcessVgWalInfoReq(pVnode->pTq, pMsg);
13✔
897
    case TDMT_VND_TMQ_VG_COMMITTEDINFO:
2✔
898
      return tqProcessVgCommittedInfoReq(pVnode->pTq, pMsg);
2✔
899
    case TDMT_VND_TMQ_SEEK:
24✔
900
      return tqProcessSeekReq(pVnode->pTq, pMsg);
24✔
901

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

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

917
  switch (pMsg->msgType) {
375,348!
918
    case TDMT_STREAM_TASK_RUN:
200,333✔
919
      return tqProcessTaskRunReq(pVnode->pTq, pMsg);
200,333✔
920
    case TDMT_STREAM_TASK_DISPATCH:
39,077✔
921
      return tqProcessTaskDispatchReq(pVnode->pTq, pMsg);
39,077✔
922
    case TDMT_STREAM_TASK_DISPATCH_RSP:
39,329✔
923
      return tqProcessTaskDispatchRsp(pVnode->pTq, pMsg);
39,329✔
924
    case TDMT_VND_STREAM_TASK_CHECK:
20,944✔
925
      return tqProcessTaskCheckReq(pVnode->pTq, pMsg);
20,944✔
926
    case TDMT_VND_STREAM_TASK_CHECK_RSP:
21,057✔
927
      return tqProcessTaskCheckRsp(pVnode->pTq, pMsg);
21,057✔
928
    case TDMT_STREAM_RETRIEVE:
559✔
929
      return tqProcessTaskRetrieveReq(pVnode->pTq, pMsg);
559✔
930
    case TDMT_STREAM_RETRIEVE_RSP:
442✔
931
      return tqProcessTaskRetrieveRsp(pVnode->pTq, pMsg);
442✔
932
    case TDMT_VND_STREAM_SCAN_HISTORY:
2,538✔
933
      return tqProcessTaskScanHistory(pVnode->pTq, pMsg);
2,538✔
934
    case TDMT_STREAM_TASK_CHECKPOINT_READY:
8,291✔
935
      return tqProcessTaskCheckpointReadyMsg(pVnode->pTq, pMsg);
8,291✔
936
    case TDMT_STREAM_TASK_CHECKPOINT_READY_RSP:
8,278✔
937
      return tqProcessTaskCheckpointReadyRsp(pVnode->pTq, pMsg);
8,278✔
938
    case TDMT_STREAM_RETRIEVE_TRIGGER:
×
939
      return tqProcessTaskRetrieveTriggerReq(pVnode->pTq, pMsg);
×
940
    case TDMT_STREAM_RETRIEVE_TRIGGER_RSP:
×
941
      return tqProcessTaskRetrieveTriggerRsp(pVnode->pTq, pMsg);
×
942
    case TDMT_MND_STREAM_HEARTBEAT_RSP:
23,392✔
943
      return tqProcessStreamHbRsp(pVnode->pTq, pMsg);
23,392✔
944
    case TDMT_MND_STREAM_REQ_CHKPT_RSP:
4,689✔
945
      return tqProcessStreamReqCheckpointRsp(pVnode->pTq, pMsg);
4,689✔
946
    case TDMT_VND_GET_STREAM_PROGRESS:
×
947
      return tqStreamProgressRetrieveReq(pVnode->pTq, pMsg);
×
948
    case TDMT_MND_STREAM_CHKPT_REPORT_RSP:
6,419✔
949
      return tqProcessTaskChkptReportRsp(pVnode->pTq, pMsg);
6,419✔
950
    default:
×
951
      vError("unknown msg type:%d in stream queue", pMsg->msgType);
×
952
      return TSDB_CODE_APP_ERROR;
×
953
  }
954
}
955

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

963
void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) {
198,122✔
964
  if (NULL == pMetaRsp) {
198,122!
965
    return;
×
966
  }
967

968
  strcpy(pMetaRsp->dbFName, pVnode->config.dbname);
198,122✔
969
  pMetaRsp->dbId = pVnode->config.dbId;
198,122✔
970
  pMetaRsp->vgId = TD_VID(pVnode);
198,122✔
971
  pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
198,122✔
972
}
973

974
extern int32_t vnodeAsyncRetention(SVnode *pVnode, int64_t now);
975

976
static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
216✔
977
  int32_t     code = 0;
216✔
978
  SVTrimDbReq trimReq = {0};
216✔
979

980
  // decode
981
  if (tDeserializeSVTrimDbReq(pReq, len, &trimReq) != 0) {
216!
982
    code = TSDB_CODE_INVALID_MSG;
×
983
    goto _exit;
×
984
  }
985

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

988
  code = vnodeAsyncRetention(pVnode, trimReq.timestamp);
216✔
989

990
_exit:
216✔
991
  return code;
216✔
992
}
993

994
extern int32_t vnodeAsyncS3Migrate(SVnode *pVnode, int64_t now);
995

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

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

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

1008
  code = vnodeAsyncS3Migrate(pVnode, s3migrateReq.timestamp);
×
1009

1010
_exit:
×
1011
  return code;
×
1012
}
1013

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

1022
  if (ttlReq.nUids != taosArrayGetSize(ttlReq.pTbUids)) {
×
1023
    ret = TSDB_CODE_INVALID_MSG;
×
1024
    goto end;
×
1025
  }
1026

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

1032
  if (ttlReq.nUids > 0) {
×
1033
    int32_t code = metaDropTables(pVnode->pMeta, ttlReq.pTbUids);
×
1034
    if (code) return code;
×
1035

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

1042
end:
×
1043
  taosArrayDestroy(ttlReq.pTbUids);
×
1044
  return ret;
×
1045
}
1046

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

1059
  if (tDeserializeSVDropTtlTableReq(pReq, len, &ttlReq) != 0) {
35!
1060
    terrno = TSDB_CODE_INVALID_MSG;
×
1061
    goto _end;
×
1062
  }
1063

1064
  if (!(ttlReq.nUids == taosArrayGetSize(ttlReq.pTbUids))) {
38!
1065
    terrno = TSDB_CODE_INVALID_MSG;
×
1066
    goto _end;
×
1067
  }
1068

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

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

1094
    expiredTb.name = p;
134✔
1095
    if (mr.me.type == TSDB_CHILD_TABLE) {
134✔
1096
      expiredTb.suid = mr.me.ctbEntry.suid;
89✔
1097
    }
1098

1099
    if (taosArrayPush(rsp.pExpiredTbs, &expiredTb) == NULL) {
270!
1100
      goto _end;
×
1101
    }
1102
  }
1103

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

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

1126
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
31,751✔
1127
  int32_t        code = 0;
31,751✔
1128
  SVCreateStbReq req = {0};
31,751✔
1129
  SDecoder       coder;
1130

1131
  pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
31,751✔
1132
  pRsp->code = TSDB_CODE_SUCCESS;
31,751✔
1133
  pRsp->pCont = NULL;
31,751✔
1134
  pRsp->contLen = 0;
31,751✔
1135

1136
  // decode and process req
1137
  tDecoderInit(&coder, pReq, len);
31,751✔
1138

1139
  code = tDecodeSVCreateStbReq(&coder, &req);
31,746✔
1140
  if (code) {
31,782!
1141
    pRsp->code = code;
×
1142
    goto _err;
×
1143
  }
1144

1145
  code = metaCreateSTable(pVnode->pMeta, ver, &req);
31,782✔
1146
  if (code) {
31,726✔
1147
    pRsp->code = code;
4✔
1148
    goto _err;
4✔
1149
  }
1150

1151
  if ((code = tdProcessRSmaCreate(pVnode->pSma, &req)) < 0) {
31,722!
1152
    pRsp->code = code;
×
1153
    goto _err;
×
1154
  }
1155

1156
  tDecoderClear(&coder);
31,787✔
1157
  return 0;
31,786✔
1158

1159
_err:
4✔
1160
  tDecoderClear(&coder);
4✔
1161
  return code;
4✔
1162
}
1163

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

1182
  // decode
1183
  tDecoderInit(&decoder, pReq, len);
91,306✔
1184
  if (tDecodeSVCreateTbBatchReq(&decoder, &req) < 0) {
91,300!
1185
    rcode = -1;
×
1186
    terrno = TSDB_CODE_INVALID_MSG;
×
1187
    goto _exit;
×
1188
  }
1189

1190
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(cRsp));
91,322✔
1191
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
91,326✔
1192
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
91,332✔
1193
  if (rsp.pArray == NULL || tbUids == NULL || tbNames == NULL) {
91,335!
UNCOV
1194
    rcode = -1;
×
UNCOV
1195
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1196
    goto _exit;
×
1197
  }
1198

1199
  // loop to create table
1200
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
236,000✔
1201
    pCreateReq = req.pReqs + iReq;
144,681✔
1202
    memset(&cRsp, 0, sizeof(cRsp));
144,681✔
1203

1204
    if (tsEnableAudit && tsEnableAuditCreateTable) {
144,681!
1205
      char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
144,683✔
1206
      if (str == NULL) {
144,690!
1207
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1208
        rcode = -1;
×
1209
        goto _exit;
×
1210
      }
1211
      strcpy(str, pCreateReq->name);
144,690✔
1212
      if (taosArrayPush(tbNames, &str) == NULL) {
144,695!
1213
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1214
        rcode = -1;
×
1215
        goto _exit;
×
1216
      }
1217
    }
1218

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

1232
    // do create table
1233
    if (metaCreateTable(pVnode->pMeta, ver, pCreateReq, &cRsp.pMeta) < 0) {
144,669✔
1234
      if (pCreateReq->flags & TD_CREATE_IF_NOT_EXISTS && terrno == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
1,358!
1235
        cRsp.code = TSDB_CODE_SUCCESS;
3✔
1236
      } else {
1237
        cRsp.code = terrno;
1,355✔
1238
      }
1239
    } else {
1240
      cRsp.code = TSDB_CODE_SUCCESS;
143,301✔
1241
      if (tdFetchTbUidList(pVnode->pSma, &pStore, pCreateReq->ctb.suid, pCreateReq->uid) < 0) {
143,301!
1242
        vError("vgId:%d, failed to fetch tbUid list", TD_VID(pVnode));
×
1243
      }
1244
      if (taosArrayPush(tbUids, &pCreateReq->uid) == NULL) {
286,586!
1245
        terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1246
        rcode = -1;
×
1247
        goto _exit;
×
1248
      }
1249
      vnodeUpdateMetaRsp(pVnode, cRsp.pMeta);
143,290✔
1250
    }
1251

1252
    if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
289,296!
1253
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1254
      rcode = -1;
×
1255
      goto _exit;
×
1256
    }
1257
  }
1258

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

1268
  // prepare rsp
1269
  int32_t ret = 0;
91,330✔
1270
  tEncodeSize(tEncodeSVCreateTbBatchRsp, &rsp, pRsp->contLen, ret);
91,330!
1271
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
91,327✔
1272
  if (pRsp->pCont == NULL) {
91,332!
1273
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1274
    rcode = -1;
×
1275
    goto _exit;
×
1276
  }
1277
  tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
91,332✔
1278
  if (tEncodeSVCreateTbBatchRsp(&encoder, &rsp) != 0) {
91,334!
1279
    vError("vgId:%d, failed to encode create table batch response", TD_VID(pVnode));
×
1280
  }
1281

1282
  if (tsEnableAudit && tsEnableAuditCreateTable) {
91,326!
1283
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
91,325✔
1284

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

1290
    SStringBuilder sb = {0};
91,325✔
1291
    for (int32_t i = 0; i < tbNames->size; i++) {
235,983✔
1292
      char **key = (char **)taosArrayGet(tbNames, i);
144,665✔
1293
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
144,661✔
1294
      if (i < tbNames->size - 1) {
144,666✔
1295
        taosStringBuilderAppendChar(&sb, ',');
53,346✔
1296
      }
1297
      // taosMemoryFreeClear(*key);
1298
    }
1299

1300
    size_t len = 0;
91,318✔
1301
    char  *keyJoined = taosStringBuilderGetResult(&sb, &len);
91,318✔
1302

1303
    if (pOriginRpc->info.conn.user != NULL && strlen(pOriginRpc->info.conn.user) > 0) {
91,324!
1304
      auditAddRecord(pOriginRpc, clusterId, "createTable", name.dbname, "", keyJoined, len);
71,325✔
1305
    }
1306

1307
    taosStringBuilderDestroy(&sb);
91,325✔
1308
  }
1309

1310
_exit:
1✔
1311
  tDeleteSVCreateTbBatchReq(&req);
91,322✔
1312
  taosArrayDestroyEx(rsp.pArray, tFreeSVCreateTbRsp);
91,329✔
1313
  taosArrayDestroy(tbUids);
91,329✔
1314
  tDecoderClear(&decoder);
91,333✔
1315
  tEncoderClear(&encoder);
91,335✔
1316
  taosArrayDestroyP(tbNames, taosMemoryFree);
91,334✔
1317
  return rcode;
91,334✔
1318
}
1319

1320
static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
4,910✔
1321
  int32_t        code = 0;
4,910✔
1322
  SVCreateStbReq req = {0};
4,910✔
1323
  SDecoder       dc = {0};
4,910✔
1324

1325
  pRsp->msgType = TDMT_VND_ALTER_STB_RSP;
4,910✔
1326
  pRsp->code = TSDB_CODE_SUCCESS;
4,910✔
1327
  pRsp->pCont = NULL;
4,910✔
1328
  pRsp->contLen = 0;
4,910✔
1329

1330
  tDecoderInit(&dc, pReq, len);
4,910✔
1331

1332
  // decode req
1333
  code = tDecodeSVCreateStbReq(&dc, &req);
4,910✔
1334
  if (code) {
4,910!
1335
    tDecoderClear(&dc);
×
1336
    return code;
×
1337
  }
1338

1339
  code = metaAlterSTable(pVnode->pMeta, ver, &req);
4,910✔
1340
  if (code) {
4,899!
1341
    pRsp->code = code;
×
1342
    tDecoderClear(&dc);
×
1343
    return code;
×
1344
  }
1345

1346
  tDecoderClear(&dc);
4,899✔
1347

1348
  return 0;
4,910✔
1349
}
1350

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

1357
  pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
3,379✔
1358
  pRsp->pCont = NULL;
3,379✔
1359
  pRsp->contLen = 0;
3,379✔
1360

1361
  // decode request
1362
  tDecoderInit(&decoder, pReq, len);
3,379✔
1363
  if (tDecodeSVDropStbReq(&decoder, &req) < 0) {
3,380!
1364
    rcode = TSDB_CODE_INVALID_MSG;
×
1365
    goto _exit;
×
1366
  }
1367

1368
  // process request
1369
  tbUidList = taosArrayInit(8, sizeof(int64_t));
3,381✔
1370
  if (tbUidList == NULL) goto _exit;
3,378!
1371
  if (metaDropSTable(pVnode->pMeta, ver, &req, tbUidList) < 0) {
3,378✔
1372
    rcode = terrno;
8✔
1373
    goto _exit;
8✔
1374
  }
1375

1376
  if (tqUpdateTbUidList(pVnode->pTq, tbUidList, false) < 0) {
3,377!
1377
    rcode = terrno;
×
1378
    goto _exit;
×
1379
  }
1380

1381
  if (tdProcessRSmaDrop(pVnode->pSma, &req) < 0) {
3,377!
1382
    rcode = terrno;
×
1383
    goto _exit;
×
1384
  }
1385

1386
  // return rsp
1387
_exit:
3,377✔
1388
  if (tbUidList) taosArrayDestroy(tbUidList);
3,385!
1389
  pRsp->code = rcode;
3,385✔
1390
  tDecoderClear(&decoder);
3,385✔
1391
  return 0;
3,385✔
1392
}
1393

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

1403
  pRsp->msgType = TDMT_VND_ALTER_TABLE_RSP;
5,184✔
1404
  pRsp->pCont = NULL;
5,184✔
1405
  pRsp->contLen = 0;
5,184✔
1406
  pRsp->code = TSDB_CODE_SUCCESS;
5,184✔
1407

1408
  tDecoderInit(&dc, pReq, len);
5,184✔
1409

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

1418
  // process
1419
  if (metaAlterTable(pVnode->pMeta, ver, &vAlterTbReq, &vMetaRsp) < 0) {
5,184✔
1420
    vAlterTbRsp.code = terrno;
926✔
1421
    tDecoderClear(&dc);
926✔
1422
    rcode = -1;
926✔
1423
    goto _exit;
926✔
1424
  }
1425
  tDecoderClear(&dc);
4,258✔
1426

1427
  if (NULL != vMetaRsp.pSchemas) {
4,258✔
1428
    vnodeUpdateMetaRsp(pVnode, &vMetaRsp);
1,042✔
1429
    vAlterTbRsp.pMeta = &vMetaRsp;
1,042✔
1430
  }
1431

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

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

1458
  pRsp->msgType = TDMT_VND_DROP_TABLE_RSP;
16,428✔
1459
  pRsp->pCont = NULL;
16,428✔
1460
  pRsp->contLen = 0;
16,428✔
1461
  pRsp->code = TSDB_CODE_SUCCESS;
16,428✔
1462

1463
  // decode req
1464
  tDecoderInit(&decoder, pReq, len);
16,428✔
1465
  ret = tDecodeSVDropTbBatchReq(&decoder, &req);
16,428✔
1466
  if (ret < 0) {
16,428!
1467
    terrno = TSDB_CODE_INVALID_MSG;
×
1468
    pRsp->code = terrno;
×
1469
    goto _exit;
×
1470
  }
1471

1472
  // process req
1473
  tbUids = taosArrayInit(req.nReqs, sizeof(int64_t));
16,428✔
1474
  rsp.pArray = taosArrayInit(req.nReqs, sizeof(SVDropTbRsp));
16,428✔
1475
  tbNames = taosArrayInit(req.nReqs, sizeof(char *));
16,428✔
1476
  if (tbUids == NULL || rsp.pArray == NULL || tbNames == NULL) goto _exit;
16,428!
1477

1478
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
32,881✔
1479
    SVDropTbReq *pDropTbReq = req.pReqs + iReq;
16,453✔
1480
    SVDropTbRsp  dropTbRsp = {0};
16,453✔
1481
    tb_uid_t     tbUid = 0;
16,453✔
1482

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

1500
    if (taosArrayPush(rsp.pArray, &dropTbRsp) == NULL) {
32,906!
1501
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1502
      pRsp->code = terrno;
×
1503
      goto _exit;
×
1504
    }
1505

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

1521
  if (tqUpdateTbUidList(pVnode->pTq, tbUids, false) < 0) {
16,428!
1522
    vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(terrno));
×
1523
  }
1524

1525
  if (tdUpdateTbUidList(pVnode->pSma, pStore, false) < 0) {
16,428!
1526
    goto _exit;
×
1527
  }
1528

1529
  if (tsEnableAuditCreateTable) {
16,428!
1530
    int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId;
16,428✔
1531

1532
    SName name = {0};
16,428✔
1533
    if (tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB) != 0) {
16,428!
1534
      vError("vgId:%d, failed to get name from string", TD_VID(pVnode));
×
1535
    }
1536

1537
    SStringBuilder sb = {0};
16,428✔
1538
    for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
32,881✔
1539
      char **key = (char **)taosArrayGet(tbNames, iReq);
16,453✔
1540
      taosStringBuilderAppendStringLen(&sb, *key, strlen(*key));
16,453✔
1541
      if (iReq < req.nReqs - 1) {
16,453✔
1542
        taosStringBuilderAppendChar(&sb, ',');
25✔
1543
      }
1544
      taosMemoryFreeClear(*key);
16,453!
1545
    }
1546

1547
    size_t len = 0;
16,428✔
1548
    char  *keyJoined = taosStringBuilderGetResult(&sb, &len);
16,428✔
1549

1550
    if (pOriginRpc->info.conn.user != NULL && strlen(pOriginRpc->info.conn.user) > 0) {
16,428!
1551
      auditAddRecord(pOriginRpc, clusterId, "dropTable", name.dbname, "", keyJoined, len);
16,331✔
1552
    }
1553

1554
    taosStringBuilderDestroy(&sb);
16,428✔
1555
  }
1556

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

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

1582
  tInitSubmitBlkIter(msgIter, pBlock, &blkIter);
1583
  if (blkIter.row == NULL) return 0;
1584

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

1592
  suid = msgIter->suid;
1593
  rv = TD_ROW_SVER(blkIter.row);
1594

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

1601
  taosMemoryFreeClear(pSchema);
1602

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

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

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

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

1655
  return TSDB_CODE_SUCCESS;
×
1656
}
1657

1658
static void vnodeDestroySubmitReqConvertCxt(SSubmitReqConvertCxt *pCxt) {
×
1659
  taosMemoryFreeClear(pCxt->pTbSchema);
×
1660
  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
×
1661
  taosMemoryFreeClear(pCxt->pTbData);
×
1662
  taosArrayDestroy(pCxt->pColValues);
×
1663
}
×
1664

1665
static int32_t vnodeCellValConvertToColVal(STColumn *pCol, SCellVal *pCellVal, SColVal *pColVal) {
×
1666
  if (tdValTypeIsNone(pCellVal->valType)) {
×
1667
    pColVal->flag = CV_FLAG_NONE;
×
1668
    return TSDB_CODE_SUCCESS;
×
1669
  }
1670

1671
  if (tdValTypeIsNull(pCellVal->valType)) {
×
1672
    pColVal->flag = CV_FLAG_NULL;
×
1673
    return TSDB_CODE_SUCCESS;
×
1674
  }
1675

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

1688
  pColVal->flag = CV_FLAG_VALUE;
×
1689
  return TSDB_CODE_SUCCESS;
×
1690
}
1691

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

1706
static int32_t vnodeDecodeCreateTbReq(SSubmitReqConvertCxt *pCxt) {
×
1707
  if (pCxt->msgIter.schemaLen <= 0) {
×
1708
    return TSDB_CODE_SUCCESS;
×
1709
  }
1710

1711
  pCxt->pTbData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
×
1712
  if (NULL == pCxt->pTbData->pCreateTbReq) {
×
1713
    return terrno;
×
1714
  }
1715

1716
  SDecoder decoder = {0};
×
1717
  tDecoderInit(&decoder, (uint8_t *)pCxt->pBlock->data, pCxt->msgIter.schemaLen);
×
1718
  int32_t code = tDecodeSVCreateTbReq(&decoder, pCxt->pTbData->pCreateTbReq);
×
1719
  tDecoderClear(&decoder);
×
1720

1721
  return code;
×
1722
}
1723

1724
static int32_t vnodeSubmitReqConvertToSubmitReq2(SVnode *pVnode, SSubmitReq *pReq, SSubmitReq2 *pReq2) {
×
1725
  pReq2->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData));
×
1726
  if (NULL == pReq2->aSubmitTbData) {
×
1727
    return terrno;
×
1728
  }
1729

1730
  SSubmitReqConvertCxt cxt = {0};
×
1731

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

1762
  vnodeDestroySubmitReqConvertCxt(&cxt);
×
1763
  return code;
×
1764
}
1765

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

1789
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
14,650,814✔
1790
                                     SRpcMsg *pOriginalMsg) {
1791
  int32_t code = 0;
14,650,814✔
1792
  terrno = 0;
14,650,814✔
1793

1794
  SSubmitReq2 *pSubmitReq = &(SSubmitReq2){0};
14,651,017✔
1795
  SSubmitRsp2 *pSubmitRsp = &(SSubmitRsp2){0};
14,651,017✔
1796
  SArray      *newTbUids = NULL;
14,651,017✔
1797
  int32_t      ret;
1798
  SEncoder     ec = {0};
14,651,017✔
1799

1800
  pRsp->code = TSDB_CODE_SUCCESS;
14,651,017✔
1801

1802
  void           *pAllocMsg = NULL;
14,651,017✔
1803
  SSubmitReq2Msg *pMsg = (SSubmitReq2Msg *)pReq;
14,651,017✔
1804
  if (0 == pMsg->version) {
14,651,017!
1805
    code = vnodeSubmitReqConvertToSubmitReq2(pVnode, (SSubmitReq *)pMsg, pSubmitReq);
×
1806
    if (TSDB_CODE_SUCCESS == code) {
×
1807
      code = vnodeRebuildSubmitReqMsg(pSubmitReq, &pReq);
×
1808
    }
1809
    if (TSDB_CODE_SUCCESS == code) {
×
1810
      pAllocMsg = pReq;
×
1811
    }
1812
    if (TSDB_CODE_SUCCESS != code) {
×
1813
      goto _exit;
×
1814
    }
1815
  } else {
1816
    // decode
1817
    pReq = POINTER_SHIFT(pReq, sizeof(SSubmitReq2Msg));
14,651,017✔
1818
    len -= sizeof(SSubmitReq2Msg);
14,651,017✔
1819
    SDecoder dc = {0};
14,651,017✔
1820
    tDecoderInit(&dc, pReq, len);
14,651,017✔
1821
    if (tDecodeSubmitReq(&dc, pSubmitReq) < 0) {
14,650,887!
1822
      code = TSDB_CODE_INVALID_MSG;
×
1823
      goto _exit;
×
1824
    }
1825
    tDecoderClear(&dc);
14,650,976✔
1826
  }
1827

1828
  // scan
1829
  TSKEY now = taosGetTimestamp(pVnode->config.tsdbCfg.precision);
14,650,941✔
1830
  TSKEY minKey = now - tsTickPerMin[pVnode->config.tsdbCfg.precision] * pVnode->config.tsdbCfg.keep2;
14,651,008✔
1831
  TSKEY maxKey = tsMaxKeyByPrecision[pVnode->config.tsdbCfg.precision];
14,651,008✔
1832
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
29,988,760✔
1833
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
15,338,749✔
1834

1835
    if (pSubmitTbData->pCreateTbReq && pSubmitTbData->pCreateTbReq->uid == 0) {
15,338,782!
1836
      code = TSDB_CODE_INVALID_MSG;
×
1837
      goto _exit;
×
1838
    }
1839

1840
    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
15,338,782✔
1841
      if (TARRAY_SIZE(pSubmitTbData->aCol) <= 0) {
155!
1842
        code = TSDB_CODE_INVALID_MSG;
×
1843
        goto _exit;
×
1844
      }
1845

1846
      SColData *colDataArr = TARRAY_DATA(pSubmitTbData->aCol);
155✔
1847
      SRowKey   lastKey;
1848
      tColDataArrGetRowKey(colDataArr, TARRAY_SIZE(pSubmitTbData->aCol), 0, &lastKey);
155✔
1849
      for (int32_t iRow = 1; iRow < colDataArr[0].nVal; iRow++) {
270✔
1850
        SRowKey key;
1851
        tColDataArrGetRowKey(TARRAY_DATA(pSubmitTbData->aCol), TARRAY_SIZE(pSubmitTbData->aCol), iRow, &key);
115✔
1852
        if (tRowKeyCompare(&lastKey, &key) >= 0) {
115!
1853
          code = TSDB_CODE_INVALID_MSG;
×
1854
          vError("vgId:%d %s failed 1 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(terrno), ver);
×
1855
          goto _exit;
×
1856
        }
1857
      }
1858
    } else {
1859
      int32_t nRow = TARRAY_SIZE(pSubmitTbData->aRowP);
15,338,627✔
1860
      SRow  **aRow = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP);
15,338,627✔
1861
      SRowKey lastRowKey;
1862
      for (int32_t iRow = 0; iRow < nRow; ++iRow) {
972,553,545✔
1863
        if (aRow[iRow]->ts < minKey || aRow[iRow]->ts > maxKey) {
957,215,948!
1864
          code = TSDB_CODE_INVALID_MSG;
21,317✔
1865
          vError("vgId:%d %s failed 2 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code), ver);
21,317!
1866
          goto _exit;
×
1867
        }
1868
        if (iRow == 0) {
957,194,631✔
1869
          tRowGetKey(aRow[iRow], &lastRowKey);
15,338,634✔
1870
        } else {
1871
          SRowKey rowKey;
1872
          tRowGetKey(aRow[iRow], &rowKey);
941,855,997✔
1873

1874
          if (tRowKeyCompare(&lastRowKey, &rowKey) >= 0) {
941,855,486!
1875
            code = TSDB_CODE_INVALID_MSG;
×
1876
            vError("vgId:%d %s failed 3 since %s, version:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code), ver);
×
1877
            goto _exit;
×
1878
          }
1879
          lastRowKey = rowKey;
941,873,718✔
1880
        }
1881
      }
1882
    }
1883
  }
1884

1885
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
29,990,492✔
1886
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
15,340,237✔
1887

1888
    if (pSubmitTbData->pCreateTbReq) {
15,340,144✔
1889
      pSubmitTbData->uid = pSubmitTbData->pCreateTbReq->uid;
79,831✔
1890
    } else {
1891
      SMetaInfo info = {0};
15,260,313✔
1892

1893
      code = metaGetInfo(pVnode->pMeta, pSubmitTbData->uid, &info, NULL);
15,260,313✔
1894
      if (code) {
15,260,520✔
1895
        code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
2✔
1896
        vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), pSubmitTbData->uid);
2!
1897
        goto _exit;
11✔
1898
      }
1899

1900
      if (info.suid != pSubmitTbData->suid) {
15,260,518!
1901
        code = TSDB_CODE_INVALID_MSG;
×
1902
        goto _exit;
×
1903
      }
1904

1905
      if (info.suid) {
15,260,518✔
1906
        if (metaGetInfo(pVnode->pMeta, info.suid, &info, NULL) != 0) {
14,318,302!
1907
          vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), info.suid);
×
1908
        }
1909
      }
1910

1911
      if (pSubmitTbData->sver != info.skmVer) {
15,260,650!
1912
        code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER;
×
1913
        goto _exit;
×
1914
      }
1915
    }
1916

1917
    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
15,340,481✔
1918
      int32_t   nColData = TARRAY_SIZE(pSubmitTbData->aCol);
155✔
1919
      SColData *aColData = (SColData *)TARRAY_DATA(pSubmitTbData->aCol);
155✔
1920

1921
      if (nColData <= 0) {
155!
1922
        code = TSDB_CODE_INVALID_MSG;
×
1923
        goto _exit;
×
1924
      }
1925

1926
      if (aColData[0].cid != PRIMARYKEY_TIMESTAMP_COL_ID || aColData[0].type != TSDB_DATA_TYPE_TIMESTAMP ||
155!
1927
          aColData[0].nVal <= 0) {
155!
1928
        code = TSDB_CODE_INVALID_MSG;
×
1929
        goto _exit;
×
1930
      }
1931

1932
      for (int32_t j = 1; j < nColData; j++) {
692✔
1933
        if (aColData[j].nVal != aColData[0].nVal) {
537!
1934
          code = TSDB_CODE_INVALID_MSG;
×
1935
          goto _exit;
×
1936
        }
1937
      }
1938
    }
1939
  }
1940

1941
  vDebug("vgId:%d, submit block size %d", TD_VID(pVnode), (int32_t)taosArrayGetSize(pSubmitReq->aSubmitTbData));
14,650,255✔
1942

1943
  // loop to handle
1944
  for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
29,989,161✔
1945
    SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
15,338,081✔
1946

1947
    // create table
1948
    if (pSubmitTbData->pCreateTbReq) {
15,337,884✔
1949
      // alloc if need
1950
      if (pSubmitRsp->aCreateTbRsp == NULL &&
79,821✔
1951
          (pSubmitRsp->aCreateTbRsp = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(SVCreateTbRsp))) ==
56,100!
1952
              NULL) {
1953
        code = terrno;
×
1954
        goto _exit;
8✔
1955
      }
1956

1957
      SVCreateTbRsp *pCreateTbRsp = taosArrayReserve(pSubmitRsp->aCreateTbRsp, 1);
79,821✔
1958

1959
      // create table
1960
      if (metaCreateTable(pVnode->pMeta, ver, pSubmitTbData->pCreateTbReq, &pCreateTbRsp->pMeta) == 0) {
79,822✔
1961
        // create table success
1962

1963
        if (newTbUids == NULL &&
89,699!
1964
            (newTbUids = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(int64_t))) == NULL) {
35,908✔
1965
          code = terrno;
×
1966
          goto _exit;
×
1967
        }
1968

1969
        if (taosArrayPush(newTbUids, &pSubmitTbData->uid) == NULL) {
107,583!
1970
          code = terrno;
×
1971
          goto _exit;
×
1972
        }
1973

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

1989
    // insert data
1990
    int32_t affectedRows;
1991
    code = tsdbInsertTableData(pVnode->pTsdb, ver, pSubmitTbData, &affectedRows);
15,337,877✔
1992
    if (code) goto _exit;
15,338,231!
1993

1994
    code = metaUpdateChangeTimeWithLock(pVnode->pMeta, pSubmitTbData->uid, pSubmitTbData->ctimeMs);
15,338,231✔
1995
    if (code) goto _exit;
15,338,144!
1996

1997
    pSubmitRsp->affectedRows += affectedRows;
15,338,144✔
1998
  }
1999

2000
  // update the affected table uid list
2001
  if (taosArrayGetSize(newTbUids) > 0) {
14,651,080✔
2002
    vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
35,908✔
2003
           (int32_t)taosArrayGetSize(newTbUids));
2004
    if (tqUpdateTbUidList(pVnode->pTq, newTbUids, true) != 0) {
35,908!
2005
      vError("vgId:%d, failed to update tbUid list", TD_VID(pVnode));
×
2006
    }
2007
  }
2008

2009
_exit:
14,650,995✔
2010
  // message
2011
  pRsp->code = code;
14,651,014✔
2012
  tEncodeSize(tEncodeSSubmitRsp2, pSubmitRsp, pRsp->contLen, ret);
14,651,014!
2013
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
14,650,980✔
2014
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
14,650,918✔
2015
  if (tEncodeSSubmitRsp2(&ec, pSubmitRsp) < 0) {
14,650,997!
2016
    vError("vgId:%d, failed to encode submit response", TD_VID(pVnode));
×
2017
  }
2018
  tEncoderClear(&ec);
14,650,926✔
2019

2020
  // update statistics
2021
  (void)atomic_add_fetch_64(&pVnode->statis.nInsert, pSubmitRsp->affectedRows);
14,651,031✔
2022
  (void)atomic_add_fetch_64(&pVnode->statis.nInsertSuccess, pSubmitRsp->affectedRows);
14,651,050✔
2023
  (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsert, 1);
14,651,070✔
2024

2025
  if (tsEnableMonitor && tsMonitorFqdn[0] != 0 && tsMonitorPort != 0 && pSubmitRsp->affectedRows > 0 &&
14,651,054!
2026
      strlen(pOriginalMsg->info.conn.user) > 0 && tsInsertCounter != NULL) {
×
2027
    const char *sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT_AFFECTED_ROWS,
×
2028
                                   pVnode->monitor.strClusterId,
×
2029
                                   pVnode->monitor.strDnodeId,
×
2030
                                   tsLocalEp,
2031
                                   pVnode->monitor.strVgId,
×
2032
                                   pOriginalMsg->info.conn.user,
×
2033
                                   "Success"};
2034
    int         tv = taos_counter_add(tsInsertCounter, pSubmitRsp->affectedRows, sample_labels);
×
2035
  }
2036

2037
  if (code == 0) {
14,651,054✔
2038
    (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
14,651,009✔
2039
    code = tdProcessRSmaSubmit(pVnode->pSma, ver, pSubmitReq, pReq, len);
14,651,056✔
2040
  }
2041
  /*
2042
  if (code == 0) {
2043
    atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
2044
    code = tdProcessRSmaSubmit(pVnode->pSma, ver, pSubmitReq, pReq, len);
2045

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

2059
  // clear
2060
  taosArrayDestroy(newTbUids);
14,651,054✔
2061
  tDestroySubmitReq(pSubmitReq, 0 == pMsg->version ? TSDB_MSG_FLG_CMPT : TSDB_MSG_FLG_DECODE);
14,651,001!
2062
  tDestroySSubmitRsp2(pSubmitRsp, TSDB_MSG_FLG_ENCODE);
14,651,006✔
2063

2064
  if (code) terrno = code;
14,650,921✔
2065

2066
  taosMemoryFree(pAllocMsg);
14,650,921✔
2067

2068
  return code;
14,650,918✔
2069
}
2070

2071
static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
33✔
2072
  SVCreateTSmaReq req = {0};
33✔
2073
  SDecoder        coder = {0};
33✔
2074

2075
  if (pRsp) {
33!
2076
    pRsp->msgType = TDMT_VND_CREATE_SMA_RSP;
33✔
2077
    pRsp->code = TSDB_CODE_SUCCESS;
33✔
2078
    pRsp->pCont = NULL;
33✔
2079
    pRsp->contLen = 0;
33✔
2080
  }
2081

2082
  // decode and process req
2083
  tDecoderInit(&coder, pReq, len);
33✔
2084

2085
  if (tDecodeSVCreateTSmaReq(&coder, &req) < 0) {
33!
2086
    terrno = TSDB_CODE_MSG_DECODE_ERROR;
×
2087
    if (pRsp) pRsp->code = terrno;
×
2088
    goto _err;
×
2089
  }
2090

2091
  if (tdProcessTSmaCreate(pVnode->pSma, ver, (const char *)&req) < 0) {
33!
2092
    if (pRsp) pRsp->code = terrno;
×
2093
    goto _err;
×
2094
  }
2095

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

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

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

2120
static int32_t vnodeConsolidateAlterHashRange(SVnode *pVnode, int64_t ver) {
86✔
2121
  int32_t code = TSDB_CODE_SUCCESS;
86✔
2122

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

2126
  // TODO: trim meta of tables from TDB per hash range [pVnode->config.hashBegin, pVnode->config.hashEnd]
2127
  code = metaTrimTables(pVnode->pMeta);
86✔
2128

2129
  return code;
86✔
2130
}
2131

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

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

2146
_exit:
8,311✔
2147
  pRsp->msgType = TDMT_VND_ALTER_CONFIRM_RSP;
8,311✔
2148
  pRsp->code = code;
8,311✔
2149
  pRsp->pCont = NULL;
8,311✔
2150
  pRsp->contLen = 0;
8,311✔
2151

2152
  return code;
8,311✔
2153
}
2154

2155
extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb);
2156
extern void    tsdbEnableBgTask(STsdb *pTsdb);
2157

2158
static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
859✔
2159
  bool walChanged = false;
859✔
2160
  bool tsdbChanged = false;
859✔
2161

2162
  SAlterVnodeConfigReq req = {0};
859✔
2163
  if (tDeserializeSAlterVnodeConfigReq(pReq, len, &req) != 0) {
859!
2164
    terrno = TSDB_CODE_INVALID_MSG;
×
2165
    return TSDB_CODE_INVALID_MSG;
×
2166
  }
2167

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

2177
  if (pVnode->config.cacheLastSize != req.cacheLastSize) {
861✔
2178
    pVnode->config.cacheLastSize = req.cacheLastSize;
356✔
2179
    tsdbCacheSetCapacity(pVnode, (size_t)pVnode->config.cacheLastSize * 1024 * 1024);
356✔
2180
  }
2181

2182
  if (pVnode->config.szBuf != req.buffer * 1024LL * 1024LL) {
861✔
2183
    vInfo("vgId:%d, vnode buffer is changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pVnode->config.szBuf,
10!
2184
          (uint64_t)(req.buffer * 1024LL * 1024LL));
2185
    pVnode->config.szBuf = req.buffer * 1024LL * 1024LL;
10✔
2186
  }
2187

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

2199
  if (pVnode->config.cacheLast != req.cacheLast) {
861✔
2200
    pVnode->config.cacheLast = req.cacheLast;
535✔
2201
  }
2202

2203
  if (pVnode->config.walCfg.fsyncPeriod != req.walFsyncPeriod) {
861✔
2204
    pVnode->config.walCfg.fsyncPeriod = req.walFsyncPeriod;
70✔
2205
    walChanged = true;
70✔
2206
  }
2207

2208
  if (pVnode->config.walCfg.level != req.walLevel) {
861✔
2209
    if (pVnode->config.walCfg.level == 0) {
51✔
2210
      pVnode->config.walCfg.clearFiles = 1;
3✔
2211
    }
2212
    pVnode->config.walCfg.level = req.walLevel;
51✔
2213
    walChanged = true;
51✔
2214
  }
2215

2216
  if (pVnode->config.walCfg.retentionPeriod != req.walRetentionPeriod) {
861✔
2217
    pVnode->config.walCfg.retentionPeriod = req.walRetentionPeriod;
132✔
2218
    walChanged = true;
132✔
2219
  }
2220

2221
  if (pVnode->config.walCfg.retentionSize != req.walRetentionSize) {
861!
2222
    pVnode->config.walCfg.retentionSize = req.walRetentionSize;
×
2223
    walChanged = true;
×
2224
  }
2225

2226
  if (pVnode->config.tsdbCfg.keep0 != req.daysToKeep0) {
861✔
2227
    pVnode->config.tsdbCfg.keep0 = req.daysToKeep0;
56✔
2228
    if (!VND_IS_RSMA(pVnode)) {
56!
2229
      tsdbChanged = true;
56✔
2230
    }
2231
  }
2232

2233
  if (pVnode->config.tsdbCfg.keep1 != req.daysToKeep1) {
861✔
2234
    pVnode->config.tsdbCfg.keep1 = req.daysToKeep1;
56✔
2235
    if (!VND_IS_RSMA(pVnode)) {
56!
2236
      tsdbChanged = true;
56✔
2237
    }
2238
  }
2239

2240
  if (pVnode->config.tsdbCfg.keep2 != req.daysToKeep2) {
861✔
2241
    pVnode->config.tsdbCfg.keep2 = req.daysToKeep2;
56✔
2242
    if (!VND_IS_RSMA(pVnode)) {
56!
2243
      tsdbChanged = true;
56✔
2244
    }
2245
  }
2246

2247
  if (pVnode->config.tsdbCfg.keepTimeOffset != req.keepTimeOffset) {
861✔
2248
    pVnode->config.tsdbCfg.keepTimeOffset = req.keepTimeOffset;
2✔
2249
    if (!VND_IS_RSMA(pVnode)) {
2!
2250
      tsdbChanged = true;
2✔
2251
    }
2252
  }
2253

2254
  if (req.sttTrigger != -1 && req.sttTrigger != pVnode->config.sttTrigger) {
861!
2255
    if (req.sttTrigger > 1 && pVnode->config.sttTrigger > 1) {
×
2256
      pVnode->config.sttTrigger = req.sttTrigger;
×
2257
    } else {
2258
      vnodeAWait(&pVnode->commitTask);
×
2259

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

2265
      pVnode->config.sttTrigger = req.sttTrigger;
×
2266
      tsdbEnableBgTask(pVnode->pTsdb);
×
2267
    }
2268
  }
2269

2270
  if (req.minRows != -1 && req.minRows != pVnode->config.tsdbCfg.minRows) {
861!
2271
    pVnode->config.tsdbCfg.minRows = req.minRows;
×
2272
  }
2273

2274
  if (req.s3KeepLocal != -1 && req.s3KeepLocal != pVnode->config.s3KeepLocal) {
861!
2275
    pVnode->config.s3KeepLocal = req.s3KeepLocal;
×
2276
  }
2277
  if (req.s3Compact != -1 && req.s3Compact != pVnode->config.s3Compact) {
861!
2278
    pVnode->config.s3Compact = req.s3Compact;
×
2279
  }
2280

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

2287
  if (tsdbChanged) {
863✔
2288
    tsdbSetKeepCfg(pVnode->pTsdb, &pVnode->config.tsdbCfg);
60✔
2289
  }
2290

2291
  return 0;
863✔
2292
}
2293

2294
static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
3,537✔
2295
  SBatchDeleteReq deleteReq;
2296
  SDecoder        decoder;
2297
  tDecoderInit(&decoder, pReq, len);
3,537✔
2298
  if (tDecodeSBatchDeleteReq(&decoder, &deleteReq) < 0) {
3,539!
2299
    tDecoderClear(&decoder);
×
2300
    return terrno = TSDB_CODE_INVALID_MSG;
×
2301
  }
2302

2303
  SMetaReader mr = {0};
3,545✔
2304
  metaReaderDoInit(&mr, pVnode->pMeta, META_READER_NOLOCK);
3,545✔
2305
  STsdb *pTsdb = pVnode->pTsdb;
3,541✔
2306

2307
  if (deleteReq.level) {
3,541✔
2308
    pTsdb = deleteReq.level == 1 ? VND_RSMA1(pVnode) : VND_RSMA2(pVnode);
16✔
2309
  }
2310

2311
  int32_t sz = taosArrayGetSize(deleteReq.deleteReqs);
3,541✔
2312
  for (int32_t i = 0; i < sz; i++) {
7,949✔
2313
    SSingleDeleteReq *pOneReq = taosArrayGet(deleteReq.deleteReqs, i);
4,404✔
2314
    char             *name = pOneReq->tbname;
4,406✔
2315
    if (metaGetTableEntryByName(&mr, name) < 0) {
4,406✔
2316
      vDebug("vgId:%d, stream delete msg, skip since no table: %s", pVnode->config.vgId, name);
2,331✔
2317
      continue;
2,331✔
2318
    }
2319

2320
    int64_t uid = mr.me.uid;
2,078✔
2321

2322
    int32_t code = tsdbDeleteTableData(pTsdb, ver, deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
2,078✔
2323
    if (code < 0) {
2,079!
2324
      terrno = code;
×
2325
      vError("vgId:%d, delete error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64 ", end ts:%" PRId64,
×
2326
             TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
2327
    }
2328

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

2345
static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
64,853✔
2346
                                     SRpcMsg *pOriginalMsg) {
2347
  int32_t     code = 0;
64,853✔
2348
  SDecoder   *pCoder = &(SDecoder){0};
64,853✔
2349
  SDeleteRes *pRes = &(SDeleteRes){0};
64,853✔
2350

2351
  pRsp->msgType = TDMT_VND_DELETE_RSP;
64,853✔
2352
  pRsp->pCont = NULL;
64,853✔
2353
  pRsp->contLen = 0;
64,853✔
2354
  pRsp->code = TSDB_CODE_SUCCESS;
64,853✔
2355

2356
  pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t));
64,853✔
2357
  if (pRes->uidList == NULL) {
64,854!
2358
    code = terrno;
×
2359
    goto _err;
×
2360
  }
2361

2362
  tDecoderInit(pCoder, pReq, len);
64,854✔
2363
  code = tDecodeDeleteRes(pCoder, pRes);
64,851✔
2364
  if (code) goto _err;
64,856!
2365

2366
  if (pRes->affectedRows > 0) {
64,856✔
2367
    for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) {
121,873✔
2368
      uint64_t uid = *(uint64_t *)taosArrayGet(pRes->uidList, iUid);
61,792✔
2369
      code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, uid, pRes->skey, pRes->ekey);
61,792✔
2370
      if (code) goto _err;
61,792!
2371
      code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, pRes->ctimeMs);
61,792✔
2372
      if (code) goto _err;
61,790!
2373
    }
2374
  }
2375

2376
  code = tdProcessRSmaDelete(pVnode->pSma, ver, pRes, pReq, len);
64,853✔
2377

2378
  tDecoderClear(pCoder);
64,857✔
2379
  taosArrayDestroy(pRes->uidList);
64,857✔
2380

2381
  SVDeleteRsp rsp = {.affectedRows = pRes->affectedRows};
64,858✔
2382
  int32_t     ret = 0;
64,858✔
2383
  tEncodeSize(tEncodeSVDeleteRsp, &rsp, pRsp->contLen, ret);
64,858!
2384
  pRsp->pCont = rpcMallocCont(pRsp->contLen);
64,854✔
2385
  SEncoder ec = {0};
64,854✔
2386
  tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
64,854✔
2387
  code = tEncodeSVDeleteRsp(&ec, &rsp);
64,858✔
2388
  if (code) goto _err;
64,857!
2389
  tEncoderClear(&ec);
64,857✔
2390
  return code;
64,859✔
2391

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

2408
  return code;
×
2409
}
2410
static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
987✔
2411
  SVCreateStbReq req = {0};
987✔
2412
  SDecoder       dc = {0};
987✔
2413
  int32_t        code = 0;
987✔
2414

2415
  pRsp->msgType = TDMT_VND_CREATE_INDEX_RSP;
987✔
2416
  pRsp->code = TSDB_CODE_SUCCESS;
987✔
2417
  pRsp->pCont = NULL;
987✔
2418
  pRsp->contLen = 0;
987✔
2419

2420
  tDecoderInit(&dc, pReq, len);
987✔
2421
  // decode req
2422
  if (tDecodeSVCreateStbReq(&dc, &req) < 0) {
987!
2423
    tDecoderClear(&dc);
×
2424
    return terrno = TSDB_CODE_INVALID_MSG;
×
2425
  }
2426

2427
  code = metaAddIndexToSTable(pVnode->pMeta, ver, &req);
987✔
2428
  if (code) {
987!
2429
    pRsp->code = code;
×
2430
    goto _err;
×
2431
  }
2432
  tDecoderClear(&dc);
987✔
2433
  return 0;
987✔
2434

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

2447
  if ((code = tDeserializeSDropIdxReq(pReq, len, &req))) {
2,162!
2448
    pRsp->code = code;
×
2449
    return code;
×
2450
  }
2451

2452
  code = metaDropIndexFromSTable(pVnode->pMeta, ver, &req);
2,162✔
2453
  if (code) {
2,162!
2454
    pRsp->code = code;
×
2455
    return code;
×
2456
  }
2457
  return TSDB_CODE_SUCCESS;
2,162✔
2458
}
2459

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

2462
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
53✔
2463
  if (!pVnode->restored) {
53✔
2464
    vInfo("vgId:%d, ignore compact req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
1!
2465
    return 0;
1✔
2466
  }
2467
  return vnodeAsyncCompact(pVnode, ver, pReq, len, pRsp);
52✔
2468
}
2469

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

2475
  pRsp->msgType = TDMT_SYNC_CONFIG_CHANGE_RSP;
×
2476
  pRsp->code = TSDB_CODE_SUCCESS;
×
2477
  pRsp->pCont = NULL;
×
2478
  pRsp->contLen = 0;
×
2479

2480
  return 0;
×
2481
}
2482

UNCOV
2483
static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
×
UNCOV
2484
  SSyncState syncState = syncGetState(pVnode->sync);
×
UNCOV
2485
  if (syncState.state != TAOS_SYNC_STATE_LEADER) {
×
UNCOV
2486
    return terrno = TSDB_CODE_SYN_NOT_LEADER;
×
2487
  }
2488

UNCOV
2489
  char token[TSDB_ARB_TOKEN_SIZE] = {0};
×
UNCOV
2490
  if (vnodeGetArbToken(pVnode, token) != 0) {
×
2491
    return terrno = TSDB_CODE_NOT_FOUND;
×
2492
  }
2493

UNCOV
2494
  if (strncmp(token, member0Token, TSDB_ARB_TOKEN_SIZE) != 0 &&
×
UNCOV
2495
      strncmp(token, member1Token, TSDB_ARB_TOKEN_SIZE) != 0) {
×
UNCOV
2496
    return terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
×
2497
  }
2498

2499
  terrno = TSDB_CODE_SUCCESS;
×
2500
  return 0;
×
2501
}
2502

2503
static int32_t vnodeCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
×
2504
  int32_t code = vnodePreCheckAssignedLogSyncd(pVnode, member0Token, member1Token);
×
2505
  if (code != 0) {
×
2506
    return code;
×
2507
  }
2508

2509
  return syncGetAssignedLogSynced(pVnode->sync);
×
2510
}
2511

2512
static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) {
×
2513
  int32_t code = 0;
×
2514

2515
  SVArbCheckSyncReq syncReq = {0};
×
2516

2517
  code = tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq);
×
2518
  if (code) {
×
2519
    return terrno = code;
×
2520
  }
2521

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

2527
  SVArbCheckSyncRsp syncRsp = {0};
×
2528
  syncRsp.arbToken = syncReq.arbToken;
×
2529
  syncRsp.member0Token = syncReq.member0Token;
×
2530
  syncRsp.member1Token = syncReq.member1Token;
×
2531
  syncRsp.vgId = TD_VID(pVnode);
×
2532

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

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

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

2557
  if (tSerializeSVArbCheckSyncRsp(pHead, contLen, &syncRsp) <= 0) {
×
2558
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
2559
    rpcFreeCont(pHead);
×
2560
    code = -1;
×
2561
    goto _OVER;
×
2562
  }
2563

2564
  pRsp->pCont = pHead;
×
2565
  pRsp->contLen = contLen;
×
2566

2567
  terrno = TSDB_CODE_SUCCESS;
×
2568

2569
_OVER:
×
2570
  tFreeSVArbCheckSyncReq(&syncReq);
×
2571
  return code;
×
2572
}
2573

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

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

© 2025 Coveralls, Inc