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

taosdata / TDengine / #3768

28 Mar 2025 10:15AM UTC coverage: 33.726% (-0.3%) from 33.993%
#3768

push

travis-ci

happyguoxy
test:alter lcov result

144891 of 592084 branches covered (24.47%)

Branch coverage included in aggregate %.

218795 of 486283 relevant lines covered (44.99%)

765715.29 hits per line

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

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

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

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

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

51
  if (usedbRsp->vgNum <= 0) {
2,751✔
52
    return TSDB_CODE_SUCCESS;
741✔
53
  }
54

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

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

71
  return TSDB_CODE_SUCCESS;
2,010✔
72
}
73

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

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

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

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

99
  *msg = pBuf;
1,899✔
100
  *msgLen = bufLen;
1,899✔
101

102
  return TSDB_CODE_SUCCESS;
1,899✔
103
}
104

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

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

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

127
  *msg = pBuf;
2,170✔
128
  *msgLen = bufLen;
2,170✔
129

130
  return TSDB_CODE_SUCCESS;
2,170✔
131
}
132

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

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

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

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

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

152
  return TSDB_CODE_SUCCESS;
33✔
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)) {
×
177
  QUERY_PARAM_CHECK(msg);
×
178
  QUERY_PARAM_CHECK(msgLen);
×
179

180
  SServerVerReq req = {0};
×
181

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

190
  *msg = pBuf;
×
191
  *msgLen = bufLen;
×
192

193
  return TSDB_CODE_SUCCESS;
×
194
}
195

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

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

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

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

215
  return TSDB_CODE_SUCCESS;
265✔
216
}
217

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

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

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

234
  *msg = pBuf;
×
235
  *msgLen = bufLen;
×
236

237
  return TSDB_CODE_SUCCESS;
×
238
}
239

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

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

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

270
  taosArrayDestroy(funcReq.pFuncNames);
541✔
271

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

275
  return TSDB_CODE_SUCCESS;
541✔
276
}
277

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

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

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

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

297
  return TSDB_CODE_SUCCESS;
180✔
298
}
299

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

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

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

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

319
  return TSDB_CODE_SUCCESS;
8✔
320
}
321

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

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

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

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

344
  return TSDB_CODE_SUCCESS;
47✔
345
}
346

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

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

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

363
  *msg = pBuf;
1,041✔
364
  *msgLen = bufLen;
1,041✔
365

366
  return TSDB_CODE_SUCCESS;
1,041✔
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) {
2,163✔
460
  SUseDbOutput *pOut = output;
2,163✔
461
  SUseDbRsp     usedbRsp = {0};
2,163✔
462
  int32_t       code = -1;
2,163✔
463

464
  if (NULL == output || NULL == msg || msgSize <= 0) {
2,163!
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) {
2,163!
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) {
2,163!
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);
2,163✔
483
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
8,373✔
484
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
6,210✔
485
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
6,210✔
486
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
12,508✔
487
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
6,298✔
488
    }
489
  }
490

491
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
2,163✔
492

493
PROCESS_USEDB_OVER:
2,163✔
494

495
  if (code != 0) {
2,163!
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);
2,163✔
504
  return code;
2,163✔
505
}
506

507
static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) {
1,280✔
508
  QUERY_PARAM_CHECK(pMetaMsg);
1,280!
509
  if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) {
1,280!
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) {
1,280!
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 &&
1,280✔
520
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
422!
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) {
1,280!
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) {
1,280!
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) {
1,280!
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;
1,280✔
542
}
543

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

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

555
  return TSDB_CODE_SUCCESS;
5,675✔
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) {
1,658✔
588
  QUERY_PARAM_CHECK(msg);
1,658!
589
  QUERY_PARAM_CHECK(pMeta);
1,658!
590
  int32_t total = msg->numOfColumns + msg->numOfTags;
1,658✔
591
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
1,658✔
592
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
1,658!
593
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) ? sizeof(SColRef) * msg->numOfColRefs : 0;
1,658!
594

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

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

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

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

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

631
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
1,658!
632
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
23,013✔
633
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
21,355✔
634
    if (hasPK && (i > 0)) {
21,355✔
635
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
69✔
636
        ++pTableMeta->tableInfo.numOfPKs;
35✔
637
      } else {
638
        hasPK = false;
34✔
639
      }
640
    }
641
  }
642

643
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
1,658✔
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;
1,658✔
651
  return TSDB_CODE_SUCCESS;
1,658✔
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) {
1,280✔
726
  int32_t       code = 0;
1,280✔
727
  STableMetaRsp metaRsp = {0};
1,280✔
728

729
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,280!
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) {
1,280!
736
    code = TSDB_CODE_INVALID_MSG;
×
737
    goto PROCESS_META_OVER;
×
738
  }
739

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

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

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

755
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
1,280✔
756
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
253✔
757

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

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

766
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
253✔
767
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
1,027!
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);
1,027✔
780
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
1,027✔
781
    code = queryCreateTableMetaFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
1,027✔
782
  }
783

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

789
  tFreeSTableMetaRsp(&metaRsp);
1,280✔
790
  return code;
1,280✔
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) {
33✔
863
  SQnodeListRsp out = {0};
33✔
864
  int32_t       code = 0;
33✔
865

866
  if (NULL == output || NULL == msg || msgSize <= 0) {
33!
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;
33✔
873
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
33!
874
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
×
875
    code = TSDB_CODE_INVALID_MSG;
×
876
    return code;
×
877
  }
878

879
  return code;
33✔
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) {
×
904
  SServerVerRsp out = {0};
×
905
  int32_t       code = 0;
×
906

907
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
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) {
×
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);
×
920
  if (NULL == *(char **)output) {
×
921
    return terrno;
×
922
  }
923

924
  return code;
×
925
}
926

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

930
  if (NULL == output || NULL == msg || msgSize <= 0) {
265!
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) {
265!
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));
265✔
941

942
  return TSDB_CODE_SUCCESS;
265✔
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) {
541✔
964
  SRetrieveFuncRsp out = {0};
541✔
965

966
  if (NULL == output || NULL == msg || msgSize <= 0) {
541!
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) {
541!
972
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
×
973
    return TSDB_CODE_INVALID_MSG;
×
974
  }
975

976
  if (1 != out.numOfFuncs) {
541!
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);
541✔
982

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

987
  return TSDB_CODE_SUCCESS;
541✔
988
}
989

990
int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) {
180✔
991
  if (NULL == output || NULL == msg || msgSize <= 0) {
180!
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) {
180!
997
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
998
    return TSDB_CODE_INVALID_MSG;
×
999
  }
1000

1001
  return TSDB_CODE_SUCCESS;
180✔
1002
}
1003

1004
int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
×
1005
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
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;
×
1011
  if (tDeserializeSTableIndexRsp(msg, msgSize, out) != 0) {
×
1012
    qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize);
×
1013
    return TSDB_CODE_INVALID_MSG;
×
1014
  }
1015

1016
  return TSDB_CODE_SUCCESS;
×
1017
}
1018

1019
int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
47✔
1020
  if (NULL == output || NULL == msg || msgSize <= 0) {
47!
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));
47!
1026
  if(out == NULL) {
47!
1027
    return terrno;
×
1028
  }
1029
  if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
47!
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;
47✔
1037

1038
  return TSDB_CODE_SUCCESS;
47✔
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() {
394✔
1109
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg;
394✔
1110
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryBuildTableMetaReqMsg;
394✔
1111
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;
394✔
1112
  queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg;
394✔
1113
  queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg;
394✔
1114
  queryBuildMsg[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryBuildDnodeListMsg;
394✔
1115
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg;
394✔
1116
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryBuildGetIndexMsg;
394✔
1117
  queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryBuildRetrieveFuncMsg;
394✔
1118
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryBuildGetUserAuthMsg;
394✔
1119
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryBuildGetTbIndexMsg;
394✔
1120
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
394✔
1121
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
394✔
1122
  queryBuildMsg[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryBuildGetSerVerMsg;
394✔
1123
  queryBuildMsg[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryBuildGetViewMetaMsg;
394✔
1124
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryBuildGetTableTSMAMsg;
394✔
1125
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryBuildGetTSMAMsg;
394✔
1126
  queryBuildMsg[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryBuildGetStreamProgressMsg;
394✔
1127
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryBuildVSubTablesMsg;
394✔
1128

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