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

taosdata / TDengine / #3523

06 Nov 2024 02:29AM UTC coverage: 55.861% (-2.4%) from 58.216%
#3523

push

travis-ci

web-flow
Merge pull request #28551 from taosdata/feat/TS-5215-2

test(blob): testing & fixes for blob

106075 of 245834 branches covered (43.15%)

Branch coverage included in aggregate %.

0 of 15 new or added lines in 2 files covered. (0.0%)

17003 existing lines in 254 files now uncovered.

181910 of 269703 relevant lines covered (67.45%)

1527639.59 hits per line

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

50.95
/source/dnode/vnode/src/vnd/vnodeQuery.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 "tsdb.h"
17
#include "vnd.h"
18

19
#define VNODE_GET_LOAD_RESET_VALS(pVar, oVal, vType, tags)                                                    \
20
  do {                                                                                                        \
21
    int##vType##_t newVal = atomic_sub_fetch_##vType(&(pVar), (oVal));                                        \
22
    if (newVal < 0) {                                                                                         \
23
      vWarn("vgId:%d, %s, abnormal val:%" PRIi64 ", old val:%" PRIi64, TD_VID(pVnode), tags, newVal, (oVal)); \
24
    }                                                                                                         \
25
  } while (0)
26

27
int vnodeQueryOpen(SVnode *pVnode) {
5,362✔
28
  return qWorkerInit(NODE_TYPE_VNODE, TD_VID(pVnode), (void **)&pVnode->pQuery, &pVnode->msgCb);
5,362✔
29
}
30

31
void vnodeQueryPreClose(SVnode *pVnode) { qWorkerStopAllTasks((void *)pVnode->pQuery); }
5,406✔
32

33
void vnodeQueryClose(SVnode *pVnode) { qWorkerDestroy((void **)&pVnode->pQuery); }
5,403✔
34

35
int32_t fillTableColCmpr(SMetaReader *reader, SSchemaExt *pExt, int32_t numOfCol) {
40,432✔
36
  int8_t tblType = reader->me.type;
40,432✔
37
  if (useCompress(tblType)) {
40,432✔
38
    SColCmprWrapper *p = &(reader->me.colCmpr);
40,432✔
39
    if (numOfCol != p->nCols) {
40,432!
40
      vError("fillTableColCmpr table type:%d, col num:%d, col cmpr num:%d mismatch", tblType, numOfCol, p->nCols);
×
41
      return TSDB_CODE_APP_ERROR;
×
42
    }
43
    for (int i = 0; i < p->nCols; i++) {
944,315✔
44
      SColCmpr *pCmpr = &p->pColCmpr[i];
903,883✔
45
      pExt[i].colId = pCmpr->id;
903,883✔
46
      pExt[i].compress = pCmpr->alg;
903,883✔
47
    }
48
  }
49
  return 0;
40,433✔
50
}
51

52
int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
45,248✔
53
  STableInfoReq  infoReq = {0};
45,248✔
54
  STableMetaRsp  metaRsp = {0};
45,248✔
55
  SMetaReader    mer1 = {0};
45,248✔
56
  SMetaReader    mer2 = {0};
45,248✔
57
  char           tableFName[TSDB_TABLE_FNAME_LEN];
58
  bool           reqTbUid = false;
45,248✔
59
  SRpcMsg        rpcMsg = {0};
45,248✔
60
  int32_t        code = 0;
45,248✔
61
  int32_t        rspLen = 0;
45,248✔
62
  void          *pRsp = NULL;
45,248✔
63
  SSchemaWrapper schema = {0};
45,248✔
64
  SSchemaWrapper schemaTag = {0};
45,248✔
65

66
  // decode req
67
  if (tDeserializeSTableInfoReq(pMsg->pCont, pMsg->contLen, &infoReq) != 0) {
45,248!
68
    code = terrno;
×
69
    goto _exit4;
×
70
  }
71

72
  if (infoReq.option == REQ_OPT_TBUID) reqTbUid = true;
45,259!
73
  metaRsp.dbId = pVnode->config.dbId;
45,259✔
74
  (void)strcpy(metaRsp.tbName, infoReq.tbName);
45,259✔
75
  (void)memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName));
45,259✔
76

77
  if (!reqTbUid) {
45,259✔
78
    TAOS_UNUSED(sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName));
45,250✔
79
    code = vnodeValidateTableHash(pVnode, tableFName);
45,250✔
80
    if (code) {
45,260!
81
      goto _exit4;
×
82
    }
83
  }
84

85
  // query meta
86
  metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
45,269✔
87
  if (reqTbUid) {
45,254!
88
    errno = 0;
×
89
    uint64_t tbUid = taosStr2UInt64(infoReq.tbName, NULL, 10);
×
90
    if (errno == ERANGE || tbUid == 0) {
×
91
      code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
×
92
      goto _exit3;
×
93
    }
94
    char tbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
×
95
    TAOS_CHECK_GOTO(metaGetTableNameByUid(pVnode, tbUid, tbName), NULL, _exit3);
×
96
    tstrncpy(metaRsp.tbName, varDataVal(tbName), TSDB_TABLE_NAME_LEN);
×
97
    TAOS_CHECK_GOTO(metaGetTableEntryByName(&mer1, varDataVal(tbName)), NULL, _exit3);
×
98
  } else if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) {
45,254✔
99
    code = terrno;
4,812✔
100
    goto _exit3;
4,817✔
101
  }
102

103
  metaRsp.tableType = mer1.me.type;
40,448✔
104
  metaRsp.vgId = TD_VID(pVnode);
40,448✔
105
  metaRsp.tuid = mer1.me.uid;
40,448✔
106

107
  if (mer1.me.type == TSDB_SUPER_TABLE) {
40,448✔
108
    (void)strcpy(metaRsp.stbName, mer1.me.name);
21,298✔
109
    schema = mer1.me.stbEntry.schemaRow;
21,298✔
110
    schemaTag = mer1.me.stbEntry.schemaTag;
21,298✔
111
    metaRsp.suid = mer1.me.uid;
21,298✔
112
  } else if (mer1.me.type == TSDB_CHILD_TABLE) {
19,150✔
113
    metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
18,007✔
114
    if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit2;
18,007!
115

116
    (void)strcpy(metaRsp.stbName, mer2.me.name);
18,008✔
117
    metaRsp.suid = mer2.me.uid;
18,008✔
118
    schema = mer2.me.stbEntry.schemaRow;
18,008✔
119
    schemaTag = mer2.me.stbEntry.schemaTag;
18,008✔
120
  } else if (mer1.me.type == TSDB_NORMAL_TABLE) {
1,143!
121
    schema = mer1.me.ntbEntry.schemaRow;
1,143✔
122
  } else {
123
    vError("vnodeGetTableMeta get invalid table type:%d", mer1.me.type);
×
124
    goto _exit3;
×
125
  }
126

127
  metaRsp.numOfTags = schemaTag.nCols;
40,449✔
128
  metaRsp.numOfColumns = schema.nCols;
40,449✔
129
  metaRsp.precision = pVnode->config.tsdbCfg.precision;
40,449✔
130
  metaRsp.sversion = schema.version;
40,449✔
131
  metaRsp.tversion = schemaTag.version;
40,449✔
132
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (metaRsp.numOfColumns + metaRsp.numOfTags));
40,449✔
133
  metaRsp.pSchemaExt = (SSchemaExt *)taosMemoryCalloc(metaRsp.numOfColumns, sizeof(SSchemaExt));
40,443✔
134
  if (NULL == metaRsp.pSchemas || NULL == metaRsp.pSchemaExt) {
40,442!
135
    code = terrno;
×
136
    goto _exit;
×
137
  }
138
  (void)memcpy(metaRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
40,444✔
139
  if (schemaTag.nCols) {
40,444✔
140
    (void)memcpy(metaRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
39,291✔
141
  }
142
  if (metaRsp.pSchemaExt) {
40,444✔
143
    SMetaReader *pReader = mer1.me.type == TSDB_CHILD_TABLE ? &mer2 : &mer1;
40,429✔
144
    code = fillTableColCmpr(pReader, metaRsp.pSchemaExt, metaRsp.numOfColumns);
40,429✔
145
    if (code < 0) {
40,439!
146
      goto _exit;
×
147
    }
148
  } else {
149
    code = TSDB_CODE_OUT_OF_MEMORY;
15✔
150
    goto _exit;
15✔
151
  }
152

153
  // encode and send response
154
  rspLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
40,439✔
155
  if (rspLen < 0) {
40,442✔
156
    code = terrno;
1✔
157
    goto _exit;
×
158
  }
159

160
  if (direct) {
40,441✔
161
    pRsp = rpcMallocCont(rspLen);
13✔
162
  } else {
163
    pRsp = taosMemoryCalloc(1, rspLen);
40,428✔
164
  }
165

166
  if (pRsp == NULL) {
40,431!
167
    code = terrno;
×
168
    goto _exit;
×
169
  }
170

171
  rspLen = tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp);
40,431✔
172
  if (rspLen < 0) {
40,438!
173
    code = terrno;
×
174
    goto _exit;
×
175
  }
176

177
_exit:
40,438✔
178
  taosMemoryFree(metaRsp.pSchemas);
40,453✔
179
  taosMemoryFree(metaRsp.pSchemaExt);
40,442✔
180
_exit2:
40,445✔
181
  metaReaderClear(&mer2);
40,445✔
182
_exit3:
45,261✔
183
  metaReaderClear(&mer1);
45,261✔
184
_exit4:
45,255✔
185
  rpcMsg.info = pMsg->info;
45,255✔
186
  rpcMsg.pCont = pRsp;
45,255✔
187
  rpcMsg.contLen = rspLen;
45,255✔
188
  rpcMsg.code = code;
45,255✔
189
  rpcMsg.msgType = pMsg->msgType;
45,255✔
190

191
  if (code) {
45,255✔
192
    qError("get table %s meta with %" PRIu8 " failed cause of %s", infoReq.tbName, infoReq.option, tstrerror(code));
4,817!
193
  }
194

195
  if (direct) {
45,256✔
196
    tmsgSendRsp(&rpcMsg);
1,003✔
197
  } else {
198
    *pMsg = rpcMsg;
44,253✔
199
  }
200

201
  return code;
45,259✔
202
}
203

204
int32_t vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
68✔
205
  STableCfgReq   cfgReq = {0};
68✔
206
  STableCfgRsp   cfgRsp = {0};
68✔
207
  SMetaReader    mer1 = {0};
68✔
208
  SMetaReader    mer2 = {0};
68✔
209
  char           tableFName[TSDB_TABLE_FNAME_LEN];
210
  SRpcMsg        rpcMsg = {0};
68✔
211
  int32_t        code = 0;
68✔
212
  int32_t        rspLen = 0;
68✔
213
  void          *pRsp = NULL;
68✔
214
  SSchemaWrapper schema = {0};
68✔
215
  SSchemaWrapper schemaTag = {0};
68✔
216

217
  // decode req
218
  if (tDeserializeSTableCfgReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
68!
219
    code = terrno;
×
220
    goto _exit;
×
221
  }
222

223
  (void)strcpy(cfgRsp.tbName, cfgReq.tbName);
68✔
224
  (void)memcpy(cfgRsp.dbFName, cfgReq.dbFName, sizeof(cfgRsp.dbFName));
68✔
225

226
  (void)sprintf(tableFName, "%s.%s", cfgReq.dbFName, cfgReq.tbName);
68✔
227
  code = vnodeValidateTableHash(pVnode, tableFName);
68✔
228
  if (code) {
68!
229
    goto _exit;
×
230
  }
231

232
  // query meta
233
  metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
68✔
234

235
  if (metaGetTableEntryByName(&mer1, cfgReq.tbName) < 0) {
68!
236
    code = terrno;
×
237
    goto _exit;
×
238
  }
239

240
  cfgRsp.tableType = mer1.me.type;
68✔
241

242
  if (mer1.me.type == TSDB_SUPER_TABLE) {
68!
243
    code = TSDB_CODE_VND_HASH_MISMATCH;
×
244
    goto _exit;
×
245
  } else if (mer1.me.type == TSDB_CHILD_TABLE) {
68✔
246
    metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_LOCK);
51✔
247
    if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit;
51!
248

249
    (void)strcpy(cfgRsp.stbName, mer2.me.name);
51✔
250
    schema = mer2.me.stbEntry.schemaRow;
51✔
251
    schemaTag = mer2.me.stbEntry.schemaTag;
51✔
252
    cfgRsp.ttl = mer1.me.ctbEntry.ttlDays;
51✔
253
    cfgRsp.commentLen = mer1.me.ctbEntry.commentLen;
51✔
254
    if (mer1.me.ctbEntry.commentLen > 0) {
51!
255
      cfgRsp.pComment = taosStrdup(mer1.me.ctbEntry.comment);
×
256
      if (NULL == cfgRsp.pComment) {
×
257
        code = terrno;
×
258
        goto _exit;
×
259
      }
260
    }
261
    STag *pTag = (STag *)mer1.me.ctbEntry.pTags;
51✔
262
    cfgRsp.tagsLen = pTag->len;
51✔
263
    cfgRsp.pTags = taosMemoryMalloc(cfgRsp.tagsLen);
51✔
264
    if (NULL == cfgRsp.pTags) {
51!
265
      code = terrno;
×
266
      goto _exit;
×
267
    }
268
    (void)memcpy(cfgRsp.pTags, pTag, cfgRsp.tagsLen);
51✔
269
  } else if (mer1.me.type == TSDB_NORMAL_TABLE) {
17!
270
    schema = mer1.me.ntbEntry.schemaRow;
17✔
271
    cfgRsp.ttl = mer1.me.ntbEntry.ttlDays;
17✔
272
    cfgRsp.commentLen = mer1.me.ntbEntry.commentLen;
17✔
273
    if (mer1.me.ntbEntry.commentLen > 0) {
17!
274
      cfgRsp.pComment = taosStrdup(mer1.me.ntbEntry.comment);
×
275
      if (NULL == cfgRsp.pComment) {
×
276
        code = terrno;
×
277
        goto _exit;
×
278
      }
279
    }
280
  } else {
281
    vError("vnodeGetTableCfg get invalid table type:%d", mer1.me.type);
×
282
    return TSDB_CODE_APP_ERROR;
×
283
  }
284

285
  cfgRsp.numOfTags = schemaTag.nCols;
68✔
286
  cfgRsp.numOfColumns = schema.nCols;
68✔
287
  cfgRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (cfgRsp.numOfColumns + cfgRsp.numOfTags));
68✔
288
  cfgRsp.pSchemaExt = (SSchemaExt *)taosMemoryMalloc(cfgRsp.numOfColumns * sizeof(SSchemaExt));
68✔
289

290
  if (NULL == cfgRsp.pSchemas || NULL == cfgRsp.pSchemaExt) {
68!
291
    code = terrno;
×
292
    goto _exit;
×
293
  }
294
  (void)memcpy(cfgRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
68✔
295
  if (schemaTag.nCols) {
68✔
296
    (void)memcpy(cfgRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
51✔
297
  }
298

299
  // if (useCompress(cfgRsp.tableType)) {
300

301
  SMetaReader     *pReader = mer1.me.type == TSDB_CHILD_TABLE ? &mer2 : &mer1;
68✔
302
  SColCmprWrapper *pColCmpr = &pReader->me.colCmpr;
68✔
303

304
  for (int32_t i = 0; i < cfgRsp.numOfColumns; i++) {
631✔
305
    SColCmpr   *pCmpr = &pColCmpr->pColCmpr[i];
563✔
306
    SSchemaExt *pSchExt = cfgRsp.pSchemaExt + i;
563✔
307
    pSchExt->colId = pCmpr->id;
563✔
308
    pSchExt->compress = pCmpr->alg;
563✔
309
  }
310
  //}
311

312
  // encode and send response
313
  rspLen = tSerializeSTableCfgRsp(NULL, 0, &cfgRsp);
68✔
314
  if (rspLen < 0) {
68!
315
    code = terrno;
×
316
    goto _exit;
×
317
  }
318

319
  if (direct) {
68!
320
    pRsp = rpcMallocCont(rspLen);
×
321
  } else {
322
    pRsp = taosMemoryCalloc(1, rspLen);
68✔
323
  }
324

325
  if (pRsp == NULL) {
68!
326
    code = terrno;
×
327
    goto _exit;
×
328
  }
329

330
  rspLen = tSerializeSTableCfgRsp(pRsp, rspLen, &cfgRsp);
68✔
331
  if (rspLen < 0) {
68!
332
    code = terrno;
×
333
    goto _exit;
×
334
  }
335

336
_exit:
68✔
337
  rpcMsg.info = pMsg->info;
68✔
338
  rpcMsg.pCont = pRsp;
68✔
339
  rpcMsg.contLen = rspLen;
68✔
340
  rpcMsg.code = code;
68✔
341
  rpcMsg.msgType = pMsg->msgType;
68✔
342

343
  if (code) {
68!
344
    qError("get table %s cfg failed cause of %s", cfgReq.tbName, tstrerror(code));
×
345
  }
346

347
  if (direct) {
68!
348
    tmsgSendRsp(&rpcMsg);
×
349
  } else {
350
    *pMsg = rpcMsg;
68✔
351
  }
352

353
  tFreeSTableCfgRsp(&cfgRsp);
68✔
354
  metaReaderClear(&mer2);
68✔
355
  metaReaderClear(&mer1);
68✔
356
  return code;
68✔
357
}
358

359
static FORCE_INLINE void vnodeFreeSBatchRspMsg(void *p) {
360
  if (NULL == p) {
361
    return;
362
  }
363

364
  SBatchRspMsg *pRsp = (SBatchRspMsg *)p;
365
  rpcFreeCont(pRsp->msg);
366
}
367

368
int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
21,302✔
369
  int32_t      code = 0;
21,302✔
370
  int32_t      rspSize = 0;
21,302✔
371
  SBatchReq    batchReq = {0};
21,302✔
372
  SBatchMsg   *req = NULL;
21,302✔
373
  SBatchRspMsg rsp = {0};
21,302✔
374
  SBatchRsp    batchRsp = {0};
21,302✔
375
  SRpcMsg      reqMsg = *pMsg;
21,302✔
376
  SRpcMsg      rspMsg = {0};
21,302✔
377
  void        *pRsp = NULL;
21,302✔
378

379
  if (tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) {
21,302!
380
    code = terrno;
×
381
    qError("tDeserializeSBatchReq failed");
×
382
    goto _exit;
×
383
  }
384

385
  int32_t msgNum = taosArrayGetSize(batchReq.pMsgs);
21,301✔
386
  if (msgNum >= MAX_META_MSG_IN_BATCH) {
21,298!
387
    code = TSDB_CODE_INVALID_MSG;
×
388
    qError("too many msgs %d in vnode batch meta req", msgNum);
×
389
    goto _exit;
×
390
  }
391

392
  batchRsp.pRsps = taosArrayInit(msgNum, sizeof(SBatchRspMsg));
21,298✔
393
  if (NULL == batchRsp.pRsps) {
21,306!
UNCOV
394
    code = terrno;
×
395
    qError("taosArrayInit %d SBatchRspMsg failed", msgNum);
×
396
    goto _exit;
×
397
  }
398

399
  for (int32_t i = 0; i < msgNum; ++i) {
65,618✔
400
    req = taosArrayGet(batchReq.pMsgs, i);
44,319✔
401
    if (req == NULL) {
44,318✔
402
      code = terrno;
2✔
403
      goto _exit;
×
404
    }
405

406
    reqMsg.msgType = req->msgType;
44,316✔
407
    reqMsg.pCont = req->msg;
44,316✔
408
    reqMsg.contLen = req->msgLen;
44,316✔
409

410
    switch (req->msgType) {
44,316!
411
      case TDMT_VND_TABLE_META:
44,248✔
412
        // error code has been set into reqMsg, no need to handle it here.
413
        if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
44,248✔
414
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
3,827!
415
        }
416
        break;
44,252✔
417
      case TDMT_VND_TABLE_NAME:
×
418
        // error code has been set into reqMsg, no need to handle it here.
419
        if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
×
420
          qWarn("vnodeGetBatchName failed, msgType:%d", req->msgType);
×
421
        }
422
        break;
×
423
      case TDMT_VND_TABLE_CFG:
68✔
424
        // error code has been set into reqMsg, no need to handle it here.
425
        if (TSDB_CODE_SUCCESS != vnodeGetTableCfg(pVnode, &reqMsg, false)) {
68!
426
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
×
427
        }
428
        break;
68✔
429
      case TDMT_VND_GET_STREAM_PROGRESS:
×
430
        // error code has been set into reqMsg, no need to handle it here.
431
        if (TSDB_CODE_SUCCESS != vnodeGetStreamProgress(pVnode, &reqMsg, false)) {
×
432
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
×
433
        }
434
        break;
×
435
      default:
×
436
        qError("invalid req msgType %d", req->msgType);
×
437
        reqMsg.code = TSDB_CODE_INVALID_MSG;
×
438
        reqMsg.pCont = NULL;
×
439
        reqMsg.contLen = 0;
×
440
        break;
×
441
    }
442

443
    rsp.msgIdx = req->msgIdx;
44,320✔
444
    rsp.reqType = reqMsg.msgType;
44,320✔
445
    rsp.msgLen = reqMsg.contLen;
44,320✔
446
    rsp.rspCode = reqMsg.code;
44,320✔
447
    rsp.msg = reqMsg.pCont;
44,320✔
448

449
    if (NULL == taosArrayPush(batchRsp.pRsps, &rsp)) {
88,632!
450
      qError("taosArrayPush failed");
×
451
      code = terrno;
×
452
      goto _exit;
×
453
    }
454
  }
455

456
  rspSize = tSerializeSBatchRsp(NULL, 0, &batchRsp);
21,299✔
457
  if (rspSize < 0) {
21,306!
458
    qError("tSerializeSBatchRsp failed");
×
459
    code = terrno;
×
460
    goto _exit;
×
461
  }
462
  pRsp = rpcMallocCont(rspSize);
21,306✔
463
  if (pRsp == NULL) {
21,306!
464
    qError("rpcMallocCont %d failed", rspSize);
×
465
    code = terrno;
×
466
    goto _exit;
×
467
  }
468
  if (tSerializeSBatchRsp(pRsp, rspSize, &batchRsp) < 0) {
21,306!
469
    qError("tSerializeSBatchRsp %d failed", rspSize);
×
470
    code = terrno;
×
471
    goto _exit;
×
472
  }
473

474
_exit:
21,308✔
475

476
  rspMsg.info = pMsg->info;
21,308✔
477
  rspMsg.pCont = pRsp;
21,308✔
478
  rspMsg.contLen = rspSize;
21,308✔
479
  rspMsg.code = code;
21,308✔
480
  rspMsg.msgType = pMsg->msgType;
21,308✔
481

482
  if (code) {
21,308!
483
    qError("vnd get batch meta failed cause of %s", tstrerror(code));
×
484
  }
485

486
  taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
21,308✔
487
  taosArrayDestroyEx(batchRsp.pRsps, tFreeSBatchRspMsg);
21,305✔
488

489
  tmsgSendRsp(&rspMsg);
21,303✔
490

491
  return code;
21,303✔
492
}
493

494
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
3,022,346✔
495
  SSyncState state = syncGetState(pVnode->sync);
3,022,346✔
496

497
  pLoad->vgId = TD_VID(pVnode);
3,022,346✔
498
  pLoad->syncState = state.state;
3,022,346✔
499
  pLoad->syncRestore = state.restored;
3,022,346✔
500
  pLoad->syncTerm = state.term;
3,022,346✔
501
  pLoad->roleTimeMs = state.roleTimeMs;
3,022,346✔
502
  pLoad->startTimeMs = state.startTimeMs;
3,022,346✔
503
  pLoad->syncCanRead = state.canRead;
3,022,346✔
504
  pLoad->learnerProgress = state.progress;
3,022,346✔
505
  pLoad->cacheUsage = tsdbCacheGetUsage(pVnode);
3,022,346✔
506
  pLoad->numOfCachedTables = tsdbCacheGetElems(pVnode);
3,022,346✔
507
  pLoad->numOfTables = metaGetTbNum(pVnode->pMeta);
3,022,346✔
508
  pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1);
3,022,346✔
509
  pLoad->totalStorage = (int64_t)3 * 1073741824;
3,022,346✔
510
  pLoad->compStorage = (int64_t)2 * 1073741824;
3,022,346✔
511
  pLoad->pointsWritten = 100;
3,022,346✔
512
  pLoad->numOfSelectReqs = 1;
3,022,346✔
513
  pLoad->numOfInsertReqs = atomic_load_64(&pVnode->statis.nInsert);
3,022,346✔
514
  pLoad->numOfInsertSuccessReqs = atomic_load_64(&pVnode->statis.nInsertSuccess);
3,022,346✔
515
  pLoad->numOfBatchInsertReqs = atomic_load_64(&pVnode->statis.nBatchInsert);
3,022,346✔
516
  pLoad->numOfBatchInsertSuccessReqs = atomic_load_64(&pVnode->statis.nBatchInsertSuccess);
3,022,346✔
517
  return 0;
3,022,346✔
518
}
519

520
int32_t vnodeGetLoadLite(SVnode *pVnode, SVnodeLoadLite *pLoad) {
×
521
  SSyncState syncState = syncGetState(pVnode->sync);
×
522
  if (syncState.state == TAOS_SYNC_STATE_LEADER || syncState.state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
×
523
    pLoad->vgId = TD_VID(pVnode);
×
524
    pLoad->nTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1);
×
525
    return 0;
×
526
  }
527
  return -1;
×
528
}
529
/**
530
 * @brief Reset the statistics value by monitor interval
531
 *
532
 * @param pVnode
533
 * @param pLoad
534
 */
535
void vnodeResetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
20✔
536
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsert, pLoad->numOfInsertReqs, 64, "nInsert");
20!
537
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsertSuccess, pLoad->numOfInsertSuccessReqs, 64, "nInsertSuccess");
20!
538
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsert, pLoad->numOfBatchInsertReqs, 64, "nBatchInsert");
20!
539
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsertSuccess, pLoad->numOfBatchInsertSuccessReqs, 64,
20!
540
                            "nBatchInsertSuccess");
541
}
20✔
542

543
void vnodeGetInfo(void *pVnode, const char **dbname, int32_t *vgId, int64_t *numOfTables, int64_t *numOfNormalTables) {
12,787✔
544
  SVnode    *pVnodeObj = pVnode;
12,787✔
545
  SVnodeCfg *pConf = &pVnodeObj->config;
12,787✔
546

547
  if (dbname) {
12,787✔
548
    *dbname = pConf->dbname;
12,749✔
549
  }
550

551
  if (vgId) {
12,787✔
552
    *vgId = TD_VID(pVnodeObj);
12,325✔
553
  }
554

555
  if (numOfTables) {
12,787✔
556
    *numOfTables = pConf->vndStats.numOfNTables + pConf->vndStats.numOfCTables;
18✔
557
  }
558

559
  if (numOfNormalTables) {
12,787✔
560
    *numOfNormalTables = pConf->vndStats.numOfNTables;
31✔
561
  }
562
}
12,787✔
563

564
int32_t vnodeGetTableList(void *pVnode, int8_t type, SArray *pList) {
31✔
565
  if (type == TSDB_SUPER_TABLE) {
31!
566
    return vnodeGetStbIdList(pVnode, 0, pList);
31✔
567
  } else {
568
    return TSDB_CODE_INVALID_PARA;
×
569
  }
570
}
571

572
int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) {
×
573
  int32_t      code = TSDB_CODE_SUCCESS;
×
574
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, uid, 1);
×
575
  if (NULL == pCur) {
×
576
    qError("vnode get all table list failed");
×
577
    return terrno;
×
578
  }
579

580
  while (1) {
×
581
    tb_uid_t id = metaCtbCursorNext(pCur);
×
582
    if (id == 0) {
×
583
      break;
×
584
    }
585

586
    STableKeyInfo info = {uid = id};
×
587
    if (NULL == taosArrayPush(list, &info)) {
×
588
      qError("taosArrayPush failed");
×
589
      code = terrno;
×
590
      goto _exit;
×
591
    }
592
  }
593
_exit:
×
594
  metaCloseCtbCursor(pCur);
×
595
  return code;
×
596
}
597

598
int32_t vnodeGetCtbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg), void *arg) {
×
599
  return 0;
×
600
}
601

602
int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) {
77,470✔
603
  int32_t      code = TSDB_CODE_SUCCESS;
77,470✔
604
  SVnode      *pVnodeObj = pVnode;
77,470✔
605
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnodeObj, suid, 1);
77,470✔
606
  if (NULL == pCur) {
77,455✔
607
    qError("vnode get all table list failed");
10!
608
    return terrno;
10✔
609
  }
610

611
  while (1) {
571,042✔
612
    tb_uid_t id = metaCtbCursorNext(pCur);
648,487✔
613
    if (id == 0) {
648,374✔
614
      break;
77,471✔
615
    }
616

617
    if (NULL == taosArrayPush(list, &id)) {
571,042!
618
      qError("taosArrayPush failed");
×
619
      code = terrno;
×
620
      goto _exit;
×
621
    }
622
  }
623

624
_exit:
77,471✔
625
  metaCloseCtbCursor(pCur);
77,471✔
626
  return code;
77,462✔
627
}
628

629
int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) {
470,087✔
630
  int32_t      code = TSDB_CODE_SUCCESS;
470,087✔
631
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
470,087✔
632
  if (!pCur) {
470,088!
633
    return TSDB_CODE_OUT_OF_MEMORY;
×
634
  }
635

636
  while (1) {
70,770✔
637
    tb_uid_t id = metaStbCursorNext(pCur);
540,858✔
638
    if (id == 0) {
540,856✔
639
      break;
470,088✔
640
    }
641

642
    if (NULL == taosArrayPush(list, &id)) {
70,770!
643
      qError("taosArrayPush failed");
×
644
      code = terrno;
×
645
      goto _exit;
×
646
    }
647
  }
648

649
_exit:
470,088✔
650
  metaCloseStbCursor(pCur);
470,088✔
651
  return code;
470,087✔
652
}
653

654
int32_t vnodeGetStbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg, void *arg1),
×
655
                                  void *arg) {
656
  int32_t      code = TSDB_CODE_SUCCESS;
×
657
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
×
658
  if (!pCur) {
×
659
    return terrno;
×
660
  }
661

662
  while (1) {
×
663
    tb_uid_t id = metaStbCursorNext(pCur);
×
664
    if (id == 0) {
×
665
      break;
×
666
    }
667

668
    if ((*filter) && (*filter)(arg, &id)) {
×
669
      continue;
×
670
    }
671

672
    if (NULL == taosArrayPush(list, &id)) {
×
673
      qError("taosArrayPush failed");
×
674
      code = terrno;
×
675
      goto _exit;
×
676
    }
677
  }
678

679
_exit:
×
680
  metaCloseStbCursor(pCur);
×
681
  return code;
×
682
}
683

684
int32_t vnodeGetCtbNum(SVnode *pVnode, int64_t suid, int64_t *num) {
6,298✔
685
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, suid, 0);
6,298✔
686
  if (!pCur) {
6,299!
687
    return terrno;
×
688
  }
689

690
  *num = 0;
6,299✔
691
  while (1) {
47✔
692
    tb_uid_t id = metaCtbCursorNext(pCur);
6,346✔
693
    if (id == 0) {
6,345✔
694
      break;
6,298✔
695
    }
696

697
    ++(*num);
47✔
698
  }
699

700
  metaCloseCtbCursor(pCur);
6,298✔
701
  return TSDB_CODE_SUCCESS;
6,301✔
702
}
703

704
int32_t vnodeGetStbColumnNum(SVnode *pVnode, tb_uid_t suid, int *num) {
6,299✔
705
  SSchemaWrapper *pSW = metaGetTableSchema(pVnode->pMeta, suid, -1, 0, NULL);
6,299✔
706
  if (pSW) {
6,298!
707
    *num = pSW->nCols;
6,298!
708
    tDeleteSchemaWrapper(pSW);
709
  } else {
710
    *num = 2;
×
711
  }
712

713
  return TSDB_CODE_SUCCESS;
6,301✔
714
}
715

716
#ifdef TD_ENTERPRISE
717
const char *tkLogStb[] = {"cluster_info",
718
                          "data_dir",
719
                          "dnodes_info",
720
                          "d_info",
721
                          "grants_info",
722
                          "keeper_monitor",
723
                          "logs",
724
                          "log_dir",
725
                          "log_summary",
726
                          "m_info",
727
                          "taosadapter_restful_http_request_fail",
728
                          "taosadapter_restful_http_request_in_flight",
729
                          "taosadapter_restful_http_request_summary_milliseconds",
730
                          "taosadapter_restful_http_request_total",
731
                          "taosadapter_system_cpu_percent",
732
                          "taosadapter_system_mem_percent",
733
                          "temp_dir",
734
                          "vgroups_info",
735
                          "vnodes_role"};
736
const char *tkAuditStb[] = {"operations"};
737
const int   tkLogStbNum = ARRAY_SIZE(tkLogStb);
738
const int   tkAuditStbNum = ARRAY_SIZE(tkAuditStb);
739

740
// exclude stbs of taoskeeper log
741
static int32_t vnodeGetTimeSeriesBlackList(SVnode *pVnode, int32_t *tbSize) {
470,040✔
742
  int32_t      code = TSDB_CODE_SUCCESS;
470,040✔
743
  int32_t      tbNum = 0;
470,040✔
744
  const char **pTbArr = NULL;
470,040✔
745
  const char  *dbName = NULL;
470,040✔
746
  *tbSize = 0;
470,040✔
747

748
  if (!(dbName = strchr(pVnode->config.dbname, '.'))) return 0;
470,040!
749
  if (0 == strncmp(++dbName, "log", TSDB_DB_NAME_LEN)) {
470,040!
750
    tbNum = tkLogStbNum;
×
751
    pTbArr = (const char **)&tkLogStb;
×
752
  } else if (0 == strncmp(dbName, "audit", TSDB_DB_NAME_LEN)) {
470,040!
753
    tbNum = tkAuditStbNum;
×
754
    pTbArr = (const char **)&tkAuditStb;
×
755
  }
756
  if (tbNum && pTbArr) {
470,040!
757
    *tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 0);
×
758
    if (*tbSize < tbNum) {
×
759
      for (int32_t i = 0; i < tbNum; ++i) {
×
760
        tb_uid_t suid = metaGetTableEntryUidByName(pVnode->pMeta, pTbArr[i]);
×
761
        if (suid != 0) {
×
762
          code = metaPutTbToFilterCache(pVnode->pMeta, &suid, 0);
×
763
          if (TSDB_CODE_SUCCESS != code) {
×
764
            return code;
×
765
          }
766
        }
767
      }
768
      *tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 0);
×
769
    }
770
  }
771

772
  return code;
470,040✔
773
}
774
#endif
775

776
static bool vnodeTimeSeriesFilter(void *arg1, void *arg2) {
×
777
  SVnode *pVnode = (SVnode *)arg1;
×
778

779
  if (metaTbInFilterCache(pVnode->pMeta, arg2, 0)) {
×
780
    return true;
×
781
  }
782
  return false;
×
783
}
784

785
int32_t vnodeGetTimeSeriesNum(SVnode *pVnode, int64_t *num) {
470,039✔
786
  SArray *suidList = NULL;
470,039✔
787

788
  if (!(suidList = taosArrayInit(1, sizeof(tb_uid_t)))) {
470,039!
789
    return terrno;
×
790
  }
791

792
  int32_t tbFilterSize = 0;
470,040✔
793
  int32_t code = TSDB_CODE_SUCCESS;
470,040✔
794
#ifdef TD_ENTERPRISE
795
  code = vnodeGetTimeSeriesBlackList(pVnode, &tbFilterSize);
470,040✔
796
  if (TSDB_CODE_SUCCESS != code) {
470,039!
797
    goto _exit;
×
798
  }
799
#endif
800

801
  if ((!tbFilterSize && vnodeGetStbIdList(pVnode, 0, suidList) < 0) ||
470,039!
802
      (tbFilterSize && vnodeGetStbIdListByFilter(pVnode, 0, suidList, vnodeTimeSeriesFilter, pVnode) < 0)) {
470,039!
803
    qError("vgId:%d, failed to get stb id list error: %s", TD_VID(pVnode), terrstr());
×
804
    taosArrayDestroy(suidList);
×
805
    return terrno;
×
806
  }
807

808
  *num = 0;
470,039✔
809
  int64_t arrSize = taosArrayGetSize(suidList);
470,039✔
810
  for (int64_t i = 0; i < arrSize; ++i) {
540,751✔
811
    tb_uid_t suid = *(tb_uid_t *)taosArrayGet(suidList, i);
70,708✔
812

813
    int64_t ctbNum = 0;
70,708✔
814
    int32_t numOfCols = 0;
70,708✔
815
    code = metaGetStbStats(pVnode, suid, &ctbNum, &numOfCols);
70,708✔
816
    if (TSDB_CODE_SUCCESS != code) {
70,712!
817
      goto _exit;
×
818
    }
819
    *num += ctbNum * (numOfCols - 1);
70,712✔
820
  }
821

822
_exit:
470,043✔
823
  taosArrayDestroy(suidList);
470,043✔
824
  return TSDB_CODE_SUCCESS;
470,040✔
825
}
826

827
int32_t vnodeGetAllCtbNum(SVnode *pVnode, int64_t *num) {
×
828
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, 0);
×
829
  if (!pCur) {
×
830
    return terrno;
×
831
  }
832

833
  *num = 0;
×
834
  while (1) {
×
835
    tb_uid_t id = metaStbCursorNext(pCur);
×
836
    if (id == 0) {
×
837
      break;
×
838
    }
839

840
    int64_t ctbNum = 0;
×
841
    int32_t code = vnodeGetCtbNum(pVnode, id, &ctbNum);
×
842
    if (TSDB_CODE_SUCCESS != code) {
×
843
      metaCloseStbCursor(pCur);
×
844
      return code;
×
845
    }
846

847
    *num += ctbNum;
×
848
  }
849

850
  metaCloseStbCursor(pCur);
×
851
  return TSDB_CODE_SUCCESS;
×
852
}
853

854
void *vnodeGetIdx(void *pVnode) {
4,024✔
855
  if (pVnode == NULL) {
4,024!
856
    return NULL;
×
857
  }
858

859
  return metaGetIdx(((SVnode *)pVnode)->pMeta);
4,024✔
860
}
861

862
void *vnodeGetIvtIdx(void *pVnode) {
4,023✔
863
  if (pVnode == NULL) {
4,023!
864
    return NULL;
×
865
  }
866
  return metaGetIvtIdx(((SVnode *)pVnode)->pMeta);
4,023✔
867
}
868

869
int32_t vnodeGetTableSchema(void *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid) {
19✔
870
  return tsdbGetTableSchema(((SVnode *)pVnode)->pMeta, uid, pSchema, suid);
19✔
871
}
872

873
int32_t vnodeGetStreamProgress(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
×
874
  int32_t            code = 0;
×
875
  SStreamProgressReq req;
876
  SStreamProgressRsp rsp = {0};
×
877
  SRpcMsg            rpcMsg = {.info = pMsg->info, .code = 0};
×
878
  char              *buf = NULL;
×
879
  int32_t            rspLen = 0;
×
880
  code = tDeserializeStreamProgressReq(pMsg->pCont, pMsg->contLen, &req);
×
881

882
  if (code == TSDB_CODE_SUCCESS) {
×
883
    rsp.fetchIdx = req.fetchIdx;
×
884
    rsp.subFetchIdx = req.subFetchIdx;
×
885
    rsp.vgId = req.vgId;
×
886
    rsp.streamId = req.streamId;
×
887
    rspLen = tSerializeStreamProgressRsp(0, 0, &rsp);
×
888
    if (rspLen < 0) {
×
889
      code = terrno;
×
890
      goto _OVER;
×
891
    }
892
    if (direct) {
×
893
      buf = rpcMallocCont(rspLen);
×
894
    } else {
895
      buf = taosMemoryCalloc(1, rspLen);
×
896
    }
897
    if (!buf) {
×
898
      code = terrno;
×
899
      goto _OVER;
×
900
    }
901
  }
902

903
  if (code == TSDB_CODE_SUCCESS) {
×
904
    code = tqGetStreamExecInfo(pVnode, req.streamId, &rsp.progressDelay, &rsp.fillHisFinished);
×
905
  }
906
  if (code == TSDB_CODE_SUCCESS) {
×
907
    rspLen = tSerializeStreamProgressRsp(buf, rspLen, &rsp);
×
908
    if (rspLen < 0) {
×
909
      code = terrno;
×
910
      goto _OVER;
×
911
    }
912
    rpcMsg.pCont = buf;
×
913
    buf = NULL;
×
914
    rpcMsg.contLen = rspLen;
×
915
    rpcMsg.code = code;
×
916
    rpcMsg.msgType = pMsg->msgType;
×
917
    if (direct) {
×
918
      tmsgSendRsp(&rpcMsg);
×
919
    } else {
920
      *pMsg = rpcMsg;
×
921
    }
922
  }
923

924
_OVER:
×
925
  if (buf) {
×
926
    taosMemoryFree(buf);
×
927
  }
928
  return code;
×
929
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc