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

taosdata / TDengine / #4795

13 Oct 2025 06:50AM UTC coverage: 58.426% (+0.2%) from 58.201%
#4795

push

travis-ci

web-flow
Merge pull request #33213 from taosdata/fix/huoh/timemoe_model_directory

fix: fix tdgpt timemoe model directory

138954 of 303332 branches covered (45.81%)

Branch coverage included in aggregate %.

210571 of 294900 relevant lines covered (71.4%)

16934524.21 hits per line

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

54.42
/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 "tutil.h"
18
#include "vnd.h"
19

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

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

32
void vnodeQueryPreClose(SVnode *pVnode) { qWorkerStopAllTasks((void *)pVnode->pQuery); }
10,110✔
33

34
void vnodeQueryClose(SVnode *pVnode) { qWorkerDestroy((void **)&pVnode->pQuery); }
10,109✔
35

36
int32_t fillTableColCmpr(SMetaReader *reader, SSchemaExt *pExt, int32_t numOfCol) {
1,996,519✔
37
  int8_t tblType = reader->me.type;
1,996,519✔
38
  if (withExtSchema(tblType)) {
1,996,519✔
39
    SColCmprWrapper *p = &(reader->me.colCmpr);
1,996,530✔
40
    if (numOfCol != p->nCols) {
1,996,530!
41
      vError("fillTableColCmpr table type:%d, col num:%d, col cmpr num:%d mismatch", tblType, numOfCol, p->nCols);
×
42
      return TSDB_CODE_APP_ERROR;
×
43
    }
44
    for (int i = 0; i < p->nCols; i++) {
50,691,300✔
45
      SColCmpr *pCmpr = &p->pColCmpr[i];
48,694,770✔
46
      pExt[i].colId = pCmpr->id;
48,694,770✔
47
      pExt[i].compress = pCmpr->alg;
48,694,770✔
48
    }
49
  }
50
  return 0;
1,996,888✔
51
}
52

53
void vnodePrintTableMeta(STableMetaRsp *pMeta) {
1,996,795✔
54
  if (!(qDebugFlag & DEBUG_DEBUG)) {
1,996,795✔
55
    return;
1,939,747✔
56
  }
57

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

81
int32_t fillTableColRef(SMetaReader *reader, SColRef *pRef, int32_t numOfCol) {
415✔
82
  int8_t tblType = reader->me.type;
415✔
83
  if (hasRefCol(tblType)) {
415!
84
    SColRefWrapper *p = &(reader->me.colRef);
415✔
85
    if (numOfCol != p->nCols) {
415!
86
      vError("fillTableColRef table type:%d, col num:%d, col cmpr num:%d mismatch", tblType, numOfCol, p->nCols);
×
87
      return TSDB_CODE_APP_ERROR;
×
88
    }
89
    for (int i = 0; i < p->nCols; i++) {
3,313✔
90
      SColRef *pColRef = &p->pColRef[i];
2,898✔
91
      pRef[i].hasRef = pColRef->hasRef;
2,898✔
92
      pRef[i].id = pColRef->id;
2,898✔
93
      if(pRef[i].hasRef) {
2,898✔
94
        tstrncpy(pRef[i].refDbName, pColRef->refDbName, TSDB_DB_NAME_LEN);
2,046✔
95
        tstrncpy(pRef[i].refTableName, pColRef->refTableName, TSDB_TABLE_NAME_LEN);
2,046✔
96
        tstrncpy(pRef[i].refColName, pColRef->refColName, TSDB_COL_NAME_LEN);
2,046✔
97
      }
98
    }
99
  }
100
  return 0;
415✔
101
}
102

103
int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
2,042,751✔
104
  STableInfoReq  infoReq = {0};
2,042,751✔
105
  STableMetaRsp  metaRsp = {0};
2,042,751✔
106
  SMetaReader    mer1 = {0};
2,042,751✔
107
  SMetaReader    mer2 = {0};
2,042,751✔
108
  char           tableFName[TSDB_TABLE_FNAME_LEN];
109
  bool           reqTbUid = false;
2,042,751✔
110
  SRpcMsg        rpcMsg = {0};
2,042,751✔
111
  int32_t        code = 0;
2,042,751✔
112
  int32_t        rspLen = 0;
2,042,751✔
113
  void          *pRsp = NULL;
2,042,751✔
114
  SSchemaWrapper schema = {0};
2,042,751✔
115
  SSchemaWrapper schemaTag = {0};
2,042,751✔
116
  uint8_t        autoCreateCtb = 0;
2,042,751✔
117

118
  // decode req
119
  if (tDeserializeSTableInfoReq(pMsg->pCont, pMsg->contLen, &infoReq) != 0) {
2,042,751!
120
    code = terrno;
×
121
    goto _exit4;
×
122
  }
123
  autoCreateCtb = infoReq.autoCreateCtb;
2,045,927✔
124

125
  if (infoReq.option == REQ_OPT_TBUID) reqTbUid = true;
2,045,927✔
126
  metaRsp.dbId = pVnode->config.dbId;
2,045,927✔
127
  tstrncpy(metaRsp.tbName, infoReq.tbName, TSDB_TABLE_NAME_LEN);
2,045,927✔
128
  (void)memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName));
2,045,927✔
129

130
  if (!reqTbUid) {
2,045,927✔
131
    (void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", infoReq.dbFName, infoReq.tbName);
2,043,335✔
132
    if (pVnode->mounted) tTrimMountPrefix(tableFName);
2,044,298✔
133
    code = vnodeValidateTableHash(pVnode, tableFName);
2,044,298✔
134
    if (code) {
2,043,892!
135
      goto _exit4;
×
136
    }
137
  }
138

139
  // query meta
140
  metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
2,046,484✔
141
  if (reqTbUid) {
2,045,845✔
142
    SET_ERRNO(0);
1,690✔
143
    uint64_t tbUid = taosStr2UInt64(infoReq.tbName, NULL, 10);
1,690✔
144
    if (ERRNO == ERANGE || tbUid == 0) {
1,690!
145
      code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
×
146
      goto _exit3;
677✔
147
    }
148
    SMetaReader mr3 = {0};
1,690✔
149
    metaReaderDoInit(&mr3, ((SVnode *)pVnode)->pMeta, META_READER_NOLOCK);
1,690✔
150
    if ((code = metaReaderGetTableEntryByUid(&mr3, tbUid)) < 0) {
1,690✔
151
      metaReaderClear(&mr3);
677✔
152
      TAOS_CHECK_GOTO(code, NULL, _exit3);
677!
153
    }
154
    tstrncpy(metaRsp.tbName, mr3.me.name, TSDB_TABLE_NAME_LEN);
1,013✔
155
    metaReaderClear(&mr3);
1,013✔
156
    TAOS_CHECK_GOTO(metaGetTableEntryByName(&mer1, metaRsp.tbName), NULL, _exit3);
1,013!
157
  } else if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) {
2,044,155✔
158
    code = terrno;
47,908✔
159
    goto _exit3;
48,170✔
160
  }
161

162
  metaRsp.tableType = mer1.me.type;
1,997,336✔
163
  metaRsp.vgId = TD_VID(pVnode);
1,997,336✔
164
  metaRsp.tuid = mer1.me.uid;
1,997,336✔
165

166
  switch (mer1.me.type) {
1,997,336!
167
    case TSDB_SUPER_TABLE: {
1,357,372✔
168
      (void)strcpy(metaRsp.stbName, mer1.me.name);
1,357,372✔
169
      schema = mer1.me.stbEntry.schemaRow;
1,357,372✔
170
      schemaTag = mer1.me.stbEntry.schemaTag;
1,357,372✔
171
      metaRsp.suid = mer1.me.uid;
1,357,372✔
172
      break;
1,357,372✔
173
    }
174
    case TSDB_CHILD_TABLE:
599,744✔
175
    case TSDB_VIRTUAL_CHILD_TABLE:{
176
      metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
599,744✔
177
      if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit2;
599,749!
178

179
      (void)strcpy(metaRsp.stbName, mer2.me.name);
599,753✔
180
      metaRsp.suid = mer2.me.uid;
599,753✔
181
      schema = mer2.me.stbEntry.schemaRow;
599,753✔
182
      schemaTag = mer2.me.stbEntry.schemaTag;
599,753✔
183
      break;
599,753✔
184
    }
185
    case TSDB_NORMAL_TABLE:
40,220✔
186
    case TSDB_VIRTUAL_NORMAL_TABLE: {
187
      schema = mer1.me.ntbEntry.schemaRow;
40,220✔
188
      break;
40,220✔
189
    }
190
    default: {
×
191
      vError("vnodeGetTableMeta get invalid table type:%d", mer1.me.type);
×
192
      goto _exit3;
×
193
    }
194
  }
195

196
  metaRsp.numOfTags = schemaTag.nCols;
1,997,345✔
197
  metaRsp.numOfColumns = schema.nCols;
1,997,345✔
198
  metaRsp.precision = pVnode->config.tsdbCfg.precision;
1,997,345✔
199
  metaRsp.sversion = schema.version;
1,997,345✔
200
  metaRsp.tversion = schemaTag.version;
1,997,345✔
201
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (metaRsp.numOfColumns + metaRsp.numOfTags));
1,997,345!
202
  metaRsp.pSchemaExt = (SSchemaExt *)taosMemoryCalloc(metaRsp.numOfColumns, sizeof(SSchemaExt));
1,997,086!
203
  if (NULL == metaRsp.pSchemas || NULL == metaRsp.pSchemaExt) {
1,996,585!
204
    code = terrno;
×
205
    goto _exit;
×
206
  }
207
  (void)memcpy(metaRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
1,996,672✔
208
  if (schemaTag.nCols) {
1,996,672✔
209
    (void)memcpy(metaRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
1,955,999✔
210
  }
211
  if (metaRsp.pSchemaExt) {
1,996,672✔
212
    SMetaReader *pReader = mer1.me.type == TSDB_CHILD_TABLE ? &mer2 : &mer1;
1,996,293✔
213
    code = fillTableColCmpr(pReader, metaRsp.pSchemaExt, metaRsp.numOfColumns);
1,996,293✔
214
    if (code < 0) {
1,996,964!
215
      goto _exit;
×
216
    }
217
    for (int32_t i = 0; i < metaRsp.numOfColumns && pReader->me.pExtSchemas; i++) {
2,054,918✔
218
      metaRsp.pSchemaExt[i].typeMod = pReader->me.pExtSchemas[i].typeMod;
57,954✔
219
    }
220
  } else {
221
    code = TSDB_CODE_OUT_OF_MEMORY;
379✔
222
    goto _exit;
379✔
223
  }
224
  if (hasRefCol(mer1.me.type)) {
1,996,964✔
225
    metaRsp.rversion = mer1.me.colRef.version;
486✔
226
    metaRsp.pColRefs = (SColRef*)taosMemoryMalloc(sizeof(SColRef) * metaRsp.numOfColumns);
486!
227
    if (metaRsp.pColRefs) {
415!
228
      code = fillTableColRef(&mer1, metaRsp.pColRefs, metaRsp.numOfColumns);
415✔
229
      if (code < 0) {
415!
230
        goto _exit;
×
231
      }
232
    }
233
    metaRsp.numOfColRefs = metaRsp.numOfColumns;
415✔
234
  } else {
235
    metaRsp.pColRefs = NULL;
1,996,408✔
236
    metaRsp.numOfColRefs = 0;
1,996,408✔
237
  }
238

239
  vnodePrintTableMeta(&metaRsp);
1,996,823✔
240

241
  // encode and send response
242
  rspLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
1,996,733✔
243
  if (rspLen < 0) {
1,996,658!
244
    code = terrno;
×
245
    goto _exit;
×
246
  }
247

248
  if (direct) {
1,996,658✔
249
    pRsp = rpcMallocCont(rspLen);
745✔
250
  } else {
251
    pRsp = taosMemoryCalloc(1, rspLen);
1,995,913!
252
  }
253

254
  if (pRsp == NULL) {
1,995,790!
255
    code = terrno;
×
256
    goto _exit;
×
257
  }
258

259
  rspLen = tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp);
1,995,790✔
260
  if (rspLen < 0) {
1,996,992!
261
    code = terrno;
×
262
    goto _exit;
×
263
  }
264

265
_exit:
1,996,992✔
266
  taosMemoryFree(metaRsp.pColRefs);
1,997,371!
267
  taosMemoryFree(metaRsp.pSchemas);
1,996,465!
268
  taosMemoryFree(metaRsp.pSchemaExt);
1,996,593!
269
_exit2:
1,997,070✔
270
  metaReaderClear(&mer2);
1,997,070✔
271
_exit3:
2,045,586✔
272
  metaReaderClear(&mer1);
2,045,586✔
273
_exit4:
2,045,927✔
274
  rpcMsg.info = pMsg->info;
2,045,927✔
275
  rpcMsg.pCont = pRsp;
2,045,927✔
276
  rpcMsg.contLen = rspLen;
2,045,927✔
277
  rpcMsg.code = code;
2,045,927✔
278
  rpcMsg.msgType = pMsg->msgType;
2,045,927✔
279

280
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST && autoCreateCtb == 1) {
2,045,927✔
281
    code = TSDB_CODE_SUCCESS;
39,037✔
282
  }
283

284
  if (code) {
2,045,927✔
285
    qError("get table %s meta with %" PRIu8 " failed cause of %s", infoReq.tbName, infoReq.option, tstrerror(code));
9,810!
286
  }
287

288
  if (direct) {
2,045,622✔
289
    tmsgSendRsp(&rpcMsg);
3,547✔
290
  } else {
291
    *pMsg = rpcMsg;
2,042,075✔
292
  }
293

294
  return code;
2,045,592✔
295
}
296

297
int32_t vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
169✔
298
  STableCfgReq   cfgReq = {0};
169✔
299
  STableCfgRsp   cfgRsp = {0};
169✔
300
  SMetaReader    mer1 = {0};
169✔
301
  SMetaReader    mer2 = {0};
169✔
302
  char           tableFName[TSDB_TABLE_FNAME_LEN];
303
  SRpcMsg        rpcMsg = {0};
169✔
304
  int32_t        code = 0;
169✔
305
  int32_t        rspLen = 0;
169✔
306
  void          *pRsp = NULL;
169✔
307
  SSchemaWrapper schema = {0};
169✔
308
  SSchemaWrapper schemaTag = {0};
169✔
309

310
  // decode req
311
  if (tDeserializeSTableCfgReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
169!
312
    code = terrno;
×
313
    goto _exit;
×
314
  }
315

316
  tstrncpy(cfgRsp.tbName, cfgReq.tbName, TSDB_TABLE_NAME_LEN);
169✔
317
  (void)memcpy(cfgRsp.dbFName, cfgReq.dbFName, sizeof(cfgRsp.dbFName));
169✔
318

319
  (void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", cfgReq.dbFName, cfgReq.tbName);
169✔
320
  if (pVnode->mounted) tTrimMountPrefix(tableFName);
169✔
321
  code = vnodeValidateTableHash(pVnode, tableFName);
169✔
322
  if (code) {
169!
323
    goto _exit;
×
324
  }
325

326
  // query meta
327
  metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
169✔
328

329
  if (metaGetTableEntryByName(&mer1, cfgReq.tbName) < 0) {
169!
330
    code = terrno;
×
331
    goto _exit;
×
332
  }
333

334
  cfgRsp.tableType = mer1.me.type;
169✔
335

336
  if (mer1.me.type == TSDB_SUPER_TABLE) {
169!
337
    code = TSDB_CODE_VND_HASH_MISMATCH;
×
338
    goto _exit;
×
339
  } else if (mer1.me.type == TSDB_CHILD_TABLE || mer1.me.type == TSDB_VIRTUAL_CHILD_TABLE) {
169✔
340
    metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
104✔
341
    if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit;
104!
342

343
    tstrncpy(cfgRsp.stbName, mer2.me.name, TSDB_TABLE_NAME_LEN);
104✔
344
    schema = mer2.me.stbEntry.schemaRow;
104✔
345
    schemaTag = mer2.me.stbEntry.schemaTag;
104✔
346
    cfgRsp.ttl = mer1.me.ctbEntry.ttlDays;
104✔
347
    cfgRsp.commentLen = mer1.me.ctbEntry.commentLen;
104✔
348
    if (mer1.me.ctbEntry.commentLen > 0) {
104!
349
      cfgRsp.pComment = taosStrdup(mer1.me.ctbEntry.comment);
×
350
      if (NULL == cfgRsp.pComment) {
×
351
        code = terrno;
×
352
        goto _exit;
×
353
      }
354
    }
355
    STag *pTag = (STag *)mer1.me.ctbEntry.pTags;
104✔
356
    cfgRsp.tagsLen = pTag->len;
104✔
357
    cfgRsp.pTags = taosMemoryMalloc(cfgRsp.tagsLen);
104!
358
    if (NULL == cfgRsp.pTags) {
104!
359
      code = terrno;
×
360
      goto _exit;
×
361
    }
362
    (void)memcpy(cfgRsp.pTags, pTag, cfgRsp.tagsLen);
104✔
363
  } else if (mer1.me.type == TSDB_NORMAL_TABLE || mer1.me.type == TSDB_VIRTUAL_NORMAL_TABLE) {
65!
364
    schema = mer1.me.ntbEntry.schemaRow;
65✔
365
    cfgRsp.ttl = mer1.me.ntbEntry.ttlDays;
65✔
366
    cfgRsp.commentLen = mer1.me.ntbEntry.commentLen;
65✔
367
    if (mer1.me.ntbEntry.commentLen > 0) {
65!
368
      cfgRsp.pComment = taosStrdup(mer1.me.ntbEntry.comment);
×
369
      if (NULL == cfgRsp.pComment) {
×
370
        code = terrno;
×
371
        goto _exit;
×
372
      }
373
    }
374
  } else {
375
    vError("vnodeGetTableCfg get invalid table type:%d", mer1.me.type);
×
376
    code = TSDB_CODE_APP_ERROR;
×
377
    goto _exit;
×
378
  }
379

380
  cfgRsp.numOfTags = schemaTag.nCols;
169✔
381
  cfgRsp.numOfColumns = schema.nCols;
169✔
382
  cfgRsp.virtualStb = false; // vnode don't have super table, so it's always false
169✔
383
  cfgRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (cfgRsp.numOfColumns + cfgRsp.numOfTags));
169!
384
  cfgRsp.pSchemaExt = (SSchemaExt *)taosMemoryMalloc(cfgRsp.numOfColumns * sizeof(SSchemaExt));
169!
385
  cfgRsp.pColRefs = (SColRef *)taosMemoryMalloc(sizeof(SColRef) * cfgRsp.numOfColumns);
169!
386

387
  if (NULL == cfgRsp.pSchemas || NULL == cfgRsp.pSchemaExt || NULL == cfgRsp.pColRefs) {
169!
388
    code = terrno;
×
389
    goto _exit;
×
390
  }
391
  (void)memcpy(cfgRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
169✔
392
  if (schemaTag.nCols) {
169✔
393
    (void)memcpy(cfgRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
104✔
394
  }
395

396
  SMetaReader     *pReader = (mer1.me.type == TSDB_CHILD_TABLE || mer1.me.type == TSDB_VIRTUAL_CHILD_TABLE) ? &mer2 : &mer1;
169✔
397
  SColCmprWrapper *pColCmpr = &pReader->me.colCmpr;
169✔
398
  SColRefWrapper  *pColRef = &mer1.me.colRef;
169✔
399

400
  if (withExtSchema(cfgRsp.tableType)) {
169✔
401
    for (int32_t i = 0; i < cfgRsp.numOfColumns; i++) {
1,161✔
402
      SColCmpr   *pCmpr = &pColCmpr->pColCmpr[i];
998✔
403
      SSchemaExt *pSchExt = cfgRsp.pSchemaExt + i;
998✔
404
      pSchExt->colId = pCmpr->id;
998✔
405
      pSchExt->compress = pCmpr->alg;
998✔
406
      if (pReader->me.pExtSchemas)
998!
407
        pSchExt->typeMod = pReader->me.pExtSchemas[i].typeMod;
×
408
      else
409
        pSchExt->typeMod = 0;
998✔
410
    }
411
  }
412

413
  cfgRsp.virtualStb = false;
169✔
414
  if (hasRefCol(cfgRsp.tableType)) {
169✔
415
    for (int32_t i = 0; i < cfgRsp.numOfColumns; i++) {
58✔
416
      SColRef *pRef = &pColRef->pColRef[i];
52✔
417
      cfgRsp.pColRefs[i].hasRef = pRef->hasRef;
52✔
418
      cfgRsp.pColRefs[i].id = pRef->id;
52✔
419
      if (cfgRsp.pColRefs[i].hasRef) {
52✔
420
        tstrncpy(cfgRsp.pColRefs[i].refDbName, pRef->refDbName, TSDB_DB_NAME_LEN);
23✔
421
        tstrncpy(cfgRsp.pColRefs[i].refTableName, pRef->refTableName, TSDB_TABLE_NAME_LEN);
23✔
422
        tstrncpy(cfgRsp.pColRefs[i].refColName, pRef->refColName, TSDB_COL_NAME_LEN);
23✔
423
      }
424
    }
425
  }
426

427
  // encode and send response
428
  rspLen = tSerializeSTableCfgRsp(NULL, 0, &cfgRsp);
169✔
429
  if (rspLen < 0) {
169!
430
    code = terrno;
×
431
    goto _exit;
×
432
  }
433

434
  if (direct) {
169!
435
    pRsp = rpcMallocCont(rspLen);
×
436
  } else {
437
    pRsp = taosMemoryCalloc(1, rspLen);
169!
438
  }
439

440
  if (pRsp == NULL) {
169!
441
    code = terrno;
×
442
    goto _exit;
×
443
  }
444

445
  rspLen = tSerializeSTableCfgRsp(pRsp, rspLen, &cfgRsp);
169✔
446
  if (rspLen < 0) {
169!
447
    code = terrno;
×
448
    goto _exit;
×
449
  }
450

451
_exit:
169✔
452
  rpcMsg.info = pMsg->info;
169✔
453
  rpcMsg.pCont = pRsp;
169✔
454
  rpcMsg.contLen = rspLen;
169✔
455
  rpcMsg.code = code;
169✔
456
  rpcMsg.msgType = pMsg->msgType;
169✔
457

458
  if (code) {
169!
459
    qError("get table %s cfg failed cause of %s", cfgReq.tbName, tstrerror(code));
×
460
  }
461

462
  if (direct) {
169!
463
    tmsgSendRsp(&rpcMsg);
×
464
  } else {
465
    *pMsg = rpcMsg;
169✔
466
  }
467

468
  tFreeSTableCfgRsp(&cfgRsp);
169✔
469
  metaReaderClear(&mer2);
169✔
470
  metaReaderClear(&mer1);
169✔
471
  return code;
169✔
472
}
473

474
static FORCE_INLINE void vnodeFreeSBatchRspMsg(void *p) {
475
  if (NULL == p) {
476
    return;
477
  }
478

479
  SBatchRspMsg *pRsp = (SBatchRspMsg *)p;
480
  rpcFreeCont(pRsp->msg);
481
}
482

483
int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
1,165,348✔
484
  int32_t      code = 0;
1,165,348✔
485
  int32_t      rspSize = 0;
1,165,348✔
486
  SBatchReq    batchReq = {0};
1,165,348✔
487
  SBatchMsg   *req = NULL;
1,165,348✔
488
  SBatchRspMsg rsp = {0};
1,165,348✔
489
  SBatchRsp    batchRsp = {0};
1,165,348✔
490
  SRpcMsg      reqMsg = *pMsg;
1,165,348✔
491
  SRpcMsg      rspMsg = {0};
1,165,348✔
492
  void        *pRsp = NULL;
1,165,348✔
493

494
  if (tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) {
1,165,348!
495
    code = terrno;
×
496
    qError("tDeserializeSBatchReq failed");
×
497
    goto _exit;
×
498
  }
499

500
  int32_t msgNum = taosArrayGetSize(batchReq.pMsgs);
1,166,237✔
501
  if (msgNum >= MAX_META_MSG_IN_BATCH) {
1,165,862!
502
    code = TSDB_CODE_INVALID_MSG;
×
503
    qError("too many msgs %d in vnode batch meta req", msgNum);
×
504
    goto _exit;
×
505
  }
506

507
  batchRsp.pRsps = taosArrayInit(msgNum, sizeof(SBatchRspMsg));
1,165,862✔
508
  if (NULL == batchRsp.pRsps) {
1,166,093!
509
    code = terrno;
×
510
    qError("taosArrayInit %d SBatchRspMsg failed", msgNum);
×
511
    goto _exit;
×
512
  }
513

514
  for (int32_t i = 0; i < msgNum; ++i) {
3,209,594✔
515
    req = taosArrayGet(batchReq.pMsgs, i);
2,044,454✔
516
    if (req == NULL) {
2,042,042✔
517
      code = terrno;
42✔
518
      goto _exit;
×
519
    }
520

521
    reqMsg.msgType = req->msgType;
2,042,000✔
522
    reqMsg.pCont = req->msg;
2,042,000✔
523
    reqMsg.contLen = req->msgLen;
2,042,000✔
524

525
    switch (req->msgType) {
2,042,000!
526
      case TDMT_VND_TABLE_META:
2,037,878✔
527
        // error code has been set into reqMsg, no need to handle it here.
528
        if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
2,037,878✔
529
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
6,331!
530
        }
531
        break;
2,040,123✔
532
      case TDMT_VND_TABLE_NAME:
1,690✔
533
        // error code has been set into reqMsg, no need to handle it here.
534
        if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
1,690✔
535
          qWarn("vnodeGetBatchName failed, msgType:%d", req->msgType);
677!
536
        }
537
        break;
1,690✔
538
      case TDMT_VND_TABLE_CFG:
169✔
539
        // error code has been set into reqMsg, no need to handle it here.
540
        if (TSDB_CODE_SUCCESS != vnodeGetTableCfg(pVnode, &reqMsg, false)) {
169!
541
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
×
542
        }
543
        break;
169✔
544
      case TDMT_VND_VSUBTABLES_META:
×
545
        // error code has been set into reqMsg, no need to handle it here.
546
        if (TSDB_CODE_SUCCESS != vnodeGetVSubtablesMeta(pVnode, &reqMsg)) {
×
547
          qWarn("vnodeGetVSubtablesMeta failed, msgType:%d", req->msgType);
×
548
        }
549
        break;
×
550
      case TDMT_VND_VSTB_REF_DBS:
2,263✔
551
        // error code has been set into reqMsg, no need to handle it here.
552
        if (TSDB_CODE_SUCCESS != vnodeGetVStbRefDbs(pVnode, &reqMsg)) {
2,263!
553
          qWarn("vnodeGetVStbRefDbs failed, msgType:%d", req->msgType);
×
554
        }
555
        break;
2,264✔
556
      default:
×
557
        qError("invalid req msgType %d", req->msgType);
×
558
        reqMsg.code = TSDB_CODE_INVALID_MSG;
×
559
        reqMsg.pCont = NULL;
×
560
        reqMsg.contLen = 0;
×
561
        break;
×
562
    }
563

564
    rsp.msgIdx = req->msgIdx;
2,044,246✔
565
    rsp.reqType = reqMsg.msgType;
2,044,246✔
566
    rsp.msgLen = reqMsg.contLen;
2,044,246✔
567
    rsp.rspCode = reqMsg.code;
2,044,246✔
568
    rsp.msg = reqMsg.pCont;
2,044,246✔
569

570
    if (NULL == taosArrayPush(batchRsp.pRsps, &rsp)) {
4,087,745!
571
      qError("taosArrayPush failed");
×
572
      code = terrno;
×
573
      goto _exit;
×
574
    }
575
  }
576

577
  rspSize = tSerializeSBatchRsp(NULL, 0, &batchRsp);
1,165,140✔
578
  if (rspSize < 0) {
1,166,328!
579
    qError("tSerializeSBatchRsp failed");
×
580
    code = terrno;
×
581
    goto _exit;
×
582
  }
583
  pRsp = rpcMallocCont(rspSize);
1,166,328✔
584
  if (pRsp == NULL) {
1,166,385!
585
    qError("rpcMallocCont %d failed", rspSize);
×
586
    code = terrno;
×
587
    goto _exit;
×
588
  }
589
  if (tSerializeSBatchRsp(pRsp, rspSize, &batchRsp) < 0) {
1,166,385!
590
    qError("tSerializeSBatchRsp %d failed", rspSize);
×
591
    code = terrno;
×
592
    goto _exit;
×
593
  }
594

595
_exit:
1,166,390✔
596

597
  rspMsg.info = pMsg->info;
1,166,390✔
598
  rspMsg.pCont = pRsp;
1,166,390✔
599
  rspMsg.contLen = rspSize;
1,166,390✔
600
  rspMsg.code = code;
1,166,390✔
601
  rspMsg.msgType = pMsg->msgType;
1,166,390✔
602

603
  if (code) {
1,166,390!
604
    qError("vnd get batch meta failed cause of %s", tstrerror(code));
×
605
  }
606

607
  taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
1,166,390✔
608
  taosArrayDestroyEx(batchRsp.pRsps, tFreeSBatchRspMsg);
1,166,248✔
609

610
  tmsgSendRsp(&rspMsg);
1,166,297✔
611

612
  return code;
1,166,390✔
613
}
614

615
#define VNODE_DO_META_QUERY(pVnode, cmd)                 \
616
  do {                                                   \
617
    (void)taosThreadRwlockRdlock(&(pVnode)->metaRWLock); \
618
    cmd;                                                 \
619
    (void)taosThreadRwlockUnlock(&(pVnode)->metaRWLock); \
620
  } while (0)
621

622
int32_t vnodeReadVSubtables(SReadHandle* pHandle, int64_t suid, SArray** ppRes) {
×
623
  int32_t                    code = TSDB_CODE_SUCCESS;
×
624
  int32_t                    line = 0;
×
625
  SMetaReader                mr = {0};
×
626
  bool                       readerInit = false;
×
627
  SVCTableRefCols*           pTb = NULL;
×
628
  int32_t                    refColsNum = 0;
×
629
  char                       tbFName[TSDB_TABLE_FNAME_LEN];
630
  SSHashObj*                 pSrcTbls = NULL;
×
631

632
  SArray *pList = taosArrayInit(10, sizeof(uint64_t));
×
633
  QUERY_CHECK_NULL(pList, code, line, _return, terrno);
×
634

635
  QUERY_CHECK_CODE(pHandle->api.metaFn.getChildTableList(pHandle->vnode, suid, pList), line, _return);
×
636

637
  size_t num = taosArrayGetSize(pList);
×
638
  *ppRes = taosArrayInit(num, POINTER_BYTES);
×
639
  QUERY_CHECK_NULL(*ppRes, code, line, _return, terrno);
×
640
  pSrcTbls = tSimpleHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY));
×
641
  QUERY_CHECK_NULL(pSrcTbls, code, line, _return, terrno);
×
642

643
  for (int32_t i = 0; i < num; ++i) {
×
644
    uint64_t* id = taosArrayGet(pList, i);
×
645
    QUERY_CHECK_NULL(id, code, line, _return, terrno);
×
646
    pHandle->api.metaReaderFn.initReader(&mr, pHandle->vnode, META_READER_LOCK, &pHandle->api.metaFn);
×
647
    QUERY_CHECK_CODE(pHandle->api.metaReaderFn.getTableEntryByUid(&mr, *id), line, _return);
×
648
    readerInit = true;
×
649

650
    refColsNum = 0;
×
651
    for (int32_t j = 0; j < mr.me.colRef.nCols; j++) {
×
652
      if (mr.me.colRef.pColRef[j].hasRef) {
×
653
        refColsNum++;
×
654
      }
655
    }
656

657
    if (refColsNum <= 0) {
×
658
      pHandle->api.metaReaderFn.clearReader(&mr);
×
659
      readerInit = false;
×
660
      continue;
×
661
    }
662

663
    pTb = taosMemoryCalloc(1, refColsNum * sizeof(SRefColInfo) + sizeof(*pTb));
×
664
    QUERY_CHECK_NULL(pTb, code, line, _return, terrno);
×
665

666
    pTb->uid = mr.me.uid;
×
667
    pTb->numOfColRefs = refColsNum;
×
668
    pTb->refCols = (SRefColInfo*)(pTb + 1);
×
669

670
    refColsNum = 0;
×
671
    tSimpleHashClear(pSrcTbls);
×
672
    for (int32_t j = 0; j < mr.me.colRef.nCols; j++) {
×
673
      if (!mr.me.colRef.pColRef[j].hasRef) {
×
674
        continue;
×
675
      }
676

677
      pTb->refCols[refColsNum].colId = mr.me.colRef.pColRef[j].id;
×
678
      tstrncpy(pTb->refCols[refColsNum].refColName, mr.me.colRef.pColRef[j].refColName, TSDB_COL_NAME_LEN);
×
679
      tstrncpy(pTb->refCols[refColsNum].refTableName, mr.me.colRef.pColRef[j].refTableName, TSDB_TABLE_NAME_LEN);
×
680
      tstrncpy(pTb->refCols[refColsNum].refDbName, mr.me.colRef.pColRef[j].refDbName, TSDB_DB_NAME_LEN);
×
681

682
      snprintf(tbFName, sizeof(tbFName), "%s.%s", pTb->refCols[refColsNum].refDbName, pTb->refCols[refColsNum].refTableName);
×
683

684
      if (NULL == tSimpleHashGet(pSrcTbls, tbFName, strlen(tbFName))) {
×
685
        QUERY_CHECK_CODE(tSimpleHashPut(pSrcTbls, tbFName, strlen(tbFName), &code, sizeof(code)), line, _return);
×
686
      }
687

688
      refColsNum++;
×
689
    }
690

691
    pTb->numOfSrcTbls = tSimpleHashGetSize(pSrcTbls);
×
692
    QUERY_CHECK_NULL(taosArrayPush(*ppRes, &pTb), code, line, _return, terrno);
×
693
    pTb = NULL;
×
694

695
    pHandle->api.metaReaderFn.clearReader(&mr);
×
696
    readerInit = false;
×
697
  }
698

699
_return:
×
700

701
  if (readerInit) {
×
702
    pHandle->api.metaReaderFn.clearReader(&mr);
×
703
  }
704

705
  taosArrayDestroy(pList);
×
706
  taosMemoryFree(pTb);
×
707
  tSimpleHashCleanup(pSrcTbls);
×
708

709
  if (code) {
×
710
    qError("%s failed since %s", __func__, tstrerror(code));
×
711
  }
712
  return code;
×
713
}
714

715
int32_t vnodeReadVStbRefDbs(SReadHandle* pHandle, int64_t suid, SArray** ppRes) {
2,264✔
716
  int32_t                    code = TSDB_CODE_SUCCESS;
2,264✔
717
  int32_t                    line = 0;
2,264✔
718
  SMetaReader                mr = {0};
2,264✔
719
  bool                       readerInit = false;
2,264✔
720
  SSHashObj*                 pDbNameHash = NULL;
2,264✔
721
  SArray*                    pList = NULL;
2,264✔
722

723
  pList = taosArrayInit(10, sizeof(uint64_t));
2,264✔
724
  QUERY_CHECK_NULL(pList, code, line, _return, terrno);
2,265!
725

726
  *ppRes = taosArrayInit(10, POINTER_BYTES);
2,265✔
727
  QUERY_CHECK_NULL(*ppRes, code, line, _return, terrno)
2,266!
728
  
729
  // lookup in cache
730
  code = pHandle->api.metaFn.metaGetCachedRefDbs(pHandle->vnode, suid, *ppRes);
2,266✔
731
  QUERY_CHECK_CODE(code, line, _return);
2,266!
732

733
  if (taosArrayGetSize(*ppRes) > 0) {
2,266✔
734
    // found in cache
735
    goto _return;
2,225✔
736
  } else {
737
    code = pHandle->api.metaFn.getChildTableList(pHandle->vnode, suid, pList);
41✔
738
    QUERY_CHECK_CODE(code, line, _return);
41!
739

740
    size_t num = taosArrayGetSize(pList);
41✔
741
    pDbNameHash = tSimpleHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY));
41✔
742
    QUERY_CHECK_NULL(pDbNameHash, code, line, _return, terrno);
41!
743

744
    for (int32_t i = 0; i < num; ++i) {
148✔
745
      uint64_t* id = taosArrayGet(pList, i);
107✔
746
      QUERY_CHECK_NULL(id, code, line, _return, terrno);
107!
747

748
      pHandle->api.metaReaderFn.initReader(&mr, pHandle->vnode, META_READER_LOCK, &pHandle->api.metaFn);
107✔
749
      readerInit = true;
107✔
750

751
      code = pHandle->api.metaReaderFn.getTableEntryByUid(&mr, *id);
107✔
752
      QUERY_CHECK_CODE(code, line, _return);
107!
753

754
      for (int32_t j = 0; j < mr.me.colRef.nCols; j++) {
841✔
755
        if (mr.me.colRef.pColRef[j].hasRef) {
732✔
756
          if (NULL == tSimpleHashGet(pDbNameHash, mr.me.colRef.pColRef[j].refDbName, strlen(mr.me.colRef.pColRef[j].refDbName))) {
471✔
757
            char *refDbName = taosStrdup(mr.me.colRef.pColRef[j].refDbName);
55!
758
            QUERY_CHECK_NULL(refDbName, code, line, _return, terrno);
53!
759

760
            QUERY_CHECK_NULL(taosArrayPush(*ppRes, &refDbName), code, line, _return, terrno);
106!
761

762
            code = tSimpleHashPut(pDbNameHash, refDbName, strlen(refDbName), NULL, 0);
53✔
763
            QUERY_CHECK_CODE(code, line, _return);
53!
764
          }
765
        }
766
      }
767

768
      pHandle->api.metaReaderFn.clearReader(&mr);
109✔
769
      readerInit = false;
107✔
770
    }
771

772
    code = pHandle->api.metaFn.metaPutRefDbsToCache(pHandle->vnode, suid, *ppRes);
41✔
773
    QUERY_CHECK_CODE(code, line, _return);
41!
774
  }
775

776
_return:
41✔
777

778
  if (readerInit) {
2,266!
779
    pHandle->api.metaReaderFn.clearReader(&mr);
×
780
  }
781

782
  taosArrayDestroy(pList);
2,266✔
783
  tSimpleHashCleanup(pDbNameHash);
2,266✔
784

785
  if (code) {
2,265!
786
    qError("%s failed since %s", __func__, tstrerror(code));
×
787
  }
788
  return code;
2,265✔
789
}
790

791
int32_t vnodeGetVSubtablesMeta(SVnode *pVnode, SRpcMsg *pMsg) {
×
792
  int32_t        code = 0;
×
793
  int32_t        rspSize = 0;
×
794
  SVSubTablesReq req = {0};
×
795
  SVSubTablesRsp rsp = {0};
×
796
  SRpcMsg      rspMsg = {0};
×
797
  void        *pRsp = NULL;
×
798
  int32_t      line = 0;
×
799

800
  if (tDeserializeSVSubTablesReq(pMsg->pCont, pMsg->contLen, &req)) {
×
801
    code = terrno;
×
802
    qError("tDeserializeSVSubTablesReq failed");
×
803
    goto _return;
×
804
  }
805

806
  SReadHandle handle = {0};
×
807
  handle.vnode = pVnode;
×
808
  initStorageAPI(&handle.api);
×
809

810
  QUERY_CHECK_CODE(vnodeReadVSubtables(&handle, req.suid, &rsp.pTables), line, _return);
×
811
  rsp.vgId = TD_VID(pVnode);
×
812

813
  rspSize = tSerializeSVSubTablesRsp(NULL, 0, &rsp);
×
814
  if (rspSize < 0) {
×
815
    code = rspSize;
×
816
    qError("tSerializeSVSubTablesRsp failed, error:%d", rspSize);
×
817
    goto _return;
×
818
  }
819
  pRsp = taosMemoryCalloc(1, rspSize);
×
820
  if (pRsp == NULL) {
×
821
    code = terrno;
×
822
    qError("rpcMallocCont %d failed, error:%d", rspSize, terrno);
×
823
    goto _return;
×
824
  }
825
  rspSize = tSerializeSVSubTablesRsp(pRsp, rspSize, &rsp);
×
826
  if (rspSize < 0) {
×
827
    code = rspSize;
×
828
    qError("tSerializeSVSubTablesRsp failed, error:%d", rspSize);
×
829
    goto _return;
×
830
  }
831

832
_return:
×
833

834
  rspMsg.info = pMsg->info;
×
835
  rspMsg.pCont = pRsp;
×
836
  rspMsg.contLen = rspSize;
×
837
  rspMsg.code = code;
×
838
  rspMsg.msgType = pMsg->msgType;
×
839

840
  if (code) {
×
841
    qError("vnd get virtual subtables failed cause of %s", tstrerror(code));
×
842
  }
843

844
  *pMsg = rspMsg;
×
845
  
846
  tDestroySVSubTablesRsp(&rsp);
×
847

848
  //tmsgSendRsp(&rspMsg);
849

850
  return code;
×
851
}
852

853
int32_t vnodeGetVStbRefDbs(SVnode *pVnode, SRpcMsg *pMsg) {
2,263✔
854
  int32_t        code = 0;
2,263✔
855
  int32_t        rspSize = 0;
2,263✔
856
  SVStbRefDbsReq req = {0};
2,263✔
857
  SVStbRefDbsRsp rsp = {0};
2,263✔
858
  SRpcMsg        rspMsg = {0};
2,263✔
859
  void          *pRsp = NULL;
2,263✔
860
  int32_t        line = 0;
2,263✔
861

862
  if (tDeserializeSVStbRefDbsReq(pMsg->pCont, pMsg->contLen, &req)) {
2,263!
863
    code = terrno;
×
864
    qError("tDeserializeSVSubTablesReq failed");
×
865
    goto _return;
×
866
  }
867

868
  SReadHandle handle = {0};
2,266✔
869
  handle.vnode = pVnode;
2,266✔
870
  initStorageAPI(&handle.api);
2,266✔
871

872
  code = vnodeReadVStbRefDbs(&handle, req.suid, &rsp.pDbs);
2,266✔
873
  QUERY_CHECK_CODE(code, line, _return);
2,265!
874
  rsp.vgId = TD_VID(pVnode);
2,265✔
875

876
  rspSize = tSerializeSVStbRefDbsRsp(NULL, 0, &rsp);
2,265✔
877
  if (rspSize < 0) {
2,265!
878
    code = rspSize;
×
879
    qError("tSerializeSVStbRefDbsRsp failed, error:%d", rspSize);
×
880
    goto _return;
×
881
  }
882
  pRsp = taosMemoryCalloc(1, rspSize);
2,265!
883
  if (pRsp == NULL) {
2,264!
884
    code = terrno;
×
885
    qError("rpcMallocCont %d failed, error:%d", rspSize, terrno);
×
886
    goto _return;
×
887
  }
888
  rspSize = tSerializeSVStbRefDbsRsp(pRsp, rspSize, &rsp);
2,264✔
889
  if (rspSize < 0) {
2,263!
890
    code = rspSize;
×
891
    qError("tSerializeSVStbRefDbsRsp failed, error:%d", rspSize);
×
892
    goto _return;
×
893
  }
894

895
_return:
2,263✔
896

897
  rspMsg.info = pMsg->info;
2,263✔
898
  rspMsg.pCont = pRsp;
2,263✔
899
  rspMsg.contLen = rspSize;
2,263✔
900
  rspMsg.code = code;
2,263✔
901
  rspMsg.msgType = pMsg->msgType;
2,263✔
902

903
  if (code) {
2,263!
904
    qError("vnd get virtual stb ref db failed cause of %s", tstrerror(code));
×
905
  }
906

907
  *pMsg = rspMsg;
2,263✔
908

909
  tDestroySVStbRefDbsRsp(&rsp);
2,263✔
910

911
  return code;
2,265✔
912
}
913

914
static int32_t vnodeGetCompStorage(SVnode *pVnode, int64_t *output) {
658,354✔
915
  int32_t code = 0;
658,354✔
916
#ifdef TD_ENTERPRISE
917
  int32_t now = taosGetTimestampSec();
658,354✔
918
  if (llabs(now - pVnode->config.vndStats.storageLastUpd) >= 30) {
658,354✔
919
    pVnode->config.vndStats.storageLastUpd = now;
27,523✔
920

921
    SDbSizeStatisInfo info = {0};
27,523✔
922
    if (0 == (code = vnodeGetDBSize(pVnode, &info))) {
27,523!
923
      int64_t compSize =
27,523✔
924
          info.l1Size + info.l2Size + info.l3Size + info.cacheSize + info.walSize + info.metaSize + +info.ssSize;
27,523✔
925
      if (compSize >= 0) {
27,523!
926
        pVnode->config.vndStats.compStorage = compSize;
27,523✔
927
      } else {
928
        vError("vnode get comp storage failed since compSize is negative:%" PRIi64, compSize);
×
929
        code = TSDB_CODE_APP_ERROR;
×
930
      }
931
    } else {
932
      vWarn("vnode get comp storage failed since %s", tstrerror(code));
×
933
    }
934
  }
935
  if (output) *output = pVnode->config.vndStats.compStorage;
658,354!
936
#endif
937
  return code;
658,354✔
938
}
939

940
static void vnodeGetBufferInfo(SVnode *pVnode, int64_t *bufferSegmentUsed, int64_t *bufferSegmentSize) {
658,354✔
941
  *bufferSegmentUsed = 0;
658,354✔
942
  *bufferSegmentSize = 0;
658,354✔
943
  if (pVnode) {
658,354!
944
    (void)taosThreadMutexLock(&pVnode->mutex);
658,354✔
945

946
    if (pVnode->inUse) {
658,354✔
947
      *bufferSegmentUsed = pVnode->inUse->size;
658,314✔
948
    }
949
    *bufferSegmentSize = pVnode->config.szBuf / VNODE_BUFPOOL_SEGMENTS;
658,354✔
950

951
    (void)taosThreadMutexUnlock(&pVnode->mutex);
658,354✔
952
  }
953
}
658,354✔
954

955
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
658,354✔
956
  SSyncState state = syncGetState(pVnode->sync);
658,354✔
957
  pLoad->syncAppliedIndex = pVnode->state.applied;
658,354✔
958
  syncGetCommitIndex(pVnode->sync, &pLoad->syncCommitIndex);
658,354✔
959

960
  pLoad->vgId = TD_VID(pVnode);
658,354✔
961
  pLoad->syncState = state.state;
658,354✔
962
  pLoad->syncRestore = state.restored;
658,354✔
963
  pLoad->syncTerm = state.term;
658,354✔
964
  pLoad->roleTimeMs = state.roleTimeMs;
658,354✔
965
  pLoad->startTimeMs = state.startTimeMs;
658,354✔
966
  pLoad->syncCanRead = state.canRead;
658,354✔
967
  pLoad->learnerProgress = state.progress;
658,354✔
968
  pLoad->cacheUsage = tsdbCacheGetUsage(pVnode);
658,354✔
969
  pLoad->numOfCachedTables = tsdbCacheGetElems(pVnode);
658,354✔
970
  VNODE_DO_META_QUERY(pVnode, pLoad->numOfTables = metaGetTbNum(pVnode->pMeta));
658,354✔
971
  VNODE_DO_META_QUERY(pVnode, pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1));
658,354✔
972
  pLoad->totalStorage = (int64_t)3 * 1073741824;  // TODO
658,354✔
973
  (void)vnodeGetCompStorage(pVnode, &pLoad->compStorage);
658,354✔
974
  pLoad->pointsWritten = 100;
658,354✔
975
  pLoad->numOfSelectReqs = 1;
658,354✔
976
  pLoad->numOfInsertReqs = atomic_load_64(&pVnode->statis.nInsert);
658,354✔
977
  pLoad->numOfInsertSuccessReqs = atomic_load_64(&pVnode->statis.nInsertSuccess);
658,354✔
978
  pLoad->numOfBatchInsertReqs = atomic_load_64(&pVnode->statis.nBatchInsert);
658,354✔
979
  pLoad->numOfBatchInsertSuccessReqs = atomic_load_64(&pVnode->statis.nBatchInsertSuccess);
658,354✔
980
  vnodeGetBufferInfo(pVnode, &pLoad->bufferSegmentUsed, &pLoad->bufferSegmentSize);
658,354✔
981
  return 0;
658,354✔
982
}
983

984
int32_t vnodeGetLoadLite(SVnode *pVnode, SVnodeLoadLite *pLoad) {
×
985
  SSyncState syncState = syncGetState(pVnode->sync);
×
986
  if (syncState.state == TAOS_SYNC_STATE_LEADER || syncState.state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
×
987
    pLoad->vgId = TD_VID(pVnode);
×
988
    pLoad->nTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1);
×
989
    return 0;
×
990
  }
991
  return -1;
×
992
}
993
/**
994
 * @brief Reset the statistics value by monitor interval
995
 *
996
 * @param pVnode
997
 * @param pLoad
998
 */
999
void vnodeResetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
6✔
1000
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsert, pLoad->numOfInsertReqs, 64, "nInsert");
6!
1001
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsertSuccess, pLoad->numOfInsertSuccessReqs, 64, "nInsertSuccess");
6!
1002
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsert, pLoad->numOfBatchInsertReqs, 64, "nBatchInsert");
6!
1003
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsertSuccess, pLoad->numOfBatchInsertSuccessReqs, 64,
6!
1004
                            "nBatchInsertSuccess");
1005
}
6✔
1006

1007
void vnodeGetInfo(void *pVnode, const char **dbname, int32_t *vgId, int64_t *numOfTables, int64_t *numOfNormalTables) {
974,405✔
1008
  SVnode    *pVnodeObj = pVnode;
974,405✔
1009
  SVnodeCfg *pConf = &pVnodeObj->config;
974,405✔
1010

1011
  if (dbname) {
974,405!
1012
    *dbname = pConf->dbname;
975,308✔
1013
  }
1014

1015
  if (vgId) {
974,405!
1016
    *vgId = TD_VID(pVnodeObj);
974,435✔
1017
  }
1018

1019
  if (numOfTables) {
974,405!
1020
    *numOfTables = pConf->vndStats.numOfNTables + pConf->vndStats.numOfCTables;
×
1021
  }
1022

1023
  if (numOfNormalTables) {
974,405!
1024
    *numOfNormalTables = pConf->vndStats.numOfNTables;
×
1025
  }
1026
}
974,405✔
1027

1028
int32_t vnodeGetTableList(void *pVnode, int8_t type, SArray *pList) {
×
1029
  if (type == TSDB_SUPER_TABLE) {
×
1030
    return vnodeGetStbIdList(pVnode, 0, pList);
×
1031
  } else {
1032
    return TSDB_CODE_INVALID_PARA;
×
1033
  }
1034
}
1035

1036
int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) {
×
1037
  int32_t      code = TSDB_CODE_SUCCESS;
×
1038
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, uid, 1);
×
1039
  if (NULL == pCur) {
×
1040
    qError("vnode get all table list failed");
×
1041
    return terrno;
×
1042
  }
1043

1044
  while (1) {
×
1045
    tb_uid_t id = metaCtbCursorNext(pCur);
×
1046
    if (id == 0) {
×
1047
      break;
×
1048
    }
1049

1050
    STableKeyInfo info = {uid = id};
×
1051
    if (NULL == taosArrayPush(list, &info)) {
×
1052
      qError("taosArrayPush failed");
×
1053
      code = terrno;
×
1054
      goto _exit;
×
1055
    }
1056
  }
1057
_exit:
×
1058
  metaCloseCtbCursor(pCur);
×
1059
  return code;
×
1060
}
1061

1062
int32_t vnodeGetCtbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg), void *arg) {
×
1063
  return 0;
×
1064
}
1065

1066
int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) {
2,349,207✔
1067
  int32_t      code = TSDB_CODE_SUCCESS;
2,349,207✔
1068
  SVnode      *pVnodeObj = pVnode;
2,349,207✔
1069
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnodeObj, suid, 1);
2,349,207✔
1070
  if (NULL == pCur) {
2,351,776!
1071
    qError("vnode get all table list failed");
×
1072
    return terrno;
×
1073
  }
1074

1075
  while (1) {
7,314,871✔
1076
    tb_uid_t id = metaCtbCursorNext(pCur);
9,666,647✔
1077
    if (id == 0) {
9,665,134✔
1078
      break;
2,354,842✔
1079
    }
1080

1081
    if (NULL == taosArrayPush(list, &id)) {
7,314,871!
1082
      qError("taosArrayPush failed");
×
1083
      code = terrno;
×
1084
      goto _exit;
×
1085
    }
1086
  }
1087

1088
_exit:
2,354,842✔
1089
  metaCloseCtbCursor(pCur);
2,354,842✔
1090
  return code;
2,352,886✔
1091
}
1092

1093
int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) {
213,346✔
1094
  int32_t      code = TSDB_CODE_SUCCESS;
213,346✔
1095
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
213,346✔
1096
  if (!pCur) {
213,346!
1097
    return TSDB_CODE_OUT_OF_MEMORY;
×
1098
  }
1099

1100
  while (1) {
632,123✔
1101
    tb_uid_t id = metaStbCursorNext(pCur);
845,469✔
1102
    if (id == 0) {
845,465✔
1103
      break;
213,346✔
1104
    }
1105

1106
    if (NULL == taosArrayPush(list, &id)) {
632,123!
1107
      qError("taosArrayPush failed");
×
1108
      code = terrno;
×
1109
      goto _exit;
×
1110
    }
1111
  }
1112

1113
_exit:
213,346✔
1114
  metaCloseStbCursor(pCur);
213,346✔
1115
  return code;
213,346✔
1116
}
1117

1118
int32_t vnodeGetStbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg, void *arg1),
2✔
1119
                                  void *arg) {
1120
  int32_t      code = TSDB_CODE_SUCCESS;
2✔
1121
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
2✔
1122
  if (!pCur) {
2!
1123
    return terrno;
×
1124
  }
1125

1126
  while (1) {
10✔
1127
    tb_uid_t id = metaStbCursorNext(pCur);
12✔
1128
    if (id == 0) {
12✔
1129
      break;
2✔
1130
    }
1131

1132
    if ((*filter) && (*filter)(arg, &id)) {
10!
1133
      continue;
10✔
1134
    }
1135

1136
    if (NULL == taosArrayPush(list, &id)) {
×
1137
      qError("taosArrayPush failed");
×
1138
      code = terrno;
×
1139
      goto _exit;
×
1140
    }
1141
  }
1142

1143
_exit:
2✔
1144
  metaCloseStbCursor(pCur);
2✔
1145
  return code;
2✔
1146
}
1147

1148
int32_t vnodeGetCtbNum(SVnode *pVnode, int64_t suid, int64_t *num) {
21,876✔
1149
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, suid, 0);
21,876✔
1150
  if (!pCur) {
21,877!
1151
    return terrno;
×
1152
  }
1153

1154
  *num = 0;
21,879✔
1155
  while (1) {
13,104✔
1156
    tb_uid_t id = metaCtbCursorNext(pCur);
34,983✔
1157
    if (id == 0) {
34,985✔
1158
      break;
21,881✔
1159
    }
1160

1161
    ++(*num);
13,104✔
1162
  }
1163

1164
  metaCloseCtbCursor(pCur);
21,881✔
1165
  return TSDB_CODE_SUCCESS;
21,881✔
1166
}
1167

1168
int32_t vnodeGetStbColumnNum(SVnode *pVnode, tb_uid_t suid, int *num) {
21,874✔
1169
  SSchemaWrapper *pSW = metaGetTableSchema(pVnode->pMeta, suid, -1, 0, NULL, 0);
21,874✔
1170
  if (pSW) {
21,876!
1171
    *num = pSW->nCols;
21,876!
1172
    tDeleteSchemaWrapper(pSW);
1173
  } else {
1174
    *num = 2;
×
1175
  }
1176

1177
  return TSDB_CODE_SUCCESS;
21,875✔
1178
}
1179

1180
int32_t vnodeGetStbInfo(SVnode *pVnode, tb_uid_t suid, int64_t *keep, int8_t *flags) {
21,876✔
1181
  SMetaReader mr = {0};
21,876✔
1182
  metaReaderDoInit(&mr, pVnode->pMeta, META_READER_NOLOCK);
21,876✔
1183

1184
  int32_t code = metaReaderGetTableEntryByUid(&mr, suid);
21,878✔
1185
  if (code == TSDB_CODE_SUCCESS) {
21,878!
1186
    if (keep) *keep = mr.me.stbEntry.keep;
21,878!
1187
    if (flags) *flags = mr.me.flags;
21,878!
1188
  } else {
1189
    if (keep) *keep = 0;
×
1190
    if (flags) *flags = 0;
×
1191
  }
1192

1193
  metaReaderClear(&mr);
21,878✔
1194
  return TSDB_CODE_SUCCESS;
21,881✔
1195
}
1196

1197
#ifdef TD_ENTERPRISE
1198
const char *tkLogStb[] = {"cluster_info",
1199
                          "data_dir",
1200
                          "dnodes_info",
1201
                          "d_info",
1202
                          "grants_info",
1203
                          "keeper_monitor",
1204
                          "logs",
1205
                          "log_dir",
1206
                          "log_summary",
1207
                          "m_info",
1208
                          "taosadapter_restful_http_request_fail",
1209
                          "taosadapter_restful_http_request_in_flight",
1210
                          "taosadapter_restful_http_request_summary_milliseconds",
1211
                          "taosadapter_restful_http_request_total",
1212
                          "taosadapter_system_cpu_percent",
1213
                          "taosadapter_system_mem_percent",
1214
                          "temp_dir",
1215
                          "vgroups_info",
1216
                          "vnodes_role"};
1217
const char *tkAuditStb[] = {"operations"};
1218
const int   tkLogStbNum = ARRAY_SIZE(tkLogStb);
1219
const int   tkAuditStbNum = ARRAY_SIZE(tkAuditStb);
1220

1221
// exclude stbs of taoskeeper log
1222
static int32_t vnodeGetTimeSeriesBlackList(SVnode *pVnode, int32_t *tbSize) {
213,354✔
1223
  int32_t      code = TSDB_CODE_SUCCESS;
213,354✔
1224
  int32_t      tbNum = 0;
213,354✔
1225
  const char **pTbArr = NULL;
213,354✔
1226
  const char  *dbName = NULL;
213,354✔
1227
  *tbSize = 0;
213,354✔
1228

1229
  if (!(dbName = strchr(pVnode->config.dbname, '.'))) return 0;
213,354!
1230
  if (0 == strncmp(++dbName, "log", TSDB_DB_NAME_LEN)) {
213,354✔
1231
    tbNum = tkLogStbNum;
14✔
1232
    pTbArr = (const char **)&tkLogStb;
14✔
1233
  } else if (0 == strncmp(dbName, "audit", TSDB_DB_NAME_LEN)) {
213,340!
1234
    tbNum = tkAuditStbNum;
×
1235
    pTbArr = (const char **)&tkAuditStb;
×
1236
  }
1237
  if (tbNum && pTbArr) {
213,354!
1238
    *tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 0);
14✔
1239
    if (*tbSize < tbNum) {
14!
1240
      for (int32_t i = 0; i < tbNum; ++i) {
190✔
1241
        tb_uid_t suid = metaGetTableEntryUidByName(pVnode->pMeta, pTbArr[i]);
186✔
1242
        if (suid != 0) {
186✔
1243
          code = metaPutTbToFilterCache(pVnode->pMeta, &suid, 0);
20✔
1244
          if (TSDB_CODE_SUCCESS != code) {
20✔
1245
            return code;
10✔
1246
          }
1247
        }
1248
      }
1249
      *tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 0);
4✔
1250
    }
1251
  }
1252

1253
  return code;
213,344✔
1254
}
1255
#endif
1256

1257
static bool vnodeTimeSeriesFilter(void *arg1, void *arg2) {
10✔
1258
  SVnode *pVnode = (SVnode *)arg1;
10✔
1259

1260
  if (metaTbInFilterCache(pVnode->pMeta, arg2, 0)) {
10!
1261
    return true;
10✔
1262
  }
1263
  return false;
×
1264
}
1265

1266
int32_t vnodeGetTimeSeriesNum(SVnode *pVnode, int64_t *num) {
213,354✔
1267
  SArray *suidList = NULL;
213,354✔
1268

1269
  if (!(suidList = taosArrayInit(1, sizeof(tb_uid_t)))) {
213,354!
1270
    return terrno;
×
1271
  }
1272

1273
  int32_t tbFilterSize = 0;
213,354✔
1274
  int32_t code = TSDB_CODE_SUCCESS;
213,354✔
1275
#ifdef TD_ENTERPRISE
1276
  code = vnodeGetTimeSeriesBlackList(pVnode, &tbFilterSize);
213,354✔
1277
  if (TSDB_CODE_SUCCESS != code) {
213,354✔
1278
    goto _exit;
10✔
1279
  }
1280
#endif
1281

1282
  if ((!tbFilterSize && vnodeGetStbIdList(pVnode, 0, suidList) < 0) ||
213,344!
1283
      (tbFilterSize && vnodeGetStbIdListByFilter(pVnode, 0, suidList, vnodeTimeSeriesFilter, pVnode) < 0)) {
213,344!
1284
    qError("vgId:%d, failed to get stb id list error: %s", TD_VID(pVnode), terrstr());
×
1285
    taosArrayDestroy(suidList);
×
1286
    return terrno;
×
1287
  }
1288

1289
  *num = 0;
213,344✔
1290
  int64_t arrSize = taosArrayGetSize(suidList);
213,344✔
1291
  for (int64_t i = 0; i < arrSize; ++i) {
845,472✔
1292
    tb_uid_t suid = *(tb_uid_t *)taosArrayGet(suidList, i);
632,127✔
1293

1294
    int64_t ctbNum = 0;
632,127✔
1295
    int32_t numOfCols = 0;
632,127✔
1296
    int8_t  flags = 0;
632,127✔
1297
    code = metaGetStbStats(pVnode, suid, &ctbNum, &numOfCols, &flags);
632,127✔
1298
    if (TSDB_CODE_SUCCESS != code) {
632,128!
1299
      goto _exit;
×
1300
    }
1301
    if (!TABLE_IS_VIRTUAL(flags)) {
632,128✔
1302
      *num += ctbNum * (numOfCols - 1);
630,354✔
1303
    }
1304
  }
1305

1306
_exit:
213,345✔
1307
  taosArrayDestroy(suidList);
213,355✔
1308
  return TSDB_CODE_SUCCESS;
213,354✔
1309
}
1310

1311
int32_t vnodeGetAllCtbNum(SVnode *pVnode, int64_t *num) {
×
1312
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, 0);
×
1313
  if (!pCur) {
×
1314
    return terrno;
×
1315
  }
1316

1317
  *num = 0;
×
1318
  while (1) {
×
1319
    tb_uid_t id = metaStbCursorNext(pCur);
×
1320
    if (id == 0) {
×
1321
      break;
×
1322
    }
1323

1324
    int64_t ctbNum = 0;
×
1325
    int32_t code = vnodeGetCtbNum(pVnode, id, &ctbNum);
×
1326
    if (TSDB_CODE_SUCCESS != code) {
×
1327
      metaCloseStbCursor(pCur);
×
1328
      return code;
×
1329
    }
1330

1331
    *num += ctbNum;
×
1332
  }
1333

1334
  metaCloseStbCursor(pCur);
×
1335
  return TSDB_CODE_SUCCESS;
×
1336
}
1337

1338
void *vnodeGetIdx(void *pVnode) {
55,990✔
1339
  if (pVnode == NULL) {
55,990!
1340
    return NULL;
×
1341
  }
1342

1343
  return metaGetIdx(((SVnode *)pVnode)->pMeta);
55,990✔
1344
}
1345

1346
void *vnodeGetIvtIdx(void *pVnode) {
55,913✔
1347
  if (pVnode == NULL) {
55,913!
1348
    return NULL;
×
1349
  }
1350
  return metaGetIvtIdx(((SVnode *)pVnode)->pMeta);
55,913✔
1351
}
1352

1353
int32_t vnodeGetTableSchema(void *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid, SSchemaWrapper **pTagSchema) {
134✔
1354
  return tsdbGetTableSchema(((SVnode *)pVnode)->pMeta, uid, pSchema, suid, pTagSchema);
134✔
1355
}
1356

1357
static FORCE_INLINE int32_t vnodeGetDBPrimaryInfo(SVnode *pVnode, SDbSizeStatisInfo *pInfo) {
1358
  int32_t code = 0;
27,601✔
1359
  char    path[TSDB_FILENAME_LEN] = {0};
27,601✔
1360

1361
  char   *dirName[] = {VNODE_TSDB_DIR, VNODE_WAL_DIR, VNODE_META_DIR, VNODE_TSDB_CACHE_DIR};
27,601✔
1362
  int64_t dirSize[4];
1363

1364
  vnodeGetPrimaryPath(pVnode, false, path, TSDB_FILENAME_LEN);
27,601✔
1365
  int32_t offset = strlen(path);
27,601✔
1366

1367
  for (int i = 0; i < sizeof(dirName) / sizeof(dirName[0]); i++) {
138,005✔
1368
    int64_t size = {0};
110,404✔
1369
    (void)snprintf(path + offset, TSDB_FILENAME_LEN - offset, "%s%s", TD_DIRSEP, dirName[i]);
110,404✔
1370
    code = taosGetDirSize(path, &size);
110,404✔
1371
    if (code != 0) {
110,404!
1372
      uWarn("vnode %d get dir %s %s size failed since %s", TD_VID(pVnode), path, dirName[i], tstrerror(code));
×
1373
    }
1374
    path[offset] = 0;
110,404✔
1375
    dirSize[i] = size;
110,404✔
1376
  }
1377

1378
  pInfo->l1Size = 0;
27,601✔
1379
  pInfo->walSize = dirSize[1];
27,601✔
1380
  pInfo->metaSize = dirSize[2];
27,601✔
1381
  pInfo->cacheSize = dirSize[3];
27,601✔
1382
  return code;
27,601✔
1383
}
1384
int32_t vnodeGetDBSize(void *pVnode, SDbSizeStatisInfo *pInfo) {
27,601✔
1385
  int32_t code = 0;
27,601✔
1386
  int32_t lino = 0;
27,601✔
1387
  SVnode *pVnodeObj = pVnode;
27,601✔
1388
  if (pVnodeObj == NULL) {
27,601!
1389
    return TSDB_CODE_VND_NOT_EXIST;
×
1390
  }
1391
  code = vnodeGetDBPrimaryInfo(pVnode, pInfo);
27,601✔
1392
  if (code != 0) goto _exit;
27,601!
1393

1394
  code = tsdbGetFsSize(pVnodeObj->pTsdb, pInfo);
27,601✔
1395
_exit:
27,601✔
1396
  return code;
27,601✔
1397
}
1398

1399
/*
1400
 * Get raw write metrics for a vnode
1401
 */
1402
int32_t vnodeGetRawWriteMetrics(void *pVnode, SRawWriteMetrics *pRawMetrics) {
×
1403
  if (pVnode == NULL || pRawMetrics == NULL) {
×
1404
    return TSDB_CODE_INVALID_PARA;
×
1405
  }
1406

1407
  SVnode      *pVnode1 = (SVnode *)pVnode;
×
1408
  SSyncMetrics syncMetrics = syncGetMetrics(pVnode1->sync);
×
1409

1410
  // Copy values following SRawWriteMetrics structure order
1411
  pRawMetrics->total_requests = atomic_load_64(&pVnode1->writeMetrics.total_requests);
×
1412
  pRawMetrics->total_rows = atomic_load_64(&pVnode1->writeMetrics.total_rows);
×
1413
  pRawMetrics->total_bytes = atomic_load_64(&pVnode1->writeMetrics.total_bytes);
×
1414
  pRawMetrics->fetch_batch_meta_time = atomic_load_64(&pVnode1->writeMetrics.fetch_batch_meta_time);
×
1415
  pRawMetrics->fetch_batch_meta_count = atomic_load_64(&pVnode1->writeMetrics.fetch_batch_meta_count);
×
1416
  pRawMetrics->preprocess_time = atomic_load_64(&pVnode1->writeMetrics.preprocess_time);
×
1417
  pRawMetrics->wal_write_bytes = atomic_load_64(&syncMetrics.wal_write_bytes);
×
1418
  pRawMetrics->wal_write_time = atomic_load_64(&syncMetrics.wal_write_time);
×
1419
  pRawMetrics->apply_bytes = atomic_load_64(&pVnode1->writeMetrics.apply_bytes);
×
1420
  pRawMetrics->apply_time = atomic_load_64(&pVnode1->writeMetrics.apply_time);
×
1421
  pRawMetrics->commit_count = atomic_load_64(&pVnode1->writeMetrics.commit_count);
×
1422
  pRawMetrics->commit_time = atomic_load_64(&pVnode1->writeMetrics.commit_time);
×
1423
  pRawMetrics->memtable_wait_time = atomic_load_64(&pVnode1->writeMetrics.memtable_wait_time);
×
1424
  pRawMetrics->blocked_commit_count = atomic_load_64(&pVnode1->writeMetrics.blocked_commit_count);
×
1425
  pRawMetrics->blocked_commit_time = atomic_load_64(&pVnode1->writeMetrics.block_commit_time);
×
1426
  pRawMetrics->merge_count = atomic_load_64(&pVnode1->writeMetrics.merge_count);
×
1427
  pRawMetrics->merge_time = atomic_load_64(&pVnode1->writeMetrics.merge_time);
×
1428
  pRawMetrics->last_cache_commit_time = atomic_load_64(&pVnode1->writeMetrics.last_cache_commit_time);
×
1429
  pRawMetrics->last_cache_commit_count = atomic_load_64(&pVnode1->writeMetrics.last_cache_commit_count);
×
1430

1431
  return 0;
×
1432
}
1433

1434
/*
1435
 * Reset raw write metrics for a vnode by subtracting old values
1436
 */
1437
int32_t vnodeResetRawWriteMetrics(void *pVnode, const SRawWriteMetrics *pOldMetrics) {
×
1438
  if (pVnode == NULL || pOldMetrics == NULL) {
×
1439
    return TSDB_CODE_INVALID_PARA;
×
1440
  }
1441

1442
  SVnode *pVnode1 = (SVnode *)pVnode;
×
1443

1444
  // Reset vnode write metrics using atomic operations to subtract old values
1445
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.total_requests, pOldMetrics->total_requests);
×
1446
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.total_rows, pOldMetrics->total_rows);
×
1447
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.total_bytes, pOldMetrics->total_bytes);
×
1448

1449
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.fetch_batch_meta_time, pOldMetrics->fetch_batch_meta_time);
×
1450
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.fetch_batch_meta_count, pOldMetrics->fetch_batch_meta_count);
×
1451
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.preprocess_time, pOldMetrics->preprocess_time);
×
1452
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.apply_bytes, pOldMetrics->apply_bytes);
×
1453
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.apply_time, pOldMetrics->apply_time);
×
1454
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.commit_count, pOldMetrics->commit_count);
×
1455

1456
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.commit_time, pOldMetrics->commit_time);
×
1457
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.merge_time, pOldMetrics->merge_time);
×
1458

1459
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.memtable_wait_time, pOldMetrics->memtable_wait_time);
×
1460
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.blocked_commit_count, pOldMetrics->blocked_commit_count);
×
1461
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.block_commit_time, pOldMetrics->blocked_commit_time);
×
1462
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.merge_count, pOldMetrics->merge_count);
×
1463

1464
  // Reset new cache metrics
1465
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.last_cache_commit_time, pOldMetrics->last_cache_commit_time);
×
1466
  (void)atomic_sub_fetch_64(&pVnode1->writeMetrics.last_cache_commit_count, pOldMetrics->last_cache_commit_count);
×
1467

1468
  // Reset sync metrics
1469
  SSyncMetrics syncMetrics = {
×
1470
      .wal_write_bytes = pOldMetrics->wal_write_bytes,
×
1471
      .wal_write_time = pOldMetrics->wal_write_time,
×
1472
  };
1473
  syncResetMetrics(pVnode1->sync, &syncMetrics);
×
1474

1475
  return 0;
×
1476
}
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