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

taosdata / TDengine / #4069

12 May 2025 05:35AM UTC coverage: 63.048% (+0.5%) from 62.547%
#4069

push

travis-ci

web-flow
Merge pull request #31053 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

157521 of 317858 branches covered (49.56%)

Branch coverage included in aggregate %.

374 of 573 new or added lines in 31 files covered. (65.27%)

4949 existing lines in 87 files now uncovered.

242707 of 316936 relevant lines covered (76.58%)

18229906.31 hits per line

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

47.28
/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) {
14,641✔
29
  return qWorkerInit(NODE_TYPE_VNODE, TD_VID(pVnode), (void **)&pVnode->pQuery, &pVnode->msgCb);
14,641✔
30
}
31

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

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

36
int32_t fillTableColCmpr(SMetaReader *reader, SSchemaExt *pExt, int32_t numOfCol) {
2,027,088✔
37
  int8_t tblType = reader->me.type;
2,027,088✔
38
  if (withExtSchema(tblType)) {
2,027,088!
39
    SColCmprWrapper *p = &(reader->me.colCmpr);
2,027,224✔
40
    if (numOfCol != p->nCols) {
2,027,224!
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++) {
51,264,414✔
45
      SColCmpr *pCmpr = &p->pColCmpr[i];
49,237,190✔
46
      pExt[i].colId = pCmpr->id;
49,237,190✔
47
      pExt[i].compress = pCmpr->alg;
49,237,190✔
48
    }
49
  }
50
  return 0;
2,027,176✔
51
}
52

53
void vnodePrintTableMeta(STableMetaRsp *pMeta) {
2,027,256✔
54
  if (!(qDebugFlag & DEBUG_DEBUG)) {
2,027,256✔
55
    return;
1,994,794✔
56
  }
57

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

81
int32_t fillTableColRef(SMetaReader *reader, SColRef *pRef, int32_t numOfCol) {
×
82
  int8_t tblType = reader->me.type;
×
83
  if (hasRefCol(tblType)) {
×
84
    SColRefWrapper *p = &(reader->me.colRef);
×
85
    if (numOfCol != p->nCols) {
×
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++) {
×
90
      SColRef *pColRef = &p->pColRef[i];
×
91
      pRef[i].hasRef = pColRef->hasRef;
×
92
      pRef[i].id = pColRef->id;
×
93
      if(pRef[i].hasRef) {
×
94
        tstrncpy(pRef[i].refDbName, pColRef->refDbName, TSDB_DB_NAME_LEN);
×
95
        tstrncpy(pRef[i].refTableName, pColRef->refTableName, TSDB_TABLE_NAME_LEN);
×
96
        tstrncpy(pRef[i].refColName, pColRef->refColName, TSDB_COL_NAME_LEN);
×
97
      }
98
    }
99
  }
100
  return 0;
×
101
}
102

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

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

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

130
  if (!reqTbUid) {
2,088,566✔
131
    (void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", infoReq.dbFName, infoReq.tbName);
2,087,382✔
132
    code = vnodeValidateTableHash(pVnode, tableFName);
2,087,964✔
133
    if (code) {
2,087,720!
134
      goto _exit4;
×
135
    }
136
  }
137

138
  // query meta
139
  metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
2,088,904✔
140
  if (reqTbUid) {
2,088,537✔
141
    SET_ERRNO(0);
533✔
142
    uint64_t tbUid = taosStr2UInt64(infoReq.tbName, NULL, 10);
533✔
143
    if (ERRNO == ERANGE || tbUid == 0) {
534!
144
      code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
×
145
      goto _exit3;
134✔
146
    }
147
    SMetaReader mr3 = {0};
534✔
148
    metaReaderDoInit(&mr3, ((SVnode *)pVnode)->pMeta, META_READER_NOLOCK);
534✔
149
    if ((code = metaReaderGetTableEntryByUid(&mr3, tbUid)) < 0) {
534✔
150
      metaReaderClear(&mr3);
134✔
151
      TAOS_CHECK_GOTO(code, NULL, _exit3);
134!
152
    }
153
    tstrncpy(metaRsp.tbName, mr3.me.name, TSDB_TABLE_NAME_LEN);
399✔
154
    metaReaderClear(&mr3);
399✔
155
    TAOS_CHECK_GOTO(metaGetTableEntryByName(&mer1, metaRsp.tbName), NULL, _exit3);
399!
156
  } else if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) {
2,088,004✔
157
    code = terrno;
60,559✔
158
    goto _exit3;
60,814✔
159
  }
160

161
  metaRsp.tableType = mer1.me.type;
2,027,894✔
162
  metaRsp.vgId = TD_VID(pVnode);
2,027,894✔
163
  metaRsp.tuid = mer1.me.uid;
2,027,894✔
164

165
  switch (mer1.me.type) {
2,027,894!
166
    case TSDB_SUPER_TABLE: {
1,345,710✔
167
      (void)strcpy(metaRsp.stbName, mer1.me.name);
1,345,710✔
168
      schema = mer1.me.stbEntry.schemaRow;
1,345,710✔
169
      schemaTag = mer1.me.stbEntry.schemaTag;
1,345,710✔
170
      metaRsp.suid = mer1.me.uid;
1,345,710✔
171
      break;
1,345,710✔
172
    }
173
    case TSDB_CHILD_TABLE:
612,851✔
174
    case TSDB_VIRTUAL_CHILD_TABLE:{
175
      metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
612,851✔
176
      if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit2;
612,852!
177

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

195
  metaRsp.numOfTags = schemaTag.nCols;
2,027,896✔
196
  metaRsp.numOfColumns = schema.nCols;
2,027,896✔
197
  metaRsp.precision = pVnode->config.tsdbCfg.precision;
2,027,896✔
198
  metaRsp.sversion = schema.version;
2,027,896✔
199
  metaRsp.tversion = schemaTag.version;
2,027,896✔
200
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (metaRsp.numOfColumns + metaRsp.numOfTags));
2,027,896!
201
  metaRsp.pSchemaExt = (SSchemaExt *)taosMemoryCalloc(metaRsp.numOfColumns, sizeof(SSchemaExt));
2,027,696!
202
  if (NULL == metaRsp.pSchemas || NULL == metaRsp.pSchemaExt) {
2,027,204!
203
    code = terrno;
17✔
204
    goto _exit;
×
205
  }
206
  (void)memcpy(metaRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
2,027,187✔
207
  if (schemaTag.nCols) {
2,027,187✔
208
    (void)memcpy(metaRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
1,957,454✔
209
  }
210
  if (metaRsp.pSchemaExt) {
2,027,187✔
211
    SMetaReader *pReader = mer1.me.type == TSDB_CHILD_TABLE ? &mer2 : &mer1;
2,026,843✔
212
    code = fillTableColCmpr(pReader, metaRsp.pSchemaExt, metaRsp.numOfColumns);
2,026,843✔
213
    if (code < 0) {
2,027,420!
214
      goto _exit;
×
215
    }
216
    for (int32_t i = 0; i < metaRsp.numOfColumns && pReader->me.pExtSchemas; i++) {
2,407,902✔
217
      metaRsp.pSchemaExt[i].typeMod = pReader->me.pExtSchemas[i].typeMod;
380,482✔
218
    }
219
  } else {
220
    code = TSDB_CODE_OUT_OF_MEMORY;
344✔
221
    goto _exit;
344✔
222
  }
223
  if (hasRefCol(mer1.me.type)) {
2,027,420✔
224
    metaRsp.rversion = mer1.me.colRef.version;
115✔
225
    metaRsp.pColRefs = (SColRef*)taosMemoryMalloc(sizeof(SColRef) * metaRsp.numOfColumns);
115!
226
    if (metaRsp.pColRefs) {
×
227
      code = fillTableColRef(&mer1, metaRsp.pColRefs, metaRsp.numOfColumns);
×
228
      if (code < 0) {
×
229
        goto _exit;
×
230
      }
231
    }
UNCOV
232
    metaRsp.numOfColRefs = metaRsp.numOfColumns;
×
233
  } else {
234
    metaRsp.pColRefs = NULL;
2,027,279✔
235
    metaRsp.numOfColRefs = 0;
2,027,279✔
236
  }
237

238
  vnodePrintTableMeta(&metaRsp);
2,027,279✔
239

240
  // encode and send response
241
  rspLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
2,027,245✔
242
  if (rspLen < 0) {
2,026,697!
UNCOV
243
    code = terrno;
×
244
    goto _exit;
×
245
  }
246

247
  if (direct) {
2,026,697✔
248
    pRsp = rpcMallocCont(rspLen);
201✔
249
  } else {
250
    pRsp = taosMemoryCalloc(1, rspLen);
2,026,496!
251
  }
252

253
  if (pRsp == NULL) {
2,026,582!
UNCOV
254
    code = terrno;
×
255
    goto _exit;
×
256
  }
257

258
  rspLen = tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp);
2,026,582✔
259
  if (rspLen < 0) {
2,027,415!
UNCOV
260
    code = terrno;
×
261
    goto _exit;
×
262
  }
263

264
_exit:
2,027,415✔
265
  taosMemoryFree(metaRsp.pColRefs);
2,027,759!
266
  taosMemoryFree(metaRsp.pSchemas);
2,027,019!
267
  taosMemoryFree(metaRsp.pSchemaExt);
2,027,184!
268
_exit2:
2,027,628✔
269
  metaReaderClear(&mer2);
2,027,628✔
270
_exit3:
2,088,359✔
271
  metaReaderClear(&mer1);
2,088,359✔
272
_exit4:
2,088,493✔
273
  rpcMsg.info = pMsg->info;
2,088,493✔
274
  rpcMsg.pCont = pRsp;
2,088,493✔
275
  rpcMsg.contLen = rspLen;
2,088,493✔
276
  rpcMsg.code = code;
2,088,493✔
277
  rpcMsg.msgType = pMsg->msgType;
2,088,493✔
278

279
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST && autoCreateCtb == 1) {
2,088,493✔
280
    code = TSDB_CODE_SUCCESS;
40,813✔
281
  }
282

283
  if (code) {
2,088,493✔
284
    qError("get table %s meta with %" PRIu8 " failed cause of %s", infoReq.tbName, infoReq.option, tstrerror(code));
20,135!
285
  }
286

287
  if (direct) {
2,088,138✔
288
    tmsgSendRsp(&rpcMsg);
2,976✔
289
  } else {
290
    *pMsg = rpcMsg;
2,085,162✔
291
  }
292

293
  return code;
2,088,207✔
294
}
295

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

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

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

318
  (void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", cfgReq.dbFName, cfgReq.tbName);
102✔
319
  code = vnodeValidateTableHash(pVnode, tableFName);
102✔
320
  if (code) {
102!
UNCOV
321
    goto _exit;
×
322
  }
323

324
  // query meta
325
  metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
102✔
326

327
  if (metaGetTableEntryByName(&mer1, cfgReq.tbName) < 0) {
102!
UNCOV
328
    code = terrno;
×
329
    goto _exit;
×
330
  }
331

332
  cfgRsp.tableType = mer1.me.type;
102✔
333

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

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

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

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

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

398
  if (withExtSchema(cfgRsp.tableType)) {
102!
399
    for (int32_t i = 0; i < cfgRsp.numOfColumns; i++) {
938✔
400
      SColCmpr   *pCmpr = &pColCmpr->pColCmpr[i];
836✔
401
      SSchemaExt *pSchExt = cfgRsp.pSchemaExt + i;
836✔
402
      pSchExt->colId = pCmpr->id;
836✔
403
      pSchExt->compress = pCmpr->alg;
836✔
404
      if (pReader->me.pExtSchemas)
836✔
405
        pSchExt->typeMod = pReader->me.pExtSchemas[i].typeMod;
165✔
406
      else
407
        pSchExt->typeMod = 0;
671✔
408
    }
409
  }
410

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

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

432
  if (direct) {
102!
UNCOV
433
    pRsp = rpcMallocCont(rspLen);
×
434
  } else {
435
    pRsp = taosMemoryCalloc(1, rspLen);
102!
436
  }
437

438
  if (pRsp == NULL) {
102!
UNCOV
439
    code = terrno;
×
440
    goto _exit;
×
441
  }
442

443
  rspLen = tSerializeSTableCfgRsp(pRsp, rspLen, &cfgRsp);
102✔
444
  if (rspLen < 0) {
102!
UNCOV
445
    code = terrno;
×
446
    goto _exit;
×
447
  }
448

449
_exit:
102✔
450
  rpcMsg.info = pMsg->info;
102✔
451
  rpcMsg.pCont = pRsp;
102✔
452
  rpcMsg.contLen = rspLen;
102✔
453
  rpcMsg.code = code;
102✔
454
  rpcMsg.msgType = pMsg->msgType;
102✔
455

456
  if (code) {
102!
UNCOV
457
    qError("get table %s cfg failed cause of %s", cfgReq.tbName, tstrerror(code));
×
458
  }
459

460
  if (direct) {
102!
UNCOV
461
    tmsgSendRsp(&rpcMsg);
×
462
  } else {
463
    *pMsg = rpcMsg;
102✔
464
  }
465

466
  tFreeSTableCfgRsp(&cfgRsp);
102✔
467
  metaReaderClear(&mer2);
102✔
468
  metaReaderClear(&mer1);
102✔
469
  return code;
102✔
470
}
471

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

477
  SBatchRspMsg *pRsp = (SBatchRspMsg *)p;
478
  rpcFreeCont(pRsp->msg);
479
}
480

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

492
  if (tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) {
1,195,209!
UNCOV
493
    code = terrno;
×
494
    qError("tDeserializeSBatchReq failed");
×
495
    goto _exit;
×
496
  }
497

498
  int32_t msgNum = taosArrayGetSize(batchReq.pMsgs);
1,196,035✔
499
  if (msgNum >= MAX_META_MSG_IN_BATCH) {
1,195,691!
UNCOV
500
    code = TSDB_CODE_INVALID_MSG;
×
501
    qError("too many msgs %d in vnode batch meta req", msgNum);
×
502
    goto _exit;
×
503
  }
504

505
  batchRsp.pRsps = taosArrayInit(msgNum, sizeof(SBatchRspMsg));
1,195,691✔
506
  if (NULL == batchRsp.pRsps) {
1,195,944✔
507
    code = terrno;
4✔
508
    qError("taosArrayInit %d SBatchRspMsg failed", msgNum);
×
509
    goto _exit;
×
510
  }
511

512
  for (int32_t i = 0; i < msgNum; ++i) {
3,282,936✔
513
    req = taosArrayGet(batchReq.pMsgs, i);
2,088,637✔
514
    if (req == NULL) {
2,086,860✔
515
      code = terrno;
21✔
UNCOV
516
      goto _exit;
×
517
    }
518

519
    reqMsg.msgType = req->msgType;
2,086,839✔
520
    reqMsg.pCont = req->msg;
2,086,839✔
521
    reqMsg.contLen = req->msgLen;
2,086,839✔
522

523
    switch (req->msgType) {
2,086,839!
524
      case TDMT_VND_TABLE_META:
2,082,908✔
525
        // error code has been set into reqMsg, no need to handle it here.
526
        if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
2,082,908✔
527
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
17,226!
528
        }
529
        break;
2,084,499✔
530
      case TDMT_VND_TABLE_NAME:
533✔
531
        // error code has been set into reqMsg, no need to handle it here.
532
        if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
533✔
533
          qWarn("vnodeGetBatchName failed, msgType:%d", req->msgType);
134!
534
        }
535
        break;
533✔
536
      case TDMT_VND_TABLE_CFG:
102✔
537
        // error code has been set into reqMsg, no need to handle it here.
538
        if (TSDB_CODE_SUCCESS != vnodeGetTableCfg(pVnode, &reqMsg, false)) {
102!
UNCOV
539
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
×
540
        }
541
        break;
102✔
542
      case TDMT_VND_GET_STREAM_PROGRESS:
3,296✔
543
        // error code has been set into reqMsg, no need to handle it here.
544
        if (TSDB_CODE_SUCCESS != vnodeGetStreamProgress(pVnode, &reqMsg, false)) {
3,296!
UNCOV
545
          qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
×
546
        }
547
        break;
3,296✔
UNCOV
548
      case TDMT_VND_VSUBTABLES_META:
×
549
        // error code has been set into reqMsg, no need to handle it here.
UNCOV
550
        if (TSDB_CODE_SUCCESS != vnodeGetVSubtablesMeta(pVnode, &reqMsg)) {
×
551
          qWarn("vnodeGetVSubtablesMeta failed, msgType:%d", req->msgType);
×
552
        }
UNCOV
553
        break;
×
554
      case TDMT_VND_VSTB_REF_DBS:
×
555
        // error code has been set into reqMsg, no need to handle it here.
UNCOV
556
        if (TSDB_CODE_SUCCESS != vnodeGetVStbRefDbs(pVnode, &reqMsg)) {
×
557
          qWarn("vnodeGetVStbRefDbs failed, msgType:%d", req->msgType);
×
558
        }
UNCOV
559
        break;
×
560
      default:
×
561
        qError("invalid req msgType %d", req->msgType);
×
562
        reqMsg.code = TSDB_CODE_INVALID_MSG;
×
563
        reqMsg.pCont = NULL;
×
564
        reqMsg.contLen = 0;
×
565
        break;
×
566
    }
567

568
    rsp.msgIdx = req->msgIdx;
2,088,430✔
569
    rsp.reqType = reqMsg.msgType;
2,088,430✔
570
    rsp.msgLen = reqMsg.contLen;
2,088,430✔
571
    rsp.rspCode = reqMsg.code;
2,088,430✔
572
    rsp.msg = reqMsg.pCont;
2,088,430✔
573

574
    if (NULL == taosArrayPush(batchRsp.pRsps, &rsp)) {
4,175,426!
UNCOV
575
      qError("taosArrayPush failed");
×
576
      code = terrno;
×
577
      goto _exit;
×
578
    }
579
  }
580

581
  rspSize = tSerializeSBatchRsp(NULL, 0, &batchRsp);
1,194,299✔
582
  if (rspSize < 0) {
1,196,186!
UNCOV
583
    qError("tSerializeSBatchRsp failed");
×
584
    code = terrno;
×
585
    goto _exit;
×
586
  }
587
  pRsp = rpcMallocCont(rspSize);
1,196,186✔
588
  if (pRsp == NULL) {
1,196,188!
UNCOV
589
    qError("rpcMallocCont %d failed", rspSize);
×
590
    code = terrno;
×
591
    goto _exit;
×
592
  }
593
  if (tSerializeSBatchRsp(pRsp, rspSize, &batchRsp) < 0) {
1,196,188!
UNCOV
594
    qError("tSerializeSBatchRsp %d failed", rspSize);
×
595
    code = terrno;
×
596
    goto _exit;
×
597
  }
598

599
_exit:
1,196,233✔
600

601
  rspMsg.info = pMsg->info;
1,196,233✔
602
  rspMsg.pCont = pRsp;
1,196,233✔
603
  rspMsg.contLen = rspSize;
1,196,233✔
604
  rspMsg.code = code;
1,196,233✔
605
  rspMsg.msgType = pMsg->msgType;
1,196,233✔
606

607
  if (code) {
1,196,233!
UNCOV
608
    qError("vnd get batch meta failed cause of %s", tstrerror(code));
×
609
  }
610

611
  taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
1,196,233✔
612
  taosArrayDestroyEx(batchRsp.pRsps, tFreeSBatchRspMsg);
1,196,138✔
613

614
  tmsgSendRsp(&rspMsg);
1,196,183✔
615

616
  return code;
1,196,229✔
617
}
618

619
#define VNODE_DO_META_QUERY(pVnode, cmd)                 \
620
  do {                                                   \
621
    (void)taosThreadRwlockRdlock(&(pVnode)->metaRWLock); \
622
    cmd;                                                 \
623
    (void)taosThreadRwlockUnlock(&(pVnode)->metaRWLock); \
624
  } while (0)
625

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

UNCOV
636
  SArray *pList = taosArrayInit(10, sizeof(uint64_t));
×
637
  QUERY_CHECK_NULL(pList, code, line, _return, terrno);
×
638

UNCOV
639
  QUERY_CHECK_CODE(pHandle->api.metaFn.getChildTableList(pHandle->vnode, suid, pList), line, _return);
×
640

UNCOV
641
  size_t num = taosArrayGetSize(pList);
×
642
  *ppRes = taosArrayInit(num, POINTER_BYTES);
×
643
  QUERY_CHECK_NULL(*ppRes, code, line, _return, terrno);
×
644
  pSrcTbls = tSimpleHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY));
×
645
  QUERY_CHECK_NULL(pSrcTbls, code, line, _return, terrno);
×
646

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

UNCOV
654
    refColsNum = 0;
×
655
    for (int32_t j = 0; j < mr.me.colRef.nCols; j++) {
×
656
      if (mr.me.colRef.pColRef[j].hasRef) {
×
657
        refColsNum++;
×
658
      }
659
    }
660

UNCOV
661
    if (refColsNum <= 0) {
×
662
      pHandle->api.metaReaderFn.clearReader(&mr);
×
663
      readerInit = false;
×
664
      continue;
×
665
    }
666

UNCOV
667
    pTb = taosMemoryCalloc(1, refColsNum * sizeof(SRefColInfo) + sizeof(*pTb));
×
668
    QUERY_CHECK_NULL(pTb, code, line, _return, terrno);
×
669

UNCOV
670
    pTb->uid = mr.me.uid;
×
671
    pTb->numOfColRefs = refColsNum;
×
672
    pTb->refCols = (SRefColInfo*)(pTb + 1);
×
673

UNCOV
674
    refColsNum = 0;
×
675
    tSimpleHashClear(pSrcTbls);
×
676
    for (int32_t j = 0; j < mr.me.colRef.nCols; j++) {
×
677
      if (!mr.me.colRef.pColRef[j].hasRef) {
×
678
        continue;
×
679
      }
680

UNCOV
681
      pTb->refCols[refColsNum].colId = mr.me.colRef.pColRef[j].id;
×
682
      tstrncpy(pTb->refCols[refColsNum].refColName, mr.me.colRef.pColRef[j].refColName, TSDB_COL_NAME_LEN);
×
683
      tstrncpy(pTb->refCols[refColsNum].refTableName, mr.me.colRef.pColRef[j].refTableName, TSDB_TABLE_NAME_LEN);
×
684
      tstrncpy(pTb->refCols[refColsNum].refDbName, mr.me.colRef.pColRef[j].refDbName, TSDB_DB_NAME_LEN);
×
685

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

UNCOV
688
      if (NULL == tSimpleHashGet(pSrcTbls, tbFName, strlen(tbFName))) {
×
689
        QUERY_CHECK_CODE(tSimpleHashPut(pSrcTbls, tbFName, strlen(tbFName), &code, sizeof(code)), line, _return);
×
690
      }
691

UNCOV
692
      refColsNum++;
×
693
    }
694

UNCOV
695
    pTb->numOfSrcTbls = tSimpleHashGetSize(pSrcTbls);
×
696
    QUERY_CHECK_NULL(taosArrayPush(*ppRes, &pTb), code, line, _return, terrno);
×
697
    pTb = NULL;
×
698

UNCOV
699
    pHandle->api.metaReaderFn.clearReader(&mr);
×
700
    readerInit = false;
×
701
  }
702

UNCOV
703
_return:
×
704

UNCOV
705
  if (readerInit) {
×
706
    pHandle->api.metaReaderFn.clearReader(&mr);
×
707
  }
708

UNCOV
709
  taosArrayDestroy(pList);
×
710
  taosMemoryFree(pTb);
×
711
  tSimpleHashCleanup(pSrcTbls);
×
712

UNCOV
713
  if (code) {
×
714
    qError("%s failed since %s", __func__, tstrerror(code));
×
715
  }
UNCOV
716
  return code;
×
717
}
718

UNCOV
719
int32_t vnodeReadVStbRefDbs(SReadHandle* pHandle, int64_t suid, SArray** ppRes) {
×
720
  int32_t                    code = TSDB_CODE_SUCCESS;
×
721
  int32_t                    line = 0;
×
722
  SMetaReader                mr = {0};
×
723
  bool                       readerInit = false;
×
724
  SSHashObj*                 pDbNameHash = NULL;
×
725
  SArray*                    pList = NULL;
×
726

UNCOV
727
  pList = taosArrayInit(10, sizeof(uint64_t));
×
728
  QUERY_CHECK_NULL(pList, code, line, _return, terrno);
×
729

UNCOV
730
  *ppRes = taosArrayInit(10, POINTER_BYTES);
×
731
  QUERY_CHECK_NULL(*ppRes, code, line, _return, terrno)
×
732
  
733
  // lookup in cache
UNCOV
734
  code = pHandle->api.metaFn.metaGetCachedRefDbs(pHandle->vnode, suid, *ppRes);
×
735
  QUERY_CHECK_CODE(code, line, _return);
×
736

UNCOV
737
  if (taosArrayGetSize(*ppRes) > 0) {
×
738
    // found in cache
UNCOV
739
    goto _return;
×
740
  } else {
UNCOV
741
    code = pHandle->api.metaFn.getChildTableList(pHandle->vnode, suid, pList);
×
742
    QUERY_CHECK_CODE(code, line, _return);
×
743

UNCOV
744
    size_t num = taosArrayGetSize(pList);
×
745
    pDbNameHash = tSimpleHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY));
×
746
    QUERY_CHECK_NULL(pDbNameHash, code, line, _return, terrno);
×
747

UNCOV
748
    for (int32_t i = 0; i < num; ++i) {
×
749
      uint64_t* id = taosArrayGet(pList, i);
×
750
      QUERY_CHECK_NULL(id, code, line, _return, terrno);
×
751

UNCOV
752
      pHandle->api.metaReaderFn.initReader(&mr, pHandle->vnode, META_READER_LOCK, &pHandle->api.metaFn);
×
753
      readerInit = true;
×
754

UNCOV
755
      code = pHandle->api.metaReaderFn.getTableEntryByUid(&mr, *id);
×
756
      QUERY_CHECK_CODE(code, line, _return);
×
757

UNCOV
758
      for (int32_t j = 0; j < mr.me.colRef.nCols; j++) {
×
759
        if (mr.me.colRef.pColRef[j].hasRef) {
×
760
          if (NULL == tSimpleHashGet(pDbNameHash, mr.me.colRef.pColRef[j].refDbName, strlen(mr.me.colRef.pColRef[j].refDbName))) {
×
761
            char *refDbName = taosStrdup(mr.me.colRef.pColRef[j].refDbName);
×
762
            QUERY_CHECK_NULL(refDbName, code, line, _return, terrno);
×
763

UNCOV
764
            QUERY_CHECK_NULL(taosArrayPush(*ppRes, &refDbName), code, line, _return, terrno);
×
765

UNCOV
766
            code = tSimpleHashPut(pDbNameHash, refDbName, strlen(refDbName), NULL, 0);
×
767
            QUERY_CHECK_CODE(code, line, _return);
×
768
          }
769
        }
770
      }
771

UNCOV
772
      pHandle->api.metaReaderFn.clearReader(&mr);
×
773
      readerInit = false;
×
774
    }
775

UNCOV
776
    code = pHandle->api.metaFn.metaPutRefDbsToCache(pHandle->vnode, suid, *ppRes);
×
777
    QUERY_CHECK_CODE(code, line, _return);
×
778
  }
779

UNCOV
780
_return:
×
781

UNCOV
782
  if (readerInit) {
×
783
    pHandle->api.metaReaderFn.clearReader(&mr);
×
784
  }
785

UNCOV
786
  taosArrayDestroy(pList);
×
787
  tSimpleHashCleanup(pDbNameHash);
×
788

UNCOV
789
  if (code) {
×
790
    qError("%s failed since %s", __func__, tstrerror(code));
×
791
  }
UNCOV
792
  return code;
×
793
}
794

UNCOV
795
int32_t vnodeGetVSubtablesMeta(SVnode *pVnode, SRpcMsg *pMsg) {
×
796
  int32_t        code = 0;
×
797
  int32_t        rspSize = 0;
×
798
  SVSubTablesReq req = {0};
×
799
  SVSubTablesRsp rsp = {0};
×
800
  SRpcMsg      rspMsg = {0};
×
801
  void        *pRsp = NULL;
×
802
  int32_t      line = 0;
×
803

UNCOV
804
  if (tDeserializeSVSubTablesReq(pMsg->pCont, pMsg->contLen, &req)) {
×
805
    code = terrno;
×
806
    qError("tDeserializeSVSubTablesReq failed");
×
807
    goto _return;
×
808
  }
809

UNCOV
810
  SReadHandle handle = {.vnode = pVnode};
×
811
  initStorageAPI(&handle.api);
×
812

UNCOV
813
  QUERY_CHECK_CODE(vnodeReadVSubtables(&handle, req.suid, &rsp.pTables), line, _return);
×
814
  rsp.vgId = TD_VID(pVnode);
×
815

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

UNCOV
835
_return:
×
836

UNCOV
837
  rspMsg.info = pMsg->info;
×
838
  rspMsg.pCont = pRsp;
×
839
  rspMsg.contLen = rspSize;
×
840
  rspMsg.code = code;
×
841
  rspMsg.msgType = pMsg->msgType;
×
842

UNCOV
843
  if (code) {
×
844
    qError("vnd get virtual subtables failed cause of %s", tstrerror(code));
×
845
  }
846

UNCOV
847
  *pMsg = rspMsg;
×
848
  
UNCOV
849
  tDestroySVSubTablesRsp(&rsp);
×
850

851
  //tmsgSendRsp(&rspMsg);
852

UNCOV
853
  return code;
×
854
}
855

UNCOV
856
int32_t vnodeGetVStbRefDbs(SVnode *pVnode, SRpcMsg *pMsg) {
×
857
  int32_t        code = 0;
×
858
  int32_t        rspSize = 0;
×
859
  SVStbRefDbsReq req = {0};
×
860
  SVStbRefDbsRsp rsp = {0};
×
861
  SRpcMsg        rspMsg = {0};
×
862
  void          *pRsp = NULL;
×
863
  int32_t        line = 0;
×
864

UNCOV
865
  if (tDeserializeSVStbRefDbsReq(pMsg->pCont, pMsg->contLen, &req)) {
×
866
    code = terrno;
×
867
    qError("tDeserializeSVSubTablesReq failed");
×
868
    goto _return;
×
869
  }
870

UNCOV
871
  SReadHandle handle = {.vnode = pVnode};
×
872
  initStorageAPI(&handle.api);
×
873

UNCOV
874
  code = vnodeReadVStbRefDbs(&handle, req.suid, &rsp.pDbs);
×
875
  QUERY_CHECK_CODE(code, line, _return);
×
876
  rsp.vgId = TD_VID(pVnode);
×
877

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

UNCOV
897
_return:
×
898

UNCOV
899
  rspMsg.info = pMsg->info;
×
900
  rspMsg.pCont = pRsp;
×
901
  rspMsg.contLen = rspSize;
×
902
  rspMsg.code = code;
×
903
  rspMsg.msgType = pMsg->msgType;
×
904

UNCOV
905
  if (code) {
×
906
    qError("vnd get virtual stb ref db failed cause of %s", tstrerror(code));
×
907
  }
908

UNCOV
909
  *pMsg = rspMsg;
×
910

UNCOV
911
  tDestroySVStbRefDbsRsp(&rsp);
×
912

UNCOV
913
  return code;
×
914
}
915

916

917
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
699,544✔
918
  SSyncState state = syncGetState(pVnode->sync);
699,544✔
919
  pLoad->syncAppliedIndex = pVnode->state.applied;
699,544✔
920
  syncGetCommitIndex(pVnode->sync, &pLoad->syncCommitIndex);
699,544✔
921

922
  pLoad->vgId = TD_VID(pVnode);
699,544✔
923
  pLoad->syncState = state.state;
699,544✔
924
  pLoad->syncRestore = state.restored;
699,544✔
925
  pLoad->syncTerm = state.term;
699,544✔
926
  pLoad->roleTimeMs = state.roleTimeMs;
699,544✔
927
  pLoad->startTimeMs = state.startTimeMs;
699,544✔
928
  pLoad->syncCanRead = state.canRead;
699,544✔
929
  pLoad->learnerProgress = state.progress;
699,544✔
930
  pLoad->cacheUsage = tsdbCacheGetUsage(pVnode);
699,544✔
931
  pLoad->numOfCachedTables = tsdbCacheGetElems(pVnode);
699,544✔
932
  VNODE_DO_META_QUERY(pVnode, pLoad->numOfTables = metaGetTbNum(pVnode->pMeta));
699,544✔
933
  VNODE_DO_META_QUERY(pVnode, pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1));
699,544✔
934
  pLoad->totalStorage = (int64_t)3 * 1073741824;
699,544✔
935
  pLoad->compStorage = (int64_t)2 * 1073741824;
699,544✔
936
  pLoad->pointsWritten = 100;
699,544✔
937
  pLoad->numOfSelectReqs = 1;
699,544✔
938
  pLoad->numOfInsertReqs = atomic_load_64(&pVnode->statis.nInsert);
699,544✔
939
  pLoad->numOfInsertSuccessReqs = atomic_load_64(&pVnode->statis.nInsertSuccess);
699,544✔
940
  pLoad->numOfBatchInsertReqs = atomic_load_64(&pVnode->statis.nBatchInsert);
699,544✔
941
  pLoad->numOfBatchInsertSuccessReqs = atomic_load_64(&pVnode->statis.nBatchInsertSuccess);
699,544✔
942
  return 0;
699,544✔
943
}
944

UNCOV
945
int32_t vnodeGetLoadLite(SVnode *pVnode, SVnodeLoadLite *pLoad) {
×
946
  SSyncState syncState = syncGetState(pVnode->sync);
×
947
  if (syncState.state == TAOS_SYNC_STATE_LEADER || syncState.state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
×
948
    pLoad->vgId = TD_VID(pVnode);
×
949
    pLoad->nTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1);
×
950
    return 0;
×
951
  }
UNCOV
952
  return -1;
×
953
}
954
/**
955
 * @brief Reset the statistics value by monitor interval
956
 *
957
 * @param pVnode
958
 * @param pLoad
959
 */
960
void vnodeResetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
34✔
961
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsert, pLoad->numOfInsertReqs, 64, "nInsert");
34!
962
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsertSuccess, pLoad->numOfInsertSuccessReqs, 64, "nInsertSuccess");
34!
963
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsert, pLoad->numOfBatchInsertReqs, 64, "nBatchInsert");
34!
964
  VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsertSuccess, pLoad->numOfBatchInsertSuccessReqs, 64,
34!
965
                            "nBatchInsertSuccess");
966
}
34✔
967

968
void vnodeGetInfo(void *pVnode, const char **dbname, int32_t *vgId, int64_t *numOfTables, int64_t *numOfNormalTables) {
1,009,828✔
969
  SVnode    *pVnodeObj = pVnode;
1,009,828✔
970
  SVnodeCfg *pConf = &pVnodeObj->config;
1,009,828✔
971

972
  if (dbname) {
1,009,828!
973
    *dbname = pConf->dbname;
1,010,716✔
974
  }
975

976
  if (vgId) {
1,009,828✔
977
    *vgId = TD_VID(pVnodeObj);
1,009,636✔
978
  }
979

980
  if (numOfTables) {
1,009,828!
UNCOV
981
    *numOfTables = pConf->vndStats.numOfNTables + pConf->vndStats.numOfCTables;
×
982
  }
983

984
  if (numOfNormalTables) {
1,009,828!
UNCOV
985
    *numOfNormalTables = pConf->vndStats.numOfNTables;
×
986
  }
987
}
1,009,828✔
988

UNCOV
989
int32_t vnodeGetTableList(void *pVnode, int8_t type, SArray *pList) {
×
990
  if (type == TSDB_SUPER_TABLE) {
×
991
    return vnodeGetStbIdList(pVnode, 0, pList);
×
992
  } else {
UNCOV
993
    return TSDB_CODE_INVALID_PARA;
×
994
  }
995
}
996

UNCOV
997
int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) {
×
998
  int32_t      code = TSDB_CODE_SUCCESS;
×
999
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, uid, 1);
×
1000
  if (NULL == pCur) {
×
1001
    qError("vnode get all table list failed");
×
1002
    return terrno;
×
1003
  }
1004

UNCOV
1005
  while (1) {
×
1006
    tb_uid_t id = metaCtbCursorNext(pCur);
×
1007
    if (id == 0) {
×
1008
      break;
×
1009
    }
1010

UNCOV
1011
    STableKeyInfo info = {uid = id};
×
1012
    if (NULL == taosArrayPush(list, &info)) {
×
1013
      qError("taosArrayPush failed");
×
1014
      code = terrno;
×
1015
      goto _exit;
×
1016
    }
1017
  }
UNCOV
1018
_exit:
×
1019
  metaCloseCtbCursor(pCur);
×
1020
  return code;
×
1021
}
1022

UNCOV
1023
int32_t vnodeGetCtbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg), void *arg) {
×
1024
  return 0;
×
1025
}
1026

1027
int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) {
2,891,818✔
1028
  int32_t      code = TSDB_CODE_SUCCESS;
2,891,818✔
1029
  SVnode      *pVnodeObj = pVnode;
2,891,818✔
1030
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnodeObj, suid, 1);
2,891,818✔
1031
  if (NULL == pCur) {
2,897,226!
UNCOV
1032
    qError("vnode get all table list failed");
×
1033
    return terrno;
×
1034
  }
1035

1036
  while (1) {
9,220,489✔
1037
    tb_uid_t id = metaCtbCursorNext(pCur);
12,117,715✔
1038
    if (id == 0) {
12,121,002✔
1039
      break;
2,899,595✔
1040
    }
1041

1042
    if (NULL == taosArrayPush(list, &id)) {
9,220,489!
UNCOV
1043
      qError("taosArrayPush failed");
×
1044
      code = terrno;
×
1045
      goto _exit;
×
1046
    }
1047
  }
1048

1049
_exit:
2,899,595✔
1050
  metaCloseCtbCursor(pCur);
2,899,595✔
1051
  return code;
2,898,884✔
1052
}
1053

1054
int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) {
165,205✔
1055
  int32_t      code = TSDB_CODE_SUCCESS;
165,205✔
1056
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
165,205✔
1057
  if (!pCur) {
165,205!
UNCOV
1058
    return TSDB_CODE_OUT_OF_MEMORY;
×
1059
  }
1060

1061
  while (1) {
144,713✔
1062
    tb_uid_t id = metaStbCursorNext(pCur);
309,918✔
1063
    if (id == 0) {
309,909✔
1064
      break;
165,205✔
1065
    }
1066

1067
    if (NULL == taosArrayPush(list, &id)) {
144,713!
UNCOV
1068
      qError("taosArrayPush failed");
×
1069
      code = terrno;
×
1070
      goto _exit;
×
1071
    }
1072
  }
1073

1074
_exit:
165,205✔
1075
  metaCloseStbCursor(pCur);
165,205✔
1076
  return code;
165,206✔
1077
}
1078

1079
int32_t vnodeGetStbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg, void *arg1),
59✔
1080
                                  void *arg) {
1081
  int32_t      code = TSDB_CODE_SUCCESS;
59✔
1082
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
59✔
1083
  if (!pCur) {
59!
UNCOV
1084
    return terrno;
×
1085
  }
1086

1087
  while (1) {
67✔
1088
    tb_uid_t id = metaStbCursorNext(pCur);
126✔
1089
    if (id == 0) {
126✔
1090
      break;
59✔
1091
    }
1092

1093
    if ((*filter) && (*filter)(arg, &id)) {
67!
1094
      continue;
67✔
1095
    }
1096

UNCOV
1097
    if (NULL == taosArrayPush(list, &id)) {
×
1098
      qError("taosArrayPush failed");
×
1099
      code = terrno;
×
1100
      goto _exit;
×
1101
    }
1102
  }
1103

1104
_exit:
59✔
1105
  metaCloseStbCursor(pCur);
59✔
1106
  return code;
59✔
1107
}
1108

1109
int32_t vnodeGetCtbNum(SVnode *pVnode, int64_t suid, int64_t *num) {
25,235✔
1110
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, suid, 0);
25,235✔
1111
  if (!pCur) {
25,243!
UNCOV
1112
    return terrno;
×
1113
  }
1114

1115
  *num = 0;
25,243✔
1116
  while (1) {
23,456✔
1117
    tb_uid_t id = metaCtbCursorNext(pCur);
48,699✔
1118
    if (id == 0) {
48,704✔
1119
      break;
25,248✔
1120
    }
1121

1122
    ++(*num);
23,456✔
1123
  }
1124

1125
  metaCloseCtbCursor(pCur);
25,248✔
1126
  return TSDB_CODE_SUCCESS;
25,246✔
1127
}
1128

1129
int32_t vnodeGetStbColumnNum(SVnode *pVnode, tb_uid_t suid, int *num) {
25,243✔
1130
  SSchemaWrapper *pSW = metaGetTableSchema(pVnode->pMeta, suid, -1, 0, NULL);
25,243✔
1131
  if (pSW) {
25,248✔
1132
    *num = pSW->nCols;
25,247!
1133
    tDeleteSchemaWrapper(pSW);
1134
  } else {
1135
    *num = 2;
1✔
1136
  }
1137

1138
  return TSDB_CODE_SUCCESS;
25,248✔
1139
}
1140

1141
int32_t vnodeGetStbInfo(SVnode *pVnode, tb_uid_t suid, int64_t *keep, int8_t *flags) {
25,245✔
1142
  SMetaReader mr = {0};
25,245✔
1143
  metaReaderDoInit(&mr, pVnode->pMeta, META_READER_NOLOCK);
25,245✔
1144

1145
  int32_t code = metaReaderGetTableEntryByUid(&mr, suid);
25,246✔
1146
  if (code == TSDB_CODE_SUCCESS) {
25,246✔
1147
    if (keep) *keep = mr.me.stbEntry.keep;
25,245!
1148
    if (flags) *flags = mr.me.flags;
25,245!
1149
  } else {
1150
    if (keep) *keep = 0;
1!
1151
    if (flags) *flags = 0;
1!
1152
  }
1153

1154
  metaReaderClear(&mr);
25,246✔
1155
  return TSDB_CODE_SUCCESS;
25,249✔
1156
}
1157

1158
#ifdef TD_ENTERPRISE
1159
const char *tkLogStb[] = {"cluster_info",
1160
                          "data_dir",
1161
                          "dnodes_info",
1162
                          "d_info",
1163
                          "grants_info",
1164
                          "keeper_monitor",
1165
                          "logs",
1166
                          "log_dir",
1167
                          "log_summary",
1168
                          "m_info",
1169
                          "taosadapter_restful_http_request_fail",
1170
                          "taosadapter_restful_http_request_in_flight",
1171
                          "taosadapter_restful_http_request_summary_milliseconds",
1172
                          "taosadapter_restful_http_request_total",
1173
                          "taosadapter_system_cpu_percent",
1174
                          "taosadapter_system_mem_percent",
1175
                          "temp_dir",
1176
                          "vgroups_info",
1177
                          "vnodes_role"};
1178
const char *tkAuditStb[] = {"operations"};
1179
const int   tkLogStbNum = ARRAY_SIZE(tkLogStb);
1180
const int   tkAuditStbNum = ARRAY_SIZE(tkAuditStb);
1181

1182
// exclude stbs of taoskeeper log
1183
static int32_t vnodeGetTimeSeriesBlackList(SVnode *pVnode, int32_t *tbSize) {
165,257✔
1184
  int32_t      code = TSDB_CODE_SUCCESS;
165,257✔
1185
  int32_t      tbNum = 0;
165,257✔
1186
  const char **pTbArr = NULL;
165,257✔
1187
  const char  *dbName = NULL;
165,257✔
1188
  *tbSize = 0;
165,257✔
1189

1190
  if (!(dbName = strchr(pVnode->config.dbname, '.'))) return 0;
165,257!
1191
  if (0 == strncmp(++dbName, "log", TSDB_DB_NAME_LEN)) {
165,257✔
1192
    tbNum = tkLogStbNum;
18✔
1193
    pTbArr = (const char **)&tkLogStb;
18✔
1194
  } else if (0 == strncmp(dbName, "audit", TSDB_DB_NAME_LEN)) {
165,239✔
1195
    tbNum = tkAuditStbNum;
58✔
1196
    pTbArr = (const char **)&tkAuditStb;
58✔
1197
  }
1198
  if (tbNum && pTbArr) {
165,257!
1199
    *tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 0);
76✔
1200
    if (*tbSize < tbNum) {
76✔
1201
      for (int32_t i = 0; i < tbNum; ++i) {
240✔
1202
        tb_uid_t suid = metaGetTableEntryUidByName(pVnode->pMeta, pTbArr[i]);
233✔
1203
        if (suid != 0) {
233✔
1204
          code = metaPutTbToFilterCache(pVnode->pMeta, &suid, 0);
26✔
1205
          if (TSDB_CODE_SUCCESS != code) {
26✔
1206
            return code;
14✔
1207
          }
1208
        }
1209
      }
1210
      *tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 0);
7✔
1211
    }
1212
  }
1213

1214
  return code;
165,243✔
1215
}
1216
#endif
1217

1218
static bool vnodeTimeSeriesFilter(void *arg1, void *arg2) {
67✔
1219
  SVnode *pVnode = (SVnode *)arg1;
67✔
1220

1221
  if (metaTbInFilterCache(pVnode->pMeta, arg2, 0)) {
67!
1222
    return true;
67✔
1223
  }
UNCOV
1224
  return false;
×
1225
}
1226

1227
int32_t vnodeGetTimeSeriesNum(SVnode *pVnode, int64_t *num) {
165,256✔
1228
  SArray *suidList = NULL;
165,256✔
1229

1230
  if (!(suidList = taosArrayInit(1, sizeof(tb_uid_t)))) {
165,256!
UNCOV
1231
    return terrno;
×
1232
  }
1233

1234
  int32_t tbFilterSize = 0;
165,258✔
1235
  int32_t code = TSDB_CODE_SUCCESS;
165,258✔
1236
#ifdef TD_ENTERPRISE
1237
  code = vnodeGetTimeSeriesBlackList(pVnode, &tbFilterSize);
165,258✔
1238
  if (TSDB_CODE_SUCCESS != code) {
165,258✔
1239
    goto _exit;
14✔
1240
  }
1241
#endif
1242

1243
  if ((!tbFilterSize && vnodeGetStbIdList(pVnode, 0, suidList) < 0) ||
165,244✔
1244
      (tbFilterSize && vnodeGetStbIdListByFilter(pVnode, 0, suidList, vnodeTimeSeriesFilter, pVnode) < 0)) {
165,243!
UNCOV
1245
    qError("vgId:%d, failed to get stb id list error: %s", TD_VID(pVnode), terrstr());
×
1246
    taosArrayDestroy(suidList);
×
1247
    return terrno;
×
1248
  }
1249

1250
  *num = 0;
165,244✔
1251
  int64_t arrSize = taosArrayGetSize(suidList);
165,244✔
1252
  for (int64_t i = 0; i < arrSize; ++i) {
309,971✔
1253
    tb_uid_t suid = *(tb_uid_t *)taosArrayGet(suidList, i);
144,726✔
1254

1255
    int64_t ctbNum = 0;
144,723✔
1256
    int32_t numOfCols = 0;
144,723✔
1257
    int8_t  flags = 0;
144,723✔
1258
    code = metaGetStbStats(pVnode, suid, &ctbNum, &numOfCols, &flags);
144,723✔
1259
    if (TSDB_CODE_SUCCESS != code) {
144,728!
UNCOV
1260
      goto _exit;
×
1261
    }
1262
    if (!TABLE_IS_VIRTUAL(flags)) {
144,728✔
1263
      *num += ctbNum * (numOfCols - 1);
144,718✔
1264
    }
1265
  }
1266

1267
_exit:
165,245✔
1268
  taosArrayDestroy(suidList);
165,259✔
1269
  return TSDB_CODE_SUCCESS;
165,259✔
1270
}
1271

UNCOV
1272
int32_t vnodeGetAllCtbNum(SVnode *pVnode, int64_t *num) {
×
1273
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, 0);
×
1274
  if (!pCur) {
×
1275
    return terrno;
×
1276
  }
1277

UNCOV
1278
  *num = 0;
×
1279
  while (1) {
×
1280
    tb_uid_t id = metaStbCursorNext(pCur);
×
1281
    if (id == 0) {
×
1282
      break;
×
1283
    }
1284

UNCOV
1285
    int64_t ctbNum = 0;
×
1286
    int32_t code = vnodeGetCtbNum(pVnode, id, &ctbNum);
×
1287
    if (TSDB_CODE_SUCCESS != code) {
×
1288
      metaCloseStbCursor(pCur);
×
1289
      return code;
×
1290
    }
1291

UNCOV
1292
    *num += ctbNum;
×
1293
  }
1294

UNCOV
1295
  metaCloseStbCursor(pCur);
×
1296
  return TSDB_CODE_SUCCESS;
×
1297
}
1298

1299
void *vnodeGetIdx(void *pVnode) {
55,343✔
1300
  if (pVnode == NULL) {
55,343!
UNCOV
1301
    return NULL;
×
1302
  }
1303

1304
  return metaGetIdx(((SVnode *)pVnode)->pMeta);
55,343✔
1305
}
1306

1307
void *vnodeGetIvtIdx(void *pVnode) {
55,283✔
1308
  if (pVnode == NULL) {
55,283!
UNCOV
1309
    return NULL;
×
1310
  }
1311
  return metaGetIvtIdx(((SVnode *)pVnode)->pMeta);
55,283✔
1312
}
1313

1314
int32_t vnodeGetTableSchema(void *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid) {
267✔
1315
  return tsdbGetTableSchema(((SVnode *)pVnode)->pMeta, uid, pSchema, suid);
267✔
1316
}
1317

1318
static FORCE_INLINE int32_t vnodeGetDBPrimaryInfo(SVnode *pVnode, SDbSizeStatisInfo *pInfo) {
1319
  int32_t code = 0;
26✔
1320
  char    path[TSDB_FILENAME_LEN] = {0};
26✔
1321

1322
  char   *dirName[] = {VNODE_TSDB_DIR, VNODE_WAL_DIR, VNODE_META_DIR, VNODE_TSDB_CACHE_DIR};
26✔
1323
  int64_t dirSize[4];
1324

1325
  vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, path, TSDB_FILENAME_LEN);
26✔
1326
  int32_t offset = strlen(path);
26✔
1327

1328
  for (int i = 0; i < sizeof(dirName) / sizeof(dirName[0]); i++) {
130✔
1329
    int64_t size = {0};
104✔
1330
    (void)snprintf(path + offset, TSDB_FILENAME_LEN, "%s%s", TD_DIRSEP, dirName[i]);
104✔
1331
    code = taosGetDirSize(path, &size);
104✔
1332
    if (code != 0) {
104!
UNCOV
1333
      return code;
×
1334
    }
1335
    path[offset] = 0;
104✔
1336
    dirSize[i] = size;
104✔
1337
  }
1338

1339
  pInfo->l1Size = 0;
26✔
1340
  pInfo->walSize = dirSize[1];
26✔
1341
  pInfo->metaSize = dirSize[2];
26✔
1342
  pInfo->cacheSize = dirSize[3];
26✔
1343
  return code;
26✔
1344
}
1345
int32_t vnodeGetDBSize(void *pVnode, SDbSizeStatisInfo *pInfo) {
26✔
1346
  int32_t code = 0;
26✔
1347
  int32_t lino = 0;
26✔
1348
  SVnode *pVnodeObj = pVnode;
26✔
1349
  if (pVnodeObj == NULL) {
26!
UNCOV
1350
    return TSDB_CODE_VND_NOT_EXIST;
×
1351
  }
1352
  code = vnodeGetDBPrimaryInfo(pVnode, pInfo);
26✔
1353
  if (code != 0) goto _exit;
26!
1354

1355
  code = tsdbGetFsSize(pVnodeObj->pTsdb, pInfo);
26✔
1356
_exit:
26✔
1357
  return code;
26✔
1358
}
1359

1360
int32_t vnodeGetStreamProgress(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
3,296✔
1361
  int32_t            code = 0;
3,296✔
1362
  SStreamProgressReq req;
1363
  SStreamProgressRsp rsp = {0};
3,296✔
1364
  SRpcMsg            rpcMsg = {.info = pMsg->info, .code = 0};
3,296✔
1365
  char              *buf = NULL;
3,296✔
1366
  int32_t            rspLen = 0;
3,296✔
1367
  code = tDeserializeStreamProgressReq(pMsg->pCont, pMsg->contLen, &req);
3,296✔
1368

1369
  if (code == TSDB_CODE_SUCCESS) {
3,296!
1370
    rsp.fetchIdx = req.fetchIdx;
3,296✔
1371
    rsp.subFetchIdx = req.subFetchIdx;
3,296✔
1372
    rsp.vgId = req.vgId;
3,296✔
1373
    rsp.streamId = req.streamId;
3,296✔
1374
    rspLen = tSerializeStreamProgressRsp(0, 0, &rsp);
3,296✔
1375
    if (rspLen < 0) {
3,295!
UNCOV
1376
      code = terrno;
×
1377
      goto _OVER;
×
1378
    }
1379
    if (direct) {
3,295!
UNCOV
1380
      buf = rpcMallocCont(rspLen);
×
1381
    } else {
1382
      buf = taosMemoryCalloc(1, rspLen);
3,295!
1383
    }
1384
    if (!buf) {
3,296!
UNCOV
1385
      code = terrno;
×
1386
      goto _OVER;
×
1387
    }
1388
  }
1389

1390
  if (code == TSDB_CODE_SUCCESS) {
3,296!
1391
    code = tqGetStreamExecInfo(pVnode, req.streamId, &rsp.progressDelay, &rsp.fillHisFinished);
3,296✔
1392
  }
1393
  if (code == TSDB_CODE_SUCCESS) {
3,296!
1394
    rspLen = tSerializeStreamProgressRsp(buf, rspLen, &rsp);
3,296✔
1395
    if (rspLen < 0) {
3,296!
UNCOV
1396
      code = terrno;
×
1397
      goto _OVER;
×
1398
    }
1399
    rpcMsg.pCont = buf;
3,296✔
1400
    buf = NULL;
3,296✔
1401
    rpcMsg.contLen = rspLen;
3,296✔
1402
    rpcMsg.code = code;
3,296✔
1403
    rpcMsg.msgType = pMsg->msgType;
3,296✔
1404
    if (direct) {
3,296!
UNCOV
1405
      tmsgSendRsp(&rpcMsg);
×
1406
    } else {
1407
      *pMsg = rpcMsg;
3,296✔
1408
    }
1409
  }
1410

UNCOV
1411
_OVER:
×
1412
  if (buf) {
3,296!
UNCOV
1413
    taosMemoryFree(buf);
×
1414
  }
1415
  return code;
3,296✔
1416
}
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