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

taosdata / TDengine / #3657

14 Mar 2025 08:10AM UTC coverage: 62.877% (+0.04%) from 62.841%
#3657

push

travis-ci

web-flow
feat(keep): support keep on super table level. (#30097)

* Feat: support use keep while create super table.

* Test(keep): add test for create super table with keep option.

* Feat(keep): Add tmsg for create keep.

* Feat(keep): support alter table option keep.

* Fix(keep): Add baisc test for alter table option.

* Fix(keep): memory leek.

* Feat(keep): add keep to metaEntry&metaCache and fix earliestTs with stn keep.

* Test(keep): add some cases for select with stb keep.

* Fix: fix ci core while alter stb.

* Feat(keep): delete expired data in super table level.

* Feat: remove get stb keep while query.

* Fix : build error.

* Revert "Fix : build error."

This reverts commit 0ed66e4e8.

* Revert "Feat(keep): delete expired data in super table level."

This reverts commit 36330f6b4.

* Fix : build errors.

* Feat : support restart taosd.

* Fix : alter table comment problems.

* Test : add tests for super table keep.

* Fix: change sdb stb reserve size.

* Test: add more tests.

* Feat: Disable normal tables and sub tables from setting the keep parameter

* Fix: add more checks to avoid unknown address.

* Docs: Add docs for stable keep.

* Fix: some review changes.

* Fix: review errors.

147792 of 302527 branches covered (48.85%)

Branch coverage included in aggregate %.

88 of 99 new or added lines in 12 files covered. (88.89%)

3160 existing lines in 17 files now uncovered.

232856 of 302857 relevant lines covered (76.89%)

6602224.33 hits per line

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

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

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

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

35
int32_t fillTableColCmpr(SMetaReader *reader, SSchemaExt *pExt, int32_t numOfCol) {
22,460✔
36
  int8_t tblType = reader->me.type;
22,460✔
37
  if (useCompress(tblType)) {
22,460!
38
    SColCmprWrapper *p = &(reader->me.colCmpr);
22,462✔
39
    if (numOfCol != p->nCols) {
22,462!
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++) {
415,473✔
44
      SColCmpr *pCmpr = &p->pColCmpr[i];
393,011✔
45
      pExt[i].colId = pCmpr->id;
393,011✔
46
      pExt[i].compress = pCmpr->alg;
393,011✔
47
    }
48
  }
49
  return 0;
22,462✔
50
}
51

52
void vnodePrintTableMeta(STableMetaRsp *pMeta) {
22,460✔
53
  if (!(qDebugFlag & DEBUG_DEBUG)) {
22,460✔
54
    return;
17,793✔
55
  }
56

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

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

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

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

107
  if (!reqTbUid) {
59,036✔
108
    (void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", infoReq.dbFName, infoReq.tbName);
58,498✔
109
    code = vnodeValidateTableHash(pVnode, tableFName);
58,502✔
110
    if (code) {
58,503!
111
      goto _exit4;
×
112
    }
113
  }
114

115
  // query meta
116
  metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
59,041✔
117
  if (reqTbUid) {
59,033✔
118
    SET_ERRNO(0);
533✔
119
    uint64_t tbUid = taosStr2UInt64(infoReq.tbName, NULL, 10);
533✔
120
    if (ERRNO == ERANGE || tbUid == 0) {
533!
121
      code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
×
122
      goto _exit3;
132✔
123
    }
124
    SMetaReader mr3 = {0};
533✔
125
    metaReaderDoInit(&mr3, ((SVnode *)pVnode)->pMeta, META_READER_NOLOCK);
533✔
126
    if ((code = metaReaderGetTableEntryByUid(&mr3, tbUid)) < 0) {
532✔
127
      metaReaderClear(&mr3);
132✔
128
      TAOS_CHECK_GOTO(code, NULL, _exit3);
132!
129
    }
130
    tstrncpy(metaRsp.tbName, mr3.me.name, TSDB_TABLE_NAME_LEN);
401✔
131
    metaReaderClear(&mr3);
401✔
132
    TAOS_CHECK_GOTO(metaGetTableEntryByName(&mer1, metaRsp.tbName), NULL, _exit3);
402!
133
  } else if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) {
58,500✔
134
    code = terrno;
36,440✔
135
    goto _exit3;
36,443✔
136
  }
137

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

142
  if (mer1.me.type == TSDB_SUPER_TABLE) {
22,461✔
143
    tstrncpy(metaRsp.stbName, mer1.me.name, TSDB_TABLE_NAME_LEN);
7,180✔
144
    schema = mer1.me.stbEntry.schemaRow;
7,180✔
145
    schemaTag = mer1.me.stbEntry.schemaTag;
7,180✔
146
    metaRsp.suid = mer1.me.uid;
7,180✔
147
  } else if (mer1.me.type == TSDB_CHILD_TABLE) {
15,281✔
148
    metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
9,957✔
149
    if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit2;
9,957!
150

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

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

188
  vnodePrintTableMeta(&metaRsp);
22,462✔
189

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

197
  if (direct) {
22,460✔
198
    pRsp = rpcMallocCont(rspLen);
241✔
199
  } else {
200
    pRsp = taosMemoryCalloc(1, rspLen);
22,219!
201
  }
202

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

208
  rspLen = tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp);
22,460✔
209
  if (rspLen < 0) {
22,462!
210
    code = terrno;
×
211
    goto _exit;
×
212
  }
213

214
_exit:
22,462✔
215
  taosMemoryFree(metaRsp.pSchemas);
22,461!
216
  taosMemoryFree(metaRsp.pSchemaExt);
22,462!
217
_exit2:
22,462✔
218
  metaReaderClear(&mer2);
22,462✔
219
_exit3:
59,035✔
220
  metaReaderClear(&mer1);
59,035✔
221
_exit4:
59,034✔
222
  rpcMsg.info = pMsg->info;
59,034✔
223
  rpcMsg.pCont = pRsp;
59,034✔
224
  rpcMsg.contLen = rspLen;
59,034✔
225
  rpcMsg.code = code;
59,034✔
226
  rpcMsg.msgType = pMsg->msgType;
59,034✔
227

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

232
  if (code) {
59,034✔
233
    qError("get table %s meta with %" PRIu8 " failed cause of %s", infoReq.tbName, infoReq.option, tstrerror(code));
36,574!
234
  }
235

236
  if (direct) {
59,036✔
237
    tmsgSendRsp(&rpcMsg);
2,023✔
238
  } else {
239
    *pMsg = rpcMsg;
57,013✔
240
  }
241

242
  return code;
59,035✔
243
}
244

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

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

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

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

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

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

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

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

290
    tstrncpy(cfgRsp.stbName, mer2.me.name, TSDB_TABLE_NAME_LEN);
49✔
291
    schema = mer2.me.stbEntry.schemaRow;
49✔
292
    schemaTag = mer2.me.stbEntry.schemaTag;
49✔
293
    cfgRsp.ttl = mer1.me.ctbEntry.ttlDays;
49✔
294
    cfgRsp.commentLen = mer1.me.ctbEntry.commentLen;
49✔
295
    if (mer1.me.ctbEntry.commentLen > 0) {
49!
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;
49✔
303
    cfgRsp.tagsLen = pTag->len;
49✔
304
    cfgRsp.pTags = taosMemoryMalloc(cfgRsp.tagsLen);
49!
305
    if (NULL == cfgRsp.pTags) {
49!
306
      code = terrno;
×
307
      goto _exit;
×
308
    }
309
    (void)memcpy(cfgRsp.pTags, pTag, cfgRsp.tagsLen);
49✔
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;
66✔
328
  cfgRsp.numOfColumns = schema.nCols;
66✔
329
  cfgRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (cfgRsp.numOfColumns + cfgRsp.numOfTags));
66!
330
  cfgRsp.pSchemaExt = (SSchemaExt *)taosMemoryMalloc(cfgRsp.numOfColumns * sizeof(SSchemaExt));
66!
331

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

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

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

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

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

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

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

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

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

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

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

395
  tFreeSTableCfgRsp(&cfgRsp);
66✔
396
  metaReaderClear(&mer2);
66✔
397
  metaReaderClear(&mer1);
66✔
398
  return code;
66✔
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) {
59,581✔
411
  int32_t      code = 0;
59,581✔
412
  int32_t      rspSize = 0;
59,581✔
413
  SBatchReq    batchReq = {0};
59,581✔
414
  SBatchMsg   *req = NULL;
59,581✔
415
  SBatchRspMsg rsp = {0};
59,581✔
416
  SBatchRsp    batchRsp = {0};
59,581✔
417
  SRpcMsg      reqMsg = *pMsg;
59,581✔
418
  SRpcMsg      rspMsg = {0};
59,581✔
419
  void        *pRsp = NULL;
59,581✔
420

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

427
  int32_t msgNum = taosArrayGetSize(batchReq.pMsgs);
59,585✔
428
  if (msgNum >= MAX_META_MSG_IN_BATCH) {
59,582!
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));
59,582✔
435
  if (NULL == batchRsp.pRsps) {
59,583✔
436
    code = terrno;
1✔
437
    qError("taosArrayInit %d SBatchRspMsg failed", msgNum);
×
438
    goto _exit;
×
439
  }
440

441
  for (int32_t i = 0; i < msgNum; ++i) {
122,519✔
442
    req = taosArrayGet(batchReq.pMsgs, i);
62,936✔
443
    if (req == NULL) {
62,934✔
444
      code = terrno;
2✔
445
      goto _exit;
×
446
    }
447

448
    reqMsg.msgType = req->msgType;
62,932✔
449
    reqMsg.pCont = req->msg;
62,932✔
450
    reqMsg.contLen = req->msgLen;
62,932✔
451

452
    switch (req->msgType) {
62,932!
453
      case TDMT_VND_TABLE_META:
56,473✔
454
        // error code has been set into reqMsg, no need to handle it here.
455
        if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
56,473✔
456
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
34,661!
457
        }
458
        break;
56,477✔
459
      case TDMT_VND_TABLE_NAME:
533✔
460
        // error code has been set into reqMsg, no need to handle it here.
461
        if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
533✔
462
          qWarn("vnodeGetBatchName failed, msgType:%d", req->msgType);
132!
463
        }
464
        break;
533✔
465
      case TDMT_VND_TABLE_CFG:
66✔
466
        // error code has been set into reqMsg, no need to handle it here.
467
        if (TSDB_CODE_SUCCESS != vnodeGetTableCfg(pVnode, &reqMsg, false)) {
66!
468
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
×
469
        }
470
        break;
66✔
471
      case TDMT_VND_GET_STREAM_PROGRESS:
5,860✔
472
        // error code has been set into reqMsg, no need to handle it here.
473
        if (TSDB_CODE_SUCCESS != vnodeGetStreamProgress(pVnode, &reqMsg, false)) {
5,860!
474
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
×
475
        }
476
        break;
5,861✔
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;
62,937✔
486
    rsp.reqType = reqMsg.msgType;
62,937✔
487
    rsp.msgLen = reqMsg.contLen;
62,937✔
488
    rsp.rspCode = reqMsg.code;
62,937✔
489
    rsp.msg = reqMsg.pCont;
62,937✔
490

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

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

516
_exit:
59,587✔
517

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

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

528
  taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
59,587✔
529
  taosArrayDestroyEx(batchRsp.pRsps, tFreeSBatchRspMsg);
59,584✔
530

531
  tmsgSendRsp(&rspMsg);
59,587✔
532

533
  return code;
59,587✔
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) {
204,531✔
544
  SSyncState state = syncGetState(pVnode->sync);
204,531✔
545
  pLoad->syncAppliedIndex = pVnode->state.applied;
204,531✔
546
  syncGetCommitIndex(pVnode->sync, &pLoad->syncCommitIndex);
204,531✔
547

548
  pLoad->vgId = TD_VID(pVnode);
204,531✔
549
  pLoad->syncState = state.state;
204,531✔
550
  pLoad->syncRestore = state.restored;
204,531✔
551
  pLoad->syncTerm = state.term;
204,531✔
552
  pLoad->roleTimeMs = state.roleTimeMs;
204,531✔
553
  pLoad->startTimeMs = state.startTimeMs;
204,531✔
554
  pLoad->syncCanRead = state.canRead;
204,531✔
555
  pLoad->learnerProgress = state.progress;
204,531✔
556
  pLoad->cacheUsage = tsdbCacheGetUsage(pVnode);
204,531✔
557
  pLoad->numOfCachedTables = tsdbCacheGetElems(pVnode);
204,531✔
558
  VNODE_DO_META_QUERY(pVnode, pLoad->numOfTables = metaGetTbNum(pVnode->pMeta));
204,531✔
559
  VNODE_DO_META_QUERY(pVnode, pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1));
204,531✔
560
  pLoad->totalStorage = (int64_t)3 * 1073741824;
204,531✔
561
  pLoad->compStorage = (int64_t)2 * 1073741824;
204,531✔
562
  pLoad->pointsWritten = 100;
204,531✔
563
  pLoad->numOfSelectReqs = 1;
204,531✔
564
  pLoad->numOfInsertReqs = atomic_load_64(&pVnode->statis.nInsert);
204,531✔
565
  pLoad->numOfInsertSuccessReqs = atomic_load_64(&pVnode->statis.nInsertSuccess);
204,531✔
566
  pLoad->numOfBatchInsertReqs = atomic_load_64(&pVnode->statis.nBatchInsert);
204,531✔
567
  pLoad->numOfBatchInsertSuccessReqs = atomic_load_64(&pVnode->statis.nBatchInsertSuccess);
204,531✔
568
  return 0;
204,531✔
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) {
35,337✔
595
  SVnode    *pVnodeObj = pVnode;
35,337✔
596
  SVnodeCfg *pConf = &pVnodeObj->config;
35,337✔
597

598
  if (dbname) {
35,337!
599
    *dbname = pConf->dbname;
35,356✔
600
  }
601

602
  if (vgId) {
35,337✔
603
    *vgId = TD_VID(pVnodeObj);
33,874✔
604
  }
605

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

610
  if (numOfNormalTables) {
35,337!
611
    *numOfNormalTables = pConf->vndStats.numOfNTables;
×
612
  }
613
}
35,337✔
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) {
619,292✔
654
  int32_t      code = TSDB_CODE_SUCCESS;
619,292✔
655
  SVnode      *pVnodeObj = pVnode;
619,292✔
656
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnodeObj, suid, 1);
619,292✔
657
  if (NULL == pCur) {
620,152!
658
    qError("vnode get all table list failed");
×
659
    return terrno;
×
660
  }
661

662
  while (1) {
2,431,760✔
663
    tb_uid_t id = metaCtbCursorNext(pCur);
3,051,912✔
664
    if (id == 0) {
3,051,757✔
665
      break;
620,948✔
666
    }
667

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

675
_exit:
620,948✔
676
  metaCloseCtbCursor(pCur);
620,948✔
677
  return code;
621,159✔
678
}
679

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

687
  while (1) {
73,361✔
688
    tb_uid_t id = metaStbCursorNext(pCur);
171,269✔
689
    if (id == 0) {
171,268✔
690
      break;
97,907✔
691
    }
692

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

700
_exit:
97,907✔
701
  metaCloseStbCursor(pCur);
97,907✔
702
  return code;
97,909✔
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) {
19,367✔
736
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, suid, 0);
19,367✔
737
  if (!pCur) {
19,373!
738
    return terrno;
×
739
  }
740

741
  *num = 0;
19,373✔
742
  while (1) {
19,059✔
743
    tb_uid_t id = metaCtbCursorNext(pCur);
38,432✔
744
    if (id == 0) {
38,431✔
745
      break;
19,372✔
746
    }
747

748
    ++(*num);
19,059✔
749
  }
750

751
  metaCloseCtbCursor(pCur);
19,372✔
752
  return TSDB_CODE_SUCCESS;
19,375✔
753
}
754

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

764
  return TSDB_CODE_SUCCESS;
19,376✔
765
}
766

767
int32_t vnodeGetStbKeep(SVnode *pVnode, tb_uid_t suid, int64_t *keep) {
19,375✔
768
  SMetaReader mr = {0};
19,375✔
769
  metaReaderDoInit(&mr, pVnode->pMeta, META_READER_NOLOCK);
19,375✔
770

771
  int32_t code = metaReaderGetTableEntryByUid(&mr, suid);
19,378✔
772
  if (code == TSDB_CODE_SUCCESS) {
19,373!
773
    *keep = mr.me.stbEntry.keep;
19,373✔
774
  } else {
NEW
775
    *keep = 0;  // Default value if not found
×
776
  }
777

778
  metaReaderClear(&mr);
19,373✔
779
  return TSDB_CODE_SUCCESS;
19,374✔
780
}
781

782
#ifdef TD_ENTERPRISE
783
const char *tkLogStb[] = {"cluster_info",
784
                          "data_dir",
785
                          "dnodes_info",
786
                          "d_info",
787
                          "grants_info",
788
                          "keeper_monitor",
789
                          "logs",
790
                          "log_dir",
791
                          "log_summary",
792
                          "m_info",
793
                          "taosadapter_restful_http_request_fail",
794
                          "taosadapter_restful_http_request_in_flight",
795
                          "taosadapter_restful_http_request_summary_milliseconds",
796
                          "taosadapter_restful_http_request_total",
797
                          "taosadapter_system_cpu_percent",
798
                          "taosadapter_system_mem_percent",
799
                          "temp_dir",
800
                          "vgroups_info",
801
                          "vnodes_role"};
802
const char *tkAuditStb[] = {"operations"};
803
const int   tkLogStbNum = ARRAY_SIZE(tkLogStb);
804
const int   tkAuditStbNum = ARRAY_SIZE(tkAuditStb);
805

806
// exclude stbs of taoskeeper log
807
static int32_t vnodeGetTimeSeriesBlackList(SVnode *pVnode, int32_t *tbSize) {
97,893✔
808
  int32_t      code = TSDB_CODE_SUCCESS;
97,893✔
809
  int32_t      tbNum = 0;
97,893✔
810
  const char **pTbArr = NULL;
97,893✔
811
  const char  *dbName = NULL;
97,893✔
812
  *tbSize = 0;
97,893✔
813

814
  if (!(dbName = strchr(pVnode->config.dbname, '.'))) return 0;
97,893!
815
  if (0 == strncmp(++dbName, "log", TSDB_DB_NAME_LEN)) {
97,893!
UNCOV
816
    tbNum = tkLogStbNum;
×
UNCOV
817
    pTbArr = (const char **)&tkLogStb;
×
818
  } else if (0 == strncmp(dbName, "audit", TSDB_DB_NAME_LEN)) {
97,893!
UNCOV
819
    tbNum = tkAuditStbNum;
×
UNCOV
820
    pTbArr = (const char **)&tkAuditStb;
×
821
  }
822
  if (tbNum && pTbArr) {
97,893!
UNCOV
823
    *tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 0);
×
UNCOV
824
    if (*tbSize < tbNum) {
×
UNCOV
825
      for (int32_t i = 0; i < tbNum; ++i) {
×
UNCOV
826
        tb_uid_t suid = metaGetTableEntryUidByName(pVnode->pMeta, pTbArr[i]);
×
UNCOV
827
        if (suid != 0) {
×
UNCOV
828
          code = metaPutTbToFilterCache(pVnode->pMeta, &suid, 0);
×
UNCOV
829
          if (TSDB_CODE_SUCCESS != code) {
×
UNCOV
830
            return code;
×
831
          }
832
        }
833
      }
834
      *tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 0);
×
835
    }
836
  }
837

838
  return code;
97,893✔
839
}
840
#endif
841

842
static bool vnodeTimeSeriesFilter(void *arg1, void *arg2) {
×
843
  SVnode *pVnode = (SVnode *)arg1;
×
844

845
  if (metaTbInFilterCache(pVnode->pMeta, arg2, 0)) {
×
UNCOV
846
    return true;
×
847
  }
UNCOV
848
  return false;
×
849
}
850

851
int32_t vnodeGetTimeSeriesNum(SVnode *pVnode, int64_t *num) {
97,892✔
852
  SArray *suidList = NULL;
97,892✔
853

854
  if (!(suidList = taosArrayInit(1, sizeof(tb_uid_t)))) {
97,892!
UNCOV
855
    return terrno;
×
856
  }
857

858
  int32_t tbFilterSize = 0;
97,893✔
859
  int32_t code = TSDB_CODE_SUCCESS;
97,893✔
860
#ifdef TD_ENTERPRISE
861
  code = vnodeGetTimeSeriesBlackList(pVnode, &tbFilterSize);
97,893✔
862
  if (TSDB_CODE_SUCCESS != code) {
97,891!
863
    goto _exit;
×
864
  }
865
#endif
866

867
  if ((!tbFilterSize && vnodeGetStbIdList(pVnode, 0, suidList) < 0) ||
97,891!
868
      (tbFilterSize && vnodeGetStbIdListByFilter(pVnode, 0, suidList, vnodeTimeSeriesFilter, pVnode) < 0)) {
97,892!
UNCOV
869
    qError("vgId:%d, failed to get stb id list error: %s", TD_VID(pVnode), terrstr());
×
870
    taosArrayDestroy(suidList);
×
UNCOV
871
    return terrno;
×
872
  }
873

874
  *num = 0;
97,892✔
875
  int64_t arrSize = taosArrayGetSize(suidList);
97,892✔
876
  for (int64_t i = 0; i < arrSize; ++i) {
171,245✔
877
    tb_uid_t suid = *(tb_uid_t *)taosArrayGet(suidList, i);
73,353✔
878

879
    int64_t ctbNum = 0;
73,338✔
880
    int32_t numOfCols = 0;
73,338✔
881
    code = metaGetStbStats(pVnode, suid, &ctbNum, &numOfCols);
73,338✔
882
    if (TSDB_CODE_SUCCESS != code) {
73,353!
UNCOV
883
      goto _exit;
×
884
    }
885
    *num += ctbNum * (numOfCols - 1);
73,353✔
886
  }
887

888
_exit:
97,892✔
889
  taosArrayDestroy(suidList);
97,892✔
890
  return TSDB_CODE_SUCCESS;
97,893✔
891
}
892

UNCOV
893
int32_t vnodeGetAllCtbNum(SVnode *pVnode, int64_t *num) {
×
UNCOV
894
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, 0);
×
UNCOV
895
  if (!pCur) {
×
UNCOV
896
    return terrno;
×
897
  }
898

UNCOV
899
  *num = 0;
×
UNCOV
900
  while (1) {
×
UNCOV
901
    tb_uid_t id = metaStbCursorNext(pCur);
×
UNCOV
902
    if (id == 0) {
×
UNCOV
903
      break;
×
904
    }
905

UNCOV
906
    int64_t ctbNum = 0;
×
UNCOV
907
    int32_t code = vnodeGetCtbNum(pVnode, id, &ctbNum);
×
908
    if (TSDB_CODE_SUCCESS != code) {
×
909
      metaCloseStbCursor(pCur);
×
910
      return code;
×
911
    }
912

UNCOV
913
    *num += ctbNum;
×
914
  }
915

916
  metaCloseStbCursor(pCur);
×
917
  return TSDB_CODE_SUCCESS;
×
918
}
919

920
void *vnodeGetIdx(void *pVnode) {
8,304✔
921
  if (pVnode == NULL) {
8,304!
922
    return NULL;
×
923
  }
924

925
  return metaGetIdx(((SVnode *)pVnode)->pMeta);
8,304✔
926
}
927

928
void *vnodeGetIvtIdx(void *pVnode) {
8,291✔
929
  if (pVnode == NULL) {
8,291!
UNCOV
930
    return NULL;
×
931
  }
932
  return metaGetIvtIdx(((SVnode *)pVnode)->pMeta);
8,291✔
933
}
934

935
int32_t vnodeGetTableSchema(void *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid) {
123✔
936
  return tsdbGetTableSchema(((SVnode *)pVnode)->pMeta, uid, pSchema, suid);
123✔
937
}
938

939
int32_t vnodeGetDBSize(void *pVnode, SDbSizeStatisInfo *pInfo) {
22✔
940
  SVnode *pVnodeObj = pVnode;
22✔
941
  if (pVnodeObj == NULL) {
22!
UNCOV
942
    return TSDB_CODE_VND_NOT_EXIST;
×
943
  }
944
  int32_t code = 0;
22✔
945
  char    path[TSDB_FILENAME_LEN] = {0};
22✔
946

947
  char   *dirName[] = {VNODE_TSDB_DIR, VNODE_WAL_DIR, VNODE_META_DIR, VNODE_TSDB_CACHE_DIR};
22✔
948
  int64_t dirSize[4];
949

950
  vnodeGetPrimaryDir(pVnodeObj->path, pVnodeObj->diskPrimary, pVnodeObj->pTfs, path, TSDB_FILENAME_LEN);
22✔
951
  int32_t offset = strlen(path);
22✔
952

953
  for (int i = 0; i < sizeof(dirName) / sizeof(dirName[0]); i++) {
110✔
954
    int64_t size = {0};
88✔
955
    (void)snprintf(path + offset, TSDB_FILENAME_LEN, "%s%s", TD_DIRSEP, dirName[i]);
88✔
956
    code = taosGetDirSize(path, &size);
88✔
957
    if (code != 0) {
88!
UNCOV
958
      return code;
×
959
    }
960
    path[offset] = 0;
88✔
961
    dirSize[i] = size;
88✔
962
  }
963

964
  pInfo->l1Size = dirSize[0] - dirSize[3];
22✔
965
  pInfo->walSize = dirSize[1];
22✔
966
  pInfo->metaSize = dirSize[2];
22✔
967
  pInfo->cacheSize = dirSize[3];
22✔
968

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

971
  return code;
22✔
972
}
973

974
int32_t vnodeGetStreamProgress(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
5,861✔
975
  int32_t            code = 0;
5,861✔
976
  SStreamProgressReq req;
977
  SStreamProgressRsp rsp = {0};
5,861✔
978
  SRpcMsg            rpcMsg = {.info = pMsg->info, .code = 0};
5,861✔
979
  char              *buf = NULL;
5,861✔
980
  int32_t            rspLen = 0;
5,861✔
981
  code = tDeserializeStreamProgressReq(pMsg->pCont, pMsg->contLen, &req);
5,861✔
982

983
  if (code == TSDB_CODE_SUCCESS) {
5,861!
984
    rsp.fetchIdx = req.fetchIdx;
5,861✔
985
    rsp.subFetchIdx = req.subFetchIdx;
5,861✔
986
    rsp.vgId = req.vgId;
5,861✔
987
    rsp.streamId = req.streamId;
5,861✔
988
    rspLen = tSerializeStreamProgressRsp(0, 0, &rsp);
5,861✔
989
    if (rspLen < 0) {
5,860!
UNCOV
990
      code = terrno;
×
UNCOV
991
      goto _OVER;
×
992
    }
993
    if (direct) {
5,860!
UNCOV
994
      buf = rpcMallocCont(rspLen);
×
995
    } else {
996
      buf = taosMemoryCalloc(1, rspLen);
5,860!
997
    }
998
    if (!buf) {
5,861!
UNCOV
999
      code = terrno;
×
UNCOV
1000
      goto _OVER;
×
1001
    }
1002
  }
1003

1004
  if (code == TSDB_CODE_SUCCESS) {
5,861!
1005
    code = tqGetStreamExecInfo(pVnode, req.streamId, &rsp.progressDelay, &rsp.fillHisFinished);
5,861✔
1006
  }
1007
  if (code == TSDB_CODE_SUCCESS) {
5,862!
1008
    rspLen = tSerializeStreamProgressRsp(buf, rspLen, &rsp);
5,862✔
1009
    if (rspLen < 0) {
5,860!
UNCOV
1010
      code = terrno;
×
UNCOV
1011
      goto _OVER;
×
1012
    }
1013
    rpcMsg.pCont = buf;
5,860✔
1014
    buf = NULL;
5,860✔
1015
    rpcMsg.contLen = rspLen;
5,860✔
1016
    rpcMsg.code = code;
5,860✔
1017
    rpcMsg.msgType = pMsg->msgType;
5,860✔
1018
    if (direct) {
5,860!
UNCOV
1019
      tmsgSendRsp(&rpcMsg);
×
1020
    } else {
1021
      *pMsg = rpcMsg;
5,860✔
1022
    }
1023
  }
1024

1025
_OVER:
×
1026
  if (buf) {
5,860!
UNCOV
1027
    taosMemoryFree(buf);
×
1028
  }
1029
  return code;
5,861✔
1030
}
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