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

taosdata / TDengine / #4308

14 Jun 2025 02:06PM UTC coverage: 62.454% (-0.3%) from 62.777%
#4308

push

travis-ci

web-flow
fix: taosdump windows pthread_mutex_unlock crash(3.0) (#31357)

* fix: windows pthread_mutex_unlock crash

* enh: sync from main fix taosdump crash windows

* fix: restore .github action branch to main

153985 of 315105 branches covered (48.87%)

Branch coverage included in aggregate %.

238120 of 312727 relevant lines covered (76.14%)

6462519.65 hits per line

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

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

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

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

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

51
  if (usedbRsp->vgNum <= 0) {
154,433✔
52
    return TSDB_CODE_SUCCESS;
8,874✔
53
  }
54

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

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

71
  return TSDB_CODE_SUCCESS;
145,561✔
72
}
73

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

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

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

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

99
  *msg = pBuf;
149,281✔
100
  *msgLen = bufLen;
149,281✔
101

102
  return TSDB_CODE_SUCCESS;
149,281✔
103
}
104

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

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

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

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

130
  return TSDB_CODE_SUCCESS;
148,878✔
131
}
132

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

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

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

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

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

152
  return TSDB_CODE_SUCCESS;
11,641✔
153
}
154

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

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

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

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

173
  return TSDB_CODE_SUCCESS;
457✔
174
}
175

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

180
  SServerVerReq req = {0};
1✔
181

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

190
  *msg = pBuf;
1✔
191
  *msgLen = bufLen;
1✔
192

193
  return TSDB_CODE_SUCCESS;
1✔
194
}
195

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

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

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

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

215
  return TSDB_CODE_SUCCESS;
6,405✔
216
}
217

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

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

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

234
  *msg = pBuf;
1✔
235
  *msgLen = bufLen;
1✔
236

237
  return TSDB_CODE_SUCCESS;
1✔
238
}
239

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

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

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

270
  taosArrayDestroy(funcReq.pFuncNames);
1,296✔
271

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

275
  return TSDB_CODE_SUCCESS;
1,296✔
276
}
277

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

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

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

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

297
  return TSDB_CODE_SUCCESS;
22,170✔
298
}
299

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

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

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

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

319
  return TSDB_CODE_SUCCESS;
1,398✔
320
}
321

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

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

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

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

344
  return TSDB_CODE_SUCCESS;
260✔
345
}
346

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

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

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

363
  *msg = pBuf;
44,304✔
364
  *msgLen = bufLen;
44,304✔
365

366
  return TSDB_CODE_SUCCESS;
44,304✔
367
}
368

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

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

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

386
  *msg = pBuf;
1,112✔
387
  *msgLen = bufLen;
1,112✔
388
  return TSDB_CODE_SUCCESS;
1,112✔
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,466✔
416
  QUERY_PARAM_CHECK(input);
5,466!
417
  QUERY_PARAM_CHECK(msg);
5,466!
418
  QUERY_PARAM_CHECK(msgLen);
5,466!
419

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

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

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

434

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

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

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

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

455
  return TSDB_CODE_SUCCESS;
16✔
456
}
457

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

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

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

475
  *msg = pBuf;
10,028✔
476
  *msgLen = bufLen;
10,028✔
477

478
  return TSDB_CODE_SUCCESS;
10,028✔
479
}
480

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

486
  if (NULL == output || NULL == msg || msgSize <= 0) {
147,868!
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,868!
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,868!
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,868✔
505
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
488,143✔
506
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
340,275✔
507
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
340,275✔
508
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
743,072✔
509
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
402,797✔
510
    }
511
  }
512

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

515
PROCESS_USEDB_OVER:
147,868✔
516

517
  if (code != 0) {
147,868!
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,868✔
526
  return code;
147,868✔
527
}
528

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

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

541
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
88,296✔
542
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
37,354✔
543
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
286!
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) {
88,296!
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) {
88,296!
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) {
88,296!
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) {
88,296!
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;
88,296✔
569
}
570

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

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

582
  return TSDB_CODE_SUCCESS;
146,402✔
583
}
584

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

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

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

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

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

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

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

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

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

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

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

655
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
115,404✔
656
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
115,404✔
657
    pTableMeta->schemaExt = pSchemaExt;
111,695✔
658
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
111,695✔
659
  } else {
660
    pTableMeta->schemaExt = NULL;
3,709✔
661
  }
662

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

670
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
115,403!
671
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
3,623,544✔
672
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
3,508,141✔
673
    if (hasPK && (i > 0)) {
3,508,141✔
674
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
1,298✔
675
        ++pTableMeta->tableInfo.numOfPKs;
673✔
676
      } else {
677
        hasPK = false;
625✔
678
      }
679
    }
680
  }
681

682
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
115,403✔
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;
115,405✔
690
  return TSDB_CODE_SUCCESS;
115,405✔
691
}
692

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

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

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

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

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

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

739
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
1,227!
740
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
3,988✔
741
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,761✔
742
    if (hasPK && (i > 0)) {
2,761!
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,227✔
752
  tstrncpy(pTbName, msg->tbName, tbNameSize);
1,227✔
753

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

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

769
  if (NULL == output || NULL == msg || msgSize <= 0) {
87,070!
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) {
87,070!
776
    code = TSDB_CODE_INVALID_MSG;
×
777
    goto PROCESS_META_OVER;
×
778
  }
779

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

785
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
87,069!
786
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
84,150!
787
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
788
    goto PROCESS_META_OVER;
×
789
  }
790

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

795
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
87,069✔
796
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
15,604✔
797

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

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

806
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
15,604✔
807
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
71,465✔
808
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
164✔
809

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

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

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

829
  tFreeSTableMetaRsp(&metaRsp);
87,070✔
830
  return code;
87,070✔
831
}
832

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

837
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,227!
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,227!
844
    code = TSDB_CODE_INVALID_MSG;
×
845
    goto PROCESS_NAME_OVER;
×
846
  }
847

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

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

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

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

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

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

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

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

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

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

906
  if (NULL == output || NULL == msg || msgSize <= 0) {
11,641!
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,641✔
913
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
11,641!
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,641✔
920
}
921

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

926
  if (NULL == output || NULL == msg || msgSize <= 0) {
448!
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) {
448!
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;
448✔
939

940
  return code;
448✔
941
}
942

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

947
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
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) {
1!
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);
1!
960
  if (NULL == *(char **)output) {
1!
961
    return terrno;
×
962
  }
963

964
  return code;
1✔
965
}
966

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

970
  if (NULL == output || NULL == msg || msgSize <= 0) {
5,551!
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,551!
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,551✔
981

982
  return TSDB_CODE_SUCCESS;
5,551✔
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) {
1,265✔
1004
  SRetrieveFuncRsp out = {0};
1,265✔
1005

1006
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,265!
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) {
1,265!
1012
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
×
1013
    return TSDB_CODE_INVALID_MSG;
×
1014
  }
1015

1016
  if (1 != out.numOfFuncs) {
1,265!
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);
1,265✔
1022

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

1027
  return TSDB_CODE_SUCCESS;
1,265✔
1028
}
1029

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

1041
  return TSDB_CODE_SUCCESS;
22,136✔
1042
}
1043

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

1056
  return TSDB_CODE_SUCCESS;
1✔
1057
}
1058

1059
int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
260✔
1060
  if (NULL == output || NULL == msg || msgSize <= 0) {
260!
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));
260!
1066
  if(out == NULL) {
260!
1067
    return terrno;
×
1068
  }
1069
  if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
260!
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;
260✔
1077

1078
  return TSDB_CODE_SUCCESS;
260✔
1079
}
1080

1081
int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) {
334✔
1082
  if (NULL == output || NULL == msg || msgSize <= 0) {
334!
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));
334!
1088
  if (out == NULL) {
334!
1089
    return terrno;
×
1090
  }
1091
  if (tDeserializeSViewMetaRsp(msg, msgSize, out) != 0) {
334!
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);
334✔
1099

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

1102
  return TSDB_CODE_SUCCESS;
334✔
1103
}
1104

1105
int32_t queryProcessGetTbTSMARsp(void* output, char* msg, int32_t msgSize) {
1,027✔
1106
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,027!
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,027!
1112
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1113
    return TSDB_CODE_INVALID_MSG;
×
1114
  }
1115

1116
  return TSDB_CODE_SUCCESS;
1,027✔
1117
}
1118

1119
int32_t queryProcessStreamProgressRsp(void* output, char* msg, int32_t msgSize) {
5,466✔
1120
  if (!output || !msg || msgSize <= 0) {
5,466!
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,466!
1126
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1127
    return TSDB_CODE_INVALID_MSG;
×
1128
  }
1129
  return TSDB_CODE_SUCCESS;
5,466✔
1130
}
1131

1132
int32_t queryProcessVSubTablesRsp(void* output, char* msg, int32_t msgSize) {
16✔
1133
  if (!output || !msg || msgSize <= 0) {
16!
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;
16✔
1139
  int32_t code = tDeserializeSVSubTablesRsp(msg, msgSize, pRsp);
16✔
1140
  if (code != 0) {
16!
1141
    qError("tDeserializeSVSubTablesRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1142
    return code;
×
1143
  }
1144
  
1145
  return TSDB_CODE_SUCCESS;
16✔
1146
}
1147

1148
int32_t queryProcessVStbRefDbsRsp(void* output, char* msg, int32_t msgSize) {
10,027✔
1149
  if (!output || !msg || msgSize <= 0) {
10,027!
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;
10,027✔
1155
  int32_t code = tDeserializeSVStbRefDbsRsp(msg, msgSize, pRsp);
10,027✔
1156
  if (code != 0) {
10,025!
1157
    qError("tDeserializeSVStbRefDbsRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1158
    return code;
×
1159
  }
1160

1161
  return TSDB_CODE_SUCCESS;
10,025✔
1162
}
1163

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

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