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

taosdata / TDengine / #3631

07 Mar 2025 03:18PM UTC coverage: 60.671% (-3.0%) from 63.629%
#3631

push

travis-ci

web-flow
Merge pull request #30074 from taosdata/ciup30

ci: update ci workflow to fix path issue

141481 of 300084 branches covered (47.15%)

Branch coverage included in aggregate %.

223132 of 300884 relevant lines covered (74.16%)

7878557.0 hits per line

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

57.88
/source/dnode/vnode/src/vnd/vnodeQuery.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "tsdb.h"
17
#include "vnd.h"
18

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

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

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

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

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

52
void vnodePrintTableMeta(STableMetaRsp *pMeta) {
58,353✔
53
  if (!(qDebugFlag & DEBUG_DEBUG)) {
58,353✔
54
    return;
53,778✔
55
  }
56

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

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

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

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

107
  if (!reqTbUid) {
92,242✔
108
    (void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", infoReq.dbFName, infoReq.tbName);
91,700✔
109
    code = vnodeValidateTableHash(pVnode, tableFName);
91,703✔
110
    if (code) {
91,704!
111
      goto _exit4;
×
112
    }
113
  }
114

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

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

142
  if (mer1.me.type == TSDB_SUPER_TABLE) {
58,353✔
143
    tstrncpy(metaRsp.stbName, mer1.me.name, TSDB_TABLE_NAME_LEN);
6,612✔
144
    schema = mer1.me.stbEntry.schemaRow;
6,612✔
145
    schemaTag = mer1.me.stbEntry.schemaTag;
6,612✔
146
    metaRsp.suid = mer1.me.uid;
6,612✔
147
  } else if (mer1.me.type == TSDB_CHILD_TABLE) {
51,741✔
148
    metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
47,182✔
149
    if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit2;
47,183!
150

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

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

188
  vnodePrintTableMeta(&metaRsp);
58,353✔
189

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

197
  if (direct) {
58,353✔
198
    pRsp = rpcMallocCont(rspLen);
227✔
199
  } else {
200
    pRsp = taosMemoryCalloc(1, rspLen);
58,126!
201
  }
202

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

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

214
_exit:
58,354✔
215
  taosMemoryFree(metaRsp.pSchemas);
58,353!
216
  taosMemoryFree(metaRsp.pSchemaExt);
58,354!
217
_exit2:
58,354✔
218
  metaReaderClear(&mer2);
58,354✔
219
_exit3:
92,242✔
220
  metaReaderClear(&mer1);
92,242✔
221
_exit4:
92,237✔
222
  rpcMsg.info = pMsg->info;
92,237✔
223
  rpcMsg.pCont = pRsp;
92,237✔
224
  rpcMsg.contLen = rspLen;
92,237✔
225
  rpcMsg.code = code;
92,237✔
226
  rpcMsg.msgType = pMsg->msgType;
92,237✔
227

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

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

236
  if (direct) {
92,241✔
237
    tmsgSendRsp(&rpcMsg);
1,780✔
238
  } else {
239
    *pMsg = rpcMsg;
90,461✔
240
  }
241

242
  return code;
92,240✔
243
}
244

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

434
  batchRsp.pRsps = taosArrayInit(msgNum, sizeof(SBatchRspMsg));
92,756✔
435
  if (NULL == batchRsp.pRsps) {
92,757!
436
    code = terrno;
×
437
    qError("taosArrayInit %d SBatchRspMsg failed", msgNum);
×
438
    goto _exit;
×
439
  }
440

441
  for (int32_t i = 0; i < msgNum; ++i) {
188,713✔
442
    req = taosArrayGet(batchReq.pMsgs, i);
95,950✔
443
    if (req == NULL) {
95,951✔
444
      code = terrno;
1✔
445
      goto _exit;
×
446
    }
447

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

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

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

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

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

516
_exit:
92,760✔
517

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

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

528
  taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
92,760✔
529
  taosArrayDestroyEx(batchRsp.pRsps, tFreeSBatchRspMsg);
92,760✔
530

531
  tmsgSendRsp(&rspMsg);
92,759✔
532

533
  return code;
92,758✔
534
}
535

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

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

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

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

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

598
  if (dbname) {
27,235!
599
    *dbname = pConf->dbname;
27,245✔
600
  }
601

602
  if (vgId) {
27,235✔
603
    *vgId = TD_VID(pVnodeObj);
25,885✔
604
  }
605

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

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

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

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

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

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

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

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

662
  while (1) {
2,449,715✔
663
    tb_uid_t id = metaCtbCursorNext(pCur);
3,016,097✔
664
    if (id == 0) {
3,015,466✔
665
      break;
566,836✔
666
    }
667

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

675
_exit:
566,836✔
676
  metaCloseCtbCursor(pCur);
566,836✔
677
  return code;
566,848✔
678
}
679

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

687
  while (1) {
99,332✔
688
    tb_uid_t id = metaStbCursorNext(pCur);
195,854✔
689
    if (id == 0) {
195,857✔
690
      break;
96,523✔
691
    }
692

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

700
_exit:
96,523✔
701
  metaCloseStbCursor(pCur);
96,523✔
702
  return code;
96,523✔
703
}
704

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

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

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

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

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

735
int32_t vnodeGetCtbNum(SVnode *pVnode, int64_t suid, int64_t *num) {
18,272✔
736
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, suid, 0);
18,272✔
737
  if (!pCur) {
18,276✔
738
    return terrno;
3✔
739
  }
740

741
  *num = 0;
18,273✔
742
  while (1) {
11,204✔
743
    tb_uid_t id = metaCtbCursorNext(pCur);
29,477✔
744
    if (id == 0) {
29,481✔
745
      break;
18,277✔
746
    }
747

748
    ++(*num);
11,204✔
749
  }
750

751
  metaCloseCtbCursor(pCur);
18,277✔
752
  return TSDB_CODE_SUCCESS;
18,279✔
753
}
754

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

764
  return TSDB_CODE_SUCCESS;
18,277✔
765
}
766

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

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

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

823
  return code;
96,504✔
824
}
825
#endif
826

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

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

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

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

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

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

859
  *num = 0;
96,506✔
860
  int64_t arrSize = taosArrayGetSize(suidList);
96,506✔
861
  for (int64_t i = 0; i < arrSize; ++i) {
195,864✔
862
    tb_uid_t suid = *(tb_uid_t *)taosArrayGet(suidList, i);
99,356✔
863

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

873
_exit:
96,508✔
874
  taosArrayDestroy(suidList);
96,508✔
875
  return TSDB_CODE_SUCCESS;
96,506✔
876
}
877

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

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

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

898
    *num += ctbNum;
×
899
  }
900

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

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

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

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

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

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

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

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

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

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

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

956
  return code;
22✔
957
}
958

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

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

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

1010
_OVER:
×
1011
  if (buf) {
5,428!
1012
    taosMemoryFree(buf);
×
1013
  }
1014
  return code;
5,428✔
1015
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc