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

taosdata / TDengine / #4041

09 May 2025 07:58AM UTC coverage: 62.508% (-0.3%) from 62.788%
#4041

push

travis-ci

web-flow
enh: update database fetch functions to include status in JSON output (#31005)

155567 of 317611 branches covered (48.98%)

Branch coverage included in aggregate %.

15 of 18 new or added lines in 1 file covered. (83.33%)

3906 existing lines in 185 files now uncovered.

240901 of 316655 relevant lines covered (76.08%)

6304979.72 hits per line

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

52.25
/source/libs/qcom/src/querymsg.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 "query.h"
17
#include "queryInt.h"
18
#include "systable.h"
19
#include "tmsg.h"
20
#include "trpc.h"
21

22
#pragma GCC diagnostic push
23
#ifdef COMPILER_SUPPORTS_CXX13
24
#pragma GCC diagnostic ignored "-Wformat-truncation"
25
#endif
26

27
int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
28
                                   void *(*mallocFp)(int64_t)) = {0};
29
int32_t (*queryProcessMsgRsp[TDMT_MAX])(void *output, char *msg, int32_t msgSize) = {0};
30

31
int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) {
153,172✔
32
  QUERY_PARAM_CHECK(pOut);
153,172!
33
  QUERY_PARAM_CHECK(usedbRsp);
153,172!
34
  memcpy(pOut->db, usedbRsp->db, TSDB_DB_FNAME_LEN);
153,172✔
35
  pOut->dbId = usedbRsp->uid;
153,172✔
36

37
  pOut->dbVgroup = taosMemoryCalloc(1, sizeof(SDBVgInfo));
153,172!
38
  if (NULL == pOut->dbVgroup) {
153,175!
39
    return terrno;
×
40
  }
41

42
  pOut->dbVgroup->vgVersion = usedbRsp->vgVersion;
153,175✔
43
  pOut->dbVgroup->hashMethod = usedbRsp->hashMethod;
153,175✔
44
  pOut->dbVgroup->hashPrefix = usedbRsp->hashPrefix;
153,175✔
45
  pOut->dbVgroup->hashSuffix = usedbRsp->hashSuffix;
153,175✔
46
  pOut->dbVgroup->stateTs = usedbRsp->stateTs;
153,175✔
47

48
  qDebug("db:%s, get %d vgroup, vgVersion:%d, stateTs:%" PRId64, usedbRsp->db, usedbRsp->vgNum, usedbRsp->vgVersion,
153,175✔
49
         usedbRsp->stateTs);
50

51
  if (usedbRsp->vgNum <= 0) {
153,174✔
52
    return TSDB_CODE_SUCCESS;
9,221✔
53
  }
54

55
  pOut->dbVgroup->vgHash =
287,906✔
56
      taosHashInit(usedbRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
143,953✔
57
  if (NULL == pOut->dbVgroup->vgHash) {
143,953!
58
    return terrno;
×
59
  }
60

61
  for (int32_t i = 0; i < usedbRsp->vgNum; ++i) {
487,781✔
62
    SVgroupInfo *pVgInfo = taosArrayGet(usedbRsp->pVgroupInfos, i);
343,829✔
63
    pOut->dbVgroup->numOfTable += pVgInfo->numOfTable;
343,829✔
64
    qDebug("db:%s, vgId:%d, epNum:%d, current ep:%s:%u", usedbRsp->db, pVgInfo->vgId, pVgInfo->epSet.numOfEps,
343,829✔
65
           pVgInfo->epSet.eps[pVgInfo->epSet.inUse].fqdn, pVgInfo->epSet.eps[pVgInfo->epSet.inUse].port);
66
    if (0 != taosHashPut(pOut->dbVgroup->vgHash, &pVgInfo->vgId, sizeof(int32_t), pVgInfo, sizeof(SVgroupInfo))) {
343,829!
67
      return terrno;
×
68
    }
69
  }
70

71
  return TSDB_CODE_SUCCESS;
143,952✔
72
}
73

74
int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
131,063✔
75
                                  void *(*mallcFp)(int64_t)) {
76
  QUERY_PARAM_CHECK(input);
131,063!
77
  QUERY_PARAM_CHECK(msg);
131,063!
78
  QUERY_PARAM_CHECK(msgLen);
131,063!
79
  SBuildTableInput *pInput = input;
131,063✔
80

81
  STableInfoReq infoReq = {0};
131,063✔
82
  infoReq.option = pInput->option;
131,063✔
83
  infoReq.header.vgId = pInput->vgId;
131,063✔
84
  infoReq.autoCreateCtb = pInput->autoCreateCtb;
131,063✔
85

86
  if (pInput->dbFName) {
131,063✔
87
    tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
131,062✔
88
  }
89
  tstrncpy(infoReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
131,063✔
90

91
  int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
131,063✔
92
  void   *pBuf = (*mallcFp)(bufLen);
131,060✔
93
  if (NULL == pBuf) {
131,061!
94
    return terrno;
×
95
  }
96
  int32_t ret = tSerializeSTableInfoReq(pBuf, bufLen, &infoReq);
131,061✔
97
  if (ret < 0) return ret;
131,063!
98

99
  *msg = pBuf;
131,063✔
100
  *msgLen = bufLen;
131,063✔
101

102
  return TSDB_CODE_SUCCESS;
131,063✔
103
}
104

105
int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
146,785✔
106
  QUERY_PARAM_CHECK(input);
146,785!
107
  QUERY_PARAM_CHECK(msg);
146,785!
108
  QUERY_PARAM_CHECK(msgLen);
146,785!
109
  SBuildUseDBInput *pInput = input;
146,785✔
110

111
  SUseDbReq usedbReq = {0};
146,785✔
112
  tstrncpy(usedbReq.db, pInput->db, TSDB_DB_FNAME_LEN);
146,785✔
113
  usedbReq.db[sizeof(usedbReq.db) - 1] = 0;
146,785✔
114
  usedbReq.vgVersion = pInput->vgVersion;
146,785✔
115
  usedbReq.dbId = pInput->dbId;
146,785✔
116
  usedbReq.numOfTable = pInput->numOfTable;
146,785✔
117
  usedbReq.stateTs = pInput->stateTs;
146,785✔
118

119
  int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
146,785✔
120
  void   *pBuf = (*mallcFp)(bufLen);
146,785✔
121
  if (NULL == pBuf) {
146,787!
122
    return terrno;
×
123
  }
124
  int32_t ret = tSerializeSUseDbReq(pBuf, bufLen, &usedbReq);
146,787✔
125
  if (ret < 0) return ret;
146,785!
126

127
  *msg = pBuf;
146,785✔
128
  *msgLen = bufLen;
146,785✔
129

130
  return TSDB_CODE_SUCCESS;
146,785✔
131
}
132

133
int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
11,750✔
134
  QUERY_PARAM_CHECK(msg);
11,750!
135
  QUERY_PARAM_CHECK(msgLen);
11,750!
136

137
  SQnodeListReq qnodeListReq = {0};
11,750✔
138
  qnodeListReq.rowNum = -1;
11,750✔
139

140
  int32_t bufLen = tSerializeSQnodeListReq(NULL, 0, &qnodeListReq);
11,750✔
141
  void   *pBuf = (*mallcFp)(bufLen);
11,750✔
142
  if (NULL == pBuf) {
11,750!
143
    return terrno;
×
144
  }
145

146
  int32_t ret = tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq);
11,750✔
147
  if (ret < 0) return ret;
11,750!
148

149
  *msg = pBuf;
11,750✔
150
  *msgLen = bufLen;
11,750✔
151

152
  return TSDB_CODE_SUCCESS;
11,750✔
153
}
154

155
int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
368✔
156
  QUERY_PARAM_CHECK(msg);
368!
157
  QUERY_PARAM_CHECK(msgLen);
368!
158

159
  SDnodeListReq dnodeListReq = {0};
368✔
160
  dnodeListReq.rowNum = -1;
368✔
161

162
  int32_t bufLen = tSerializeSDnodeListReq(NULL, 0, &dnodeListReq);
368✔
163
  void   *pBuf = (*mallcFp)(bufLen);
368✔
164
  if (NULL == pBuf) {
368!
165
    return terrno;
×
166
  }
167
  int32_t ret = tSerializeSDnodeListReq(pBuf, bufLen, &dnodeListReq);
368✔
168
  if (ret < 0) return ret;
368!
169

170
  *msg = pBuf;
368✔
171
  *msgLen = bufLen;
368✔
172

173
  return TSDB_CODE_SUCCESS;
368✔
174
}
175

176
int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
1✔
177
  QUERY_PARAM_CHECK(msg);
1!
178
  QUERY_PARAM_CHECK(msgLen);
1!
179

180
  SServerVerReq req = {0};
1✔
181

182
  int32_t bufLen = tSerializeSServerVerReq(NULL, 0, &req);
1✔
183
  void   *pBuf = (*mallcFp)(bufLen);
1✔
184
  if (NULL == pBuf) {
1!
185
    return terrno;
×
186
  }
187
  int32_t ret = tSerializeSServerVerReq(pBuf, bufLen, &req);
1✔
188
  if (ret < 0) return ret;
1!
189

190
  *msg = pBuf;
1✔
191
  *msgLen = bufLen;
1✔
192

193
  return TSDB_CODE_SUCCESS;
1✔
194
}
195

196
int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
6,426✔
197
  QUERY_PARAM_CHECK(input);
6,426!
198
  QUERY_PARAM_CHECK(msg);
6,426!
199
  QUERY_PARAM_CHECK(msgLen);
6,426!
200

201
  SDbCfgReq dbCfgReq = {0};
6,426✔
202
  tstrncpy(dbCfgReq.db, input, TSDB_DB_FNAME_LEN);
6,426✔
203

204
  int32_t bufLen = tSerializeSDbCfgReq(NULL, 0, &dbCfgReq);
6,426✔
205
  void   *pBuf = (*mallcFp)(bufLen);
6,426✔
206
  if (NULL == pBuf) {
6,426!
207
    return terrno;
×
208
  }
209
  int32_t ret = tSerializeSDbCfgReq(pBuf, bufLen, &dbCfgReq);
6,426✔
210
  if (ret < 0) return ret;
6,426!
211

212
  *msg = pBuf;
6,426✔
213
  *msgLen = bufLen;
6,426✔
214

215
  return TSDB_CODE_SUCCESS;
6,426✔
216
}
217

218
int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
1✔
219
  QUERY_PARAM_CHECK(input);
1!
220
  QUERY_PARAM_CHECK(msg);
1!
221
  QUERY_PARAM_CHECK(msgLen);
1!
222

223
  SUserIndexReq indexReq = {0};
1✔
224
  tstrncpy(indexReq.indexFName, input, TSDB_INDEX_FNAME_LEN);
1✔
225

226
  int32_t bufLen = tSerializeSUserIndexReq(NULL, 0, &indexReq);
1✔
227
  void   *pBuf = (*mallcFp)(bufLen);
1✔
228
  if (NULL == pBuf) {
1!
229
    return terrno;
×
230
  }
231
  int32_t ret = tSerializeSUserIndexReq(pBuf, bufLen, &indexReq);
1✔
232
  if (ret < 0) return ret;
1!
233

234
  *msg = pBuf;
1✔
235
  *msgLen = bufLen;
1✔
236

237
  return TSDB_CODE_SUCCESS;
1✔
238
}
239

240
int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
97✔
241
                                  void *(*mallcFp)(int64_t)) {
242
  QUERY_PARAM_CHECK(input);
97!
243
  QUERY_PARAM_CHECK(msg);
97!
244
  QUERY_PARAM_CHECK(msgLen);
97!
245

246
  SRetrieveFuncReq funcReq = {0};
97✔
247
  funcReq.numOfFuncs = 1;
97✔
248
  funcReq.ignoreCodeComment = true;
97✔
249
  funcReq.pFuncNames = taosArrayInit(1, strlen(input) + 1);
97✔
250
  if (NULL == funcReq.pFuncNames) {
97!
251
    return terrno;
×
252
  }
253
  if (taosArrayPush(funcReq.pFuncNames, input) == NULL) {
194!
254
    taosArrayDestroy(funcReq.pFuncNames);
×
255
    return terrno;
×
256
  }
257

258
  int32_t bufLen = tSerializeSRetrieveFuncReq(NULL, 0, &funcReq);
97✔
259
  void   *pBuf = (*mallcFp)(bufLen);
97✔
260
  if (NULL == pBuf) {
97!
261
    taosArrayDestroy(funcReq.pFuncNames);
×
262
    return terrno;
×
263
  }
264
  int32_t ret = tSerializeSRetrieveFuncReq(pBuf, bufLen, &funcReq);
97✔
265
  if (ret < 0) {
97!
266
    taosArrayDestroy(funcReq.pFuncNames);
×
267
    return ret;
×
268
  }
269

270
  taosArrayDestroy(funcReq.pFuncNames);
97✔
271

272
  *msg = pBuf;
97✔
273
  *msgLen = bufLen;
97✔
274

275
  return TSDB_CODE_SUCCESS;
97✔
276
}
277

278
int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
22,019✔
279
  QUERY_PARAM_CHECK(input);
22,019!
280
  QUERY_PARAM_CHECK(msg);
22,019!
281
  QUERY_PARAM_CHECK(msgLen);
22,019!
282

283
  SGetUserAuthReq req = {0};
22,019✔
284
  tstrncpy(req.user, input, TSDB_USER_LEN);
22,019✔
285

286
  int32_t bufLen = tSerializeSGetUserAuthReq(NULL, 0, &req);
22,019✔
287
  void   *pBuf = (*mallcFp)(bufLen);
22,025✔
288
  if (NULL == pBuf) {
22,025!
289
    return terrno;
×
290
  }
291
  int32_t ret = tSerializeSGetUserAuthReq(pBuf, bufLen, &req);
22,025✔
292
  if (ret < 0) return ret;
22,026!
293

294
  *msg = pBuf;
22,026✔
295
  *msgLen = bufLen;
22,026✔
296

297
  return TSDB_CODE_SUCCESS;
22,026✔
298
}
299

300
int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
1,407✔
301
  QUERY_PARAM_CHECK(input);
1,407!
302
  QUERY_PARAM_CHECK(msg);
1,407!
303
  QUERY_PARAM_CHECK(msgLen);
1,407!
304

305
  STableIndexReq indexReq = {0};
1,407✔
306
  tstrncpy(indexReq.tbFName, input, TSDB_TABLE_FNAME_LEN);
1,407✔
307

308
  int32_t bufLen = tSerializeSTableIndexReq(NULL, 0, &indexReq);
1,407✔
309
  void   *pBuf = (*mallcFp)(bufLen);
1,407✔
310
  if (NULL == pBuf) {
1,407!
311
    return terrno;
×
312
  }
313
  int32_t ret = tSerializeSTableIndexReq(pBuf, bufLen, &indexReq);
1,407✔
314
  if (ret < 0) return ret;
1,407!
315

316
  *msg = pBuf;
1,407✔
317
  *msgLen = bufLen;
1,407✔
318

319
  return TSDB_CODE_SUCCESS;
1,407✔
320
}
321

322
int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
278✔
323
  QUERY_PARAM_CHECK(input);
278!
324
  QUERY_PARAM_CHECK(msg);
278!
325
  QUERY_PARAM_CHECK(msgLen);
278!
326

327
  SBuildTableInput *pInput = input;
278✔
328
  STableCfgReq      cfgReq = {0};
278✔
329
  cfgReq.header.vgId = pInput->vgId;
278✔
330
  tstrncpy(cfgReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
278✔
331
  tstrncpy(cfgReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
278✔
332

333
  int32_t bufLen = tSerializeSTableCfgReq(NULL, 0, &cfgReq);
278✔
334
  void   *pBuf = (*mallcFp)(bufLen);
278✔
335
  if (NULL == pBuf) {
278!
336
    return terrno;
×
337
  }
338
  int32_t ret = tSerializeSTableCfgReq(pBuf, bufLen, &cfgReq);
278✔
339
  if (ret < 0) return ret;
278!
340

341
  *msg = pBuf;
278✔
342
  *msgLen = bufLen;
278✔
343

344
  return TSDB_CODE_SUCCESS;
278✔
345
}
346

347
int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
44,236✔
348
  QUERY_PARAM_CHECK(input);
44,236!
349
  QUERY_PARAM_CHECK(msg);
44,236!
350
  QUERY_PARAM_CHECK(msgLen);
44,236!
351

352
  SViewMetaReq req = {0};
44,236✔
353
  tstrncpy(req.fullname, input, TSDB_VIEW_FNAME_LEN);
44,236✔
354

355
  int32_t bufLen = tSerializeSViewMetaReq(NULL, 0, &req);
44,236✔
356
  void   *pBuf = (*mallcFp)(bufLen);
44,237✔
357
  if (NULL == pBuf) {
44,239!
358
    return terrno;
×
359
  }
360
  int32_t ret = tSerializeSViewMetaReq(pBuf, bufLen, &req);
44,239✔
361
  if (ret < 0) return ret;
44,238!
362

363
  *msg = pBuf;
44,238✔
364
  *msgLen = bufLen;
44,238✔
365

366
  return TSDB_CODE_SUCCESS;
44,238✔
367
}
368

369
int32_t queryBuildGetTableTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
1,117✔
370
                                  void *(*mallcFp)(int64_t)) {
371
  QUERY_PARAM_CHECK(input);
1,117!
372
  QUERY_PARAM_CHECK(msg);
1,117!
373
  QUERY_PARAM_CHECK(msgLen);
1,117!
374

375
  STableTSMAInfoReq req = {0};
1,117✔
376
  tstrncpy(req.name, input, TSDB_TABLE_FNAME_LEN);
1,117✔
377

378
  int32_t bufLen = tSerializeTableTSMAInfoReq(NULL, 0, &req);
1,117✔
379
  void *  pBuf = (*mallcFp)(bufLen);
1,117✔
380
  if (NULL == pBuf) {
1,117!
381
    return terrno;
×
382
  }
383
  int32_t ret = tSerializeTableTSMAInfoReq(pBuf, bufLen, &req);
1,117✔
384
  if (ret < 0) return ret;
1,117!
385

386
  *msg = pBuf;
1,117✔
387
  *msgLen = bufLen;
1,117✔
388
  return TSDB_CODE_SUCCESS;
1,117✔
389
}
390

391
int32_t queryBuildGetTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
60✔
392
                                  void *(*mallcFp)(int64_t)) {
393
  QUERY_PARAM_CHECK(input);
60!
394
  QUERY_PARAM_CHECK(msg);
60!
395
  QUERY_PARAM_CHECK(msgLen);
60!
396

397
  STableTSMAInfoReq req = {0};
60✔
398
  req.fetchingWithTsmaName = true;
60✔
399
  tstrncpy(req.name, input, TSDB_TABLE_FNAME_LEN);
60✔
400

401
  int32_t bufLen = tSerializeTableTSMAInfoReq(NULL, 0, &req);
60✔
402
  void *  pBuf = (*mallcFp)(bufLen);
60✔
403
  if(pBuf == NULL)
60!
404
  {
405
    return terrno;
×
406
  }
407
  int32_t ret = tSerializeTableTSMAInfoReq(pBuf, bufLen, &req);
60✔
408
  if(ret < 0) return ret;
60!
409

410
  *msg = pBuf;
60✔
411
  *msgLen = bufLen;
60✔
412
  return TSDB_CODE_SUCCESS;
60✔
413
}
414

415
int32_t queryBuildGetStreamProgressMsg(void* input, char** msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int64_t)) {
5,438✔
416
  QUERY_PARAM_CHECK(input);
5,438!
417
  QUERY_PARAM_CHECK(msg);
5,438!
418
  QUERY_PARAM_CHECK(msgLen);
5,438!
419

420
  int32_t len = tSerializeStreamProgressReq(NULL, 0, input);
5,438✔
421
  void* pBuf = (*mallcFp)(len);
5,438✔
422
  if (NULL == pBuf) {
5,438!
423
    return terrno;
×
424
  }
425

426
  int32_t ret = tSerializeStreamProgressReq(pBuf, len, input);
5,438✔
427
  if (ret < 0) return ret;
5,438!
428

429
  *msg = pBuf;
5,438✔
430
  *msgLen = len;
5,438✔
431
  return TSDB_CODE_SUCCESS;
5,438✔
432
}
433

434

435
int32_t queryBuildVSubTablesMsg(void* input, char** msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int64_t)) {
24✔
436
  QUERY_PARAM_CHECK(input);
24!
437
  QUERY_PARAM_CHECK(msg);
24!
438
  QUERY_PARAM_CHECK(msgLen);
24!
439

440
  SVSubTablesReq req = {0};
24✔
441
  req.suid = *(int64_t*)input;
24✔
442

443
  int32_t bufLen = tSerializeSVSubTablesReq(NULL, 0, &req);
24✔
444
  void   *pBuf = (*mallcFp)(bufLen);
24✔
445
  if (NULL == pBuf) {
24!
446
    return terrno;
×
447
  }
448
  if(tSerializeSVSubTablesReq(pBuf, bufLen, &req) < 0)   {
24!
449
    return TSDB_CODE_TSC_INVALID_INPUT;
×
450
  }
451

452
  *msg = pBuf;
24✔
453
  *msgLen = bufLen;
24✔
454

455
  return TSDB_CODE_SUCCESS;
24✔
456
}
457

458
int32_t queryBuildVStbRefDBsMsg(void* input, char** msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int64_t)) {
5,072✔
459
  QUERY_PARAM_CHECK(input);
5,072!
460
  QUERY_PARAM_CHECK(msg);
5,072!
461
  QUERY_PARAM_CHECK(msgLen);
5,072!
462

463
  SVStbRefDbsReq req = {0};
5,072✔
464
  req.suid = *(int64_t*)input;
5,072✔
465

466
  int32_t bufLen = tSerializeSVStbRefDbsReq(NULL, 0, &req);
5,072✔
467
  void   *pBuf = (*mallcFp)(bufLen);
5,072✔
468
  if (NULL == pBuf) {
5,072!
469
    return terrno;
×
470
  }
471
  if(tSerializeSVStbRefDbsReq(pBuf, bufLen, &req) < 0)   {
5,072!
472
    return TSDB_CODE_TSC_INVALID_INPUT;
×
473
  }
474

475
  *msg = pBuf;
5,072✔
476
  *msgLen = bufLen;
5,072✔
477

478
  return TSDB_CODE_SUCCESS;
5,072✔
479
}
480

481
int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) {
146,045✔
482
  SUseDbOutput *pOut = output;
146,045✔
483
  SUseDbRsp     usedbRsp = {0};
146,045✔
484
  int32_t       code = -1;
146,045✔
485

486
  if (NULL == output || NULL == msg || msgSize <= 0) {
146,045!
487
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
488
    qError("invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
489
    goto PROCESS_USEDB_OVER;
×
490
  }
491

492
  if (tDeserializeSUseDbRsp(msg, msgSize, &usedbRsp) != 0) {
146,045!
493
    qError("invalid use db rsp msg, msgSize:%d", msgSize);
×
494
    code = TSDB_CODE_INVALID_MSG;
×
495
    goto PROCESS_USEDB_OVER;
×
496
  }
497

498
  if (usedbRsp.vgNum < 0) {
146,043!
499
    qError("invalid db[%s] vgroup number[%d]", usedbRsp.db, usedbRsp.vgNum);
×
500
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
501
    goto PROCESS_USEDB_OVER;
×
502
  }
503

504
  qTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum);
146,043✔
505
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
482,166✔
506
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
336,122✔
507
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
336,123✔
508
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
730,275✔
509
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
394,152✔
510
    }
511
  }
512

513
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
146,044✔
514

515
PROCESS_USEDB_OVER:
146,045✔
516

517
  if (code != 0) {
146,045!
518
    if (pOut) {
×
519
      if (pOut->dbVgroup) taosHashCleanup(pOut->dbVgroup->vgHash);
×
520
      taosMemoryFreeClear(pOut->dbVgroup);
×
521
    }
522
    qError("failed to process usedb rsp since %s", terrstr());
×
523
  }
524

525
  tFreeSUsedbRsp(&usedbRsp);
146,045✔
526
  return code;
146,045✔
527
}
528

529
static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) {
88,321✔
530
  QUERY_PARAM_CHECK(pMetaMsg);
88,321!
531
  if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) {
88,321!
532
    qError("invalid numOfTags[%d] in table meta rsp msg", pMetaMsg->numOfTags);
1!
533
    return TSDB_CODE_TSC_INVALID_VALUE;
×
534
  }
535

536
  if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) {
88,320!
537
    qError("invalid numOfColumns[%d] in table meta rsp msg", pMetaMsg->numOfColumns);
1!
538
    return TSDB_CODE_TSC_INVALID_VALUE;
×
539
  }
540

541
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
88,319✔
542
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
37,254✔
543
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
153!
544
    qError("invalid tableType[%d] in table meta rsp msg", pMetaMsg->tableType);
×
545
    return TSDB_CODE_TSC_INVALID_VALUE;
×
546
  }
547

548
  if (pMetaMsg->sversion < 0) {
88,319!
549
    qError("invalid sversion[%d] in table meta rsp msg", pMetaMsg->sversion);
×
550
    return TSDB_CODE_TSC_INVALID_VALUE;
×
551
  }
552

553
  if (pMetaMsg->tversion < 0) {
88,319!
554
    qError("invalid tversion[%d] in table meta rsp msg", pMetaMsg->tversion);
×
555
    return TSDB_CODE_TSC_INVALID_VALUE;
×
556
  }
557

558
  if (pMetaMsg->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
88,319!
559
    qError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", pMetaMsg->pSchemas[0].colId);
×
560
    return TSDB_CODE_TSC_INVALID_VALUE;
×
561
  }
562

563
  return TSDB_CODE_SUCCESS;
88,319✔
564
}
565

566
int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) {
153,023✔
567
  QUERY_PARAM_CHECK(msg);
153,023!
568
  QUERY_PARAM_CHECK(pMeta);
153,023!
569
  pMeta->vgId = msg->vgId;
153,023✔
570
  pMeta->tableType = msg->tableType;
153,023✔
571
  pMeta->uid = msg->tuid;
153,023✔
572
  pMeta->suid = msg->suid;
153,023✔
573

574
  qDebug("ctb:%s, uid:0x%" PRIx64 " meta returned, type:%d vgId:%d db:%s suid:%" PRIx64, msg->tbName, pMeta->uid,
153,023✔
575
         pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid);
576

577
  return TSDB_CODE_SUCCESS;
153,026✔
578
}
579

580
int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta) {
269✔
581
  QUERY_PARAM_CHECK(msg);
269!
582
  QUERY_PARAM_CHECK(pMeta);
269!
583
  QUERY_PARAM_CHECK(msg->pColRefs);
269!
584

585
  int32_t pColRefSize = sizeof(SColRef) * msg->numOfColRefs;
269✔
586

587
  SVCTableMeta *pTableMeta = taosMemoryCalloc(1, sizeof(SVCTableMeta) + pColRefSize);
269!
588
  if (NULL == pTableMeta) {
269!
589
    qError("calloc size[%d] failed", (int32_t)sizeof(SVCTableMeta) + pColRefSize);
×
590
    return terrno;
×
591
  }
592

593
  pTableMeta->vgId = msg->vgId;
269✔
594
  pTableMeta->tableType = msg->tableType;
269✔
595
  pTableMeta->uid = msg->tuid;
269✔
596
  pTableMeta->suid = msg->suid;
269✔
597
  pTableMeta->numOfColRefs = msg->numOfColRefs;
269✔
598

599
  pTableMeta->colRef = (SColRef *)((char *)pTableMeta + sizeof(SVCTableMeta));
269✔
600
  memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
269✔
601

602
  qDebug("ctable %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s suid %" PRIx64, msg->tbName, (pTableMeta)->uid,
269!
603
         (pTableMeta)->tableType, (pTableMeta)->vgId, msg->dbFName, (pTableMeta)->suid);
604

605
  *pMeta = pTableMeta;
269✔
606
  return TSDB_CODE_SUCCESS;
269✔
607
}
608

609
int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
111,983✔
610
  QUERY_PARAM_CHECK(msg);
111,983!
611
  QUERY_PARAM_CHECK(pMeta);
111,983!
612
  int32_t total = msg->numOfColumns + msg->numOfTags;
111,983✔
613
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
111,983✔
614
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
111,983✔
615
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) ? sizeof(SColRef) * msg->numOfColRefs : 0;
111,986!
616

617
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize);
111,983!
618
  if (NULL == pTableMeta) {
111,985!
619
    qError("calloc size[%d] failed", metaSize);
×
620
    return terrno;
×
621
  }
622
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
111,985✔
623
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
111,985✔
624

625
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
111,985✔
626
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
111,985✔
627
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
111,985✔
628
  pTableMeta->suid = msg->suid;
111,985✔
629
  pTableMeta->sversion = msg->sversion;
111,985✔
630
  pTableMeta->tversion = msg->tversion;
111,985✔
631
  pTableMeta->virtualStb = msg->virtualStb;
111,985✔
632
  pTableMeta->numOfColRefs = msg->numOfColRefs;
111,985✔
633

634
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
111,985✔
635
  pTableMeta->tableInfo.precision = msg->precision;
111,985✔
636
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
111,985✔
637

638
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
111,985✔
639
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
111,985✔
640
    pTableMeta->schemaExt = pSchemaExt;
107,708✔
641
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
107,708✔
642
  } else {
643
    pTableMeta->schemaExt = NULL;
4,278✔
644
  }
645

646
  if (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) {
111,986!
647
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
625✔
648
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
625✔
649
  } else {
650
    pTableMeta->colRef = NULL;
111,362✔
651
  }
652

653
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
111,987✔
654
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
2,989,057✔
655
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,877,070✔
656
    if (hasPK && (i > 0)) {
2,877,070✔
657
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
798✔
658
        ++pTableMeta->tableInfo.numOfPKs;
416✔
659
      } else {
660
        hasPK = false;
382✔
661
      }
662
    }
663
  }
664

665
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
111,987✔
666
         " sver:%d tver:%d"
667
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
668
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
669
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
670
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
671

672
  *pMeta = pTableMeta;
111,986✔
673
  return TSDB_CODE_SUCCESS;
111,986✔
674
}
675

676
int32_t queryCreateTableMetaExFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
1,202✔
677
  QUERY_PARAM_CHECK(msg);
1,202!
678
  QUERY_PARAM_CHECK(pMeta);
1,202!
679
  int32_t total = msg->numOfColumns + msg->numOfTags;
1,202✔
680
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
1,202✔
681
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
1,202!
682
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs) ? sizeof(SColRef) * msg->numOfColRefs : 0;
1,202!
683
  int32_t tbNameSize = strlen(msg->tbName) + 1;
1,202✔
684

685
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize + tbNameSize);
1,202!
686
  if (NULL == pTableMeta) {
1,202!
687
    qError("calloc size[%d] failed", metaSize);
×
688
    return terrno;
×
689
  }
690
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
1,202✔
691
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
1,202✔
692

693
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
1,202✔
694
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
1,202✔
695
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
1,202✔
696
  pTableMeta->suid = msg->suid;
1,202✔
697
  pTableMeta->sversion = msg->sversion;
1,202✔
698
  pTableMeta->tversion = msg->tversion;
1,202✔
699
  pTableMeta->virtualStb = msg->virtualStb;
1,202✔
700
  pTableMeta->numOfColRefs = msg->numOfColRefs;
1,202✔
701

702
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
1,202✔
703
  pTableMeta->tableInfo.precision = msg->precision;
1,202✔
704
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
1,202✔
705

706
  TAOS_MEMCPY(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
1,202✔
707
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
1,202!
708
    pTableMeta->schemaExt = pSchemaExt;
1,202✔
709
    TAOS_MEMCPY(pSchemaExt, msg->pSchemaExt, schemaExtSize);
1,202✔
710
  } else {
711
    pTableMeta->schemaExt = NULL;
×
712
  }
713

714
  if (hasRefCol(msg->tableType) && msg->pColRefs) {
1,202!
715
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
×
716
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
×
717
  } else {
718
    pTableMeta->colRef = NULL;
1,202✔
719
  }
720

721
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
1,202!
722
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
3,910✔
723
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,708✔
724
    if (hasPK && (i > 0)) {
2,708!
725
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
×
726
        ++pTableMeta->tableInfo.numOfPKs;
×
727
      } else {
728
        hasPK = false;
×
729
      }
730
    }
731
  }
732

733
  char *pTbName = (char *)pTableMeta + metaSize + schemaExtSize + pColRefSize;
1,202✔
734
  tstrncpy(pTbName, msg->tbName, tbNameSize);
1,202✔
735

736
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
1,202!
737
         " sver:%d tver:%d"
738
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
739
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
740
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
741
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
742

743
  *pMeta = pTableMeta;
1,202✔
744
  return TSDB_CODE_SUCCESS;
1,202✔
745
}
746

747
int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) {
87,120✔
748
  int32_t       code = 0;
87,120✔
749
  STableMetaRsp metaRsp = {0};
87,120✔
750

751
  if (NULL == output || NULL == msg || msgSize <= 0) {
87,120!
752
    qError("queryProcessTableMetaRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
1!
753
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
754
    goto PROCESS_META_OVER;
×
755
  }
756

757
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
87,119!
758
    code = TSDB_CODE_INVALID_MSG;
×
759
    goto PROCESS_META_OVER;
×
760
  }
761

762
  code = queryConvertTableMetaMsg(&metaRsp);
87,119✔
763
  if (code != TSDB_CODE_SUCCESS) {
87,116!
764
    goto PROCESS_META_OVER;
×
765
  }
766

767
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
87,116!
768
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
83,562!
769
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
770
    goto PROCESS_META_OVER;
×
771
  }
772

773
  STableMetaOutput *pOut = output;
87,117✔
774
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
87,117✔
775
  pOut->dbId = metaRsp.dbId;
87,117✔
776

777
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
87,117✔
778
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
16,263✔
779

780
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
16,263✔
781
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
16,263✔
782

783
    pOut->ctbMeta.vgId = metaRsp.vgId;
16,263✔
784
    pOut->ctbMeta.tableType = metaRsp.tableType;
16,263✔
785
    pOut->ctbMeta.uid = metaRsp.tuid;
16,263✔
786
    pOut->ctbMeta.suid = metaRsp.suid;
16,263✔
787

788
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
16,263✔
789
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
70,854✔
790
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
94✔
791

792
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
94✔
793
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
94✔
794

795
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
94✔
796
    if (TSDB_CODE_SUCCESS != code) {
94!
797
      goto PROCESS_META_OVER;
×
798
    }
799
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
94✔
800
  } else {
801
    SET_META_TYPE_TABLE(pOut->metaType);
70,760✔
802
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
70,760✔
803
    code = queryCreateTableMetaFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
70,760✔
804
  }
805

806
PROCESS_META_OVER:
87,119✔
807
  if (code != 0) {
87,119!
808
    qError("failed to process table meta rsp since %s", tstrerror(code));
×
809
  }
810

811
  tFreeSTableMetaRsp(&metaRsp);
87,119✔
812
  return code;
87,119✔
813
}
814

815
static int32_t queryProcessTableNameRsp(void *output, char *msg, int32_t msgSize) {
1,202✔
816
  int32_t       code = 0;
1,202✔
817
  STableMetaRsp metaRsp = {0};
1,202✔
818

819
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,202!
820
    qError("queryProcessTableNameRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
821
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
822
    goto PROCESS_NAME_OVER;
×
823
  }
824

825
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
1,202!
826
    code = TSDB_CODE_INVALID_MSG;
×
827
    goto PROCESS_NAME_OVER;
×
828
  }
829

830
  code = queryConvertTableMetaMsg(&metaRsp);
1,202✔
831
  if (code != TSDB_CODE_SUCCESS) {
1,202!
832
    goto PROCESS_NAME_OVER;
×
833
  }
834

835
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
1,202!
836
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
1,202!
837
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
838
    goto PROCESS_NAME_OVER;
×
839
  }
840

841
  STableMetaOutput *pOut = output;
1,202✔
842
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
1,202✔
843
  pOut->dbId = metaRsp.dbId;
1,202✔
844

845
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
1,202✔
846
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
309✔
847

848
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
309✔
849
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
309✔
850

851
    pOut->ctbMeta.vgId = metaRsp.vgId;
309✔
852
    pOut->ctbMeta.tableType = metaRsp.tableType;
309✔
853
    pOut->ctbMeta.uid = metaRsp.tuid;
309✔
854
    pOut->ctbMeta.suid = metaRsp.suid;
309✔
855

856
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
309✔
857
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
893!
858
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
859

860
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
861
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
×
862

863
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
×
864
    if (TSDB_CODE_SUCCESS != code) {
×
865
      goto PROCESS_NAME_OVER;
×
866
    }
867

868
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
×
869
  } else {
870
    SET_META_TYPE_TABLE(pOut->metaType);
893✔
871
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
893✔
872
    code = queryCreateTableMetaExFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
893✔
873
  }
874

875
PROCESS_NAME_OVER:
1,202✔
876
  if (code != 0) {
1,202!
877
    qError("failed to process table name rsp since %s", tstrerror(code));
×
878
  }
879

880
  tFreeSTableMetaRsp(&metaRsp);
1,202✔
881
  return code;
1,202✔
882
}
883

884
int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) {
11,750✔
885
  SQnodeListRsp out = {0};
11,750✔
886
  int32_t       code = 0;
11,750✔
887

888
  if (NULL == output || NULL == msg || msgSize <= 0) {
11,750!
889
    qError("queryProcessQnodeListRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
890
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
891
    return code;
×
892
  }
893

894
  out.qnodeList = (SArray *)output;
11,750✔
895
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
11,750!
896
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
×
897
    code = TSDB_CODE_INVALID_MSG;
×
898
    return code;
×
899
  }
900

901
  return code;
11,750✔
902
}
903

904
int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) {
368✔
905
  SDnodeListRsp out = {0};
368✔
906
  int32_t       code = 0;
368✔
907

908
  if (NULL == output || NULL == msg || msgSize <= 0) {
368!
909
    qError("queryProcessDnodeListRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
910
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
911
    return code;
×
912
  }
913

914
  if (tDeserializeSDnodeListRsp(msg, msgSize, &out) != 0) {
368!
915
    qError("invalid dnode list rsp msg, msgSize:%d", msgSize);
×
916
    code = TSDB_CODE_INVALID_MSG;
×
917
    return code;
×
918
  }
919

920
  *(SArray **)output = out.dnodeList;
368✔
921

922
  return code;
368✔
923
}
924

925
int32_t queryProcessGetSerVerRsp(void *output, char *msg, int32_t msgSize) {
1✔
926
  SServerVerRsp out = {0};
1✔
927
  int32_t       code = 0;
1✔
928

929
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
930
    qError("queryProcessGetSerVerRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
931
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
932
    return code;
×
933
  }
934

935
  if (tDeserializeSServerVerRsp(msg, msgSize, &out) != 0) {
1!
936
    qError("invalid svr ver rsp msg, msgSize:%d", msgSize);
×
937
    code = TSDB_CODE_INVALID_MSG;
×
938
    return code;
×
939
  }
940

941
  *(char **)output = taosStrdup(out.ver);
1!
942
  if (NULL == *(char **)output) {
1!
943
    return terrno;
×
944
  }
945

946
  return code;
1✔
947
}
948

949
int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) {
5,589✔
950
  SDbCfgRsp out = {0};
5,589✔
951

952
  if (NULL == output || NULL == msg || msgSize <= 0) {
5,589!
953
    qError("queryProcessGetDbCfgRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
954
    return TSDB_CODE_TSC_INVALID_INPUT;
×
955
  }
956

957
  if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) {
5,589!
958
    qError("tDeserializeSDbCfgRsp failed, msgSize:%d, dbCfgRsp:%lu", msgSize, sizeof(out));
×
959
    return TSDB_CODE_INVALID_MSG;
×
960
  }
961

962
  memcpy(output, &out, sizeof(out));
5,589✔
963

964
  return TSDB_CODE_SUCCESS;
5,589✔
965
}
966

967
int32_t queryProcessGetIndexRsp(void *output, char *msg, int32_t msgSize) {
×
968
  SUserIndexRsp out = {0};
×
969

970
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
971
    qError("queryProcessGetIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
972
    return TSDB_CODE_TSC_INVALID_INPUT;
×
973
  }
974

975
  if (tDeserializeSUserIndexRsp(msg, msgSize, &out) != 0) {
×
976
    qError("tDeserializeSUserIndexRsp failed, msgSize:%d", msgSize);
×
977
    return TSDB_CODE_INVALID_MSG;
×
978
  }
979

980
  memcpy(output, &out, sizeof(out));
×
981

982
  return TSDB_CODE_SUCCESS;
×
983
}
984

985
int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
87✔
986
  SRetrieveFuncRsp out = {0};
87✔
987

988
  if (NULL == output || NULL == msg || msgSize <= 0) {
87!
989
    qError("queryProcessRetrieveFuncRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
990
    return TSDB_CODE_TSC_INVALID_INPUT;
×
991
  }
992

993
  if (tDeserializeSRetrieveFuncRsp(msg, msgSize, &out) != 0) {
87!
994
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
×
995
    return TSDB_CODE_INVALID_MSG;
×
996
  }
997

998
  if (1 != out.numOfFuncs) {
87!
999
    qError("invalid func num returned, numOfFuncs:%d", out.numOfFuncs);
×
1000
    return TSDB_CODE_INVALID_MSG;
×
1001
  }
1002

1003
  SFuncInfo *funcInfo = taosArrayGet(out.pFuncInfos, 0);
87✔
1004

1005
  memcpy(output, funcInfo, sizeof(*funcInfo));
87✔
1006
  taosArrayDestroy(out.pFuncInfos);
87✔
1007
  taosArrayDestroy(out.pFuncExtraInfos);
87✔
1008

1009
  return TSDB_CODE_SUCCESS;
87✔
1010
}
1011

1012
int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) {
22,021✔
1013
  if (NULL == output || NULL == msg || msgSize <= 0) {
22,021!
1014
    qError("queryProcessGetUserAuthRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1015
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1016
  }
1017

1018
  if (tDeserializeSGetUserAuthRsp(msg, msgSize, (SGetUserAuthRsp *)output) != 0) {
22,021!
1019
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
1020
    return TSDB_CODE_INVALID_MSG;
×
1021
  }
1022

1023
  return TSDB_CODE_SUCCESS;
22,021✔
1024
}
1025

1026
int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
1✔
1027
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
1028
    qError("queryProcessGetTbIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1029
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1030
  }
1031

1032
  STableIndexRsp *out = (STableIndexRsp *)output;
1✔
1033
  if (tDeserializeSTableIndexRsp(msg, msgSize, out) != 0) {
1!
1034
    qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize);
×
1035
    return TSDB_CODE_INVALID_MSG;
×
1036
  }
1037

1038
  return TSDB_CODE_SUCCESS;
1✔
1039
}
1040

1041
int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
278✔
1042
  if (NULL == output || NULL == msg || msgSize <= 0) {
278!
1043
    qError("queryProcessGetTbCfgRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1044
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1045
  }
1046

1047
  STableCfgRsp *out = taosMemoryCalloc(1, sizeof(STableCfgRsp));
278!
1048
  if(out == NULL) {
278!
1049
    return terrno;
×
1050
  }
1051
  if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
278!
1052
    qError("tDeserializeSTableCfgRsp failed, msgSize:%d", msgSize);
×
1053
    tFreeSTableCfgRsp(out);
×
1054
    taosMemoryFree(out);
×
1055
    return TSDB_CODE_INVALID_MSG;
×
1056
  }
1057

1058
  *(STableCfgRsp **)output = out;
278✔
1059

1060
  return TSDB_CODE_SUCCESS;
278✔
1061
}
1062

1063
int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) {
316✔
1064
  if (NULL == output || NULL == msg || msgSize <= 0) {
316!
1065
    qError("queryProcessGetViewMetaRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1066
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1067
  }
1068

1069
  SViewMetaRsp *out = taosMemoryCalloc(1, sizeof(SViewMetaRsp));
316!
1070
  if (out == NULL) {
316!
1071
    return terrno;
×
1072
  }
1073
  if (tDeserializeSViewMetaRsp(msg, msgSize, out) != 0) {
316!
1074
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1075
    tFreeSViewMetaRsp(out);
×
1076
    taosMemoryFree(out);
×
1077
    return TSDB_CODE_INVALID_MSG;
×
1078
  }
1079

1080
  qDebugL("view meta recved, dbFName:%s, view:%s, querySQL:%s", out->dbFName, out->name, out->querySql);
316✔
1081

1082
  *(SViewMetaRsp **)output = out;
316✔
1083

1084
  return TSDB_CODE_SUCCESS;
316✔
1085
}
1086

1087
int32_t queryProcessGetTbTSMARsp(void* output, char* msg, int32_t msgSize) {
1,020✔
1088
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,020!
1089
    qError("queryProcessGetTbTSMARsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1090
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1091
  }
1092

1093
  if (tDeserializeTableTSMAInfoRsp(msg, msgSize, output) != 0) {
1,020!
1094
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1095
    return TSDB_CODE_INVALID_MSG;
×
1096
  }
1097

1098
  return TSDB_CODE_SUCCESS;
1,020✔
1099
}
1100

1101
int32_t queryProcessStreamProgressRsp(void* output, char* msg, int32_t msgSize) {
5,438✔
1102
  if (!output || !msg || msgSize <= 0) {
5,438!
1103
    qError("queryProcessStreamProgressRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1104
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1105
  }
1106

1107
  if (tDeserializeSStreamProgressRsp(msg, msgSize, output) != 0) {
5,438!
1108
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1109
    return TSDB_CODE_INVALID_MSG;
×
1110
  }
1111
  return TSDB_CODE_SUCCESS;
5,436✔
1112
}
1113

1114
int32_t queryProcessVSubTablesRsp(void* output, char* msg, int32_t msgSize) {
24✔
1115
  if (!output || !msg || msgSize <= 0) {
24!
1116
    qError("queryProcessVSubTablesRsp input error, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1117
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1118
  }
1119

1120
  SVSubTablesRsp* pRsp = (SVSubTablesRsp*)output;
24✔
1121
  int32_t code = tDeserializeSVSubTablesRsp(msg, msgSize, pRsp);
24✔
1122
  if (code != 0) {
24!
1123
    qError("tDeserializeSVSubTablesRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1124
    return code;
×
1125
  }
1126
  
1127
  return TSDB_CODE_SUCCESS;
24✔
1128
}
1129

1130
int32_t queryProcessVStbRefDbsRsp(void* output, char* msg, int32_t msgSize) {
5,071✔
1131
  if (!output || !msg || msgSize <= 0) {
5,071!
UNCOV
1132
    qError("queryProcessVStbRefDbsRsp input error, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1133
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1134
  }
1135

1136
  SVStbRefDbsRsp * pRsp = (SVStbRefDbsRsp*)output;
5,071✔
1137
  int32_t code = tDeserializeSVStbRefDbsRsp(msg, msgSize, pRsp);
5,071✔
1138
  if (code != 0) {
5,069✔
1139
    qError("tDeserializeSVStbRefDbsRsp failed, msgSize: %d, error:%d", msgSize, code);
1!
1140
    return code;
×
1141
  }
1142

1143
  return TSDB_CODE_SUCCESS;
5,068✔
1144
}
1145

1146
void initQueryModuleMsgHandle() {
17,117✔
1147
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg;
17,117✔
1148
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryBuildTableMetaReqMsg;
17,117✔
1149
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;
17,117✔
1150
  queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg;
17,117✔
1151
  queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg;
17,117✔
1152
  queryBuildMsg[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryBuildDnodeListMsg;
17,117✔
1153
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg;
17,117✔
1154
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryBuildGetIndexMsg;
17,117✔
1155
  queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryBuildRetrieveFuncMsg;
17,117✔
1156
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryBuildGetUserAuthMsg;
17,117✔
1157
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryBuildGetTbIndexMsg;
17,117✔
1158
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
17,117✔
1159
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
17,117✔
1160
  queryBuildMsg[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryBuildGetSerVerMsg;
17,117✔
1161
  queryBuildMsg[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryBuildGetViewMetaMsg;
17,117✔
1162
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryBuildGetTableTSMAMsg;
17,117✔
1163
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryBuildGetTSMAMsg;
17,117✔
1164
  queryBuildMsg[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryBuildGetStreamProgressMsg;
17,117✔
1165
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryBuildVSubTablesMsg;
17,117✔
1166
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSTB_REF_DBS)] = queryBuildVStbRefDBsMsg;
17,117✔
1167

1168
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp;
17,117✔
1169
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryProcessTableNameRsp;
17,117✔
1170
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp;
17,117✔
1171
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp;
17,117✔
1172
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp;
17,117✔
1173
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryProcessDnodeListRsp;
17,117✔
1174
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp;
17,117✔
1175
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryProcessGetIndexRsp;
17,117✔
1176
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryProcessRetrieveFuncRsp;
17,117✔
1177
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryProcessGetUserAuthRsp;
17,117✔
1178
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryProcessGetTbIndexRsp;
17,117✔
1179
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
17,117✔
1180
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
17,117✔
1181
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp;
17,117✔
1182
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryProcessGetViewMetaRsp;
17,117✔
1183
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryProcessGetTbTSMARsp;
17,117✔
1184
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryProcessGetTbTSMARsp;
17,117✔
1185
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryProcessStreamProgressRsp;
17,117✔
1186
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryProcessVSubTablesRsp;
17,117✔
1187
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_VSTB_REF_DBS)] = queryProcessVStbRefDbsRsp;
17,117✔
1188
}
17,117✔
1189

1190
#pragma GCC diagnostic pop
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