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

taosdata / TDengine / #3676

22 Mar 2025 04:46PM UTC coverage: 25.147% (-36.8%) from 61.952%
#3676

push

travis-ci

web-flow
fix: userOperTest in linux (#30363)

Co-authored-by: taos-support <it@taosdata.com>

55963 of 304767 branches covered (18.36%)

Branch coverage included in aggregate %.

96374 of 301020 relevant lines covered (32.02%)

582640.8 hits per line

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

35.68
/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) {
3,245✔
32
  QUERY_PARAM_CHECK(pOut);
3,245!
33
  QUERY_PARAM_CHECK(usedbRsp);
3,245!
34
  memcpy(pOut->db, usedbRsp->db, TSDB_DB_FNAME_LEN);
3,245✔
35
  pOut->dbId = usedbRsp->uid;
3,245✔
36

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

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

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

51
  if (usedbRsp->vgNum <= 0) {
3,245✔
52
    return TSDB_CODE_SUCCESS;
20✔
53
  }
54

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

61
  for (int32_t i = 0; i < usedbRsp->vgNum; ++i) {
34,627✔
62
    SVgroupInfo *pVgInfo = taosArrayGet(usedbRsp->pVgroupInfos, i);
31,402✔
63
    pOut->dbVgroup->numOfTable += pVgInfo->numOfTable;
31,402✔
64
    qDebug("db:%s, vgId:%d, epNum:%d, current ep:%s:%u", usedbRsp->db, pVgInfo->vgId, pVgInfo->epSet.numOfEps,
31,402✔
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))) {
31,402!
67
      return terrno;
×
68
    }
69
  }
70

71
  return TSDB_CODE_SUCCESS;
3,225✔
72
}
73

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

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

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

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

99
  *msg = pBuf;
86✔
100
  *msgLen = bufLen;
86✔
101

102
  return TSDB_CODE_SUCCESS;
86✔
103
}
104

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

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

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

127
  *msg = pBuf;
3,216✔
128
  *msgLen = bufLen;
3,216✔
129

130
  return TSDB_CODE_SUCCESS;
3,216✔
131
}
132

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

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

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

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

149
  *msg = pBuf;
1✔
150
  *msgLen = bufLen;
1✔
151

152
  return TSDB_CODE_SUCCESS;
1✔
153
}
154

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

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

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

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

173
  return TSDB_CODE_SUCCESS;
1✔
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)) {
45✔
197
  QUERY_PARAM_CHECK(input);
45!
198
  QUERY_PARAM_CHECK(msg);
45!
199
  QUERY_PARAM_CHECK(msgLen);
45!
200

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

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

212
  *msg = pBuf;
45✔
213
  *msgLen = bufLen;
45✔
214

215
  return TSDB_CODE_SUCCESS;
45✔
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,
1✔
241
                                  void *(*mallcFp)(int64_t)) {
242
  QUERY_PARAM_CHECK(input);
1!
243
  QUERY_PARAM_CHECK(msg);
1!
244
  QUERY_PARAM_CHECK(msgLen);
1!
245

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

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

270
  taosArrayDestroy(funcReq.pFuncNames);
1✔
271

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

275
  return TSDB_CODE_SUCCESS;
1✔
276
}
277

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

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

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

294
  *msg = pBuf;
4✔
295
  *msgLen = bufLen;
4✔
296

297
  return TSDB_CODE_SUCCESS;
4✔
298
}
299

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

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

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

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

319
  return TSDB_CODE_SUCCESS;
1✔
320
}
321

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

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

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

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

344
  return TSDB_CODE_SUCCESS;
1✔
345
}
346

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

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

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

363
  *msg = pBuf;
17✔
364
  *msgLen = bufLen;
17✔
365

366
  return TSDB_CODE_SUCCESS;
17✔
367
}
368

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

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

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

386
  *msg = pBuf;
×
387
  *msgLen = bufLen;
×
388
  return TSDB_CODE_SUCCESS;
×
389
}
390

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

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

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

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

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

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

426
  int32_t ret = tSerializeStreamProgressReq(pBuf, len, input);
×
427
  if (ret < 0) return ret;
×
428

429
  *msg = pBuf;
×
430
  *msgLen = len;
×
431
  return TSDB_CODE_SUCCESS;
×
432
}
433

434

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

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

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

452
  *msg = pBuf;
×
453
  *msgLen = bufLen;
×
454

455
  return TSDB_CODE_SUCCESS;
×
456
}
457

458

459
int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) {
3,212✔
460
  SUseDbOutput *pOut = output;
3,212✔
461
  SUseDbRsp     usedbRsp = {0};
3,212✔
462
  int32_t       code = -1;
3,212✔
463

464
  if (NULL == output || NULL == msg || msgSize <= 0) {
3,212!
465
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
466
    qError("invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
467
    goto PROCESS_USEDB_OVER;
×
468
  }
469

470
  if (tDeserializeSUseDbRsp(msg, msgSize, &usedbRsp) != 0) {
3,212!
471
    qError("invalid use db rsp msg, msgSize:%d", msgSize);
×
472
    code = TSDB_CODE_INVALID_MSG;
×
473
    goto PROCESS_USEDB_OVER;
×
474
  }
475

476
  if (usedbRsp.vgNum < 0) {
3,212!
477
    qError("invalid db[%s] vgroup number[%d]", usedbRsp.db, usedbRsp.vgNum);
×
478
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
479
    goto PROCESS_USEDB_OVER;
×
480
  }
481

482
  qTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum);
3,212✔
483
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
34,588✔
484
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
31,376✔
485
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
31,376✔
486
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
121,572✔
487
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
90,196✔
488
    }
489
  }
490

491
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
3,212✔
492

493
PROCESS_USEDB_OVER:
3,212✔
494

495
  if (code != 0) {
3,212!
496
    if (pOut) {
×
497
      if (pOut->dbVgroup) taosHashCleanup(pOut->dbVgroup->vgHash);
×
498
      taosMemoryFreeClear(pOut->dbVgroup);
×
499
    }
500
    qError("failed to process usedb rsp since %s", terrstr());
×
501
  }
502

503
  tFreeSUsedbRsp(&usedbRsp);
3,212✔
504
  return code;
3,212✔
505
}
506

507
static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) {
54✔
508
  QUERY_PARAM_CHECK(pMetaMsg);
54!
509
  if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) {
54!
510
    qError("invalid numOfTags[%d] in table meta rsp msg", pMetaMsg->numOfTags);
×
511
    return TSDB_CODE_TSC_INVALID_VALUE;
×
512
  }
513

514
  if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) {
54!
515
    qError("invalid numOfColumns[%d] in table meta rsp msg", pMetaMsg->numOfColumns);
×
516
    return TSDB_CODE_TSC_INVALID_VALUE;
×
517
  }
518

519
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
54✔
520
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
14!
521
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
×
522
    qError("invalid tableType[%d] in table meta rsp msg", pMetaMsg->tableType);
×
523
    return TSDB_CODE_TSC_INVALID_VALUE;
×
524
  }
525

526
  if (pMetaMsg->sversion < 0) {
54!
527
    qError("invalid sversion[%d] in table meta rsp msg", pMetaMsg->sversion);
×
528
    return TSDB_CODE_TSC_INVALID_VALUE;
×
529
  }
530

531
  if (pMetaMsg->tversion < 0) {
54!
532
    qError("invalid tversion[%d] in table meta rsp msg", pMetaMsg->tversion);
×
533
    return TSDB_CODE_TSC_INVALID_VALUE;
×
534
  }
535

536
  if (pMetaMsg->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
54!
537
    qError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", pMetaMsg->pSchemas[0].colId);
×
538
    return TSDB_CODE_TSC_INVALID_VALUE;
×
539
  }
540

541
  return TSDB_CODE_SUCCESS;
54✔
542
}
543

544
int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) {
572✔
545
  QUERY_PARAM_CHECK(msg);
572!
546
  QUERY_PARAM_CHECK(pMeta);
572!
547
  pMeta->vgId = msg->vgId;
572✔
548
  pMeta->tableType = msg->tableType;
572✔
549
  pMeta->uid = msg->tuid;
572✔
550
  pMeta->suid = msg->suid;
572✔
551

552
  qDebug("ctb:%s, uid:0x%" PRIx64 " meta returned, type:%d vgId:%d db:%s suid:%" PRIx64, msg->tbName, pMeta->uid,
572!
553
         pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid);
554

555
  return TSDB_CODE_SUCCESS;
572✔
556
}
557

558
int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta) {
×
559
  QUERY_PARAM_CHECK(msg);
×
560
  QUERY_PARAM_CHECK(pMeta);
×
561
  QUERY_PARAM_CHECK(msg->pColRefs);
×
562

563
  int32_t pColRefSize = sizeof(SColRef) * msg->numOfColRefs;
×
564

565
  SVCTableMeta *pTableMeta = taosMemoryCalloc(1, sizeof(SVCTableMeta) + pColRefSize);
×
566
  if (NULL == pTableMeta) {
×
567
    qError("calloc size[%d] failed", (int32_t)sizeof(SVCTableMeta) + pColRefSize);
×
568
    return terrno;
×
569
  }
570

571
  pTableMeta->vgId = msg->vgId;
×
572
  pTableMeta->tableType = msg->tableType;
×
573
  pTableMeta->uid = msg->tuid;
×
574
  pTableMeta->suid = msg->suid;
×
575
  pTableMeta->numOfColRefs = msg->numOfColRefs;
×
576

577
  pTableMeta->colRef = (SColRef *)((char *)pTableMeta + sizeof(SVCTableMeta));
×
578
  memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
×
579

580
  qDebug("ctable %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s suid %" PRIx64, msg->tbName, (pTableMeta)->uid,
×
581
         (pTableMeta)->tableType, (pTableMeta)->vgId, msg->dbFName, (pTableMeta)->suid);
582

583
  *pMeta = pTableMeta;
×
584
  return TSDB_CODE_SUCCESS;
×
585
}
586

587
int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
109✔
588
  QUERY_PARAM_CHECK(msg);
109!
589
  QUERY_PARAM_CHECK(pMeta);
109!
590
  int32_t total = msg->numOfColumns + msg->numOfTags;
109✔
591
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
109✔
592
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
109✔
593
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) ? sizeof(SColRef) * msg->numOfColRefs : 0;
109!
594

595
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize);
109!
596
  if (NULL == pTableMeta) {
109!
597
    qError("calloc size[%d] failed", metaSize);
×
598
    return terrno;
×
599
  }
600
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
109✔
601
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
109✔
602

603
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
109✔
604
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
109✔
605
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
109✔
606
  pTableMeta->suid = msg->suid;
109✔
607
  pTableMeta->sversion = msg->sversion;
109✔
608
  pTableMeta->tversion = msg->tversion;
109✔
609
  pTableMeta->virtualStb = msg->virtualStb;
109✔
610
  pTableMeta->numOfColRefs = msg->numOfColRefs;
109✔
611

612
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
109✔
613
  pTableMeta->tableInfo.precision = msg->precision;
109✔
614
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
109✔
615

616
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
109✔
617
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
109✔
618
    pTableMeta->schemaExt = pSchemaExt;
101✔
619
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
101✔
620
  } else {
621
    pTableMeta->schemaExt = NULL;
8✔
622
  }
623

624
  if (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) {
109!
625
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
×
626
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
×
627
  } else {
628
    pTableMeta->colRef = NULL;
109✔
629
  }
630

631
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
109!
632
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
511✔
633
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
402✔
634
    if (hasPK && (i > 0)) {
402✔
635
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
3!
636
        ++pTableMeta->tableInfo.numOfPKs;
3✔
637
      } else {
638
        hasPK = false;
×
639
      }
640
    }
641
  }
642

643
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
109✔
644
         " sver:%d tver:%d"
645
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
646
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
647
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
648
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
649

650
  *pMeta = pTableMeta;
109✔
651
  return TSDB_CODE_SUCCESS;
109✔
652
}
653

654
int32_t queryCreateTableMetaExFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
×
655
  QUERY_PARAM_CHECK(msg);
×
656
  QUERY_PARAM_CHECK(pMeta);
×
657
  int32_t total = msg->numOfColumns + msg->numOfTags;
×
658
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
×
659
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
×
660
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs) ? sizeof(SColRef) * msg->numOfColRefs : 0;
×
661
  int32_t tbNameSize = strlen(msg->tbName) + 1;
×
662

663
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize + tbNameSize);
×
664
  if (NULL == pTableMeta) {
×
665
    qError("calloc size[%d] failed", metaSize);
×
666
    return terrno;
×
667
  }
668
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
×
669
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
×
670

671
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
×
672
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
×
673
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
×
674
  pTableMeta->suid = msg->suid;
×
675
  pTableMeta->sversion = msg->sversion;
×
676
  pTableMeta->tversion = msg->tversion;
×
677
  pTableMeta->virtualStb = msg->virtualStb;
×
678
  pTableMeta->numOfColRefs = msg->numOfColRefs;
×
679

680
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
×
681
  pTableMeta->tableInfo.precision = msg->precision;
×
682
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
×
683

684
  TAOS_MEMCPY(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
×
685
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
×
686
    pTableMeta->schemaExt = pSchemaExt;
×
687
    TAOS_MEMCPY(pSchemaExt, msg->pSchemaExt, schemaExtSize);
×
688
  } else {
689
    pTableMeta->schemaExt = NULL;
×
690
  }
691

692
  if (hasRefCol(msg->tableType) && msg->pColRefs) {
×
693
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
×
694
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
×
695
  } else {
696
    pTableMeta->colRef = NULL;
×
697
  }
698

699
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
×
700
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
×
701
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
×
702
    if (hasPK && (i > 0)) {
×
703
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
×
704
        ++pTableMeta->tableInfo.numOfPKs;
×
705
      } else {
706
        hasPK = false;
×
707
      }
708
    }
709
  }
710

711
  char *pTbName = (char *)pTableMeta + metaSize + schemaExtSize + pColRefSize;
×
712
  tstrncpy(pTbName, msg->tbName, tbNameSize);
×
713

714
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
×
715
         " sver:%d tver:%d"
716
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
717
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
718
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
719
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
720

721
  *pMeta = pTableMeta;
×
722
  return TSDB_CODE_SUCCESS;
×
723
}
724

725
int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) {
54✔
726
  int32_t       code = 0;
54✔
727
  STableMetaRsp metaRsp = {0};
54✔
728

729
  if (NULL == output || NULL == msg || msgSize <= 0) {
54!
730
    qError("queryProcessTableMetaRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
731
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
732
    goto PROCESS_META_OVER;
×
733
  }
734

735
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
54!
736
    code = TSDB_CODE_INVALID_MSG;
×
737
    goto PROCESS_META_OVER;
×
738
  }
739

740
  code = queryConvertTableMetaMsg(&metaRsp);
54✔
741
  if (code != TSDB_CODE_SUCCESS) {
54!
742
    goto PROCESS_META_OVER;
×
743
  }
744

745
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
54!
746
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
48!
747
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
748
    goto PROCESS_META_OVER;
×
749
  }
750

751
  STableMetaOutput *pOut = output;
54✔
752
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
54✔
753
  pOut->dbId = metaRsp.dbId;
54✔
754

755
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
54✔
756
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
10✔
757

758
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
10✔
759
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
10✔
760

761
    pOut->ctbMeta.vgId = metaRsp.vgId;
10✔
762
    pOut->ctbMeta.tableType = metaRsp.tableType;
10✔
763
    pOut->ctbMeta.uid = metaRsp.tuid;
10✔
764
    pOut->ctbMeta.suid = metaRsp.suid;
10✔
765

766
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
10✔
767
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
44!
768
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
769

770
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
771
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
×
772

773
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
×
774
    if (TSDB_CODE_SUCCESS != code) {
×
775
      goto PROCESS_META_OVER;
×
776
    }
777
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
×
778
  } else {
779
    SET_META_TYPE_TABLE(pOut->metaType);
44✔
780
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
44✔
781
    code = queryCreateTableMetaFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
44✔
782
  }
783

784
PROCESS_META_OVER:
54✔
785
  if (code != 0) {
54!
786
    qError("failed to process table meta rsp since %s", tstrerror(code));
×
787
  }
788

789
  tFreeSTableMetaRsp(&metaRsp);
54✔
790
  return code;
54✔
791
}
792

793
static int32_t queryProcessTableNameRsp(void *output, char *msg, int32_t msgSize) {
×
794
  int32_t       code = 0;
×
795
  STableMetaRsp metaRsp = {0};
×
796

797
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
798
    qError("queryProcessTableNameRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
799
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
800
    goto PROCESS_NAME_OVER;
×
801
  }
802

803
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
×
804
    code = TSDB_CODE_INVALID_MSG;
×
805
    goto PROCESS_NAME_OVER;
×
806
  }
807

808
  code = queryConvertTableMetaMsg(&metaRsp);
×
809
  if (code != TSDB_CODE_SUCCESS) {
×
810
    goto PROCESS_NAME_OVER;
×
811
  }
812

813
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
×
814
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
×
815
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
816
    goto PROCESS_NAME_OVER;
×
817
  }
818

819
  STableMetaOutput *pOut = output;
×
820
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
×
821
  pOut->dbId = metaRsp.dbId;
×
822

823
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
×
824
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
×
825

826
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
827
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
×
828

829
    pOut->ctbMeta.vgId = metaRsp.vgId;
×
830
    pOut->ctbMeta.tableType = metaRsp.tableType;
×
831
    pOut->ctbMeta.uid = metaRsp.tuid;
×
832
    pOut->ctbMeta.suid = metaRsp.suid;
×
833

834
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
×
835
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
×
836
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
837

838
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
839
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
×
840

841
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
×
842
    if (TSDB_CODE_SUCCESS != code) {
×
843
      goto PROCESS_NAME_OVER;
×
844
    }
845

846
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
×
847
  } else {
848
    SET_META_TYPE_TABLE(pOut->metaType);
×
849
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
850
    code = queryCreateTableMetaExFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
×
851
  }
852

853
PROCESS_NAME_OVER:
×
854
  if (code != 0) {
×
855
    qError("failed to process table name rsp since %s", tstrerror(code));
×
856
  }
857

858
  tFreeSTableMetaRsp(&metaRsp);
×
859
  return code;
×
860
}
861

862
int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) {
1✔
863
  SQnodeListRsp out = {0};
1✔
864
  int32_t       code = 0;
1✔
865

866
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
867
    qError("queryProcessQnodeListRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
868
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
869
    return code;
×
870
  }
871

872
  out.qnodeList = (SArray *)output;
1✔
873
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
1!
874
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
×
875
    code = TSDB_CODE_INVALID_MSG;
×
876
    return code;
×
877
  }
878

879
  return code;
1✔
880
}
881

882
int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) {
1✔
883
  SDnodeListRsp out = {0};
1✔
884
  int32_t       code = 0;
1✔
885

886
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
887
    qError("queryProcessDnodeListRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
888
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
889
    return code;
×
890
  }
891

892
  if (tDeserializeSDnodeListRsp(msg, msgSize, &out) != 0) {
1!
893
    qError("invalid dnode list rsp msg, msgSize:%d", msgSize);
×
894
    code = TSDB_CODE_INVALID_MSG;
×
895
    return code;
×
896
  }
897

898
  *(SArray **)output = out.dnodeList;
1✔
899

900
  return code;
1✔
901
}
902

903
int32_t queryProcessGetSerVerRsp(void *output, char *msg, int32_t msgSize) {
1✔
904
  SServerVerRsp out = {0};
1✔
905
  int32_t       code = 0;
1✔
906

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

913
  if (tDeserializeSServerVerRsp(msg, msgSize, &out) != 0) {
1!
914
    qError("invalid svr ver rsp msg, msgSize:%d", msgSize);
×
915
    code = TSDB_CODE_INVALID_MSG;
×
916
    return code;
×
917
  }
918

919
  *(char **)output = taosStrdup(out.ver);
1!
920
  if (NULL == *(char **)output) {
1!
921
    return terrno;
×
922
  }
923

924
  return code;
1✔
925
}
926

927
int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) {
45✔
928
  SDbCfgRsp out = {0};
45✔
929

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

935
  if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) {
45!
936
    qError("tDeserializeSDbCfgRsp failed, msgSize:%d, dbCfgRsp:%lu", msgSize, sizeof(out));
×
937
    return TSDB_CODE_INVALID_MSG;
×
938
  }
939

940
  memcpy(output, &out, sizeof(out));
45✔
941

942
  return TSDB_CODE_SUCCESS;
45✔
943
}
944

945
int32_t queryProcessGetIndexRsp(void *output, char *msg, int32_t msgSize) {
×
946
  SUserIndexRsp out = {0};
×
947

948
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
949
    qError("queryProcessGetIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
950
    return TSDB_CODE_TSC_INVALID_INPUT;
×
951
  }
952

953
  if (tDeserializeSUserIndexRsp(msg, msgSize, &out) != 0) {
×
954
    qError("tDeserializeSUserIndexRsp failed, msgSize:%d", msgSize);
×
955
    return TSDB_CODE_INVALID_MSG;
×
956
  }
957

958
  memcpy(output, &out, sizeof(out));
×
959

960
  return TSDB_CODE_SUCCESS;
×
961
}
962

963
int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
1✔
964
  SRetrieveFuncRsp out = {0};
1✔
965

966
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
967
    qError("queryProcessRetrieveFuncRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
968
    return TSDB_CODE_TSC_INVALID_INPUT;
×
969
  }
970

971
  if (tDeserializeSRetrieveFuncRsp(msg, msgSize, &out) != 0) {
1!
972
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
×
973
    return TSDB_CODE_INVALID_MSG;
×
974
  }
975

976
  if (1 != out.numOfFuncs) {
1!
977
    qError("invalid func num returned, numOfFuncs:%d", out.numOfFuncs);
×
978
    return TSDB_CODE_INVALID_MSG;
×
979
  }
980

981
  SFuncInfo *funcInfo = taosArrayGet(out.pFuncInfos, 0);
1✔
982

983
  memcpy(output, funcInfo, sizeof(*funcInfo));
1✔
984
  taosArrayDestroy(out.pFuncInfos);
1✔
985
  taosArrayDestroy(out.pFuncExtraInfos);
1✔
986

987
  return TSDB_CODE_SUCCESS;
1✔
988
}
989

990
int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) {
4✔
991
  if (NULL == output || NULL == msg || msgSize <= 0) {
4!
992
    qError("queryProcessGetUserAuthRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
993
    return TSDB_CODE_TSC_INVALID_INPUT;
×
994
  }
995

996
  if (tDeserializeSGetUserAuthRsp(msg, msgSize, (SGetUserAuthRsp *)output) != 0) {
4!
997
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
998
    return TSDB_CODE_INVALID_MSG;
×
999
  }
1000

1001
  return TSDB_CODE_SUCCESS;
4✔
1002
}
1003

1004
int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
1✔
1005
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
1006
    qError("queryProcessGetTbIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1007
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1008
  }
1009

1010
  STableIndexRsp *out = (STableIndexRsp *)output;
1✔
1011
  if (tDeserializeSTableIndexRsp(msg, msgSize, out) != 0) {
1!
1012
    qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize);
×
1013
    return TSDB_CODE_INVALID_MSG;
×
1014
  }
1015

1016
  return TSDB_CODE_SUCCESS;
1✔
1017
}
1018

1019
int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
1✔
1020
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
1021
    qError("queryProcessGetTbCfgRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1022
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1023
  }
1024

1025
  STableCfgRsp *out = taosMemoryCalloc(1, sizeof(STableCfgRsp));
1!
1026
  if(out == NULL) {
1!
1027
    return terrno;
×
1028
  }
1029
  if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
1!
1030
    qError("tDeserializeSTableCfgRsp failed, msgSize:%d", msgSize);
×
1031
    tFreeSTableCfgRsp(out);
×
1032
    taosMemoryFree(out);
×
1033
    return TSDB_CODE_INVALID_MSG;
×
1034
  }
1035

1036
  *(STableCfgRsp **)output = out;
1✔
1037

1038
  return TSDB_CODE_SUCCESS;
1✔
1039
}
1040

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

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

1058
  qDebugL("view meta recved, dbFName:%s, view:%s, querySQL:%s", out->dbFName, out->name, out->querySql);
×
1059

1060
  *(SViewMetaRsp **)output = out;
×
1061

1062
  return TSDB_CODE_SUCCESS;
×
1063
}
1064

1065
int32_t queryProcessGetTbTSMARsp(void* output, char* msg, int32_t msgSize) {
×
1066
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
1067
    qError("queryProcessGetTbTSMARsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1068
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1069
  }
1070

1071
  if (tDeserializeTableTSMAInfoRsp(msg, msgSize, output) != 0) {
×
1072
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1073
    return TSDB_CODE_INVALID_MSG;
×
1074
  }
1075

1076
  return TSDB_CODE_SUCCESS;
×
1077
}
1078

1079
int32_t queryProcessStreamProgressRsp(void* output, char* msg, int32_t msgSize) {
×
1080
  if (!output || !msg || msgSize <= 0) {
×
1081
    qError("queryProcessStreamProgressRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1082
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1083
  }
1084

1085
  if (tDeserializeSStreamProgressRsp(msg, msgSize, output) != 0) {
×
1086
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1087
    return TSDB_CODE_INVALID_MSG;
×
1088
  }
1089
  return TSDB_CODE_SUCCESS;
×
1090
}
1091

1092
int32_t queryProcessVSubTablesRsp(void* output, char* msg, int32_t msgSize) {
×
1093
  if (!output || !msg || msgSize <= 0) {
×
1094
    qError("queryProcessVSubTablesRsp input error, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1095
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1096
  }
1097

1098
  SVSubTablesRsp* pRsp = (SVSubTablesRsp*)output;
×
1099
  int32_t code = tDeserializeSVSubTablesRsp(msg, msgSize, pRsp);
×
1100
  if (code != 0) {
×
1101
    qError("tDeserializeSVSubTablesRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1102
    return code;
×
1103
  }
1104
  
1105
  return TSDB_CODE_SUCCESS;
×
1106
}
1107

1108
void initQueryModuleMsgHandle() {
36✔
1109
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg;
36✔
1110
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryBuildTableMetaReqMsg;
36✔
1111
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;
36✔
1112
  queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg;
36✔
1113
  queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg;
36✔
1114
  queryBuildMsg[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryBuildDnodeListMsg;
36✔
1115
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg;
36✔
1116
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryBuildGetIndexMsg;
36✔
1117
  queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryBuildRetrieveFuncMsg;
36✔
1118
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryBuildGetUserAuthMsg;
36✔
1119
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryBuildGetTbIndexMsg;
36✔
1120
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
36✔
1121
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
36✔
1122
  queryBuildMsg[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryBuildGetSerVerMsg;
36✔
1123
  queryBuildMsg[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryBuildGetViewMetaMsg;
36✔
1124
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryBuildGetTableTSMAMsg;
36✔
1125
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryBuildGetTSMAMsg;
36✔
1126
  queryBuildMsg[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryBuildGetStreamProgressMsg;
36✔
1127
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryBuildVSubTablesMsg;
36✔
1128

1129
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp;
36✔
1130
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryProcessTableNameRsp;
36✔
1131
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp;
36✔
1132
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp;
36✔
1133
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp;
36✔
1134
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryProcessDnodeListRsp;
36✔
1135
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp;
36✔
1136
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryProcessGetIndexRsp;
36✔
1137
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryProcessRetrieveFuncRsp;
36✔
1138
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryProcessGetUserAuthRsp;
36✔
1139
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryProcessGetTbIndexRsp;
36✔
1140
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
36✔
1141
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
36✔
1142
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp;
36✔
1143
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryProcessGetViewMetaRsp;
36✔
1144
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryProcessGetTbTSMARsp;
36✔
1145
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryProcessGetTbTSMARsp;
36✔
1146
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryProcessStreamProgressRsp;
36✔
1147
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryProcessVSubTablesRsp;
36✔
1148
}
36✔
1149

1150
#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