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

taosdata / TDengine / #4756

25 Sep 2025 05:58AM UTC coverage: 58.829% (+0.2%) from 58.63%
#4756

push

travis-ci

web-flow
enh: taos command line support '-uroot' on windows (#33055)

135574 of 293169 branches covered (46.24%)

Branch coverage included in aggregate %.

204395 of 284720 relevant lines covered (71.79%)

18747092.16 hits per line

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

40.56
/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 "streamMsg.h"
19
#include "systable.h"
20
#include "tmsg.h"
21
#include "trpc.h"
22

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

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

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

38
  pOut->dbVgroup = taosMemoryCalloc(1, sizeof(SDBVgInfo));
26,574!
39
  if (NULL == pOut->dbVgroup) {
26,585!
40
    return terrno;
×
41
  }
42

43
  pOut->dbVgroup->vgVersion = usedbRsp->vgVersion;
26,585✔
44
  pOut->dbVgroup->hashMethod = usedbRsp->hashMethod;
26,585✔
45
  pOut->dbVgroup->hashPrefix = usedbRsp->hashPrefix;
26,585✔
46
  pOut->dbVgroup->hashSuffix = usedbRsp->hashSuffix;
26,585✔
47
  pOut->dbVgroup->stateTs = usedbRsp->stateTs;
26,585✔
48
  pOut->dbVgroup->flags = usedbRsp->flags;
26,585✔
49

50
  qDebug("db:%s, get %d vgroup, vgVersion:%d, stateTs:%" PRId64, usedbRsp->db, usedbRsp->vgNum, usedbRsp->vgVersion,
26,585✔
51
         usedbRsp->stateTs);
52

53
  if (usedbRsp->vgNum <= 0) {
26,586✔
54
    return TSDB_CODE_SUCCESS;
4,582✔
55
  }
56

57
  pOut->dbVgroup->vgHash =
44,002✔
58
      taosHashInit(usedbRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
22,004✔
59
  if (NULL == pOut->dbVgroup->vgHash) {
22,001!
60
    return terrno;
×
61
  }
62

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

73
  return TSDB_CODE_SUCCESS;
22,008✔
74
}
75

76
int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
51,707✔
77
                                  void *(*mallcFp)(int64_t)) {
78
  QUERY_PARAM_CHECK(input);
51,707!
79
  QUERY_PARAM_CHECK(msg);
51,707!
80
  QUERY_PARAM_CHECK(msgLen);
51,707!
81
  SBuildTableInput *pInput = input;
51,707✔
82

83
  STableInfoReq infoReq = {0};
51,707✔
84
  infoReq.option = pInput->option;
51,707✔
85
  infoReq.header.vgId = pInput->vgId;
51,707✔
86
  infoReq.autoCreateCtb = pInput->autoCreateCtb;
51,707✔
87

88
  if (pInput->dbFName) {
51,707!
89
    tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
51,714✔
90
  }
91
  tstrncpy(infoReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
51,707✔
92

93
  int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
51,707✔
94
  void   *pBuf = (*mallcFp)(bufLen);
51,719✔
95
  if (NULL == pBuf) {
51,725!
96
    return terrno;
×
97
  }
98
  int32_t ret = tSerializeSTableInfoReq(pBuf, bufLen, &infoReq);
51,725✔
99
  if (ret < 0) return ret;
51,728!
100

101
  *msg = pBuf;
51,728✔
102
  *msgLen = bufLen;
51,728✔
103

104
  return TSDB_CODE_SUCCESS;
51,728✔
105
}
106

107
int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
21,057✔
108
  QUERY_PARAM_CHECK(input);
21,057!
109
  QUERY_PARAM_CHECK(msg);
21,057!
110
  QUERY_PARAM_CHECK(msgLen);
21,057!
111
  SBuildUseDBInput *pInput = input;
21,057✔
112

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

121
  int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
21,057✔
122
  void   *pBuf = (*mallcFp)(bufLen);
21,055✔
123
  if (NULL == pBuf) {
21,053!
124
    return terrno;
×
125
  }
126
  int32_t ret = tSerializeSUseDbReq(pBuf, bufLen, &usedbReq);
21,053✔
127
  if (ret < 0) return ret;
21,059!
128

129
  *msg = pBuf;
21,059✔
130
  *msgLen = bufLen;
21,059✔
131

132
  return TSDB_CODE_SUCCESS;
21,059✔
133
}
134

135
int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
3✔
136
  QUERY_PARAM_CHECK(msg);
3!
137
  QUERY_PARAM_CHECK(msgLen);
3!
138

139
  SQnodeListReq qnodeListReq = {0};
3✔
140
  qnodeListReq.rowNum = -1;
3✔
141

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

148
  int32_t ret = tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq);
3✔
149
  if (ret < 0) return ret;
3!
150

151
  *msg = pBuf;
3✔
152
  *msgLen = bufLen;
3✔
153

154
  return TSDB_CODE_SUCCESS;
3✔
155
}
156

157
int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
14✔
158
  QUERY_PARAM_CHECK(msg);
14!
159
  QUERY_PARAM_CHECK(msgLen);
14!
160

161
  SDnodeListReq dnodeListReq = {0};
14✔
162
  dnodeListReq.rowNum = -1;
14✔
163

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

172
  *msg = pBuf;
14✔
173
  *msgLen = bufLen;
14✔
174

175
  return TSDB_CODE_SUCCESS;
14✔
176
}
177

178
int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
3✔
179
  QUERY_PARAM_CHECK(msg);
3!
180
  QUERY_PARAM_CHECK(msgLen);
3!
181

182
  SServerVerReq req = {0};
3✔
183

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

192
  *msg = pBuf;
3✔
193
  *msgLen = bufLen;
3✔
194

195
  return TSDB_CODE_SUCCESS;
3✔
196
}
197

198
int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
1,943✔
199
  QUERY_PARAM_CHECK(input);
1,943!
200
  QUERY_PARAM_CHECK(msg);
1,943!
201
  QUERY_PARAM_CHECK(msgLen);
1,943!
202

203
  SDbCfgReq dbCfgReq = {0};
1,943✔
204
  tstrncpy(dbCfgReq.db, input, TSDB_DB_FNAME_LEN);
1,943✔
205

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

214
  *msg = pBuf;
1,943✔
215
  *msgLen = bufLen;
1,943✔
216

217
  return TSDB_CODE_SUCCESS;
1,943✔
218
}
219

220
int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
3✔
221
  QUERY_PARAM_CHECK(input);
3!
222
  QUERY_PARAM_CHECK(msg);
3!
223
  QUERY_PARAM_CHECK(msgLen);
3!
224

225
  SUserIndexReq indexReq = {0};
3✔
226
  tstrncpy(indexReq.indexFName, input, TSDB_INDEX_FNAME_LEN);
3✔
227

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

236
  *msg = pBuf;
3✔
237
  *msgLen = bufLen;
3✔
238

239
  return TSDB_CODE_SUCCESS;
3✔
240
}
241

242
int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
11✔
243
                                  void *(*mallcFp)(int64_t)) {
244
  QUERY_PARAM_CHECK(input);
11!
245
  QUERY_PARAM_CHECK(msg);
11!
246
  QUERY_PARAM_CHECK(msgLen);
11!
247

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

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

272
  taosArrayDestroy(funcReq.pFuncNames);
11✔
273

274
  *msg = pBuf;
11✔
275
  *msgLen = bufLen;
11✔
276

277
  return TSDB_CODE_SUCCESS;
11✔
278
}
279

280
int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
2,052✔
281
  QUERY_PARAM_CHECK(input);
2,052!
282
  QUERY_PARAM_CHECK(msg);
2,052!
283
  QUERY_PARAM_CHECK(msgLen);
2,052!
284

285
  SGetUserAuthReq req = {0};
2,052✔
286
  tstrncpy(req.user, input, TSDB_USER_LEN);
2,052✔
287

288
  int32_t bufLen = tSerializeSGetUserAuthReq(NULL, 0, &req);
2,052✔
289
  void   *pBuf = (*mallcFp)(bufLen);
2,055✔
290
  if (NULL == pBuf) {
2,054!
291
    return terrno;
×
292
  }
293
  int32_t ret = tSerializeSGetUserAuthReq(pBuf, bufLen, &req);
2,054✔
294
  if (ret < 0) return ret;
2,055!
295

296
  *msg = pBuf;
2,055✔
297
  *msgLen = bufLen;
2,055✔
298

299
  return TSDB_CODE_SUCCESS;
2,055✔
300
}
301

302
int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
3✔
303
  QUERY_PARAM_CHECK(input);
3!
304
  QUERY_PARAM_CHECK(msg);
3!
305
  QUERY_PARAM_CHECK(msgLen);
3!
306

307
  STableIndexReq indexReq = {0};
3✔
308
  tstrncpy(indexReq.tbFName, input, TSDB_TABLE_FNAME_LEN);
3✔
309

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

318
  *msg = pBuf;
3✔
319
  *msgLen = bufLen;
3✔
320

321
  return TSDB_CODE_SUCCESS;
3✔
322
}
323

324
int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
83✔
325
  QUERY_PARAM_CHECK(input);
83!
326
  QUERY_PARAM_CHECK(msg);
83!
327
  QUERY_PARAM_CHECK(msgLen);
83!
328

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

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

343
  *msg = pBuf;
83✔
344
  *msgLen = bufLen;
83✔
345

346
  return TSDB_CODE_SUCCESS;
83✔
347
}
348

349
int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
9,707✔
350
  QUERY_PARAM_CHECK(input);
9,707!
351
  QUERY_PARAM_CHECK(msg);
9,707!
352
  QUERY_PARAM_CHECK(msgLen);
9,707!
353

354
  SViewMetaReq req = {0};
9,707✔
355
  tstrncpy(req.fullname, input, TSDB_VIEW_FNAME_LEN);
9,707✔
356

357
  int32_t bufLen = tSerializeSViewMetaReq(NULL, 0, &req);
9,707✔
358
  void   *pBuf = (*mallcFp)(bufLen);
9,708✔
359
  if (NULL == pBuf) {
9,710!
360
    return terrno;
×
361
  }
362
  int32_t ret = tSerializeSViewMetaReq(pBuf, bufLen, &req);
9,710✔
363
  if (ret < 0) return ret;
9,709!
364

365
  *msg = pBuf;
9,709✔
366
  *msgLen = bufLen;
9,709✔
367

368
  return TSDB_CODE_SUCCESS;
9,709✔
369
}
370

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

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

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

388
  *msg = pBuf;
×
389
  *msgLen = bufLen;
×
390
  return TSDB_CODE_SUCCESS;
×
391
}
392

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

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

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

412
  *msg = pBuf;
×
413
  *msgLen = bufLen;
×
414
  return TSDB_CODE_SUCCESS;
×
415
}
416

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

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

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

431
  *msg = pBuf;
×
432
  *msgLen = len;
×
433
  return TSDB_CODE_SUCCESS;
×
434
}
435

436

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

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

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

454
  *msg = pBuf;
×
455
  *msgLen = bufLen;
×
456

457
  return TSDB_CODE_SUCCESS;
×
458
}
459

460
int32_t queryBuildVStbRefDBsMsg(void* input, char** msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int64_t)) {
140✔
461
  QUERY_PARAM_CHECK(input);
140!
462
  QUERY_PARAM_CHECK(msg);
140!
463
  QUERY_PARAM_CHECK(msgLen);
140!
464

465
  SVStbRefDbsReq req = {0};
140✔
466
  req.suid = *(int64_t*)input;
140✔
467

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

477
  *msg = pBuf;
140✔
478
  *msgLen = bufLen;
140✔
479

480
  return TSDB_CODE_SUCCESS;
140✔
481
}
482

483
int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) {
21,036✔
484
  SUseDbOutput *pOut = output;
21,036✔
485
  SUseDbRsp     usedbRsp = {0};
21,036✔
486
  int32_t       code = -1;
21,036✔
487

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

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

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

506
  qTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum);
21,034✔
507
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
150,404✔
508
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
129,369✔
509
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
129,369✔
510
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
435,947✔
511
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
306,578✔
512
    }
513
  }
514

515
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
21,035✔
516

517
PROCESS_USEDB_OVER:
21,037✔
518

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

527
  tFreeSUsedbRsp(&usedbRsp);
21,037✔
528
  return code;
21,038✔
529
}
530

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

538
  if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) {
46,315!
539
    qError("invalid numOfColumns[%d] in table meta rsp msg", pMetaMsg->numOfColumns);
×
540
    return TSDB_CODE_TSC_INVALID_VALUE;
×
541
  }
542

543
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
46,315✔
544
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
2,832✔
545
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
68!
546
    qError("invalid tableType[%d] in table meta rsp msg", pMetaMsg->tableType);
×
547
    return TSDB_CODE_TSC_INVALID_VALUE;
×
548
  }
549

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

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

560
  if (pMetaMsg->rversion < 0) {
46,315!
561
    qError("invalid rversion[%d] in table meta rsp msg", pMetaMsg->rversion);
×
562
    return TSDB_CODE_TSC_INVALID_VALUE;
×
563
  }
564

565
  if (pMetaMsg->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
46,315!
566
    qError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", pMetaMsg->pSchemas[0].colId);
×
567
    return TSDB_CODE_TSC_INVALID_VALUE;
×
568
  }
569

570
  return TSDB_CODE_SUCCESS;
46,315✔
571
}
572

573
int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) {
61,544✔
574
  QUERY_PARAM_CHECK(msg);
61,544!
575
  QUERY_PARAM_CHECK(pMeta);
61,544!
576
  pMeta->vgId = msg->vgId;
61,544✔
577
  pMeta->tableType = msg->tableType;
61,544✔
578
  pMeta->uid = msg->tuid;
61,544✔
579
  pMeta->suid = msg->suid;
61,544✔
580

581
  qDebug("ctb:%s, uid:0x%" PRIx64 " meta returned, type:%d vgId:%d db:%s suid:%" PRIx64, msg->tbName, pMeta->uid,
61,544✔
582
         pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid);
583

584
  return TSDB_CODE_SUCCESS;
61,543✔
585
}
586

587
int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta) {
448✔
588
  QUERY_PARAM_CHECK(msg);
448!
589
  QUERY_PARAM_CHECK(pMeta);
448!
590
  QUERY_PARAM_CHECK(msg->pColRefs);
448!
591

592
  int32_t pColRefSize = sizeof(SColRef) * msg->numOfColRefs;
448✔
593

594
  SVCTableMeta *pTableMeta = taosMemoryCalloc(1, sizeof(SVCTableMeta) + pColRefSize);
448!
595
  if (NULL == pTableMeta) {
448!
596
    qError("calloc size[%d] failed", (int32_t)sizeof(SVCTableMeta) + pColRefSize);
×
597
    return terrno;
×
598
  }
599

600
  pTableMeta->vgId = msg->vgId;
448✔
601
  pTableMeta->tableType = msg->tableType;
448✔
602
  pTableMeta->uid = msg->tuid;
448✔
603
  pTableMeta->suid = msg->suid;
448✔
604
  pTableMeta->numOfColRefs = msg->numOfColRefs;
448✔
605
  pTableMeta->rversion = msg->rversion;
448✔
606

607
  pTableMeta->colRef = (SColRef *)((char *)pTableMeta + sizeof(SVCTableMeta));
448✔
608
  memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
448✔
609

610
  qDebug("ctable %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s suid %" PRIx64, msg->tbName, (pTableMeta)->uid,
448✔
611
         (pTableMeta)->tableType, (pTableMeta)->vgId, msg->dbFName, (pTableMeta)->suid);
612

613
  *pMeta = pTableMeta;
448✔
614
  return TSDB_CODE_SUCCESS;
448✔
615
}
616

617
int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
49,822✔
618
  QUERY_PARAM_CHECK(msg);
49,822!
619
  QUERY_PARAM_CHECK(pMeta);
49,822!
620
  int32_t total = msg->numOfColumns + msg->numOfTags;
49,822✔
621
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
49,822✔
622
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
49,822✔
623
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) ? sizeof(SColRef) * msg->numOfColRefs : 0;
49,823!
624

625
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize);
49,825!
626
  if (NULL == pTableMeta) {
49,828!
627
    qError("calloc size[%d] failed", metaSize);
×
628
    return terrno;
×
629
  }
630
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
49,828✔
631
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
49,828✔
632

633
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
49,828✔
634
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
49,828✔
635
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
49,828✔
636
  pTableMeta->suid = msg->suid;
49,828✔
637
  pTableMeta->sversion = msg->sversion;
49,828✔
638
  pTableMeta->tversion = msg->tversion;
49,828✔
639
  pTableMeta->rversion = msg->rversion;
49,828✔
640
  if (msg->virtualStb) {
49,828✔
641
    pTableMeta->virtualStb = 1;
87✔
642
    pTableMeta->numOfColRefs = 0;
87✔
643
  } else {
644
    if (msg->tableType == TSDB_VIRTUAL_CHILD_TABLE && isStb) {
49,741!
645
      pTableMeta->virtualStb = 1;
39✔
646
      pTableMeta->numOfColRefs = 0;
39✔
647
    } else {
648
      pTableMeta->virtualStb = 0;
49,702✔
649
      pTableMeta->numOfColRefs = msg->numOfColRefs;
49,702✔
650
    }
651
  }
652

653
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
49,828✔
654
  pTableMeta->tableInfo.precision = msg->precision;
49,828✔
655
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
49,828✔
656

657
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
49,828✔
658
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
49,828✔
659
    pTableMeta->schemaExt = pSchemaExt;
48,384✔
660
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
48,384✔
661
  } else {
662
    pTableMeta->schemaExt = NULL;
1,445✔
663
  }
664

665
  if (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) {
49,829!
666
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
33✔
667
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
33✔
668
  } else {
669
    pTableMeta->colRef = NULL;
49,797✔
670
  }
671

672
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
49,830!
673
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
482,056✔
674
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
432,226✔
675
    if (hasPK && (i > 0)) {
432,226✔
676
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
63,536✔
677
        ++pTableMeta->tableInfo.numOfPKs;
31,785✔
678
      } else {
679
        hasPK = false;
31,751✔
680
      }
681
    }
682
  }
683

684
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
49,830✔
685
         " sver:%d tver:%d"
686
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
687
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
688
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
689
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
690

691
  *pMeta = pTableMeta;
49,828✔
692
  return TSDB_CODE_SUCCESS;
49,828✔
693
}
694

695
int32_t queryCreateTableMetaExFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
×
696
  QUERY_PARAM_CHECK(msg);
×
697
  QUERY_PARAM_CHECK(pMeta);
×
698
  int32_t total = msg->numOfColumns + msg->numOfTags;
×
699
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
×
700
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
×
701
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs) ? sizeof(SColRef) * msg->numOfColRefs : 0;
×
702
  int32_t tbNameSize = strlen(msg->tbName) + 1;
×
703

704
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize + tbNameSize);
×
705
  if (NULL == pTableMeta) {
×
706
    qError("calloc size[%d] failed", metaSize);
×
707
    return terrno;
×
708
  }
709
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
×
710
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
×
711

712
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
×
713
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
×
714
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
×
715
  pTableMeta->suid = msg->suid;
×
716
  pTableMeta->sversion = msg->sversion;
×
717
  pTableMeta->tversion = msg->tversion;
×
718
  pTableMeta->rversion = msg->rversion;
×
719
  pTableMeta->virtualStb = msg->virtualStb;
×
720
  pTableMeta->numOfColRefs = msg->numOfColRefs;
×
721

722
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
×
723
  pTableMeta->tableInfo.precision = msg->precision;
×
724
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
×
725

726
  TAOS_MEMCPY(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
×
727
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
×
728
    pTableMeta->schemaExt = pSchemaExt;
×
729
    TAOS_MEMCPY(pSchemaExt, msg->pSchemaExt, schemaExtSize);
×
730
  } else {
731
    pTableMeta->schemaExt = NULL;
×
732
  }
733

734
  if (hasRefCol(msg->tableType) && msg->pColRefs) {
×
735
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
×
736
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
×
737
  } else {
738
    pTableMeta->colRef = NULL;
×
739
  }
740

741
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
×
742
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
×
743
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
×
744
    if (hasPK && (i > 0)) {
×
745
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
×
746
        ++pTableMeta->tableInfo.numOfPKs;
×
747
      } else {
748
        hasPK = false;
×
749
      }
750
    }
751
  }
752

753
  char *pTbName = (char *)pTableMeta + metaSize + schemaExtSize + pColRefSize;
×
754
  tstrncpy(pTbName, msg->tbName, tbNameSize);
×
755

756
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
×
757
         " sver:%d tver:%d"
758
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
759
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
760
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
761
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
762

763
  *pMeta = pTableMeta;
×
764
  return TSDB_CODE_SUCCESS;
×
765
}
766

767
int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) {
46,313✔
768
  int32_t       code = 0;
46,313✔
769
  STableMetaRsp metaRsp = {0};
46,313✔
770

771
  if (NULL == output || NULL == msg || msgSize <= 0) {
46,313!
772
    qError("queryProcessTableMetaRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
773
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
774
    goto PROCESS_META_OVER;
×
775
  }
776

777
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
46,315!
778
    code = TSDB_CODE_INVALID_MSG;
×
779
    goto PROCESS_META_OVER;
×
780
  }
781

782
  code = queryConvertTableMetaMsg(&metaRsp);
46,317✔
783
  if (code != TSDB_CODE_SUCCESS) {
46,312!
784
    goto PROCESS_META_OVER;
×
785
  }
786

787
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
46,312!
788
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
44,944!
789
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
790
    goto PROCESS_META_OVER;
×
791
  }
792

793
  STableMetaOutput *pOut = output;
46,314✔
794
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
46,314✔
795
  pOut->dbId = metaRsp.dbId;
46,314✔
796

797
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
46,314✔
798
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
33,587✔
799

800
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
33,587✔
801
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
33,587✔
802

803
    pOut->ctbMeta.vgId = metaRsp.vgId;
33,587✔
804
    pOut->ctbMeta.tableType = metaRsp.tableType;
33,587✔
805
    pOut->ctbMeta.uid = metaRsp.tuid;
33,587✔
806
    pOut->ctbMeta.suid = metaRsp.suid;
33,587✔
807

808
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
33,587✔
809
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
12,727✔
810
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
39✔
811

812
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
39✔
813
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
39✔
814

815
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
39✔
816
    if (TSDB_CODE_SUCCESS != code) {
39!
817
      goto PROCESS_META_OVER;
×
818
    }
819
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
39✔
820
  } else {
821
    SET_META_TYPE_TABLE(pOut->metaType);
12,688✔
822
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
12,688✔
823
    code = queryCreateTableMetaFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
12,688✔
824
  }
825

826
PROCESS_META_OVER:
46,317✔
827
  if (code != 0) {
46,317!
828
    qError("failed to process table meta rsp since %s", tstrerror(code));
×
829
  }
830

831
  tFreeSTableMetaRsp(&metaRsp);
46,317✔
832
  return code;
46,318✔
833
}
834

835
static int32_t queryProcessTableNameRsp(void *output, char *msg, int32_t msgSize) {
×
836
  int32_t       code = 0;
×
837
  STableMetaRsp metaRsp = {0};
×
838

839
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
840
    qError("queryProcessTableNameRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
841
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
842
    goto PROCESS_NAME_OVER;
×
843
  }
844

845
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
×
846
    code = TSDB_CODE_INVALID_MSG;
×
847
    goto PROCESS_NAME_OVER;
×
848
  }
849

850
  code = queryConvertTableMetaMsg(&metaRsp);
×
851
  if (code != TSDB_CODE_SUCCESS) {
×
852
    goto PROCESS_NAME_OVER;
×
853
  }
854

855
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
×
856
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
×
857
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
858
    goto PROCESS_NAME_OVER;
×
859
  }
860

861
  STableMetaOutput *pOut = output;
×
862
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
×
863
  pOut->dbId = metaRsp.dbId;
×
864

865
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
×
866
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
×
867

868
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
869
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
×
870

871
    pOut->ctbMeta.vgId = metaRsp.vgId;
×
872
    pOut->ctbMeta.tableType = metaRsp.tableType;
×
873
    pOut->ctbMeta.uid = metaRsp.tuid;
×
874
    pOut->ctbMeta.suid = metaRsp.suid;
×
875

876
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
×
877
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
×
878
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
879

880
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
881
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
×
882

883
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
×
884
    if (TSDB_CODE_SUCCESS != code) {
×
885
      goto PROCESS_NAME_OVER;
×
886
    }
887

888
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
×
889
  } else {
890
    SET_META_TYPE_TABLE(pOut->metaType);
×
891
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
892
    code = queryCreateTableMetaExFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
×
893
  }
894

895
PROCESS_NAME_OVER:
×
896
  if (code != 0) {
×
897
    qError("failed to process table name rsp since %s", tstrerror(code));
×
898
  }
899

900
  tFreeSTableMetaRsp(&metaRsp);
×
901
  return code;
×
902
}
903

904
int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) {
3✔
905
  SQnodeListRsp out = {0};
3✔
906
  int32_t       code = 0;
3✔
907

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

914
  out.qnodeList = (SArray *)output;
3✔
915
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
3!
916
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
×
917
    code = TSDB_CODE_INVALID_MSG;
×
918
    return code;
×
919
  }
920

921
  return code;
3✔
922
}
923

924
int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) {
14✔
925
  SDnodeListRsp out = {0};
14✔
926
  int32_t       code = 0;
14✔
927

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

934
  if (tDeserializeSDnodeListRsp(msg, msgSize, &out) != 0) {
14!
935
    qError("invalid dnode list rsp msg, msgSize:%d", msgSize);
×
936
    code = TSDB_CODE_INVALID_MSG;
×
937
    return code;
×
938
  }
939

940
  *(SArray **)output = out.dnodeList;
14✔
941

942
  return code;
14✔
943
}
944

945
int32_t queryProcessGetSerVerRsp(void *output, char *msg, int32_t msgSize) {
3✔
946
  SServerVerRsp out = {0};
3✔
947
  int32_t       code = 0;
3✔
948

949
  if (NULL == output || NULL == msg || msgSize <= 0) {
3!
950
    qError("queryProcessGetSerVerRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
951
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
952
    return code;
×
953
  }
954

955
  if (tDeserializeSServerVerRsp(msg, msgSize, &out) != 0) {
3!
956
    qError("invalid svr ver rsp msg, msgSize:%d", msgSize);
×
957
    code = TSDB_CODE_INVALID_MSG;
×
958
    return code;
×
959
  }
960

961
  *(char **)output = taosStrdup(out.ver);
3!
962
  if (NULL == *(char **)output) {
3!
963
    return terrno;
×
964
  }
965

966
  return code;
3✔
967
}
968

969
int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) {
1,930✔
970
  SDbCfgRsp out = {0};
1,930✔
971

972
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,930!
973
    qError("queryProcessGetDbCfgRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
974
    return TSDB_CODE_TSC_INVALID_INPUT;
×
975
  }
976

977
  if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) {
1,931✔
978
    qError("tDeserializeSDbCfgRsp failed, msgSize:%d, dbCfgRsp:%lu", msgSize, sizeof(out));
1!
979
    return TSDB_CODE_INVALID_MSG;
×
980
  }
981

982
  memcpy(output, &out, sizeof(out));
1,931✔
983

984
  return TSDB_CODE_SUCCESS;
1,931✔
985
}
986

987
int32_t queryProcessGetIndexRsp(void *output, char *msg, int32_t msgSize) {
×
988
  SUserIndexRsp out = {0};
×
989

990
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
991
    qError("queryProcessGetIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
992
    return TSDB_CODE_TSC_INVALID_INPUT;
×
993
  }
994

995
  if (tDeserializeSUserIndexRsp(msg, msgSize, &out) != 0) {
×
996
    qError("tDeserializeSUserIndexRsp failed, msgSize:%d", msgSize);
×
997
    return TSDB_CODE_INVALID_MSG;
×
998
  }
999

1000
  memcpy(output, &out, sizeof(out));
×
1001

1002
  return TSDB_CODE_SUCCESS;
×
1003
}
1004

1005
int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
11✔
1006
  SRetrieveFuncRsp out = {0};
11✔
1007

1008
  if (NULL == output || NULL == msg || msgSize <= 0) {
11!
1009
    qError("queryProcessRetrieveFuncRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1010
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1011
  }
1012

1013
  if (tDeserializeSRetrieveFuncRsp(msg, msgSize, &out) != 0) {
11!
1014
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
×
1015
    return TSDB_CODE_INVALID_MSG;
×
1016
  }
1017

1018
  if (1 != out.numOfFuncs) {
11!
1019
    qError("invalid func num returned, numOfFuncs:%d", out.numOfFuncs);
×
1020
    return TSDB_CODE_INVALID_MSG;
×
1021
  }
1022

1023
  SFuncInfo *funcInfo = taosArrayGet(out.pFuncInfos, 0);
11✔
1024

1025
  memcpy(output, funcInfo, sizeof(*funcInfo));
11✔
1026
  taosArrayDestroy(out.pFuncInfos);
11✔
1027
  taosArrayDestroy(out.pFuncExtraInfos);
11✔
1028

1029
  return TSDB_CODE_SUCCESS;
11✔
1030
}
1031

1032
int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) {
2,055✔
1033
  if (NULL == output || NULL == msg || msgSize <= 0) {
2,055!
1034
    qError("queryProcessGetUserAuthRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1035
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1036
  }
1037

1038
  if (tDeserializeSGetUserAuthRsp(msg, msgSize, (SGetUserAuthRsp *)output) != 0) {
2,056!
1039
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
1040
    return TSDB_CODE_INVALID_MSG;
×
1041
  }
1042

1043
  return TSDB_CODE_SUCCESS;
2,055✔
1044
}
1045

1046
int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
3✔
1047
  if (NULL == output || NULL == msg || msgSize <= 0) {
3!
1048
    qError("queryProcessGetTbIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1049
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1050
  }
1051

1052
  STableIndexRsp *out = (STableIndexRsp *)output;
3✔
1053
  if (tDeserializeSTableIndexRsp(msg, msgSize, out) != 0) {
3!
1054
    qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize);
×
1055
    return TSDB_CODE_INVALID_MSG;
×
1056
  }
1057

1058
  return TSDB_CODE_SUCCESS;
3✔
1059
}
1060

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

1067
  STableCfgRsp *out = taosMemoryCalloc(1, sizeof(STableCfgRsp));
83!
1068
  if(out == NULL) {
83!
1069
    return terrno;
×
1070
  }
1071
  if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
83!
1072
    qError("tDeserializeSTableCfgRsp failed, msgSize:%d", msgSize);
×
1073
    tFreeSTableCfgRsp(out);
×
1074
    taosMemoryFree(out);
×
1075
    return TSDB_CODE_INVALID_MSG;
×
1076
  }
1077

1078
  *(STableCfgRsp **)output = out;
83✔
1079

1080
  return TSDB_CODE_SUCCESS;
83✔
1081
}
1082

1083
int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) {
7✔
1084
  if (NULL == output || NULL == msg || msgSize <= 0) {
7!
1085
    qError("queryProcessGetViewMetaRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1086
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1087
  }
1088

1089
  SViewMetaRsp *out = taosMemoryCalloc(1, sizeof(SViewMetaRsp));
7!
1090
  if (out == NULL) {
7!
1091
    return terrno;
×
1092
  }
1093
  if (tDeserializeSViewMetaRsp(msg, msgSize, out) != 0) {
7!
1094
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1095
    tFreeSViewMetaRsp(out);
×
1096
    taosMemoryFree(out);
×
1097
    return TSDB_CODE_INVALID_MSG;
×
1098
  }
1099

1100
  qDebugL("view meta recved, dbFName:%s, view:%s, querySQL:%s", out->dbFName, out->name, out->querySql);
7!
1101

1102
  *(SViewMetaRsp **)output = out;
7✔
1103

1104
  return TSDB_CODE_SUCCESS;
7✔
1105
}
1106

1107
int32_t queryProcessGetTbTSMARsp(void* output, char* msg, int32_t msgSize) {
×
1108
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
1109
    qError("queryProcessGetTbTSMARsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1110
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1111
  }
1112

1113
  if (tDeserializeTableTSMAInfoRsp(msg, msgSize, output) != 0) {
×
1114
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1115
    return TSDB_CODE_INVALID_MSG;
×
1116
  }
1117

1118
  return TSDB_CODE_SUCCESS;
×
1119
}
1120

1121
int32_t queryProcessStreamProgressRsp(void* output, char* msg, int32_t msgSize) {
×
1122
  if (!output || !msg || msgSize <= 0) {
×
1123
    qError("queryProcessStreamProgressRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1124
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1125
  }
1126

1127
  if (tDeserializeSStreamProgressRsp(msg, msgSize, output) != 0) {
×
1128
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1129
    return TSDB_CODE_INVALID_MSG;
×
1130
  }
1131
  return TSDB_CODE_SUCCESS;
×
1132
}
1133

1134
int32_t queryProcessVSubTablesRsp(void* output, char* msg, int32_t msgSize) {
×
1135
  if (!output || !msg || msgSize <= 0) {
×
1136
    qError("queryProcessVSubTablesRsp input error, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1137
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1138
  }
1139

1140
  SVSubTablesRsp* pRsp = (SVSubTablesRsp*)output;
×
1141
  int32_t code = tDeserializeSVSubTablesRsp(msg, msgSize, pRsp);
×
1142
  if (code != 0) {
×
1143
    qError("tDeserializeSVSubTablesRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1144
    return code;
×
1145
  }
1146
  
1147
  return TSDB_CODE_SUCCESS;
×
1148
}
1149

1150
int32_t queryProcessVStbRefDbsRsp(void* output, char* msg, int32_t msgSize) {
140✔
1151
  if (!output || !msg || msgSize <= 0) {
140!
1152
    qError("queryProcessVStbRefDbsRsp input error, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1153
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1154
  }
1155

1156
  SVStbRefDbsRsp * pRsp = (SVStbRefDbsRsp*)output;
140✔
1157
  int32_t code = tDeserializeSVStbRefDbsRsp(msg, msgSize, pRsp);
140✔
1158
  if (code != 0) {
140!
1159
    qError("tDeserializeSVStbRefDbsRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1160
    return code;
×
1161
  }
1162

1163
  return TSDB_CODE_SUCCESS;
140✔
1164
}
1165

1166
void initQueryModuleMsgHandle() {
3,018✔
1167
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg;
3,018✔
1168
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryBuildTableMetaReqMsg;
3,018✔
1169
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;
3,018✔
1170
  queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg;
3,018✔
1171
  queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg;
3,018✔
1172
  queryBuildMsg[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryBuildDnodeListMsg;
3,018✔
1173
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg;
3,018✔
1174
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryBuildGetIndexMsg;
3,018✔
1175
  queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryBuildRetrieveFuncMsg;
3,018✔
1176
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryBuildGetUserAuthMsg;
3,018✔
1177
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryBuildGetTbIndexMsg;
3,018✔
1178
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
3,018✔
1179
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
3,018✔
1180
  queryBuildMsg[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryBuildGetSerVerMsg;
3,018✔
1181
  queryBuildMsg[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryBuildGetViewMetaMsg;
3,018✔
1182
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryBuildGetTableTSMAMsg;
3,018✔
1183
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryBuildGetTSMAMsg;
3,018✔
1184
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_STREAM_PROGRESS)] = queryBuildGetStreamProgressMsg;
3,018✔
1185
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryBuildVSubTablesMsg;
3,018✔
1186
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSTB_REF_DBS)] = queryBuildVStbRefDBsMsg;
3,018✔
1187

1188
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp;
3,018✔
1189
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryProcessTableNameRsp;
3,018✔
1190
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp;
3,018✔
1191
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp;
3,018✔
1192
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp;
3,018✔
1193
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryProcessDnodeListRsp;
3,018✔
1194
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp;
3,018✔
1195
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryProcessGetIndexRsp;
3,018✔
1196
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryProcessRetrieveFuncRsp;
3,018✔
1197
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryProcessGetUserAuthRsp;
3,018✔
1198
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryProcessGetTbIndexRsp;
3,018✔
1199
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
3,018✔
1200
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
3,018✔
1201
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp;
3,018✔
1202
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryProcessGetViewMetaRsp;
3,018✔
1203
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryProcessGetTbTSMARsp;
3,018✔
1204
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryProcessGetTbTSMARsp;
3,018✔
1205
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_STREAM_PROGRESS)] = queryProcessStreamProgressRsp;
3,018✔
1206
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryProcessVSubTablesRsp;
3,018✔
1207
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_VSTB_REF_DBS)] = queryProcessVStbRefDbsRsp;
3,018✔
1208
}
3,018✔
1209

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