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

taosdata / TDengine / #3829

28 Mar 2025 06:51AM UTC coverage: 63.162% (+0.5%) from 62.668%
#3829

push

travis-ci

web-flow
fix(tdb): disable page recycling (#30529)

155078 of 313582 branches covered (49.45%)

Branch coverage included in aggregate %.

240930 of 313390 relevant lines covered (76.88%)

20393545.98 hits per line

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

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

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

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

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

51
  if (usedbRsp->vgNum <= 0) {
101,362✔
52
    return TSDB_CODE_SUCCESS;
10,281✔
53
  }
54

55
  pOut->dbVgroup->vgHash =
182,160✔
56
      taosHashInit(usedbRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
91,081✔
57
  if (NULL == pOut->dbVgroup->vgHash) {
91,080!
58
    return terrno;
×
59
  }
60

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

71
  return TSDB_CODE_SUCCESS;
91,081✔
72
}
73

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

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

86
  if (pInput->dbFName) {
193,889!
87
    tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
193,890✔
88
  }
89
  tstrncpy(infoReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
193,889✔
90

91
  int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
193,889✔
92
  void   *pBuf = (*mallcFp)(bufLen);
193,900✔
93
  if (NULL == pBuf) {
193,909!
94
    return terrno;
×
95
  }
96
  int32_t ret = tSerializeSTableInfoReq(pBuf, bufLen, &infoReq);
193,909✔
97
  if (ret < 0) return ret;
193,923!
98

99
  *msg = pBuf;
193,923✔
100
  *msgLen = bufLen;
193,923✔
101

102
  return TSDB_CODE_SUCCESS;
193,923✔
103
}
104

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

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

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

127
  *msg = pBuf;
93,447✔
128
  *msgLen = bufLen;
93,447✔
129

130
  return TSDB_CODE_SUCCESS;
93,447✔
131
}
132

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

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

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

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

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

152
  return TSDB_CODE_SUCCESS;
10,986✔
153
}
154

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

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

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

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

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

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

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

212
  *msg = pBuf;
3,847✔
213
  *msgLen = bufLen;
3,847✔
214

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

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

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

270
  taosArrayDestroy(funcReq.pFuncNames);
97✔
271

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

275
  return TSDB_CODE_SUCCESS;
97✔
276
}
277

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

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

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

294
  *msg = pBuf;
17,685✔
295
  *msgLen = bufLen;
17,685✔
296

297
  return TSDB_CODE_SUCCESS;
17,685✔
298
}
299

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

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

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

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

319
  return TSDB_CODE_SUCCESS;
7,212✔
320
}
321

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

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

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

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

344
  return TSDB_CODE_SUCCESS;
223✔
345
}
346

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

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

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

363
  *msg = pBuf;
35,341✔
364
  *msgLen = bufLen;
35,341✔
365

366
  return TSDB_CODE_SUCCESS;
35,341✔
367
}
368

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

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

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

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

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

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

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

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

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

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

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

429
  *msg = pBuf;
4,468✔
430
  *msgLen = len;
4,468✔
431
  return TSDB_CODE_SUCCESS;
4,468✔
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

459
int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) {
92,852✔
460
  SUseDbOutput *pOut = output;
92,852✔
461
  SUseDbRsp     usedbRsp = {0};
92,852✔
462
  int32_t       code = -1;
92,852✔
463

464
  if (NULL == output || NULL == msg || msgSize <= 0) {
92,852!
465
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
466
    qError("invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
467
    goto PROCESS_USEDB_OVER;
×
468
  }
469

470
  if (tDeserializeSUseDbRsp(msg, msgSize, &usedbRsp) != 0) {
92,852!
471
    qError("invalid use db rsp msg, msgSize:%d", msgSize);
×
472
    code = TSDB_CODE_INVALID_MSG;
×
473
    goto PROCESS_USEDB_OVER;
×
474
  }
475

476
  if (usedbRsp.vgNum < 0) {
92,852!
477
    qError("invalid db[%s] vgroup number[%d]", usedbRsp.db, usedbRsp.vgNum);
×
478
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
479
    goto PROCESS_USEDB_OVER;
×
480
  }
481

482
  qTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum);
92,852✔
483
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
317,135✔
484
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
224,283✔
485
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
224,283✔
486
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
482,994✔
487
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
258,711✔
488
    }
489
  }
490

491
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
92,852✔
492

493
PROCESS_USEDB_OVER:
92,853✔
494

495
  if (code != 0) {
92,853!
496
    if (pOut) {
×
497
      if (pOut->dbVgroup) taosHashCleanup(pOut->dbVgroup->vgHash);
×
498
      taosMemoryFreeClear(pOut->dbVgroup);
×
499
    }
500
    qError("failed to process usedb rsp since %s", terrstr());
×
501
  }
502

503
  tFreeSUsedbRsp(&usedbRsp);
92,853✔
504
  return code;
92,851✔
505
}
506

507
static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) {
158,271✔
508
  QUERY_PARAM_CHECK(pMetaMsg);
158,271!
509
  if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) {
158,271!
510
    qError("invalid numOfTags[%d] in table meta rsp msg", pMetaMsg->numOfTags);
×
511
    return TSDB_CODE_TSC_INVALID_VALUE;
×
512
  }
513

514
  if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) {
158,273!
515
    qError("invalid numOfColumns[%d] in table meta rsp msg", pMetaMsg->numOfColumns);
×
516
    return TSDB_CODE_TSC_INVALID_VALUE;
×
517
  }
518

519
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
158,273✔
520
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
17,520✔
521
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
86!
522
    qError("invalid tableType[%d] in table meta rsp msg", pMetaMsg->tableType);
×
523
    return TSDB_CODE_TSC_INVALID_VALUE;
×
524
  }
525

526
  if (pMetaMsg->sversion < 0) {
158,273!
527
    qError("invalid sversion[%d] in table meta rsp msg", pMetaMsg->sversion);
×
528
    return TSDB_CODE_TSC_INVALID_VALUE;
×
529
  }
530

531
  if (pMetaMsg->tversion < 0) {
158,273!
532
    qError("invalid tversion[%d] in table meta rsp msg", pMetaMsg->tversion);
×
533
    return TSDB_CODE_TSC_INVALID_VALUE;
×
534
  }
535

536
  if (pMetaMsg->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
158,273!
537
    qError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", pMetaMsg->pSchemas[0].colId);
×
538
    return TSDB_CODE_TSC_INVALID_VALUE;
×
539
  }
540

541
  return TSDB_CODE_SUCCESS;
158,273✔
542
}
543

544
int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) {
125,330✔
545
  QUERY_PARAM_CHECK(msg);
125,330!
546
  QUERY_PARAM_CHECK(pMeta);
125,330!
547
  pMeta->vgId = msg->vgId;
125,330✔
548
  pMeta->tableType = msg->tableType;
125,330✔
549
  pMeta->uid = msg->tuid;
125,330✔
550
  pMeta->suid = msg->suid;
125,330✔
551

552
  qDebug("ctb:%s, uid:0x%" PRIx64 " meta returned, type:%d vgId:%d db:%s suid:%" PRIx64, msg->tbName, pMeta->uid,
125,330✔
553
         pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid);
554

555
  return TSDB_CODE_SUCCESS;
125,335✔
556
}
557

558
int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta) {
223✔
559
  QUERY_PARAM_CHECK(msg);
223!
560
  QUERY_PARAM_CHECK(pMeta);
223!
561
  QUERY_PARAM_CHECK(msg->pColRefs);
223!
562

563
  int32_t pColRefSize = sizeof(SColRef) * msg->numOfColRefs;
223✔
564

565
  SVCTableMeta *pTableMeta = taosMemoryCalloc(1, sizeof(SVCTableMeta) + pColRefSize);
223!
566
  if (NULL == pTableMeta) {
223!
567
    qError("calloc size[%d] failed", (int32_t)sizeof(SVCTableMeta) + pColRefSize);
×
568
    return terrno;
×
569
  }
570

571
  pTableMeta->vgId = msg->vgId;
223✔
572
  pTableMeta->tableType = msg->tableType;
223✔
573
  pTableMeta->uid = msg->tuid;
223✔
574
  pTableMeta->suid = msg->suid;
223✔
575
  pTableMeta->numOfColRefs = msg->numOfColRefs;
223✔
576

577
  pTableMeta->colRef = (SColRef *)((char *)pTableMeta + sizeof(SVCTableMeta));
223✔
578
  memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
223✔
579

580
  qDebug("ctable %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s suid %" PRIx64, msg->tbName, (pTableMeta)->uid,
223!
581
         (pTableMeta)->tableType, (pTableMeta)->vgId, msg->dbFName, (pTableMeta)->suid);
582

583
  *pMeta = pTableMeta;
223✔
584
  return TSDB_CODE_SUCCESS;
223✔
585
}
586

587
int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
180,460✔
588
  QUERY_PARAM_CHECK(msg);
180,460!
589
  QUERY_PARAM_CHECK(pMeta);
180,460!
590
  int32_t total = msg->numOfColumns + msg->numOfTags;
180,460✔
591
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
180,460✔
592
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
180,460✔
593
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) ? sizeof(SColRef) * msg->numOfColRefs : 0;
180,461!
594

595
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize);
180,462!
596
  if (NULL == pTableMeta) {
180,463!
597
    qError("calloc size[%d] failed", metaSize);
×
598
    return terrno;
×
599
  }
600
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
180,463✔
601
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
180,463✔
602

603
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
180,463✔
604
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
180,463✔
605
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
180,463✔
606
  pTableMeta->suid = msg->suid;
180,463✔
607
  pTableMeta->sversion = msg->sversion;
180,463✔
608
  pTableMeta->tversion = msg->tversion;
180,463✔
609
  pTableMeta->virtualStb = msg->virtualStb;
180,463✔
610
  pTableMeta->numOfColRefs = msg->numOfColRefs;
180,463✔
611

612
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
180,463✔
613
  pTableMeta->tableInfo.precision = msg->precision;
180,463✔
614
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
180,463✔
615

616
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
180,463✔
617
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
180,463✔
618
    pTableMeta->schemaExt = pSchemaExt;
177,807✔
619
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
177,807✔
620
  } else {
621
    pTableMeta->schemaExt = NULL;
2,657✔
622
  }
623

624
  if (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) {
180,464!
625
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
544✔
626
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
544✔
627
  } else {
628
    pTableMeta->colRef = NULL;
179,922✔
629
  }
630

631
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
180,466✔
632
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
2,743,939✔
633
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,563,473✔
634
    if (hasPK && (i > 0)) {
2,563,473✔
635
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
238,476✔
636
        ++pTableMeta->tableInfo.numOfPKs;
119,249✔
637
      } else {
638
        hasPK = false;
119,227✔
639
      }
640
    }
641
  }
642

643
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
180,466✔
644
         " sver:%d tver:%d"
645
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
646
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
647
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
648
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
649

650
  *pMeta = pTableMeta;
180,464✔
651
  return TSDB_CODE_SUCCESS;
180,464✔
652
}
653

654
int32_t queryCreateTableMetaExFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
825✔
655
  QUERY_PARAM_CHECK(msg);
825!
656
  QUERY_PARAM_CHECK(pMeta);
825!
657
  int32_t total = msg->numOfColumns + msg->numOfTags;
825✔
658
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
825✔
659
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
825!
660
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs) ? sizeof(SColRef) * msg->numOfColRefs : 0;
825!
661
  int32_t tbNameSize = strlen(msg->tbName) + 1;
825✔
662

663
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize + tbNameSize);
825!
664
  if (NULL == pTableMeta) {
825!
665
    qError("calloc size[%d] failed", metaSize);
×
666
    return terrno;
×
667
  }
668
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
825✔
669
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
825✔
670

671
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
825✔
672
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
825✔
673
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
825✔
674
  pTableMeta->suid = msg->suid;
825✔
675
  pTableMeta->sversion = msg->sversion;
825✔
676
  pTableMeta->tversion = msg->tversion;
825✔
677
  pTableMeta->virtualStb = msg->virtualStb;
825✔
678
  pTableMeta->numOfColRefs = msg->numOfColRefs;
825✔
679

680
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
825✔
681
  pTableMeta->tableInfo.precision = msg->precision;
825✔
682
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
825✔
683

684
  TAOS_MEMCPY(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
825✔
685
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
825!
686
    pTableMeta->schemaExt = pSchemaExt;
825✔
687
    TAOS_MEMCPY(pSchemaExt, msg->pSchemaExt, schemaExtSize);
825✔
688
  } else {
689
    pTableMeta->schemaExt = NULL;
×
690
  }
691

692
  if (hasRefCol(msg->tableType) && msg->pColRefs) {
825!
693
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
×
694
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
×
695
  } else {
696
    pTableMeta->colRef = NULL;
825✔
697
  }
698

699
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
825!
700
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
2,781✔
701
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
1,956✔
702
    if (hasPK && (i > 0)) {
1,956!
703
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
×
704
        ++pTableMeta->tableInfo.numOfPKs;
×
705
      } else {
706
        hasPK = false;
×
707
      }
708
    }
709
  }
710

711
  char *pTbName = (char *)pTableMeta + metaSize + schemaExtSize + pColRefSize;
825✔
712
  tstrncpy(pTbName, msg->tbName, tbNameSize);
825✔
713

714
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
825!
715
         " sver:%d tver:%d"
716
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
717
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
718
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
719
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
720

721
  *pMeta = pTableMeta;
825✔
722
  return TSDB_CODE_SUCCESS;
825✔
723
}
724

725
int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) {
157,446✔
726
  int32_t       code = 0;
157,446✔
727
  STableMetaRsp metaRsp = {0};
157,446✔
728

729
  if (NULL == output || NULL == msg || msgSize <= 0) {
157,446!
730
    qError("queryProcessTableMetaRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
731
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
732
    goto PROCESS_META_OVER;
×
733
  }
734

735
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
157,446!
736
    code = TSDB_CODE_INVALID_MSG;
×
737
    goto PROCESS_META_OVER;
×
738
  }
739

740
  code = queryConvertTableMetaMsg(&metaRsp);
157,448✔
741
  if (code != TSDB_CODE_SUCCESS) {
157,443!
742
    goto PROCESS_META_OVER;
×
743
  }
744

745
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
157,443!
746
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
155,401!
747
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
748
    goto PROCESS_META_OVER;
×
749
  }
750

751
  STableMetaOutput *pOut = output;
157,446✔
752
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
157,446✔
753
  pOut->dbId = metaRsp.dbId;
157,446✔
754

755
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
157,446✔
756
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
126,158✔
757

758
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
126,158✔
759
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
126,158✔
760

761
    pOut->ctbMeta.vgId = metaRsp.vgId;
126,158✔
762
    pOut->ctbMeta.tableType = metaRsp.tableType;
126,158✔
763
    pOut->ctbMeta.uid = metaRsp.tuid;
126,158✔
764
    pOut->ctbMeta.suid = metaRsp.suid;
126,158✔
765

766
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
126,158✔
767
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
31,288✔
768
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
66✔
769

770
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
66✔
771
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
66✔
772

773
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
66✔
774
    if (TSDB_CODE_SUCCESS != code) {
66!
775
      goto PROCESS_META_OVER;
×
776
    }
777
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
66✔
778
  } else {
779
    SET_META_TYPE_TABLE(pOut->metaType);
31,222✔
780
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
31,222✔
781
    code = queryCreateTableMetaFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
31,222✔
782
  }
783

784
PROCESS_META_OVER:
157,450✔
785
  if (code != 0) {
157,450!
786
    qError("failed to process table meta rsp since %s", tstrerror(code));
×
787
  }
788

789
  tFreeSTableMetaRsp(&metaRsp);
157,450✔
790
  return code;
157,450✔
791
}
792

793
static int32_t queryProcessTableNameRsp(void *output, char *msg, int32_t msgSize) {
825✔
794
  int32_t       code = 0;
825✔
795
  STableMetaRsp metaRsp = {0};
825✔
796

797
  if (NULL == output || NULL == msg || msgSize <= 0) {
825!
798
    qError("queryProcessTableNameRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
799
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
800
    goto PROCESS_NAME_OVER;
×
801
  }
802

803
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
825!
804
    code = TSDB_CODE_INVALID_MSG;
×
805
    goto PROCESS_NAME_OVER;
×
806
  }
807

808
  code = queryConvertTableMetaMsg(&metaRsp);
825✔
809
  if (code != TSDB_CODE_SUCCESS) {
825!
810
    goto PROCESS_NAME_OVER;
×
811
  }
812

813
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
825!
814
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
825!
815
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
816
    goto PROCESS_NAME_OVER;
×
817
  }
818

819
  STableMetaOutput *pOut = output;
825✔
820
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
825✔
821
  pOut->dbId = metaRsp.dbId;
825✔
822

823
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
825✔
824
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
311✔
825

826
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
311✔
827
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
311✔
828

829
    pOut->ctbMeta.vgId = metaRsp.vgId;
311✔
830
    pOut->ctbMeta.tableType = metaRsp.tableType;
311✔
831
    pOut->ctbMeta.uid = metaRsp.tuid;
311✔
832
    pOut->ctbMeta.suid = metaRsp.suid;
311✔
833

834
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
311✔
835
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
514!
836
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
837

838
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
839
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
×
840

841
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
×
842
    if (TSDB_CODE_SUCCESS != code) {
×
843
      goto PROCESS_NAME_OVER;
×
844
    }
845

846
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
×
847
  } else {
848
    SET_META_TYPE_TABLE(pOut->metaType);
514✔
849
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
514✔
850
    code = queryCreateTableMetaExFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
514✔
851
  }
852

853
PROCESS_NAME_OVER:
825✔
854
  if (code != 0) {
825!
855
    qError("failed to process table name rsp since %s", tstrerror(code));
×
856
  }
857

858
  tFreeSTableMetaRsp(&metaRsp);
825✔
859
  return code;
825✔
860
}
861

862
int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) {
10,986✔
863
  SQnodeListRsp out = {0};
10,986✔
864
  int32_t       code = 0;
10,986✔
865

866
  if (NULL == output || NULL == msg || msgSize <= 0) {
10,986!
867
    qError("queryProcessQnodeListRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
868
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
869
    return code;
×
870
  }
871

872
  out.qnodeList = (SArray *)output;
10,986✔
873
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
10,986!
874
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
×
875
    code = TSDB_CODE_INVALID_MSG;
×
876
    return code;
×
877
  }
878

879
  return code;
10,986✔
880
}
881

882
int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) {
345✔
883
  SDnodeListRsp out = {0};
345✔
884
  int32_t       code = 0;
345✔
885

886
  if (NULL == output || NULL == msg || msgSize <= 0) {
345!
887
    qError("queryProcessDnodeListRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
888
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
889
    return code;
×
890
  }
891

892
  if (tDeserializeSDnodeListRsp(msg, msgSize, &out) != 0) {
345!
893
    qError("invalid dnode list rsp msg, msgSize:%d", msgSize);
×
894
    code = TSDB_CODE_INVALID_MSG;
×
895
    return code;
×
896
  }
897

898
  *(SArray **)output = out.dnodeList;
345✔
899

900
  return code;
345✔
901
}
902

903
int32_t queryProcessGetSerVerRsp(void *output, char *msg, int32_t msgSize) {
1✔
904
  SServerVerRsp out = {0};
1✔
905
  int32_t       code = 0;
1✔
906

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

913
  if (tDeserializeSServerVerRsp(msg, msgSize, &out) != 0) {
1!
914
    qError("invalid svr ver rsp msg, msgSize:%d", msgSize);
×
915
    code = TSDB_CODE_INVALID_MSG;
×
916
    return code;
×
917
  }
918

919
  *(char **)output = taosStrdup(out.ver);
1!
920
  if (NULL == *(char **)output) {
1!
921
    return terrno;
×
922
  }
923

924
  return code;
1✔
925
}
926

927
int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) {
3,826✔
928
  SDbCfgRsp out = {0};
3,826✔
929

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

935
  if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) {
3,826!
936
    qError("tDeserializeSDbCfgRsp failed, msgSize:%d, dbCfgRsp:%lu", msgSize, sizeof(out));
×
937
    return TSDB_CODE_INVALID_MSG;
×
938
  }
939

940
  memcpy(output, &out, sizeof(out));
3,826✔
941

942
  return TSDB_CODE_SUCCESS;
3,826✔
943
}
944

945
int32_t queryProcessGetIndexRsp(void *output, char *msg, int32_t msgSize) {
×
946
  SUserIndexRsp out = {0};
×
947

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

953
  if (tDeserializeSUserIndexRsp(msg, msgSize, &out) != 0) {
×
954
    qError("tDeserializeSUserIndexRsp failed, msgSize:%d", msgSize);
×
955
    return TSDB_CODE_INVALID_MSG;
×
956
  }
957

958
  memcpy(output, &out, sizeof(out));
×
959

960
  return TSDB_CODE_SUCCESS;
×
961
}
962

963
int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
87✔
964
  SRetrieveFuncRsp out = {0};
87✔
965

966
  if (NULL == output || NULL == msg || msgSize <= 0) {
87!
967
    qError("queryProcessRetrieveFuncRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
968
    return TSDB_CODE_TSC_INVALID_INPUT;
×
969
  }
970

971
  if (tDeserializeSRetrieveFuncRsp(msg, msgSize, &out) != 0) {
87!
972
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
×
973
    return TSDB_CODE_INVALID_MSG;
×
974
  }
975

976
  if (1 != out.numOfFuncs) {
87!
977
    qError("invalid func num returned, numOfFuncs:%d", out.numOfFuncs);
×
978
    return TSDB_CODE_INVALID_MSG;
×
979
  }
980

981
  SFuncInfo *funcInfo = taosArrayGet(out.pFuncInfos, 0);
87✔
982

983
  memcpy(output, funcInfo, sizeof(*funcInfo));
87✔
984
  taosArrayDestroy(out.pFuncInfos);
87✔
985
  taosArrayDestroy(out.pFuncExtraInfos);
87✔
986

987
  return TSDB_CODE_SUCCESS;
87✔
988
}
989

990
int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) {
17,682✔
991
  if (NULL == output || NULL == msg || msgSize <= 0) {
17,682!
992
    qError("queryProcessGetUserAuthRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
993
    return TSDB_CODE_TSC_INVALID_INPUT;
×
994
  }
995

996
  if (tDeserializeSGetUserAuthRsp(msg, msgSize, (SGetUserAuthRsp *)output) != 0) {
17,682!
997
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
998
    return TSDB_CODE_INVALID_MSG;
×
999
  }
1000

1001
  return TSDB_CODE_SUCCESS;
17,682✔
1002
}
1003

1004
int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
1✔
1005
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
1006
    qError("queryProcessGetTbIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1007
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1008
  }
1009

1010
  STableIndexRsp *out = (STableIndexRsp *)output;
1✔
1011
  if (tDeserializeSTableIndexRsp(msg, msgSize, out) != 0) {
1!
1012
    qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize);
×
1013
    return TSDB_CODE_INVALID_MSG;
×
1014
  }
1015

1016
  return TSDB_CODE_SUCCESS;
1✔
1017
}
1018

1019
int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
223✔
1020
  if (NULL == output || NULL == msg || msgSize <= 0) {
223!
1021
    qError("queryProcessGetTbCfgRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1022
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1023
  }
1024

1025
  STableCfgRsp *out = taosMemoryCalloc(1, sizeof(STableCfgRsp));
223!
1026
  if(out == NULL) {
223!
1027
    return terrno;
×
1028
  }
1029
  if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
223!
1030
    qError("tDeserializeSTableCfgRsp failed, msgSize:%d", msgSize);
×
1031
    tFreeSTableCfgRsp(out);
×
1032
    taosMemoryFree(out);
×
1033
    return TSDB_CODE_INVALID_MSG;
×
1034
  }
1035

1036
  *(STableCfgRsp **)output = out;
223✔
1037

1038
  return TSDB_CODE_SUCCESS;
223✔
1039
}
1040

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

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

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

1060
  *(SViewMetaRsp **)output = out;
312✔
1061

1062
  return TSDB_CODE_SUCCESS;
312✔
1063
}
1064

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

1071
  if (tDeserializeTableTSMAInfoRsp(msg, msgSize, output) != 0) {
856!
1072
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1073
    return TSDB_CODE_INVALID_MSG;
×
1074
  }
1075

1076
  return TSDB_CODE_SUCCESS;
856✔
1077
}
1078

1079
int32_t queryProcessStreamProgressRsp(void* output, char* msg, int32_t msgSize) {
4,468✔
1080
  if (!output || !msg || msgSize <= 0) {
4,468!
1081
    qError("queryProcessStreamProgressRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1082
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1083
  }
1084

1085
  if (tDeserializeSStreamProgressRsp(msg, msgSize, output) != 0) {
4,468!
1086
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1087
    return TSDB_CODE_INVALID_MSG;
×
1088
  }
1089
  return TSDB_CODE_SUCCESS;
4,466✔
1090
}
1091

1092
int32_t queryProcessVSubTablesRsp(void* output, char* msg, int32_t msgSize) {
24✔
1093
  if (!output || !msg || msgSize <= 0) {
24!
1094
    qError("queryProcessVSubTablesRsp input error, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1095
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1096
  }
1097

1098
  SVSubTablesRsp* pRsp = (SVSubTablesRsp*)output;
24✔
1099
  int32_t code = tDeserializeSVSubTablesRsp(msg, msgSize, pRsp);
24✔
1100
  if (code != 0) {
24!
1101
    qError("tDeserializeSVSubTablesRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1102
    return code;
×
1103
  }
1104
  
1105
  return TSDB_CODE_SUCCESS;
24✔
1106
}
1107

1108
void initQueryModuleMsgHandle() {
16,604✔
1109
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg;
16,604✔
1110
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryBuildTableMetaReqMsg;
16,604✔
1111
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;
16,604✔
1112
  queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg;
16,604✔
1113
  queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg;
16,604✔
1114
  queryBuildMsg[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryBuildDnodeListMsg;
16,604✔
1115
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg;
16,604✔
1116
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryBuildGetIndexMsg;
16,604✔
1117
  queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryBuildRetrieveFuncMsg;
16,604✔
1118
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryBuildGetUserAuthMsg;
16,604✔
1119
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryBuildGetTbIndexMsg;
16,604✔
1120
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
16,604✔
1121
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
16,604✔
1122
  queryBuildMsg[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryBuildGetSerVerMsg;
16,604✔
1123
  queryBuildMsg[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryBuildGetViewMetaMsg;
16,604✔
1124
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryBuildGetTableTSMAMsg;
16,604✔
1125
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryBuildGetTSMAMsg;
16,604✔
1126
  queryBuildMsg[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryBuildGetStreamProgressMsg;
16,604✔
1127
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryBuildVSubTablesMsg;
16,604✔
1128

1129
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp;
16,604✔
1130
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryProcessTableNameRsp;
16,604✔
1131
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp;
16,604✔
1132
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp;
16,604✔
1133
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp;
16,604✔
1134
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryProcessDnodeListRsp;
16,604✔
1135
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp;
16,604✔
1136
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryProcessGetIndexRsp;
16,604✔
1137
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryProcessRetrieveFuncRsp;
16,604✔
1138
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryProcessGetUserAuthRsp;
16,604✔
1139
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryProcessGetTbIndexRsp;
16,604✔
1140
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
16,604✔
1141
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
16,604✔
1142
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp;
16,604✔
1143
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryProcessGetViewMetaRsp;
16,604✔
1144
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryProcessGetTbTSMARsp;
16,604✔
1145
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryProcessGetTbTSMARsp;
16,604✔
1146
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryProcessStreamProgressRsp;
16,604✔
1147
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryProcessVSubTablesRsp;
16,604✔
1148
}
16,604✔
1149

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