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

taosdata / TDengine / #4541

19 Jul 2025 01:13AM UTC coverage: 56.753% (-1.6%) from 58.31%
#4541

push

travis-ci

web-flow
fix: subquery memleak (#32024)

124299 of 282344 branches covered (44.02%)

Branch coverage included in aggregate %.

181106 of 255787 relevant lines covered (70.8%)

24937406.43 hits per line

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

43.43
/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) {
144,224✔
33
  QUERY_PARAM_CHECK(pOut);
144,224!
34
  QUERY_PARAM_CHECK(usedbRsp);
144,224!
35
  memcpy(pOut->db, usedbRsp->db, TSDB_DB_FNAME_LEN);
144,224✔
36
  pOut->dbId = usedbRsp->uid;
144,224✔
37

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

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

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

53
  if (usedbRsp->vgNum <= 0) {
144,241✔
54
    return TSDB_CODE_SUCCESS;
9,500✔
55
  }
56

57
  pOut->dbVgroup->vgHash =
269,479✔
58
      taosHashInit(usedbRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
134,741✔
59
  if (NULL == pOut->dbVgroup->vgHash) {
134,739!
60
    return terrno;
×
61
  }
62

63
  for (int32_t i = 0; i < usedbRsp->vgNum; ++i) {
452,455✔
64
    SVgroupInfo *pVgInfo = taosArrayGet(usedbRsp->pVgroupInfos, i);
317,707✔
65
    pOut->dbVgroup->numOfTable += pVgInfo->numOfTable;
317,694✔
66
    qDebug("db:%s, vgId:%d, epNum:%d, current ep:%s:%u", usedbRsp->db, pVgInfo->vgId, pVgInfo->epSet.numOfEps,
317,694✔
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))) {
317,693✔
69
      return terrno;
4✔
70
    }
71
  }
72

73
  return TSDB_CODE_SUCCESS;
134,748✔
74
}
75

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

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

88
  if (pInput->dbFName) {
263,794✔
89
    tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
263,789✔
90
  }
91
  tstrncpy(infoReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
263,794✔
92

93
  int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
263,794✔
94
  void   *pBuf = (*mallcFp)(bufLen);
263,792✔
95
  if (NULL == pBuf) {
263,806!
96
    return terrno;
×
97
  }
98
  int32_t ret = tSerializeSTableInfoReq(pBuf, bufLen, &infoReq);
263,806✔
99
  if (ret < 0) return ret;
263,809!
100

101
  *msg = pBuf;
263,809✔
102
  *msgLen = bufLen;
263,809✔
103

104
  return TSDB_CODE_SUCCESS;
263,809✔
105
}
106

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

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

121
  int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
135,360✔
122
  void   *pBuf = (*mallcFp)(bufLen);
135,359✔
123
  if (NULL == pBuf) {
135,359!
124
    return terrno;
×
125
  }
126
  int32_t ret = tSerializeSUseDbReq(pBuf, bufLen, &usedbReq);
135,359✔
127
  if (ret < 0) return ret;
135,361!
128

129
  *msg = pBuf;
135,361✔
130
  *msgLen = bufLen;
135,361✔
131

132
  return TSDB_CODE_SUCCESS;
135,361✔
133
}
134

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

139
  SQnodeListReq qnodeListReq = {0};
12,377✔
140
  qnodeListReq.rowNum = -1;
12,377✔
141

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

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

151
  *msg = pBuf;
12,377✔
152
  *msgLen = bufLen;
12,377✔
153

154
  return TSDB_CODE_SUCCESS;
12,377✔
155
}
156

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

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

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

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

175
  return TSDB_CODE_SUCCESS;
350✔
176
}
177

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

182
  SServerVerReq req = {0};
×
183

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

192
  *msg = pBuf;
×
193
  *msgLen = bufLen;
×
194

195
  return TSDB_CODE_SUCCESS;
×
196
}
197

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

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

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

214
  *msg = pBuf;
6,145✔
215
  *msgLen = bufLen;
6,145✔
216

217
  return TSDB_CODE_SUCCESS;
6,145✔
218
}
219

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

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

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

236
  *msg = pBuf;
×
237
  *msgLen = bufLen;
×
238

239
  return TSDB_CODE_SUCCESS;
×
240
}
241

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

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

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

272
  taosArrayDestroy(funcReq.pFuncNames);
96✔
273

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

277
  return TSDB_CODE_SUCCESS;
96✔
278
}
279

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

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

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

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

299
  return TSDB_CODE_SUCCESS;
22,298✔
300
}
301

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

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

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

318
  *msg = pBuf;
×
319
  *msgLen = bufLen;
×
320

321
  return TSDB_CODE_SUCCESS;
×
322
}
323

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

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

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

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

346
  return TSDB_CODE_SUCCESS;
359✔
347
}
348

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

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

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

365
  *msg = pBuf;
53,426✔
366
  *msgLen = bufLen;
53,426✔
367

368
  return TSDB_CODE_SUCCESS;
53,426✔
369
}
370

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

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

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

388
  *msg = pBuf;
4✔
389
  *msgLen = bufLen;
4✔
390
  return TSDB_CODE_SUCCESS;
4✔
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)) {
3,128✔
461
  QUERY_PARAM_CHECK(input);
3,128!
462
  QUERY_PARAM_CHECK(msg);
3,128!
463
  QUERY_PARAM_CHECK(msgLen);
3,128!
464

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

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

477
  *msg = pBuf;
3,128✔
478
  *msgLen = bufLen;
3,128✔
479

480
  return TSDB_CODE_SUCCESS;
3,128✔
481
}
482

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

488
  if (NULL == output || NULL == msg || msgSize <= 0) {
135,017!
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) {
135,021✔
495
    qError("invalid use db rsp msg, msgSize:%d", msgSize);
3!
496
    code = TSDB_CODE_INVALID_MSG;
×
497
    goto PROCESS_USEDB_OVER;
×
498
  }
499

500
  if (usedbRsp.vgNum < 0) {
135,018!
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);
135,018✔
507
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
426,938✔
508
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
291,916✔
509
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
291,913✔
510
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
591,513✔
511
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
299,593✔
512
    }
513
  }
514

515
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
135,022✔
516

517
PROCESS_USEDB_OVER:
135,021✔
518

519
  if (code != 0) {
135,021!
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);
135,021✔
528
  return code;
135,020✔
529
}
530

531
static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) {
211,072✔
532
  QUERY_PARAM_CHECK(pMetaMsg);
211,072!
533
  if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) {
211,072!
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) {
211,076!
539
    qError("invalid numOfColumns[%d] in table meta rsp msg", pMetaMsg->numOfColumns);
1!
540
    return TSDB_CODE_TSC_INVALID_VALUE;
×
541
  }
542

543
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
211,075✔
544
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
38,380✔
545
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
404!
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) {
211,075!
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) {
211,075!
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) {
211,075!
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) {
211,075!
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;
211,075✔
571
}
572

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

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

584
  return TSDB_CODE_SUCCESS;
208,610✔
585
}
586

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

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

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

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

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

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

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

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

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

633
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
236,399✔
634
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
236,399✔
635
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
236,399✔
636
  pTableMeta->suid = msg->suid;
236,399✔
637
  pTableMeta->sversion = msg->sversion;
236,399✔
638
  pTableMeta->tversion = msg->tversion;
236,399✔
639
  pTableMeta->rversion = msg->rversion;
236,399✔
640
  if (msg->virtualStb) {
236,399✔
641
    pTableMeta->virtualStb = 1;
265✔
642
    pTableMeta->numOfColRefs = 0;
265✔
643
  } else {
644
    if (msg->tableType == TSDB_VIRTUAL_CHILD_TABLE && isStb) {
236,134✔
645
      pTableMeta->virtualStb = 1;
282✔
646
      pTableMeta->numOfColRefs = 0;
282✔
647
    } else {
648
      pTableMeta->virtualStb = 0;
235,852✔
649
      pTableMeta->numOfColRefs = msg->numOfColRefs;
235,852✔
650
    }
651
  }
652

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

657
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
236,399✔
658
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
236,399!
659
    pTableMeta->schemaExt = pSchemaExt;
231,907✔
660
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
231,907✔
661
  } else {
662
    pTableMeta->schemaExt = NULL;
4,498✔
663
  }
664

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

672
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
236,406✔
673
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
3,906,082✔
674
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
3,669,676✔
675
    if (hasPK && (i > 0)) {
3,669,676✔
676
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
127,538✔
677
        ++pTableMeta->tableInfo.numOfPKs;
63,770✔
678
      } else {
679
        hasPK = false;
63,768✔
680
      }
681
    }
682
  }
683

684
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
236,406✔
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;
236,405✔
692
  return TSDB_CODE_SUCCESS;
236,405✔
693
}
694

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

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

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

722
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
1,197✔
723
  pTableMeta->tableInfo.precision = msg->precision;
1,197✔
724
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
1,197✔
725

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

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

741
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
1,197!
742
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
3,883✔
743
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,686✔
744
    if (hasPK && (i > 0)) {
2,686!
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;
1,197✔
754
  tstrncpy(pTbName, msg->tbName, tbNameSize);
1,197✔
755

756
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
1,197!
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;
1,197✔
764
  return TSDB_CODE_SUCCESS;
1,197✔
765
}
766

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

771
  if (NULL == output || NULL == msg || msgSize <= 0) {
209,877!
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) {
209,877!
778
    code = TSDB_CODE_INVALID_MSG;
×
779
    goto PROCESS_META_OVER;
×
780
  }
781

782
  code = queryConvertTableMetaMsg(&metaRsp);
209,878✔
783
  if (code != TSDB_CODE_SUCCESS) {
209,875!
784
    goto PROCESS_META_OVER;
×
785
  }
786

787
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
209,875!
788
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
206,344!
789
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
790
    goto PROCESS_META_OVER;
×
791
  }
792

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

797
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
209,878✔
798
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
86,068✔
799

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

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

808
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
86,068✔
809
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
123,810✔
810
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
282✔
811

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

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

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

831
  tFreeSTableMetaRsp(&metaRsp);
209,881✔
832
  return code;
209,877✔
833
}
834

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

839
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,197!
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) {
1,197!
846
    code = TSDB_CODE_INVALID_MSG;
×
847
    goto PROCESS_NAME_OVER;
×
848
  }
849

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

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

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

865
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
1,197✔
866
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
323✔
867

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

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

876
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
323✔
877
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
874!
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);
874✔
891
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
874✔
892
    code = queryCreateTableMetaExFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
874✔
893
  }
894

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

900
  tFreeSTableMetaRsp(&metaRsp);
1,197✔
901
  return code;
1,197✔
902
}
903

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

908
  if (NULL == output || NULL == msg || msgSize <= 0) {
12,377!
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;
12,377✔
915
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
12,377!
916
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
×
917
    code = TSDB_CODE_INVALID_MSG;
×
918
    return code;
×
919
  }
920

921
  return code;
12,377✔
922
}
923

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

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

942
  return code;
350✔
943
}
944

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

949
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
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) {
×
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);
×
962
  if (NULL == *(char **)output) {
×
963
    return terrno;
×
964
  }
965

966
  return code;
×
967
}
968

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

972
  if (NULL == output || NULL == msg || msgSize <= 0) {
5,329!
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) {
5,329!
978
    qError("tDeserializeSDbCfgRsp failed, msgSize:%d, dbCfgRsp:%lu", msgSize, sizeof(out));
×
979
    return TSDB_CODE_INVALID_MSG;
×
980
  }
981

982
  memcpy(output, &out, sizeof(out));
5,329✔
983

984
  return TSDB_CODE_SUCCESS;
5,329✔
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) {
86✔
1006
  SRetrieveFuncRsp out = {0};
86✔
1007

1008
  if (NULL == output || NULL == msg || msgSize <= 0) {
86!
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) {
86!
1014
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
×
1015
    return TSDB_CODE_INVALID_MSG;
×
1016
  }
1017

1018
  if (1 != out.numOfFuncs) {
86!
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);
86✔
1024

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

1029
  return TSDB_CODE_SUCCESS;
86✔
1030
}
1031

1032
int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) {
22,285✔
1033
  if (NULL == output || NULL == msg || msgSize <= 0) {
22,285!
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) {
22,285!
1039
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
1040
    return TSDB_CODE_INVALID_MSG;
×
1041
  }
1042

1043
  return TSDB_CODE_SUCCESS;
22,285✔
1044
}
1045

1046
int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
×
1047
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
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;
×
1053
  if (tDeserializeSTableIndexRsp(msg, msgSize, out) != 0) {
×
1054
    qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize);
×
1055
    return TSDB_CODE_INVALID_MSG;
×
1056
  }
1057

1058
  return TSDB_CODE_SUCCESS;
×
1059
}
1060

1061
int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
359✔
1062
  if (NULL == output || NULL == msg || msgSize <= 0) {
359!
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));
359!
1068
  if(out == NULL) {
359!
1069
    return terrno;
×
1070
  }
1071
  if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
359!
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;
359✔
1079

1080
  return TSDB_CODE_SUCCESS;
359✔
1081
}
1082

1083
int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) {
318✔
1084
  if (NULL == output || NULL == msg || msgSize <= 0) {
318!
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));
318!
1090
  if (out == NULL) {
318!
1091
    return terrno;
×
1092
  }
1093
  if (tDeserializeSViewMetaRsp(msg, msgSize, out) != 0) {
318!
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);
318✔
1101

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

1104
  return TSDB_CODE_SUCCESS;
318✔
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) {
3,128✔
1151
  if (!output || !msg || msgSize <= 0) {
3,128!
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;
3,128✔
1157
  int32_t code = tDeserializeSVStbRefDbsRsp(msg, msgSize, pRsp);
3,128✔
1158
  if (code != 0) {
3,125!
1159
    qError("tDeserializeSVStbRefDbsRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1160
    return code;
×
1161
  }
1162

1163
  return TSDB_CODE_SUCCESS;
3,125✔
1164
}
1165

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

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