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

taosdata / TDengine / #3843

08 Apr 2025 10:23AM UTC coverage: 63.077% (+0.4%) from 62.696%
#3843

push

travis-ci

web-flow
fix: clear cache when meta abort (#30674)

155571 of 315083 branches covered (49.37%)

Branch coverage included in aggregate %.

241876 of 315013 relevant lines covered (76.78%)

19243431.01 hits per line

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

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

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

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

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

51
  if (usedbRsp->vgNum <= 0) {
146,867✔
52
    return TSDB_CODE_SUCCESS;
10,534✔
53
  }
54

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

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

71
  return TSDB_CODE_SUCCESS;
136,334✔
72
}
73

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

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

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

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

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

102
  return TSDB_CODE_SUCCESS;
208,153✔
103
}
104

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

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

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

127
  *msg = pBuf;
138,966✔
128
  *msgLen = bufLen;
138,966✔
129

130
  return TSDB_CODE_SUCCESS;
138,966✔
131
}
132

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

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

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

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

149
  *msg = pBuf;
10,431✔
150
  *msgLen = bufLen;
10,431✔
151

152
  return TSDB_CODE_SUCCESS;
10,431✔
153
}
154

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

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

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

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

173
  return TSDB_CODE_SUCCESS;
347✔
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)) {
4,230✔
197
  QUERY_PARAM_CHECK(input);
4,230!
198
  QUERY_PARAM_CHECK(msg);
4,230!
199
  QUERY_PARAM_CHECK(msgLen);
4,230!
200

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

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

212
  *msg = pBuf;
4,230✔
213
  *msgLen = bufLen;
4,230✔
214

215
  return TSDB_CODE_SUCCESS;
4,230✔
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,
83✔
241
                                  void *(*mallcFp)(int64_t)) {
242
  QUERY_PARAM_CHECK(input);
83!
243
  QUERY_PARAM_CHECK(msg);
83!
244
  QUERY_PARAM_CHECK(msgLen);
83!
245

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

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

270
  taosArrayDestroy(funcReq.pFuncNames);
83✔
271

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

275
  return TSDB_CODE_SUCCESS;
83✔
276
}
277

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

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

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

294
  *msg = pBuf;
20,726✔
295
  *msgLen = bufLen;
20,726✔
296

297
  return TSDB_CODE_SUCCESS;
20,726✔
298
}
299

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

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

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

316
  *msg = pBuf;
7,805✔
317
  *msgLen = bufLen;
7,805✔
318

319
  return TSDB_CODE_SUCCESS;
7,805✔
320
}
321

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

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

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

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

344
  return TSDB_CODE_SUCCESS;
234✔
345
}
346

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

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

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

363
  *msg = pBuf;
40,808✔
364
  *msgLen = bufLen;
40,808✔
365

366
  return TSDB_CODE_SUCCESS;
40,808✔
367
}
368

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

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

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

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

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

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

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

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

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

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

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

429
  *msg = pBuf;
6,862✔
430
  *msgLen = len;
6,862✔
431
  return TSDB_CODE_SUCCESS;
6,862✔
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)) {
5,066✔
459
  QUERY_PARAM_CHECK(input);
5,066!
460
  QUERY_PARAM_CHECK(msg);
5,066!
461
  QUERY_PARAM_CHECK(msgLen);
5,066!
462

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

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

475
  *msg = pBuf;
5,066✔
476
  *msgLen = bufLen;
5,066✔
477

478
  return TSDB_CODE_SUCCESS;
5,066✔
479
}
480

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

486
  if (NULL == output || NULL == msg || msgSize <= 0) {
138,355!
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) {
138,355!
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) {
138,355!
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);
138,355✔
505
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
459,979✔
506
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
321,624✔
507
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
321,624✔
508
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
703,007✔
509
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
381,383✔
510
    }
511
  }
512

513
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
138,355✔
514

515
PROCESS_USEDB_OVER:
138,355✔
516

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

529
static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) {
165,312✔
530
  QUERY_PARAM_CHECK(pMetaMsg);
165,312!
531
  if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) {
165,312!
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) {
165,312!
537
    qError("invalid numOfColumns[%d] in table meta rsp msg", pMetaMsg->numOfColumns);
1!
538
    return TSDB_CODE_TSC_INVALID_VALUE;
×
539
  }
540

541
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
165,311✔
542
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
36,813✔
543
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
163!
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) {
165,311!
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) {
165,311!
554
    qError("invalid tversion[%d] in table meta rsp msg", pMetaMsg->tversion);
×
555
    return TSDB_CODE_TSC_INVALID_VALUE;
×
556
  }
557

558
  if (pMetaMsg->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
165,311!
559
    qError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", pMetaMsg->pSchemas[0].colId);
×
560
    return TSDB_CODE_TSC_INVALID_VALUE;
×
561
  }
562

563
  return TSDB_CODE_SUCCESS;
165,311✔
564
}
565

566
int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) {
135,571✔
567
  QUERY_PARAM_CHECK(msg);
135,571!
568
  QUERY_PARAM_CHECK(pMeta);
135,571!
569
  pMeta->vgId = msg->vgId;
135,571✔
570
  pMeta->tableType = msg->tableType;
135,571✔
571
  pMeta->uid = msg->tuid;
135,571✔
572
  pMeta->suid = msg->suid;
135,571✔
573

574
  qDebug("ctb:%s, uid:0x%" PRIx64 " meta returned, type:%d vgId:%d db:%s suid:%" PRIx64, msg->tbName, pMeta->uid,
135,571✔
575
         pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid);
576

577
  return TSDB_CODE_SUCCESS;
135,569✔
578
}
579

580
int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta) {
273✔
581
  QUERY_PARAM_CHECK(msg);
273!
582
  QUERY_PARAM_CHECK(pMeta);
273!
583
  QUERY_PARAM_CHECK(msg->pColRefs);
273!
584

585
  int32_t pColRefSize = sizeof(SColRef) * msg->numOfColRefs;
273✔
586

587
  SVCTableMeta *pTableMeta = taosMemoryCalloc(1, sizeof(SVCTableMeta) + pColRefSize);
273!
588
  if (NULL == pTableMeta) {
273!
589
    qError("calloc size[%d] failed", (int32_t)sizeof(SVCTableMeta) + pColRefSize);
×
590
    return terrno;
×
591
  }
592

593
  pTableMeta->vgId = msg->vgId;
273✔
594
  pTableMeta->tableType = msg->tableType;
273✔
595
  pTableMeta->uid = msg->tuid;
273✔
596
  pTableMeta->suid = msg->suid;
273✔
597
  pTableMeta->numOfColRefs = msg->numOfColRefs;
273✔
598

599
  pTableMeta->colRef = (SColRef *)((char *)pTableMeta + sizeof(SVCTableMeta));
273✔
600
  memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
273✔
601

602
  qDebug("ctable %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s suid %" PRIx64, msg->tbName, (pTableMeta)->uid,
273!
603
         (pTableMeta)->tableType, (pTableMeta)->vgId, msg->dbFName, (pTableMeta)->suid);
604

605
  *pMeta = pTableMeta;
273✔
606
  return TSDB_CODE_SUCCESS;
273✔
607
}
608

609
int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
187,891✔
610
  QUERY_PARAM_CHECK(msg);
187,891!
611
  QUERY_PARAM_CHECK(pMeta);
187,891!
612
  int32_t total = msg->numOfColumns + msg->numOfTags;
187,891✔
613
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
187,891✔
614
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
187,891✔
615
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) ? sizeof(SColRef) * msg->numOfColRefs : 0;
187,893!
616

617
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize);
187,892!
618
  if (NULL == pTableMeta) {
187,893!
619
    qError("calloc size[%d] failed", metaSize);
×
620
    return terrno;
×
621
  }
622
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
187,893✔
623
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
187,893✔
624

625
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
187,893✔
626
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
187,893✔
627
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
187,893✔
628
  pTableMeta->suid = msg->suid;
187,893✔
629
  pTableMeta->sversion = msg->sversion;
187,893✔
630
  pTableMeta->tversion = msg->tversion;
187,893✔
631
  pTableMeta->virtualStb = msg->virtualStb;
187,893✔
632
  pTableMeta->numOfColRefs = msg->numOfColRefs;
187,893✔
633

634
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
187,893✔
635
  pTableMeta->tableInfo.precision = msg->precision;
187,893✔
636
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
187,893✔
637

638
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
187,893✔
639
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
187,893✔
640
    pTableMeta->schemaExt = pSchemaExt;
183,911✔
641
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
183,911✔
642
  } else {
643
    pTableMeta->schemaExt = NULL;
3,986✔
644
  }
645

646
  if (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) {
187,897!
647
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
615✔
648
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
615✔
649
  } else {
650
    pTableMeta->colRef = NULL;
187,281✔
651
  }
652

653
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
187,896✔
654
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
3,185,277✔
655
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,997,381✔
656
    if (hasPK && (i > 0)) {
2,997,381✔
657
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
168,537✔
658
        ++pTableMeta->tableInfo.numOfPKs;
84,287✔
659
      } else {
660
        hasPK = false;
84,250✔
661
      }
662
    }
663
  }
664

665
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
187,896✔
666
         " sver:%d tver:%d"
667
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
668
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
669
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
670
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
671

672
  *pMeta = pTableMeta;
187,895✔
673
  return TSDB_CODE_SUCCESS;
187,895✔
674
}
675

676
int32_t queryCreateTableMetaExFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
1,236✔
677
  QUERY_PARAM_CHECK(msg);
1,236!
678
  QUERY_PARAM_CHECK(pMeta);
1,236!
679
  int32_t total = msg->numOfColumns + msg->numOfTags;
1,236✔
680
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
1,236✔
681
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
1,236!
682
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs) ? sizeof(SColRef) * msg->numOfColRefs : 0;
1,236!
683
  int32_t tbNameSize = strlen(msg->tbName) + 1;
1,236✔
684

685
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize + tbNameSize);
1,236!
686
  if (NULL == pTableMeta) {
1,236!
687
    qError("calloc size[%d] failed", metaSize);
×
688
    return terrno;
×
689
  }
690
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
1,236✔
691
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
1,236✔
692

693
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
1,236✔
694
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
1,236✔
695
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
1,236✔
696
  pTableMeta->suid = msg->suid;
1,236✔
697
  pTableMeta->sversion = msg->sversion;
1,236✔
698
  pTableMeta->tversion = msg->tversion;
1,236✔
699
  pTableMeta->virtualStb = msg->virtualStb;
1,236✔
700
  pTableMeta->numOfColRefs = msg->numOfColRefs;
1,236✔
701

702
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
1,236✔
703
  pTableMeta->tableInfo.precision = msg->precision;
1,236✔
704
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
1,236✔
705

706
  TAOS_MEMCPY(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
1,236✔
707
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
1,236!
708
    pTableMeta->schemaExt = pSchemaExt;
1,236✔
709
    TAOS_MEMCPY(pSchemaExt, msg->pSchemaExt, schemaExtSize);
1,236✔
710
  } else {
711
    pTableMeta->schemaExt = NULL;
×
712
  }
713

714
  if (hasRefCol(msg->tableType) && msg->pColRefs) {
1,236!
715
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
×
716
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
×
717
  } else {
718
    pTableMeta->colRef = NULL;
1,236✔
719
  }
720

721
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
1,236!
722
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
4,006✔
723
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,770✔
724
    if (hasPK && (i > 0)) {
2,770!
725
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
×
726
        ++pTableMeta->tableInfo.numOfPKs;
×
727
      } else {
728
        hasPK = false;
×
729
      }
730
    }
731
  }
732

733
  char *pTbName = (char *)pTableMeta + metaSize + schemaExtSize + pColRefSize;
1,236✔
734
  tstrncpy(pTbName, msg->tbName, tbNameSize);
1,236✔
735

736
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
1,236!
737
         " sver:%d tver:%d"
738
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
739
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
740
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
741
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
742

743
  *pMeta = pTableMeta;
1,236✔
744
  return TSDB_CODE_SUCCESS;
1,236✔
745
}
746

747
int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) {
164,075✔
748
  int32_t       code = 0;
164,075✔
749
  STableMetaRsp metaRsp = {0};
164,075✔
750

751
  if (NULL == output || NULL == msg || msgSize <= 0) {
164,075!
752
    qError("queryProcessTableMetaRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
753
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
754
    goto PROCESS_META_OVER;
×
755
  }
756

757
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
164,076!
758
    code = TSDB_CODE_INVALID_MSG;
×
759
    goto PROCESS_META_OVER;
×
760
  }
761

762
  code = queryConvertTableMetaMsg(&metaRsp);
164,079✔
763
  if (code != TSDB_CODE_SUCCESS) {
164,073!
764
    goto PROCESS_META_OVER;
×
765
  }
766

767
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
164,073!
768
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
160,809!
769
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
770
    goto PROCESS_META_OVER;
×
771
  }
772

773
  STableMetaOutput *pOut = output;
164,074✔
774
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
164,074✔
775
  pOut->dbId = metaRsp.dbId;
164,074✔
776

777
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
164,074✔
778
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
98,849✔
779

780
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
98,849✔
781
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
98,849✔
782

783
    pOut->ctbMeta.vgId = metaRsp.vgId;
98,849✔
784
    pOut->ctbMeta.tableType = metaRsp.tableType;
98,849✔
785
    pOut->ctbMeta.uid = metaRsp.tuid;
98,849✔
786
    pOut->ctbMeta.suid = metaRsp.suid;
98,849✔
787

788
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
98,849✔
789
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
65,225✔
790
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
104✔
791

792
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
104✔
793
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
104✔
794

795
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
104✔
796
    if (TSDB_CODE_SUCCESS != code) {
104!
797
      goto PROCESS_META_OVER;
×
798
    }
799
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
104✔
800
  } else {
801
    SET_META_TYPE_TABLE(pOut->metaType);
65,121✔
802
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
65,121✔
803
    code = queryCreateTableMetaFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
65,121✔
804
  }
805

806
PROCESS_META_OVER:
164,079✔
807
  if (code != 0) {
164,079!
808
    qError("failed to process table meta rsp since %s", tstrerror(code));
×
809
  }
810

811
  tFreeSTableMetaRsp(&metaRsp);
164,079✔
812
  return code;
164,080✔
813
}
814

815
static int32_t queryProcessTableNameRsp(void *output, char *msg, int32_t msgSize) {
1,236✔
816
  int32_t       code = 0;
1,236✔
817
  STableMetaRsp metaRsp = {0};
1,236✔
818

819
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,236!
820
    qError("queryProcessTableNameRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
821
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
822
    goto PROCESS_NAME_OVER;
×
823
  }
824

825
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
1,236!
826
    code = TSDB_CODE_INVALID_MSG;
×
827
    goto PROCESS_NAME_OVER;
×
828
  }
829

830
  code = queryConvertTableMetaMsg(&metaRsp);
1,236✔
831
  if (code != TSDB_CODE_SUCCESS) {
1,236!
832
    goto PROCESS_NAME_OVER;
×
833
  }
834

835
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
1,236!
836
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
1,236!
837
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
838
    goto PROCESS_NAME_OVER;
×
839
  }
840

841
  STableMetaOutput *pOut = output;
1,236✔
842
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
1,236✔
843
  pOut->dbId = metaRsp.dbId;
1,236✔
844

845
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
1,236✔
846
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
347✔
847

848
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
347✔
849
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
347✔
850

851
    pOut->ctbMeta.vgId = metaRsp.vgId;
347✔
852
    pOut->ctbMeta.tableType = metaRsp.tableType;
347✔
853
    pOut->ctbMeta.uid = metaRsp.tuid;
347✔
854
    pOut->ctbMeta.suid = metaRsp.suid;
347✔
855

856
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
347✔
857
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
889!
858
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
859

860
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
861
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
×
862

863
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
×
864
    if (TSDB_CODE_SUCCESS != code) {
×
865
      goto PROCESS_NAME_OVER;
×
866
    }
867

868
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
×
869
  } else {
870
    SET_META_TYPE_TABLE(pOut->metaType);
889✔
871
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
889✔
872
    code = queryCreateTableMetaExFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
889✔
873
  }
874

875
PROCESS_NAME_OVER:
1,236✔
876
  if (code != 0) {
1,236!
877
    qError("failed to process table name rsp since %s", tstrerror(code));
×
878
  }
879

880
  tFreeSTableMetaRsp(&metaRsp);
1,236✔
881
  return code;
1,236✔
882
}
883

884
int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) {
10,431✔
885
  SQnodeListRsp out = {0};
10,431✔
886
  int32_t       code = 0;
10,431✔
887

888
  if (NULL == output || NULL == msg || msgSize <= 0) {
10,431!
889
    qError("queryProcessQnodeListRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
890
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
891
    return code;
×
892
  }
893

894
  out.qnodeList = (SArray *)output;
10,431✔
895
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
10,431!
896
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
×
897
    code = TSDB_CODE_INVALID_MSG;
×
898
    return code;
×
899
  }
900

901
  return code;
10,431✔
902
}
903

904
int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) {
347✔
905
  SDnodeListRsp out = {0};
347✔
906
  int32_t       code = 0;
347✔
907

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

914
  if (tDeserializeSDnodeListRsp(msg, msgSize, &out) != 0) {
347!
915
    qError("invalid dnode list rsp msg, msgSize:%d", msgSize);
×
916
    code = TSDB_CODE_INVALID_MSG;
×
917
    return code;
×
918
  }
919

920
  *(SArray **)output = out.dnodeList;
347✔
921

922
  return code;
347✔
923
}
924

925
int32_t queryProcessGetSerVerRsp(void *output, char *msg, int32_t msgSize) {
1✔
926
  SServerVerRsp out = {0};
1✔
927
  int32_t       code = 0;
1✔
928

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

935
  if (tDeserializeSServerVerRsp(msg, msgSize, &out) != 0) {
1!
936
    qError("invalid svr ver rsp msg, msgSize:%d", msgSize);
×
937
    code = TSDB_CODE_INVALID_MSG;
×
938
    return code;
×
939
  }
940

941
  *(char **)output = taosStrdup(out.ver);
1!
942
  if (NULL == *(char **)output) {
1!
943
    return terrno;
×
944
  }
945

946
  return code;
1✔
947
}
948

949
int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) {
4,181✔
950
  SDbCfgRsp out = {0};
4,181✔
951

952
  if (NULL == output || NULL == msg || msgSize <= 0) {
4,181!
953
    qError("queryProcessGetDbCfgRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
954
    return TSDB_CODE_TSC_INVALID_INPUT;
×
955
  }
956

957
  if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) {
4,181!
958
    qError("tDeserializeSDbCfgRsp failed, msgSize:%d, dbCfgRsp:%lu", msgSize, sizeof(out));
×
959
    return TSDB_CODE_INVALID_MSG;
×
960
  }
961

962
  memcpy(output, &out, sizeof(out));
4,181✔
963

964
  return TSDB_CODE_SUCCESS;
4,181✔
965
}
966

967
int32_t queryProcessGetIndexRsp(void *output, char *msg, int32_t msgSize) {
×
968
  SUserIndexRsp out = {0};
×
969

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

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

980
  memcpy(output, &out, sizeof(out));
×
981

982
  return TSDB_CODE_SUCCESS;
×
983
}
984

985
int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
73✔
986
  SRetrieveFuncRsp out = {0};
73✔
987

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

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

998
  if (1 != out.numOfFuncs) {
73!
999
    qError("invalid func num returned, numOfFuncs:%d", out.numOfFuncs);
×
1000
    return TSDB_CODE_INVALID_MSG;
×
1001
  }
1002

1003
  SFuncInfo *funcInfo = taosArrayGet(out.pFuncInfos, 0);
73✔
1004

1005
  memcpy(output, funcInfo, sizeof(*funcInfo));
73✔
1006
  taosArrayDestroy(out.pFuncInfos);
73✔
1007
  taosArrayDestroy(out.pFuncExtraInfos);
73✔
1008

1009
  return TSDB_CODE_SUCCESS;
73✔
1010
}
1011

1012
int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) {
20,719✔
1013
  if (NULL == output || NULL == msg || msgSize <= 0) {
20,719!
1014
    qError("queryProcessGetUserAuthRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1015
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1016
  }
1017

1018
  if (tDeserializeSGetUserAuthRsp(msg, msgSize, (SGetUserAuthRsp *)output) != 0) {
20,723!
1019
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
1020
    return TSDB_CODE_INVALID_MSG;
×
1021
  }
1022

1023
  return TSDB_CODE_SUCCESS;
20,723✔
1024
}
1025

1026
int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
1✔
1027
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
1028
    qError("queryProcessGetTbIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1029
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1030
  }
1031

1032
  STableIndexRsp *out = (STableIndexRsp *)output;
1✔
1033
  if (tDeserializeSTableIndexRsp(msg, msgSize, out) != 0) {
1!
1034
    qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize);
×
1035
    return TSDB_CODE_INVALID_MSG;
×
1036
  }
1037

1038
  return TSDB_CODE_SUCCESS;
1✔
1039
}
1040

1041
int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
234✔
1042
  if (NULL == output || NULL == msg || msgSize <= 0) {
234!
1043
    qError("queryProcessGetTbCfgRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1044
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1045
  }
1046

1047
  STableCfgRsp *out = taosMemoryCalloc(1, sizeof(STableCfgRsp));
234!
1048
  if(out == NULL) {
234!
1049
    return terrno;
×
1050
  }
1051
  if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
234!
1052
    qError("tDeserializeSTableCfgRsp failed, msgSize:%d", msgSize);
×
1053
    tFreeSTableCfgRsp(out);
×
1054
    taosMemoryFree(out);
×
1055
    return TSDB_CODE_INVALID_MSG;
×
1056
  }
1057

1058
  *(STableCfgRsp **)output = out;
234✔
1059

1060
  return TSDB_CODE_SUCCESS;
234✔
1061
}
1062

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

1069
  SViewMetaRsp *out = taosMemoryCalloc(1, sizeof(SViewMetaRsp));
312!
1070
  if (out == NULL) {
312!
1071
    return terrno;
×
1072
  }
1073
  if (tDeserializeSViewMetaRsp(msg, msgSize, out) != 0) {
312!
1074
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1075
    tFreeSViewMetaRsp(out);
×
1076
    taosMemoryFree(out);
×
1077
    return TSDB_CODE_INVALID_MSG;
×
1078
  }
1079

1080
  qDebugL("view meta recved, dbFName:%s, view:%s, querySQL:%s", out->dbFName, out->name, out->querySql);
312✔
1081

1082
  *(SViewMetaRsp **)output = out;
312✔
1083

1084
  return TSDB_CODE_SUCCESS;
312✔
1085
}
1086

1087
int32_t queryProcessGetTbTSMARsp(void* output, char* msg, int32_t msgSize) {
1,254✔
1088
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,254!
1089
    qError("queryProcessGetTbTSMARsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1090
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1091
  }
1092

1093
  if (tDeserializeTableTSMAInfoRsp(msg, msgSize, output) != 0) {
1,254!
1094
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1095
    return TSDB_CODE_INVALID_MSG;
×
1096
  }
1097

1098
  return TSDB_CODE_SUCCESS;
1,254✔
1099
}
1100

1101
int32_t queryProcessStreamProgressRsp(void* output, char* msg, int32_t msgSize) {
6,862✔
1102
  if (!output || !msg || msgSize <= 0) {
6,862!
1103
    qError("queryProcessStreamProgressRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1104
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1105
  }
1106

1107
  if (tDeserializeSStreamProgressRsp(msg, msgSize, output) != 0) {
6,862!
1108
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1109
    return TSDB_CODE_INVALID_MSG;
×
1110
  }
1111
  return TSDB_CODE_SUCCESS;
6,861✔
1112
}
1113

1114
int32_t queryProcessVSubTablesRsp(void* output, char* msg, int32_t msgSize) {
24✔
1115
  if (!output || !msg || msgSize <= 0) {
24!
1116
    qError("queryProcessVSubTablesRsp input error, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1117
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1118
  }
1119

1120
  SVSubTablesRsp* pRsp = (SVSubTablesRsp*)output;
24✔
1121
  int32_t code = tDeserializeSVSubTablesRsp(msg, msgSize, pRsp);
24✔
1122
  if (code != 0) {
24!
1123
    qError("tDeserializeSVSubTablesRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1124
    return code;
×
1125
  }
1126
  
1127
  return TSDB_CODE_SUCCESS;
24✔
1128
}
1129

1130
int32_t queryProcessVStbRefDbsRsp(void* output, char* msg, int32_t msgSize) {
5,065✔
1131
  if (!output || !msg || msgSize <= 0) {
5,065!
1132
    qError("queryProcessVStbRefDbsRsp input error, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1133
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1134
  }
1135

1136
  SVStbRefDbsRsp * pRsp = (SVStbRefDbsRsp*)output;
5,065✔
1137
  int32_t code = tDeserializeSVStbRefDbsRsp(msg, msgSize, pRsp);
5,065✔
1138
  if (code != 0) {
5,065!
1139
    qError("tDeserializeSVStbRefDbsRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1140
    return code;
×
1141
  }
1142

1143
  return TSDB_CODE_SUCCESS;
5,065✔
1144
}
1145

1146
void initQueryModuleMsgHandle() {
16,629✔
1147
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg;
16,629✔
1148
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryBuildTableMetaReqMsg;
16,629✔
1149
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;
16,629✔
1150
  queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg;
16,629✔
1151
  queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg;
16,629✔
1152
  queryBuildMsg[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryBuildDnodeListMsg;
16,629✔
1153
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg;
16,629✔
1154
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryBuildGetIndexMsg;
16,629✔
1155
  queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryBuildRetrieveFuncMsg;
16,629✔
1156
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryBuildGetUserAuthMsg;
16,629✔
1157
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryBuildGetTbIndexMsg;
16,629✔
1158
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
16,629✔
1159
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
16,629✔
1160
  queryBuildMsg[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryBuildGetSerVerMsg;
16,629✔
1161
  queryBuildMsg[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryBuildGetViewMetaMsg;
16,629✔
1162
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryBuildGetTableTSMAMsg;
16,629✔
1163
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryBuildGetTSMAMsg;
16,629✔
1164
  queryBuildMsg[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryBuildGetStreamProgressMsg;
16,629✔
1165
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryBuildVSubTablesMsg;
16,629✔
1166
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSTB_REF_DBS)] = queryBuildVStbRefDBsMsg;
16,629✔
1167

1168
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp;
16,629✔
1169
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryProcessTableNameRsp;
16,629✔
1170
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp;
16,629✔
1171
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp;
16,629✔
1172
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp;
16,629✔
1173
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryProcessDnodeListRsp;
16,629✔
1174
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp;
16,629✔
1175
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryProcessGetIndexRsp;
16,629✔
1176
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryProcessRetrieveFuncRsp;
16,629✔
1177
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryProcessGetUserAuthRsp;
16,629✔
1178
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryProcessGetTbIndexRsp;
16,629✔
1179
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
16,629✔
1180
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
16,629✔
1181
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp;
16,629✔
1182
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryProcessGetViewMetaRsp;
16,629✔
1183
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryProcessGetTbTSMARsp;
16,629✔
1184
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryProcessGetTbTSMARsp;
16,629✔
1185
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryProcessStreamProgressRsp;
16,629✔
1186
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryProcessVSubTablesRsp;
16,629✔
1187
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_VSTB_REF_DBS)] = queryProcessVStbRefDbsRsp;
16,629✔
1188
}
16,629✔
1189

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