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

taosdata / TDengine / #3632

08 Mar 2025 06:17AM UTC coverage: 60.719% (+0.05%) from 60.671%
#3632

push

travis-ci

web-flow
Merge pull request #29999 from taosdata/enh/TS-5089

feat: taosBenchmark supports exporting to CSV files

141890 of 300701 branches covered (47.19%)

Branch coverage included in aggregate %.

599 of 766 new or added lines in 3 files covered. (78.2%)

1025 existing lines in 124 files now uncovered.

223757 of 301490 relevant lines covered (74.22%)

17284906.68 hits per line

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

55.43
/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) {
11,299✔
28
  return qWorkerInit(NODE_TYPE_VNODE, TD_VID(pVnode), (void **)&pVnode->pQuery, &pVnode->msgCb);
11,299✔
29
}
30

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

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

35
int32_t fillTableColCmpr(SMetaReader *reader, SSchemaExt *pExt, int32_t numOfCol) {
1,310,041✔
36
  int8_t tblType = reader->me.type;
1,310,041✔
37
  if (useCompress(tblType)) {
1,310,041!
38
    SColCmprWrapper *p = &(reader->me.colCmpr);
1,310,156✔
39
    if (numOfCol != p->nCols) {
1,310,156!
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++) {
33,387,196✔
44
      SColCmpr *pCmpr = &p->pColCmpr[i];
32,077,040✔
45
      pExt[i].colId = pCmpr->id;
32,077,040✔
46
      pExt[i].compress = pCmpr->alg;
32,077,040✔
47
    }
48
  }
49
  return 0;
1,310,122✔
50
}
51

52
void vnodePrintTableMeta(STableMetaRsp *pMeta) {
1,310,251✔
53
  if (!(qDebugFlag & DEBUG_DEBUG)) {
1,310,251✔
54
    return;
1,305,623✔
55
  }
56

57
  qDebug("tbName:%s", pMeta->tbName);
4,628!
58
  qDebug("stbName:%s", pMeta->stbName);
4,628!
59
  qDebug("dbFName:%s", pMeta->dbFName);
4,628!
60
  qDebug("dbId:%" PRId64, pMeta->dbId);
4,628!
61
  qDebug("numOfTags:%d", pMeta->numOfTags);
4,628!
62
  qDebug("numOfColumns:%d", pMeta->numOfColumns);
4,628!
63
  qDebug("precision:%d", pMeta->precision);
4,628!
64
  qDebug("tableType:%d", pMeta->tableType);
4,628!
65
  qDebug("sversion:%d", pMeta->sversion);
4,628!
66
  qDebug("tversion:%d", pMeta->tversion);
4,628!
67
  qDebug("suid:%" PRIu64, pMeta->suid);
4,628!
68
  qDebug("tuid:%" PRIu64, pMeta->tuid);
4,628!
69
  qDebug("vgId:%d", pMeta->vgId);
4,628!
70
  qDebug("sysInfo:%d", pMeta->sysInfo);
4,628!
71
  if (pMeta->pSchemas) {
4,628!
72
    for (int32_t i = 0; i < (pMeta->numOfColumns + pMeta->numOfTags); ++i) {
201,589✔
73
      SSchema *pSchema = pMeta->pSchemas + i;
196,931✔
74
      qDebug("%d col/tag: type:%d, flags:%d, colId:%d, bytes:%d, name:%s", i, pSchema->type, pSchema->flags,
196,931!
75
             pSchema->colId, pSchema->bytes, pSchema->name);
76
    }
77
  }
78
}
79

80
int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
1,343,033✔
81
  STableInfoReq  infoReq = {0};
1,343,033✔
82
  STableMetaRsp  metaRsp = {0};
1,343,033✔
83
  SMetaReader    mer1 = {0};
1,343,033✔
84
  SMetaReader    mer2 = {0};
1,343,033✔
85
  char           tableFName[TSDB_TABLE_FNAME_LEN];
86
  bool           reqTbUid = false;
1,343,033✔
87
  SRpcMsg        rpcMsg = {0};
1,343,033✔
88
  int32_t        code = 0;
1,343,033✔
89
  int32_t        rspLen = 0;
1,343,033✔
90
  void          *pRsp = NULL;
1,343,033✔
91
  SSchemaWrapper schema = {0};
1,343,033✔
92
  SSchemaWrapper schemaTag = {0};
1,343,033✔
93
  uint8_t        autoCreateCtb = 0;
1,343,033✔
94

95
  // decode req
96
  if (tDeserializeSTableInfoReq(pMsg->pCont, pMsg->contLen, &infoReq) != 0) {
1,343,033!
97
    code = terrno;
×
98
    goto _exit4;
×
99
  }
100
  autoCreateCtb = infoReq.autoCreateCtb;
1,344,098✔
101

102
  if (infoReq.option == REQ_OPT_TBUID) reqTbUid = true;
1,344,098!
103
  metaRsp.dbId = pVnode->config.dbId;
1,344,098✔
104
  tstrncpy(metaRsp.tbName, infoReq.tbName, TSDB_TABLE_NAME_LEN);
1,344,098✔
105
  (void)memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName));
1,344,098✔
106

107
  if (!reqTbUid) {
1,344,098✔
108
    (void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", infoReq.dbFName, infoReq.tbName);
1,343,292✔
109
    code = vnodeValidateTableHash(pVnode, tableFName);
1,344,050✔
110
    if (code) {
1,343,955!
111
      goto _exit4;
×
112
    }
113
  }
114

115
  // query meta
116
  metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
1,344,761✔
117
  if (reqTbUid) {
1,344,022!
UNCOV
118
    errno = 0;
×
UNCOV
119
    uint64_t tbUid = taosStr2UInt64(infoReq.tbName, NULL, 10);
×
UNCOV
120
    if (errno == ERANGE || tbUid == 0) {
×
121
      code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
×
UNCOV
122
      goto _exit3;
×
123
    }
UNCOV
124
    SMetaReader mr3 = {0};
×
UNCOV
125
    metaReaderDoInit(&mr3, ((SVnode *)pVnode)->pMeta, META_READER_NOLOCK);
×
UNCOV
126
    if ((code = metaReaderGetTableEntryByUid(&mr3, tbUid)) < 0) {
×
UNCOV
127
      metaReaderClear(&mr3);
×
UNCOV
128
      TAOS_CHECK_GOTO(code, NULL, _exit3);
×
129
    }
UNCOV
130
    tstrncpy(metaRsp.tbName, mr3.me.name, TSDB_TABLE_NAME_LEN);
×
UNCOV
131
    metaReaderClear(&mr3);
×
UNCOV
132
    TAOS_CHECK_GOTO(metaGetTableEntryByName(&mer1, metaRsp.tbName), NULL, _exit3);
×
133
  } else if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) {
1,344,022✔
134
    code = terrno;
33,517✔
135
    goto _exit3;
33,662✔
136
  }
137

138
  metaRsp.tableType = mer1.me.type;
1,310,642✔
139
  metaRsp.vgId = TD_VID(pVnode);
1,310,642✔
140
  metaRsp.tuid = mer1.me.uid;
1,310,642✔
141

142
  if (mer1.me.type == TSDB_SUPER_TABLE) {
1,310,642✔
143
    tstrncpy(metaRsp.stbName, mer1.me.name, TSDB_TABLE_NAME_LEN);
698,771✔
144
    schema = mer1.me.stbEntry.schemaRow;
698,771✔
145
    schemaTag = mer1.me.stbEntry.schemaTag;
698,771✔
146
    metaRsp.suid = mer1.me.uid;
698,771✔
147
  } else if (mer1.me.type == TSDB_CHILD_TABLE) {
611,871✔
148
    metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
589,782✔
149
    if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit2;
589,783!
150

151
    tstrncpy(metaRsp.stbName, mer2.me.name, TSDB_TABLE_NAME_LEN);
589,778✔
152
    metaRsp.suid = mer2.me.uid;
589,778✔
153
    schema = mer2.me.stbEntry.schemaRow;
589,778✔
154
    schemaTag = mer2.me.stbEntry.schemaTag;
589,778✔
155
  } else if (mer1.me.type == TSDB_NORMAL_TABLE) {
22,089!
156
    schema = mer1.me.ntbEntry.schemaRow;
22,089✔
157
  } else {
158
    vError("vnodeGetTableMeta get invalid table type:%d", mer1.me.type);
×
159
    goto _exit3;
×
160
  }
161

162
  metaRsp.numOfTags = schemaTag.nCols;
1,310,638✔
163
  metaRsp.numOfColumns = schema.nCols;
1,310,638✔
164
  metaRsp.precision = pVnode->config.tsdbCfg.precision;
1,310,638✔
165
  metaRsp.sversion = schema.version;
1,310,638✔
166
  metaRsp.tversion = schemaTag.version;
1,310,638✔
167
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (metaRsp.numOfColumns + metaRsp.numOfTags));
1,310,638!
168
  metaRsp.pSchemaExt = (SSchemaExt *)taosMemoryCalloc(metaRsp.numOfColumns, sizeof(SSchemaExt));
1,310,450!
169
  if (NULL == metaRsp.pSchemas || NULL == metaRsp.pSchemaExt) {
1,310,259!
170
    code = terrno;
×
171
    goto _exit;
×
172
  }
173
  (void)memcpy(metaRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
1,310,290✔
174
  if (schemaTag.nCols) {
1,310,290✔
175
    (void)memcpy(metaRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
1,287,749✔
176
  }
177
  if (metaRsp.pSchemaExt) {
1,310,290✔
178
    SMetaReader *pReader = mer1.me.type == TSDB_CHILD_TABLE ? &mer2 : &mer1;
1,309,877✔
179
    code = fillTableColCmpr(pReader, metaRsp.pSchemaExt, metaRsp.numOfColumns);
1,309,877✔
180
    if (code < 0) {
1,310,307!
181
      goto _exit;
×
182
    }
183
  } else {
184
    code = TSDB_CODE_OUT_OF_MEMORY;
413✔
185
    goto _exit;
413✔
186
  }
187

188
  vnodePrintTableMeta(&metaRsp);
1,310,307✔
189

190
  // encode and send response
191
  rspLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
1,310,291✔
192
  if (rspLen < 0) {
1,309,900!
193
    code = terrno;
×
194
    goto _exit;
×
195
  }
196

197
  if (direct) {
1,309,900✔
198
    pRsp = rpcMallocCont(rspLen);
228✔
199
  } else {
200
    pRsp = taosMemoryCalloc(1, rspLen);
1,309,672!
201
  }
202

203
  if (pRsp == NULL) {
1,309,801!
204
    code = terrno;
×
205
    goto _exit;
×
206
  }
207

208
  rspLen = tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp);
1,309,801✔
209
  if (rspLen < 0) {
1,310,267!
210
    code = terrno;
×
211
    goto _exit;
×
212
  }
213

214
_exit:
1,310,267✔
215
  taosMemoryFree(metaRsp.pSchemas);
1,310,680!
216
  taosMemoryFree(metaRsp.pSchemaExt);
1,310,370!
217
_exit2:
1,310,352✔
218
  metaReaderClear(&mer2);
1,310,352✔
219
_exit3:
1,343,911✔
220
  metaReaderClear(&mer1);
1,343,911✔
221
_exit4:
1,344,046✔
222
  rpcMsg.info = pMsg->info;
1,344,046✔
223
  rpcMsg.pCont = pRsp;
1,344,046✔
224
  rpcMsg.contLen = rspLen;
1,344,046✔
225
  rpcMsg.code = code;
1,344,046✔
226
  rpcMsg.msgType = pMsg->msgType;
1,344,046✔
227

228
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST && autoCreateCtb == 1) {
1,344,046!
229
    code = TSDB_CODE_SUCCESS;
×
230
  }
231

232
  if (code) {
1,344,046✔
233
    qError("get table %s meta with %" PRIu8 " failed cause of %s", infoReq.tbName, infoReq.option, tstrerror(code));
33,661!
234
  }
235

236
  if (direct) {
1,343,766✔
237
    tmsgSendRsp(&rpcMsg);
1,784✔
238
  } else {
239
    *pMsg = rpcMsg;
1,341,982✔
240
  }
241

242
  return code;
1,343,655✔
243
}
244

245
int32_t vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
85✔
246
  STableCfgReq   cfgReq = {0};
85✔
247
  STableCfgRsp   cfgRsp = {0};
85✔
248
  SMetaReader    mer1 = {0};
85✔
249
  SMetaReader    mer2 = {0};
85✔
250
  char           tableFName[TSDB_TABLE_FNAME_LEN];
251
  SRpcMsg        rpcMsg = {0};
85✔
252
  int32_t        code = 0;
85✔
253
  int32_t        rspLen = 0;
85✔
254
  void          *pRsp = NULL;
85✔
255
  SSchemaWrapper schema = {0};
85✔
256
  SSchemaWrapper schemaTag = {0};
85✔
257

258
  // decode req
259
  if (tDeserializeSTableCfgReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
85!
260
    code = terrno;
×
261
    goto _exit;
×
262
  }
263

264
  tstrncpy(cfgRsp.tbName, cfgReq.tbName, TSDB_TABLE_NAME_LEN);
85✔
265
  (void)memcpy(cfgRsp.dbFName, cfgReq.dbFName, sizeof(cfgRsp.dbFName));
85✔
266

267
  (void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", cfgReq.dbFName, cfgReq.tbName);
85✔
268
  code = vnodeValidateTableHash(pVnode, tableFName);
85✔
269
  if (code) {
85!
270
    goto _exit;
×
271
  }
272

273
  // query meta
274
  metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
85✔
275

276
  if (metaGetTableEntryByName(&mer1, cfgReq.tbName) < 0) {
85!
277
    code = terrno;
×
278
    goto _exit;
×
279
  }
280

281
  cfgRsp.tableType = mer1.me.type;
85✔
282

283
  if (mer1.me.type == TSDB_SUPER_TABLE) {
85!
284
    code = TSDB_CODE_VND_HASH_MISMATCH;
×
285
    goto _exit;
×
286
  } else if (mer1.me.type == TSDB_CHILD_TABLE) {
85✔
287
    metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
68✔
288
    if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit;
68!
289

290
    tstrncpy(cfgRsp.stbName, mer2.me.name, TSDB_TABLE_NAME_LEN);
68✔
291
    schema = mer2.me.stbEntry.schemaRow;
68✔
292
    schemaTag = mer2.me.stbEntry.schemaTag;
68✔
293
    cfgRsp.ttl = mer1.me.ctbEntry.ttlDays;
68✔
294
    cfgRsp.commentLen = mer1.me.ctbEntry.commentLen;
68✔
295
    if (mer1.me.ctbEntry.commentLen > 0) {
68!
296
      cfgRsp.pComment = taosStrdup(mer1.me.ctbEntry.comment);
×
297
      if (NULL == cfgRsp.pComment) {
×
298
        code = terrno;
×
299
        goto _exit;
×
300
      }
301
    }
302
    STag *pTag = (STag *)mer1.me.ctbEntry.pTags;
68✔
303
    cfgRsp.tagsLen = pTag->len;
68✔
304
    cfgRsp.pTags = taosMemoryMalloc(cfgRsp.tagsLen);
68!
305
    if (NULL == cfgRsp.pTags) {
68!
306
      code = terrno;
×
307
      goto _exit;
×
308
    }
309
    (void)memcpy(cfgRsp.pTags, pTag, cfgRsp.tagsLen);
68✔
310
  } else if (mer1.me.type == TSDB_NORMAL_TABLE) {
17!
311
    schema = mer1.me.ntbEntry.schemaRow;
17✔
312
    cfgRsp.ttl = mer1.me.ntbEntry.ttlDays;
17✔
313
    cfgRsp.commentLen = mer1.me.ntbEntry.commentLen;
17✔
314
    if (mer1.me.ntbEntry.commentLen > 0) {
17!
315
      cfgRsp.pComment = taosStrdup(mer1.me.ntbEntry.comment);
×
316
      if (NULL == cfgRsp.pComment) {
×
317
        code = terrno;
×
318
        goto _exit;
×
319
      }
320
    }
321
  } else {
322
    vError("vnodeGetTableCfg get invalid table type:%d", mer1.me.type);
×
323
    code = TSDB_CODE_APP_ERROR;
×
324
    goto _exit;
×
325
  }
326

327
  cfgRsp.numOfTags = schemaTag.nCols;
85✔
328
  cfgRsp.numOfColumns = schema.nCols;
85✔
329
  cfgRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (cfgRsp.numOfColumns + cfgRsp.numOfTags));
85!
330
  cfgRsp.pSchemaExt = (SSchemaExt *)taosMemoryMalloc(cfgRsp.numOfColumns * sizeof(SSchemaExt));
85!
331

332
  if (NULL == cfgRsp.pSchemas || NULL == cfgRsp.pSchemaExt) {
85!
333
    code = terrno;
×
334
    goto _exit;
×
335
  }
336
  (void)memcpy(cfgRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
85✔
337
  if (schemaTag.nCols) {
85✔
338
    (void)memcpy(cfgRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
68✔
339
  }
340

341
  // if (useCompress(cfgRsp.tableType)) {
342

343
  SMetaReader     *pReader = mer1.me.type == TSDB_CHILD_TABLE ? &mer2 : &mer1;
85✔
344
  SColCmprWrapper *pColCmpr = &pReader->me.colCmpr;
85✔
345

346
  for (int32_t i = 0; i < cfgRsp.numOfColumns; i++) {
737✔
347
    SColCmpr   *pCmpr = &pColCmpr->pColCmpr[i];
652✔
348
    SSchemaExt *pSchExt = cfgRsp.pSchemaExt + i;
652✔
349
    pSchExt->colId = pCmpr->id;
652✔
350
    pSchExt->compress = pCmpr->alg;
652✔
351
  }
352
  //}
353

354
  // encode and send response
355
  rspLen = tSerializeSTableCfgRsp(NULL, 0, &cfgRsp);
85✔
356
  if (rspLen < 0) {
85!
357
    code = terrno;
×
358
    goto _exit;
×
359
  }
360

361
  if (direct) {
85!
362
    pRsp = rpcMallocCont(rspLen);
×
363
  } else {
364
    pRsp = taosMemoryCalloc(1, rspLen);
85!
365
  }
366

367
  if (pRsp == NULL) {
85!
368
    code = terrno;
×
369
    goto _exit;
×
370
  }
371

372
  rspLen = tSerializeSTableCfgRsp(pRsp, rspLen, &cfgRsp);
85✔
373
  if (rspLen < 0) {
85!
374
    code = terrno;
×
375
    goto _exit;
×
376
  }
377

378
_exit:
85✔
379
  rpcMsg.info = pMsg->info;
85✔
380
  rpcMsg.pCont = pRsp;
85✔
381
  rpcMsg.contLen = rspLen;
85✔
382
  rpcMsg.code = code;
85✔
383
  rpcMsg.msgType = pMsg->msgType;
85✔
384

385
  if (code) {
85!
386
    qError("get table %s cfg failed cause of %s", cfgReq.tbName, tstrerror(code));
×
387
  }
388

389
  if (direct) {
85!
390
    tmsgSendRsp(&rpcMsg);
×
391
  } else {
392
    *pMsg = rpcMsg;
85✔
393
  }
394

395
  tFreeSTableCfgRsp(&cfgRsp);
85✔
396
  metaReaderClear(&mer2);
85✔
397
  metaReaderClear(&mer1);
85✔
398
  return code;
85✔
399
}
400

401
static FORCE_INLINE void vnodeFreeSBatchRspMsg(void *p) {
402
  if (NULL == p) {
403
    return;
404
  }
405

406
  SBatchRspMsg *pRsp = (SBatchRspMsg *)p;
407
  rpcFreeCont(pRsp->msg);
408
}
409

410
int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
1,134,423✔
411
  int32_t      code = 0;
1,134,423✔
412
  int32_t      rspSize = 0;
1,134,423✔
413
  SBatchReq    batchReq = {0};
1,134,423✔
414
  SBatchMsg   *req = NULL;
1,134,423✔
415
  SBatchRspMsg rsp = {0};
1,134,423✔
416
  SBatchRsp    batchRsp = {0};
1,134,423✔
417
  SRpcMsg      reqMsg = *pMsg;
1,134,423✔
418
  SRpcMsg      rspMsg = {0};
1,134,423✔
419
  void        *pRsp = NULL;
1,134,423✔
420

421
  if (tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) {
1,134,423!
422
    code = terrno;
×
423
    qError("tDeserializeSBatchReq failed");
×
424
    goto _exit;
×
425
  }
426

427
  int32_t msgNum = taosArrayGetSize(batchReq.pMsgs);
1,134,709✔
428
  if (msgNum >= MAX_META_MSG_IN_BATCH) {
1,134,269!
429
    code = TSDB_CODE_INVALID_MSG;
×
430
    qError("too many msgs %d in vnode batch meta req", msgNum);
×
431
    goto _exit;
×
432
  }
433

434
  batchRsp.pRsps = taosArrayInit(msgNum, sizeof(SBatchRspMsg));
1,134,269✔
435
  if (NULL == batchRsp.pRsps) {
1,134,810✔
436
    code = terrno;
48✔
437
    qError("taosArrayInit %d SBatchRspMsg failed", msgNum);
×
438
    goto _exit;
×
439
  }
440

441
  for (int32_t i = 0; i < msgNum; ++i) {
2,482,273✔
442
    req = taosArrayGet(batchReq.pMsgs, i);
1,347,995✔
443
    if (req == NULL) {
1,347,539!
UNCOV
444
      code = terrno;
×
445
      goto _exit;
×
446
    }
447

448
    reqMsg.msgType = req->msgType;
1,347,594✔
449
    reqMsg.pCont = req->msg;
1,347,594✔
450
    reqMsg.contLen = req->msgLen;
1,347,594✔
451

452
    switch (req->msgType) {
1,347,594!
453
      case TDMT_VND_TABLE_META:
1,341,527✔
454
        // error code has been set into reqMsg, no need to handle it here.
455
        if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
1,341,527✔
456
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
32,106!
457
        }
458
        break;
1,341,933✔
UNCOV
459
      case TDMT_VND_TABLE_NAME:
×
460
        // error code has been set into reqMsg, no need to handle it here.
UNCOV
461
        if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
×
UNCOV
462
          qWarn("vnodeGetBatchName failed, msgType:%d", req->msgType);
×
463
        }
UNCOV
464
        break;
×
465
      case TDMT_VND_TABLE_CFG:
85✔
466
        // error code has been set into reqMsg, no need to handle it here.
467
        if (TSDB_CODE_SUCCESS != vnodeGetTableCfg(pVnode, &reqMsg, false)) {
85!
468
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
×
469
        }
470
        break;
85✔
471
      case TDMT_VND_GET_STREAM_PROGRESS:
5,982✔
472
        // error code has been set into reqMsg, no need to handle it here.
473
        if (TSDB_CODE_SUCCESS != vnodeGetStreamProgress(pVnode, &reqMsg, false)) {
5,982!
474
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
×
475
        }
476
        break;
5,984✔
477
      default:
×
478
        qError("invalid req msgType %d", req->msgType);
×
479
        reqMsg.code = TSDB_CODE_INVALID_MSG;
×
480
        reqMsg.pCont = NULL;
×
481
        reqMsg.contLen = 0;
×
482
        break;
×
483
    }
484

485
    rsp.msgIdx = req->msgIdx;
1,348,002✔
486
    rsp.reqType = reqMsg.msgType;
1,348,002✔
487
    rsp.msgLen = reqMsg.contLen;
1,348,002✔
488
    rsp.rspCode = reqMsg.code;
1,348,002✔
489
    rsp.msg = reqMsg.pCont;
1,348,002✔
490

491
    if (NULL == taosArrayPush(batchRsp.pRsps, &rsp)) {
2,695,513!
492
      qError("taosArrayPush failed");
×
493
      code = terrno;
×
494
      goto _exit;
×
495
    }
496
  }
497

498
  rspSize = tSerializeSBatchRsp(NULL, 0, &batchRsp);
1,134,278✔
499
  if (rspSize < 0) {
1,134,310!
500
    qError("tSerializeSBatchRsp failed");
×
501
    code = terrno;
×
502
    goto _exit;
×
503
  }
504
  pRsp = rpcMallocCont(rspSize);
1,134,310✔
505
  if (pRsp == NULL) {
1,134,611!
506
    qError("rpcMallocCont %d failed", rspSize);
×
507
    code = terrno;
×
508
    goto _exit;
×
509
  }
510
  if (tSerializeSBatchRsp(pRsp, rspSize, &batchRsp) < 0) {
1,134,611!
511
    qError("tSerializeSBatchRsp %d failed", rspSize);
×
512
    code = terrno;
×
513
    goto _exit;
×
514
  }
515

516
_exit:
1,134,462✔
517

518
  rspMsg.info = pMsg->info;
1,134,462✔
519
  rspMsg.pCont = pRsp;
1,134,462✔
520
  rspMsg.contLen = rspSize;
1,134,462✔
521
  rspMsg.code = code;
1,134,462✔
522
  rspMsg.msgType = pMsg->msgType;
1,134,462✔
523

524
  if (code) {
1,134,462!
525
    qError("vnd get batch meta failed cause of %s", tstrerror(code));
×
526
  }
527

528
  taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
1,134,462✔
529
  taosArrayDestroyEx(batchRsp.pRsps, tFreeSBatchRspMsg);
1,134,659✔
530

531
  tmsgSendRsp(&rspMsg);
1,134,670✔
532

533
  return code;
1,134,401✔
534
}
535

536
#define VNODE_DO_META_QUERY(pVnode, cmd)                 \
537
  do {                                                   \
538
    (void)taosThreadRwlockRdlock(&(pVnode)->metaRWLock); \
539
    cmd;                                                 \
540
    (void)taosThreadRwlockUnlock(&(pVnode)->metaRWLock); \
541
  } while (0)
542

543
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
1,009,629✔
544
  SSyncState state = syncGetState(pVnode->sync);
1,009,629✔
545
  pLoad->syncAppliedIndex = pVnode->state.applied;
1,009,629✔
546
  syncGetCommitIndex(pVnode->sync, &pLoad->syncCommitIndex);
1,009,629✔
547

548
  pLoad->vgId = TD_VID(pVnode);
1,009,629✔
549
  pLoad->syncState = state.state;
1,009,629✔
550
  pLoad->syncRestore = state.restored;
1,009,629✔
551
  pLoad->syncTerm = state.term;
1,009,629✔
552
  pLoad->roleTimeMs = state.roleTimeMs;
1,009,629✔
553
  pLoad->startTimeMs = state.startTimeMs;
1,009,629✔
554
  pLoad->syncCanRead = state.canRead;
1,009,629✔
555
  pLoad->learnerProgress = state.progress;
1,009,629✔
556
  pLoad->cacheUsage = tsdbCacheGetUsage(pVnode);
1,009,629✔
557
  pLoad->numOfCachedTables = tsdbCacheGetElems(pVnode);
1,009,629✔
558
  VNODE_DO_META_QUERY(pVnode, pLoad->numOfTables = metaGetTbNum(pVnode->pMeta));
1,009,629✔
559
  VNODE_DO_META_QUERY(pVnode, pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1));
1,009,629✔
560
  pLoad->totalStorage = (int64_t)3 * 1073741824;
1,009,629✔
561
  pLoad->compStorage = (int64_t)2 * 1073741824;
1,009,629✔
562
  pLoad->pointsWritten = 100;
1,009,629✔
563
  pLoad->numOfSelectReqs = 1;
1,009,629✔
564
  pLoad->numOfInsertReqs = atomic_load_64(&pVnode->statis.nInsert);
1,009,629✔
565
  pLoad->numOfInsertSuccessReqs = atomic_load_64(&pVnode->statis.nInsertSuccess);
1,009,629✔
566
  pLoad->numOfBatchInsertReqs = atomic_load_64(&pVnode->statis.nBatchInsert);
1,009,629✔
567
  pLoad->numOfBatchInsertSuccessReqs = atomic_load_64(&pVnode->statis.nBatchInsertSuccess);
1,009,629✔
568
  return 0;
1,009,629✔
569
}
570

571
int32_t vnodeGetLoadLite(SVnode *pVnode, SVnodeLoadLite *pLoad) {
×
572
  SSyncState syncState = syncGetState(pVnode->sync);
×
573
  if (syncState.state == TAOS_SYNC_STATE_LEADER || syncState.state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
×
574
    pLoad->vgId = TD_VID(pVnode);
×
575
    pLoad->nTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1);
×
576
    return 0;
×
577
  }
578
  return -1;
×
579
}
580
/**
581
 * @brief Reset the statistics value by monitor interval
582
 *
583
 * @param pVnode
584
 * @param pLoad
585
 */
586
void vnodeResetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
32✔
587
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsert, pLoad->numOfInsertReqs, 64, "nInsert");
32!
588
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsertSuccess, pLoad->numOfInsertSuccessReqs, 64, "nInsertSuccess");
32!
589
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsert, pLoad->numOfBatchInsertReqs, 64, "nBatchInsert");
32!
590
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsertSuccess, pLoad->numOfBatchInsertSuccessReqs, 64,
32!
591
                            "nBatchInsertSuccess");
592
}
32✔
593

594
void vnodeGetInfo(void *pVnode, const char **dbname, int32_t *vgId, int64_t *numOfTables, int64_t *numOfNormalTables) {
956,654✔
595
  SVnode    *pVnodeObj = pVnode;
956,654✔
596
  SVnodeCfg *pConf = &pVnodeObj->config;
956,654✔
597

598
  if (dbname) {
956,654!
599
    *dbname = pConf->dbname;
957,769✔
600
  }
601

602
  if (vgId) {
956,654!
603
    *vgId = TD_VID(pVnodeObj);
956,938✔
604
  }
605

606
  if (numOfTables) {
956,654!
607
    *numOfTables = pConf->vndStats.numOfNTables + pConf->vndStats.numOfCTables;
×
608
  }
609

610
  if (numOfNormalTables) {
956,654!
611
    *numOfNormalTables = pConf->vndStats.numOfNTables;
×
612
  }
613
}
956,654✔
614

615
int32_t vnodeGetTableList(void *pVnode, int8_t type, SArray *pList) {
×
616
  if (type == TSDB_SUPER_TABLE) {
×
617
    return vnodeGetStbIdList(pVnode, 0, pList);
×
618
  } else {
619
    return TSDB_CODE_INVALID_PARA;
×
620
  }
621
}
622

623
int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) {
×
624
  int32_t      code = TSDB_CODE_SUCCESS;
×
625
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, uid, 1);
×
626
  if (NULL == pCur) {
×
627
    qError("vnode get all table list failed");
×
628
    return terrno;
×
629
  }
630

631
  while (1) {
×
632
    tb_uid_t id = metaCtbCursorNext(pCur);
×
633
    if (id == 0) {
×
634
      break;
×
635
    }
636

637
    STableKeyInfo info = {uid = id};
×
638
    if (NULL == taosArrayPush(list, &info)) {
×
639
      qError("taosArrayPush failed");
×
640
      code = terrno;
×
641
      goto _exit;
×
642
    }
643
  }
644
_exit:
×
645
  metaCloseCtbCursor(pCur);
×
646
  return code;
×
647
}
648

649
int32_t vnodeGetCtbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg), void *arg) {
×
650
  return 0;
×
651
}
652

653
int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) {
2,787,923✔
654
  int32_t      code = TSDB_CODE_SUCCESS;
2,787,923✔
655
  SVnode      *pVnodeObj = pVnode;
2,787,923✔
656
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnodeObj, suid, 1);
2,787,923✔
657
  if (NULL == pCur) {
2,796,284!
658
    qError("vnode get all table list failed");
×
659
    return terrno;
×
660
  }
661

662
  while (1) {
9,120,439✔
663
    tb_uid_t id = metaCtbCursorNext(pCur);
11,916,723✔
664
    if (id == 0) {
11,909,439✔
665
      break;
2,797,999✔
666
    }
667

668
    if (NULL == taosArrayPush(list, &id)) {
9,120,439!
669
      qError("taosArrayPush failed");
×
670
      code = terrno;
×
671
      goto _exit;
×
672
    }
673
  }
674

675
_exit:
2,797,999✔
676
  metaCloseCtbCursor(pCur);
2,797,999✔
677
  return code;
2,795,119✔
678
}
679

680
int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) {
159,304✔
681
  int32_t      code = TSDB_CODE_SUCCESS;
159,304✔
682
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
159,304✔
683
  if (!pCur) {
159,305!
684
    return TSDB_CODE_OUT_OF_MEMORY;
×
685
  }
686

687
  while (1) {
132,578✔
688
    tb_uid_t id = metaStbCursorNext(pCur);
291,883✔
689
    if (id == 0) {
291,883✔
690
      break;
159,306✔
691
    }
692

693
    if (NULL == taosArrayPush(list, &id)) {
132,578!
694
      qError("taosArrayPush failed");
×
695
      code = terrno;
×
696
      goto _exit;
×
697
    }
698
  }
699

700
_exit:
159,306✔
701
  metaCloseStbCursor(pCur);
159,306✔
702
  return code;
159,308✔
703
}
704

705
int32_t vnodeGetStbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg, void *arg1),
×
706
                                  void *arg) {
707
  int32_t      code = TSDB_CODE_SUCCESS;
×
708
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
×
709
  if (!pCur) {
×
710
    return terrno;
×
711
  }
712

713
  while (1) {
×
714
    tb_uid_t id = metaStbCursorNext(pCur);
×
715
    if (id == 0) {
×
716
      break;
×
717
    }
718

719
    if ((*filter) && (*filter)(arg, &id)) {
×
720
      continue;
×
721
    }
722

723
    if (NULL == taosArrayPush(list, &id)) {
×
724
      qError("taosArrayPush failed");
×
725
      code = terrno;
×
726
      goto _exit;
×
727
    }
728
  }
729

730
_exit:
×
731
  metaCloseStbCursor(pCur);
×
732
  return code;
×
733
}
734

735
int32_t vnodeGetCtbNum(SVnode *pVnode, int64_t suid, int64_t *num) {
20,763✔
736
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, suid, 0);
20,763✔
737
  if (!pCur) {
20,767!
UNCOV
738
    return terrno;
×
739
  }
740

741
  *num = 0;
20,768✔
742
  while (1) {
12,384✔
743
    tb_uid_t id = metaCtbCursorNext(pCur);
33,152✔
744
    if (id == 0) {
33,153✔
745
      break;
20,769✔
746
    }
747

748
    ++(*num);
12,384✔
749
  }
750

751
  metaCloseCtbCursor(pCur);
20,769✔
752
  return TSDB_CODE_SUCCESS;
20,770✔
753
}
754

755
int32_t vnodeGetStbColumnNum(SVnode *pVnode, tb_uid_t suid, int *num) {
20,766✔
756
  SSchemaWrapper *pSW = metaGetTableSchema(pVnode->pMeta, suid, -1, 0);
20,766✔
757
  if (pSW) {
20,766!
758
    *num = pSW->nCols;
20,766!
759
    tDeleteSchemaWrapper(pSW);
760
  } else {
UNCOV
761
    *num = 2;
×
762
  }
763

764
  return TSDB_CODE_SUCCESS;
20,767✔
765
}
766

767
#ifdef TD_ENTERPRISE
768
const char *tkLogStb[] = {"cluster_info",
769
                          "data_dir",
770
                          "dnodes_info",
771
                          "d_info",
772
                          "grants_info",
773
                          "keeper_monitor",
774
                          "logs",
775
                          "log_dir",
776
                          "log_summary",
777
                          "m_info",
778
                          "taosadapter_restful_http_request_fail",
779
                          "taosadapter_restful_http_request_in_flight",
780
                          "taosadapter_restful_http_request_summary_milliseconds",
781
                          "taosadapter_restful_http_request_total",
782
                          "taosadapter_system_cpu_percent",
783
                          "taosadapter_system_mem_percent",
784
                          "temp_dir",
785
                          "vgroups_info",
786
                          "vnodes_role"};
787
const char *tkAuditStb[] = {"operations"};
788
const int   tkLogStbNum = ARRAY_SIZE(tkLogStb);
789
const int   tkAuditStbNum = ARRAY_SIZE(tkAuditStb);
790

791
// exclude stbs of taoskeeper log
792
static int32_t vnodeGetTimeSeriesBlackList(SVnode *pVnode, int32_t *tbSize) {
159,287✔
793
  int32_t      code = TSDB_CODE_SUCCESS;
159,287✔
794
  int32_t      tbNum = 0;
159,287✔
795
  const char **pTbArr = NULL;
159,287✔
796
  const char  *dbName = NULL;
159,287✔
797
  *tbSize = 0;
159,287✔
798

799
  if (!(dbName = strchr(pVnode->config.dbname, '.'))) return 0;
159,287!
800
  if (0 == strncmp(++dbName, "log", TSDB_DB_NAME_LEN)) {
159,287!
801
    tbNum = tkLogStbNum;
×
802
    pTbArr = (const char **)&tkLogStb;
×
803
  } else if (0 == strncmp(dbName, "audit", TSDB_DB_NAME_LEN)) {
159,287!
804
    tbNum = tkAuditStbNum;
×
805
    pTbArr = (const char **)&tkAuditStb;
×
806
  }
807
  if (tbNum && pTbArr) {
159,287!
808
    *tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 0);
×
809
    if (*tbSize < tbNum) {
×
810
      for (int32_t i = 0; i < tbNum; ++i) {
×
811
        tb_uid_t suid = metaGetTableEntryUidByName(pVnode->pMeta, pTbArr[i]);
×
812
        if (suid != 0) {
×
813
          code = metaPutTbToFilterCache(pVnode->pMeta, &suid, 0);
×
814
          if (TSDB_CODE_SUCCESS != code) {
×
815
            return code;
×
816
          }
817
        }
818
      }
819
      *tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 0);
×
820
    }
821
  }
822

823
  return code;
159,287✔
824
}
825
#endif
826

827
static bool vnodeTimeSeriesFilter(void *arg1, void *arg2) {
×
828
  SVnode *pVnode = (SVnode *)arg1;
×
829

830
  if (metaTbInFilterCache(pVnode->pMeta, arg2, 0)) {
×
831
    return true;
×
832
  }
833
  return false;
×
834
}
835

836
int32_t vnodeGetTimeSeriesNum(SVnode *pVnode, int64_t *num) {
159,287✔
837
  SArray *suidList = NULL;
159,287✔
838

839
  if (!(suidList = taosArrayInit(1, sizeof(tb_uid_t)))) {
159,287!
840
    return terrno;
×
841
  }
842

843
  int32_t tbFilterSize = 0;
159,290✔
844
  int32_t code = TSDB_CODE_SUCCESS;
159,290✔
845
#ifdef TD_ENTERPRISE
846
  code = vnodeGetTimeSeriesBlackList(pVnode, &tbFilterSize);
159,290✔
847
  if (TSDB_CODE_SUCCESS != code) {
159,291!
848
    goto _exit;
×
849
  }
850
#endif
851

852
  if ((!tbFilterSize && vnodeGetStbIdList(pVnode, 0, suidList) < 0) ||
159,291✔
853
      (tbFilterSize && vnodeGetStbIdListByFilter(pVnode, 0, suidList, vnodeTimeSeriesFilter, pVnode) < 0)) {
159,289!
854
    qError("vgId:%d, failed to get stb id list error: %s", TD_VID(pVnode), terrstr());
×
855
    taosArrayDestroy(suidList);
×
856
    return terrno;
×
857
  }
858

859
  *num = 0;
159,292✔
860
  int64_t arrSize = taosArrayGetSize(suidList);
159,292✔
861
  for (int64_t i = 0; i < arrSize; ++i) {
291,864✔
862
    tb_uid_t suid = *(tb_uid_t *)taosArrayGet(suidList, i);
132,574✔
863

864
    int64_t ctbNum = 0;
132,575✔
865
    int32_t numOfCols = 0;
132,575✔
866
    code = metaGetStbStats(pVnode, suid, &ctbNum, &numOfCols);
132,575✔
867
    if (TSDB_CODE_SUCCESS != code) {
132,576!
868
      goto _exit;
×
869
    }
870
    *num += ctbNum * (numOfCols - 1);
132,576✔
871
  }
872

873
_exit:
159,290✔
874
  taosArrayDestroy(suidList);
159,290✔
875
  return TSDB_CODE_SUCCESS;
159,291✔
876
}
877

878
int32_t vnodeGetAllCtbNum(SVnode *pVnode, int64_t *num) {
×
879
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, 0);
×
880
  if (!pCur) {
×
881
    return terrno;
×
882
  }
883

884
  *num = 0;
×
885
  while (1) {
×
886
    tb_uid_t id = metaStbCursorNext(pCur);
×
887
    if (id == 0) {
×
888
      break;
×
889
    }
890

891
    int64_t ctbNum = 0;
×
892
    int32_t code = vnodeGetCtbNum(pVnode, id, &ctbNum);
×
893
    if (TSDB_CODE_SUCCESS != code) {
×
894
      metaCloseStbCursor(pCur);
×
895
      return code;
×
896
    }
897

898
    *num += ctbNum;
×
899
  }
900

901
  metaCloseStbCursor(pCur);
×
902
  return TSDB_CODE_SUCCESS;
×
903
}
904

905
void *vnodeGetIdx(void *pVnode) {
56,578✔
906
  if (pVnode == NULL) {
56,578!
907
    return NULL;
×
908
  }
909

910
  return metaGetIdx(((SVnode *)pVnode)->pMeta);
56,578✔
911
}
912

913
void *vnodeGetIvtIdx(void *pVnode) {
56,538✔
914
  if (pVnode == NULL) {
56,538!
915
    return NULL;
×
916
  }
917
  return metaGetIvtIdx(((SVnode *)pVnode)->pMeta);
56,538✔
918
}
919

920
int32_t vnodeGetTableSchema(void *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid) {
119✔
921
  return tsdbGetTableSchema(((SVnode *)pVnode)->pMeta, uid, pSchema, suid);
119✔
922
}
923

924
int32_t vnodeGetDBSize(void *pVnode, SDbSizeStatisInfo *pInfo) {
22✔
925
  SVnode *pVnodeObj = pVnode;
22✔
926
  if (pVnodeObj == NULL) {
22!
927
    return TSDB_CODE_VND_NOT_EXIST;
×
928
  }
929
  int32_t code = 0;
22✔
930
  char    path[TSDB_FILENAME_LEN] = {0};
22✔
931

932
  char   *dirName[] = {VNODE_TSDB_DIR, VNODE_WAL_DIR, VNODE_META_DIR, VNODE_TSDB_CACHE_DIR};
22✔
933
  int64_t dirSize[4];
934

935
  vnodeGetPrimaryDir(pVnodeObj->path, pVnodeObj->diskPrimary, pVnodeObj->pTfs, path, TSDB_FILENAME_LEN);
22✔
936
  int32_t offset = strlen(path);
22✔
937

938
  for (int i = 0; i < sizeof(dirName) / sizeof(dirName[0]); i++) {
110✔
939
    int64_t size = {0};
88✔
940
    (void)snprintf(path + offset, TSDB_FILENAME_LEN, "%s%s", TD_DIRSEP, dirName[i]);
88✔
941
    code = taosGetDirSize(path, &size);
88✔
942
    if (code != 0) {
88!
943
      return code;
×
944
    }
945
    path[offset] = 0;
88✔
946
    dirSize[i] = size;
88✔
947
  }
948

949
  pInfo->l1Size = dirSize[0] - dirSize[3];
22✔
950
  pInfo->walSize = dirSize[1];
22✔
951
  pInfo->metaSize = dirSize[2];
22✔
952
  pInfo->cacheSize = dirSize[3];
22✔
953

954
  code = tsdbGetS3Size(pVnodeObj->pTsdb, &pInfo->s3Size);
22✔
955

956
  return code;
22✔
957
}
958

959
int32_t vnodeGetStreamProgress(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
5,982✔
960
  int32_t            code = 0;
5,982✔
961
  SStreamProgressReq req;
962
  SStreamProgressRsp rsp = {0};
5,982✔
963
  SRpcMsg            rpcMsg = {.info = pMsg->info, .code = 0};
5,982✔
964
  char              *buf = NULL;
5,982✔
965
  int32_t            rspLen = 0;
5,982✔
966
  code = tDeserializeStreamProgressReq(pMsg->pCont, pMsg->contLen, &req);
5,982✔
967

968
  if (code == TSDB_CODE_SUCCESS) {
5,983!
969
    rsp.fetchIdx = req.fetchIdx;
5,983✔
970
    rsp.subFetchIdx = req.subFetchIdx;
5,983✔
971
    rsp.vgId = req.vgId;
5,983✔
972
    rsp.streamId = req.streamId;
5,983✔
973
    rspLen = tSerializeStreamProgressRsp(0, 0, &rsp);
5,983✔
974
    if (rspLen < 0) {
5,983!
975
      code = terrno;
×
976
      goto _OVER;
×
977
    }
978
    if (direct) {
5,983!
979
      buf = rpcMallocCont(rspLen);
×
980
    } else {
981
      buf = taosMemoryCalloc(1, rspLen);
5,983!
982
    }
983
    if (!buf) {
5,982!
984
      code = terrno;
×
985
      goto _OVER;
×
986
    }
987
  }
988

989
  if (code == TSDB_CODE_SUCCESS) {
5,982!
990
    code = tqGetStreamExecInfo(pVnode, req.streamId, &rsp.progressDelay, &rsp.fillHisFinished);
5,982✔
991
  }
992
  if (code == TSDB_CODE_SUCCESS) {
5,984!
993
    rspLen = tSerializeStreamProgressRsp(buf, rspLen, &rsp);
5,984✔
994
    if (rspLen < 0) {
5,984!
995
      code = terrno;
×
996
      goto _OVER;
×
997
    }
998
    rpcMsg.pCont = buf;
5,984✔
999
    buf = NULL;
5,984✔
1000
    rpcMsg.contLen = rspLen;
5,984✔
1001
    rpcMsg.code = code;
5,984✔
1002
    rpcMsg.msgType = pMsg->msgType;
5,984✔
1003
    if (direct) {
5,984!
1004
      tmsgSendRsp(&rpcMsg);
×
1005
    } else {
1006
      *pMsg = rpcMsg;
5,984✔
1007
    }
1008
  }
1009

1010
_OVER:
×
1011
  if (buf) {
5,984!
1012
    taosMemoryFree(buf);
×
1013
  }
1014
  return code;
5,984✔
1015
}
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