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

taosdata / TDengine / #4106

19 May 2025 07:15AM UTC coverage: 62.857% (-0.2%) from 63.042%
#4106

push

travis-ci

GitHub
Merge pull request #31115 from taosdata/merge/mainto3.0

156749 of 318088 branches covered (49.28%)

Branch coverage included in aggregate %.

242535 of 317143 relevant lines covered (76.47%)

18746393.97 hits per line

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

48.62
/source/libs/qcom/src/querymsg.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "query.h"
17
#include "queryInt.h"
18
#include "systable.h"
19
#include "tmsg.h"
20
#include "trpc.h"
21

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

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

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

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

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

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

51
  if (usedbRsp->vgNum <= 0) {
156,506✔
52
    return TSDB_CODE_SUCCESS;
10,694✔
53
  }
54

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

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

71
  return TSDB_CODE_SUCCESS;
145,864✔
72
}
73

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

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

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

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

99
  *msg = pBuf;
208,186✔
100
  *msgLen = bufLen;
208,186✔
101

102
  return TSDB_CODE_SUCCESS;
208,186✔
103
}
104

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

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

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

127
  *msg = pBuf;
148,046✔
128
  *msgLen = bufLen;
148,046✔
129

130
  return TSDB_CODE_SUCCESS;
148,046✔
131
}
132

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

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

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

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

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

152
  return TSDB_CODE_SUCCESS;
11,885✔
153
}
154

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

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

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

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

173
  return TSDB_CODE_SUCCESS;
367✔
174
}
175

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

180
  SServerVerReq req = {0};
×
181

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

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

193
  return TSDB_CODE_SUCCESS;
×
194
}
195

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

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

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

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

215
  return TSDB_CODE_SUCCESS;
6,602✔
216
}
217

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

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

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

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

237
  return TSDB_CODE_SUCCESS;
×
238
}
239

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

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

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

270
  taosArrayDestroy(funcReq.pFuncNames);
96✔
271

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

275
  return TSDB_CODE_SUCCESS;
96✔
276
}
277

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

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

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

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

297
  return TSDB_CODE_SUCCESS;
22,509✔
298
}
299

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

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

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

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

319
  return TSDB_CODE_SUCCESS;
1,388✔
320
}
321

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

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

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

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

344
  return TSDB_CODE_SUCCESS;
279✔
345
}
346

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

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

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

363
  *msg = pBuf;
46,146✔
364
  *msgLen = bufLen;
46,146✔
365

366
  return TSDB_CODE_SUCCESS;
46,146✔
367
}
368

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

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

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

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

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

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

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

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

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

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

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

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

434

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

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

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

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

455
  return TSDB_CODE_SUCCESS;
24✔
456
}
457

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

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

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

475
  *msg = pBuf;
9,988✔
476
  *msgLen = bufLen;
9,988✔
477

478
  return TSDB_CODE_SUCCESS;
9,988✔
479
}
480

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

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

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

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

504
  qTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum);
147,283✔
505
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
463,936✔
506
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
316,653✔
507
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
316,653✔
508
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
640,795✔
509
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
324,142✔
510
    }
511
  }
512

513
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
147,283✔
514

515
PROCESS_USEDB_OVER:
147,283✔
516

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

525
  tFreeSUsedbRsp(&usedbRsp);
147,283✔
526
  return code;
147,283✔
527
}
528

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

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

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

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

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

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

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

568
  return TSDB_CODE_SUCCESS;
146,795✔
569
}
570

571
int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) {
194,975✔
572
  QUERY_PARAM_CHECK(msg);
194,975!
573
  QUERY_PARAM_CHECK(pMeta);
194,975!
574
  pMeta->vgId = msg->vgId;
194,975✔
575
  pMeta->tableType = msg->tableType;
194,975✔
576
  pMeta->uid = msg->tuid;
194,975✔
577
  pMeta->suid = msg->suid;
194,975✔
578

579
  qDebug("ctb:%s, uid:0x%" PRIx64 " meta returned, type:%d vgId:%d db:%s suid:%" PRIx64, msg->tbName, pMeta->uid,
194,975✔
580
         pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid);
581

582
  return TSDB_CODE_SUCCESS;
194,981✔
583
}
584

585
int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta) {
461✔
586
  QUERY_PARAM_CHECK(msg);
461!
587
  QUERY_PARAM_CHECK(pMeta);
461!
588
  QUERY_PARAM_CHECK(msg->pColRefs);
461!
589

590
  int32_t pColRefSize = sizeof(SColRef) * msg->numOfColRefs;
461✔
591

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

598
  pTableMeta->vgId = msg->vgId;
461✔
599
  pTableMeta->tableType = msg->tableType;
461✔
600
  pTableMeta->uid = msg->tuid;
461✔
601
  pTableMeta->suid = msg->suid;
461✔
602
  pTableMeta->numOfColRefs = msg->numOfColRefs;
461✔
603
  pTableMeta->rversion = msg->rversion;
461✔
604

605
  pTableMeta->colRef = (SColRef *)((char *)pTableMeta + sizeof(SVCTableMeta));
461✔
606
  memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
461✔
607

608
  qDebug("ctable %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s suid %" PRIx64, msg->tbName, (pTableMeta)->uid,
461!
609
         (pTableMeta)->tableType, (pTableMeta)->vgId, msg->dbFName, (pTableMeta)->suid);
610

611
  *pMeta = pTableMeta;
461✔
612
  return TSDB_CODE_SUCCESS;
461✔
613
}
614

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

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

631
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
173,993✔
632
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
173,993✔
633
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
173,993✔
634
  pTableMeta->suid = msg->suid;
173,993✔
635
  pTableMeta->sversion = msg->sversion;
173,993✔
636
  pTableMeta->tversion = msg->tversion;
173,993✔
637
  pTableMeta->rversion = msg->rversion;
173,993✔
638
  if (msg->virtualStb) {
173,993✔
639
    pTableMeta->virtualStb = 1;
221✔
640
    pTableMeta->numOfColRefs = 0;
221✔
641
  } else {
642
    if (msg->tableType == TSDB_VIRTUAL_CHILD_TABLE && isStb) {
173,772✔
643
      pTableMeta->virtualStb = 1;
286✔
644
      pTableMeta->numOfColRefs = 0;
286✔
645
    } else {
646
      pTableMeta->virtualStb = 0;
173,486✔
647
      pTableMeta->numOfColRefs = msg->numOfColRefs;
173,486✔
648
    }
649
  }
650

651
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
173,993✔
652
  pTableMeta->tableInfo.precision = msg->precision;
173,993✔
653
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
173,993✔
654

655
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
173,993✔
656
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
173,993!
657
    pTableMeta->schemaExt = pSchemaExt;
169,127✔
658
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
169,127✔
659
  } else {
660
    pTableMeta->schemaExt = NULL;
4,871✔
661
  }
662

663
  if (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) {
173,998!
664
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
680✔
665
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
680✔
666
  } else {
667
    pTableMeta->colRef = NULL;
173,318✔
668
  }
669

670
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
173,998✔
671
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
3,391,747✔
672
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
3,217,749✔
673
    if (hasPK && (i > 0)) {
3,217,749✔
674
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
109,008✔
675
        ++pTableMeta->tableInfo.numOfPKs;
54,522✔
676
      } else {
677
        hasPK = false;
54,486✔
678
      }
679
    }
680
  }
681

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

689
  *pMeta = pTableMeta;
173,992✔
690
  return TSDB_CODE_SUCCESS;
173,992✔
691
}
692

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

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

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

720
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
1,236✔
721
  pTableMeta->tableInfo.precision = msg->precision;
1,236✔
722
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
1,236✔
723

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

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

739
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
1,236!
740
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
4,014✔
741
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,778✔
742
    if (hasPK && (i > 0)) {
2,778!
743
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
×
744
        ++pTableMeta->tableInfo.numOfPKs;
×
745
      } else {
746
        hasPK = false;
×
747
      }
748
    }
749
  }
750

751
  char *pTbName = (char *)pTableMeta + metaSize + schemaExtSize + pColRefSize;
1,236✔
752
  tstrncpy(pTbName, msg->tbName, tbNameSize);
1,236✔
753

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

761
  *pMeta = pTableMeta;
1,236✔
762
  return TSDB_CODE_SUCCESS;
1,236✔
763
}
764

765
int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) {
145,562✔
766
  int32_t       code = 0;
145,562✔
767
  STableMetaRsp metaRsp = {0};
145,562✔
768

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

775
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
145,565!
776
    code = TSDB_CODE_INVALID_MSG;
×
777
    goto PROCESS_META_OVER;
×
778
  }
779

780
  code = queryConvertTableMetaMsg(&metaRsp);
145,562✔
781
  if (code != TSDB_CODE_SUCCESS) {
145,562!
782
    goto PROCESS_META_OVER;
×
783
  }
784

785
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
145,562!
786
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
141,661!
787
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
788
    goto PROCESS_META_OVER;
×
789
  }
790

791
  STableMetaOutput *pOut = output;
145,558✔
792
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
145,558✔
793
  pOut->dbId = metaRsp.dbId;
145,558✔
794

795
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
145,558✔
796
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
71,451✔
797

798
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
71,451✔
799
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
71,451✔
800

801
    pOut->ctbMeta.vgId = metaRsp.vgId;
71,451✔
802
    pOut->ctbMeta.tableType = metaRsp.tableType;
71,451✔
803
    pOut->ctbMeta.uid = metaRsp.tuid;
71,451✔
804
    pOut->ctbMeta.suid = metaRsp.suid;
71,451✔
805

806
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
71,451✔
807
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
74,107✔
808
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
286✔
809

810
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
286✔
811
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
286✔
812

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

824
PROCESS_META_OVER:
145,564✔
825
  if (code != 0) {
145,564!
826
    qError("failed to process table meta rsp since %s", tstrerror(code));
×
827
  }
828

829
  tFreeSTableMetaRsp(&metaRsp);
145,564✔
830
  return code;
145,564✔
831
}
832

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

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

843
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
1,236!
844
    code = TSDB_CODE_INVALID_MSG;
×
845
    goto PROCESS_NAME_OVER;
×
846
  }
847

848
  code = queryConvertTableMetaMsg(&metaRsp);
1,236✔
849
  if (code != TSDB_CODE_SUCCESS) {
1,236!
850
    goto PROCESS_NAME_OVER;
×
851
  }
852

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

859
  STableMetaOutput *pOut = output;
1,236✔
860
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
1,236✔
861
  pOut->dbId = metaRsp.dbId;
1,236✔
862

863
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
1,236✔
864
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
341✔
865

866
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
341✔
867
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
341✔
868

869
    pOut->ctbMeta.vgId = metaRsp.vgId;
341✔
870
    pOut->ctbMeta.tableType = metaRsp.tableType;
341✔
871
    pOut->ctbMeta.uid = metaRsp.tuid;
341✔
872
    pOut->ctbMeta.suid = metaRsp.suid;
341✔
873

874
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
341✔
875
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
895!
876
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
877

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

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

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

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

898
  tFreeSTableMetaRsp(&metaRsp);
1,236✔
899
  return code;
1,236✔
900
}
901

902
int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) {
11,885✔
903
  SQnodeListRsp out = {0};
11,885✔
904
  int32_t       code = 0;
11,885✔
905

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

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

919
  return code;
11,885✔
920
}
921

922
int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) {
367✔
923
  SDnodeListRsp out = {0};
367✔
924
  int32_t       code = 0;
367✔
925

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

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

938
  *(SArray **)output = out.dnodeList;
367✔
939

940
  return code;
367✔
941
}
942

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

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

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

959
  *(char **)output = taosStrdup(out.ver);
×
960
  if (NULL == *(char **)output) {
×
961
    return terrno;
×
962
  }
963

964
  return code;
×
965
}
966

967
int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) {
5,766✔
968
  SDbCfgRsp out = {0};
5,766✔
969

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

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

980
  memcpy(output, &out, sizeof(out));
5,766✔
981

982
  return TSDB_CODE_SUCCESS;
5,766✔
983
}
984

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

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

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

998
  memcpy(output, &out, sizeof(out));
×
999

1000
  return TSDB_CODE_SUCCESS;
×
1001
}
1002

1003
int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
86✔
1004
  SRetrieveFuncRsp out = {0};
86✔
1005

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

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

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

1021
  SFuncInfo *funcInfo = taosArrayGet(out.pFuncInfos, 0);
86✔
1022

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

1027
  return TSDB_CODE_SUCCESS;
86✔
1028
}
1029

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

1036
  if (tDeserializeSGetUserAuthRsp(msg, msgSize, (SGetUserAuthRsp *)output) != 0) {
22,497!
1037
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
1038
    return TSDB_CODE_INVALID_MSG;
×
1039
  }
1040

1041
  return TSDB_CODE_SUCCESS;
22,498✔
1042
}
1043

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

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

1056
  return TSDB_CODE_SUCCESS;
×
1057
}
1058

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

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

1076
  *(STableCfgRsp **)output = out;
279✔
1077

1078
  return TSDB_CODE_SUCCESS;
279✔
1079
}
1080

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

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

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

1100
  *(SViewMetaRsp **)output = out;
316✔
1101

1102
  return TSDB_CODE_SUCCESS;
316✔
1103
}
1104

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

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

1116
  return TSDB_CODE_SUCCESS;
1,028✔
1117
}
1118

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

1125
  if (tDeserializeSStreamProgressRsp(msg, msgSize, output) != 0) {
5,444!
1126
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1127
    return TSDB_CODE_INVALID_MSG;
×
1128
  }
1129
  return TSDB_CODE_SUCCESS;
5,443✔
1130
}
1131

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

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

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

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

1161
  return TSDB_CODE_SUCCESS;
9,986✔
1162
}
1163

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

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

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