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

taosdata / TDengine / #3831

02 Apr 2025 01:14AM UTC coverage: 34.081% (-0.02%) from 34.097%
#3831

push

travis-ci

happyguoxy
test:alter gcda dir

148596 of 599532 branches covered (24.79%)

Branch coverage included in aggregate %.

222550 of 489473 relevant lines covered (45.47%)

1589752.67 hits per line

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

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

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

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

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

51
  if (usedbRsp->vgNum <= 0) {
12,081✔
52
    return TSDB_CODE_SUCCESS;
2,316✔
53
  }
54

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

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

71
  return TSDB_CODE_SUCCESS;
9,765✔
72
}
73

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

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

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

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

99
  *msg = pBuf;
7,836✔
100
  *msgLen = bufLen;
7,836✔
101

102
  return TSDB_CODE_SUCCESS;
7,836✔
103
}
104

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

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

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

127
  *msg = pBuf;
10,266✔
128
  *msgLen = bufLen;
10,266✔
129

130
  return TSDB_CODE_SUCCESS;
10,266✔
131
}
132

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

137
  SQnodeListReq qnodeListReq = {0};
141✔
138
  qnodeListReq.rowNum = -1;
141✔
139

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

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

149
  *msg = pBuf;
141✔
150
  *msgLen = bufLen;
141✔
151

152
  return TSDB_CODE_SUCCESS;
141✔
153
}
154

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

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

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

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

173
  return TSDB_CODE_SUCCESS;
6✔
174
}
175

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

180
  SServerVerReq req = {0};
3✔
181

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

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

193
  return TSDB_CODE_SUCCESS;
3✔
194
}
195

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

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

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

212
  *msg = pBuf;
816✔
213
  *msgLen = bufLen;
816✔
214

215
  return TSDB_CODE_SUCCESS;
816✔
216
}
217

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

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

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

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

237
  return TSDB_CODE_SUCCESS;
3✔
238
}
239

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

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

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

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

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

275
  return TSDB_CODE_SUCCESS;
1,626✔
276
}
277

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

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

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

294
  *msg = pBuf;
579✔
295
  *msgLen = bufLen;
579✔
296

297
  return TSDB_CODE_SUCCESS;
579✔
298
}
299

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

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

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

316
  *msg = pBuf;
39✔
317
  *msgLen = bufLen;
39✔
318

319
  return TSDB_CODE_SUCCESS;
39✔
320
}
321

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

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

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

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

344
  return TSDB_CODE_SUCCESS;
144✔
345
}
346

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

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

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

363
  *msg = pBuf;
3,282✔
364
  *msgLen = bufLen;
3,282✔
365

366
  return TSDB_CODE_SUCCESS;
3,282✔
367
}
368

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

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

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

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

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

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

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

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

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

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

426
  int32_t ret = tSerializeStreamProgressReq(pBuf, len, input);
×
427
  if (ret < 0) return ret;
×
428

429
  *msg = pBuf;
×
430
  *msgLen = len;
×
431
  return TSDB_CODE_SUCCESS;
×
432
}
433

434

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

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

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

452
  *msg = pBuf;
×
453
  *msgLen = bufLen;
×
454

455
  return TSDB_CODE_SUCCESS;
×
456
}
457

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

463
  SVStbRefDbsReq req = {0};
×
464
  req.suid = *(int64_t*)input;
×
465

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

475
  *msg = pBuf;
×
476
  *msgLen = bufLen;
×
477

478
  return TSDB_CODE_SUCCESS;
×
479
}
480

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

486
  if (NULL == output || NULL == msg || msgSize <= 0) {
10,239!
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) {
10,239!
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) {
10,239!
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);
10,239✔
505
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
61,374✔
506
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
51,135✔
507
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
51,135✔
508
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
165,078✔
509
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
113,943✔
510
    }
511
  }
512

513
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
10,239✔
514

515
PROCESS_USEDB_OVER:
10,239✔
516

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

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

541
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
5,832✔
542
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
1,884!
543
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
×
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) {
5,832!
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) {
5,832!
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) {
5,832!
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;
5,832✔
564
}
565

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

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

577
  return TSDB_CODE_SUCCESS;
17,133✔
578
}
579

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

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

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

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

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

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

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

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

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

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

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

638
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
7,002✔
639
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
7,002✔
640
    pTableMeta->schemaExt = pSchemaExt;
5,325✔
641
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
5,325✔
642
  } else {
643
    pTableMeta->schemaExt = NULL;
1,677✔
644
  }
645

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

653
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
7,002!
654
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
113,208✔
655
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
106,206✔
656
    if (hasPK && (i > 0)) {
106,206✔
657
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
300✔
658
        ++pTableMeta->tableInfo.numOfPKs;
156✔
659
      } else {
660
        hasPK = false;
144✔
661
      }
662
    }
663
  }
664

665
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
7,002✔
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;
7,002✔
673
  return TSDB_CODE_SUCCESS;
7,002✔
674
}
675

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

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

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

702
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
×
703
  pTableMeta->tableInfo.precision = msg->precision;
×
704
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
×
705

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

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

721
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
×
722
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
×
723
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
×
724
    if (hasPK && (i > 0)) {
×
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;
×
734
  tstrncpy(pTbName, msg->tbName, tbNameSize);
×
735

736
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
×
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;
×
744
  return TSDB_CODE_SUCCESS;
×
745
}
746

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

751
  if (NULL == output || NULL == msg || msgSize <= 0) {
5,832!
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) {
5,832!
758
    code = TSDB_CODE_INVALID_MSG;
×
759
    goto PROCESS_META_OVER;
×
760
  }
761

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

767
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
5,832!
768
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
4,161!
769
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
770
    goto PROCESS_META_OVER;
×
771
  }
772

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

777
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
5,832✔
778
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
1,224✔
779

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

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

788
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
1,224✔
789
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
4,608!
790
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
791

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

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

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

811
  tFreeSTableMetaRsp(&metaRsp);
5,832✔
812
  return code;
5,832✔
813
}
814

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

819
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
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) {
×
826
    code = TSDB_CODE_INVALID_MSG;
×
827
    goto PROCESS_NAME_OVER;
×
828
  }
829

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

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

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

845
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
×
846
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
×
847

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

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

856
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
×
857
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
×
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);
×
871
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
872
    code = queryCreateTableMetaExFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
×
873
  }
874

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

880
  tFreeSTableMetaRsp(&metaRsp);
×
881
  return code;
×
882
}
883

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

888
  if (NULL == output || NULL == msg || msgSize <= 0) {
141!
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;
141✔
895
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
141!
896
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
×
897
    code = TSDB_CODE_INVALID_MSG;
×
898
    return code;
×
899
  }
900

901
  return code;
141✔
902
}
903

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

908
  if (NULL == output || NULL == msg || msgSize <= 0) {
6!
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) {
6!
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;
6✔
921

922
  return code;
6✔
923
}
924

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

929
  if (NULL == output || NULL == msg || msgSize <= 0) {
3!
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) {
3!
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);
3!
942
  if (NULL == *(char **)output) {
3!
943
    return terrno;
×
944
  }
945

946
  return code;
3✔
947
}
948

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

952
  if (NULL == output || NULL == msg || msgSize <= 0) {
816!
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) {
816!
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));
816✔
963

964
  return TSDB_CODE_SUCCESS;
816✔
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) {
1,626✔
986
  SRetrieveFuncRsp out = {0};
1,626✔
987

988
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,626!
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) {
1,626!
994
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
×
995
    return TSDB_CODE_INVALID_MSG;
×
996
  }
997

998
  if (1 != out.numOfFuncs) {
1,626!
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);
1,626✔
1004

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

1009
  return TSDB_CODE_SUCCESS;
1,626✔
1010
}
1011

1012
int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) {
579✔
1013
  if (NULL == output || NULL == msg || msgSize <= 0) {
579!
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) {
579!
1019
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
1020
    return TSDB_CODE_INVALID_MSG;
×
1021
  }
1022

1023
  return TSDB_CODE_SUCCESS;
579✔
1024
}
1025

1026
int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
3✔
1027
  if (NULL == output || NULL == msg || msgSize <= 0) {
3!
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;
3✔
1033
  if (tDeserializeSTableIndexRsp(msg, msgSize, out) != 0) {
3!
1034
    qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize);
×
1035
    return TSDB_CODE_INVALID_MSG;
×
1036
  }
1037

1038
  return TSDB_CODE_SUCCESS;
3✔
1039
}
1040

1041
int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
144✔
1042
  if (NULL == output || NULL == msg || msgSize <= 0) {
144!
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));
144!
1048
  if(out == NULL) {
144!
1049
    return terrno;
×
1050
  }
1051
  if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
144!
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;
144✔
1059

1060
  return TSDB_CODE_SUCCESS;
144✔
1061
}
1062

1063
int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) {
×
1064
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
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));
×
1070
  if (out == NULL) {
×
1071
    return terrno;
×
1072
  }
1073
  if (tDeserializeSViewMetaRsp(msg, msgSize, out) != 0) {
×
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);
×
1081

1082
  *(SViewMetaRsp **)output = out;
×
1083

1084
  return TSDB_CODE_SUCCESS;
×
1085
}
1086

1087
int32_t queryProcessGetTbTSMARsp(void* output, char* msg, int32_t msgSize) {
×
1088
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
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) {
×
1094
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1095
    return TSDB_CODE_INVALID_MSG;
×
1096
  }
1097

1098
  return TSDB_CODE_SUCCESS;
×
1099
}
1100

1101
int32_t queryProcessStreamProgressRsp(void* output, char* msg, int32_t msgSize) {
×
1102
  if (!output || !msg || msgSize <= 0) {
×
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) {
×
1108
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1109
    return TSDB_CODE_INVALID_MSG;
×
1110
  }
1111
  return TSDB_CODE_SUCCESS;
×
1112
}
1113

1114
int32_t queryProcessVSubTablesRsp(void* output, char* msg, int32_t msgSize) {
×
1115
  if (!output || !msg || msgSize <= 0) {
×
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;
×
1121
  int32_t code = tDeserializeSVSubTablesRsp(msg, msgSize, pRsp);
×
1122
  if (code != 0) {
×
1123
    qError("tDeserializeSVSubTablesRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1124
    return code;
×
1125
  }
1126
  
1127
  return TSDB_CODE_SUCCESS;
×
1128
}
1129

1130
int32_t queryProcessVStbRefDbsRsp(void* output, char* msg, int32_t msgSize) {
×
1131
  if (!output || !msg || msgSize <= 0) {
×
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;
×
1137
  int32_t code = tDeserializeSVStbRefDbsRsp(msg, msgSize, pRsp);
×
1138
  if (code != 0) {
×
1139
    qError("tDeserializeSVStbRefDbsRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1140
    return code;
×
1141
  }
1142

1143
  return TSDB_CODE_SUCCESS;
×
1144
}
1145

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

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