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

taosdata / TDengine / #4452

05 Jul 2025 10:40AM UTC coverage: 60.734% (-2.8%) from 63.58%
#4452

push

travis-ci

web-flow
Merge pull request #31673 from taosdata/fix/huoh/taos_log

test: fix mnode create failure

149869 of 316704 branches covered (47.32%)

Branch coverage included in aggregate %.

233489 of 314508 relevant lines covered (74.24%)

6990477.86 hits per line

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

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

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

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

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

51
  if (usedbRsp->vgNum <= 0) {
147,050✔
52
    return TSDB_CODE_SUCCESS;
7,625✔
53
  }
54

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

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

71
  return TSDB_CODE_SUCCESS;
139,425✔
72
}
73

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

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

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

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

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

102
  return TSDB_CODE_SUCCESS;
143,836✔
103
}
104

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

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

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

127
  *msg = pBuf;
143,056✔
128
  *msgLen = bufLen;
143,056✔
129

130
  return TSDB_CODE_SUCCESS;
143,056✔
131
}
132

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

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

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

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

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

152
  return TSDB_CODE_SUCCESS;
11,742✔
153
}
154

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

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

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

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

173
  return TSDB_CODE_SUCCESS;
132✔
174
}
175

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

180
  SServerVerReq req = {0};
×
181

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

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

193
  return TSDB_CODE_SUCCESS;
×
194
}
195

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

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

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

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

215
  return TSDB_CODE_SUCCESS;
6,120✔
216
}
217

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

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

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

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

237
  return TSDB_CODE_SUCCESS;
×
238
}
239

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

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

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

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

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

275
  return TSDB_CODE_SUCCESS;
1,295✔
276
}
277

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

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

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

294
  *msg = pBuf;
21,789✔
295
  *msgLen = bufLen;
21,789✔
296

297
  return TSDB_CODE_SUCCESS;
21,789✔
298
}
299

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

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

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

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

319
  return TSDB_CODE_SUCCESS;
1,411✔
320
}
321

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

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

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

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

344
  return TSDB_CODE_SUCCESS;
253✔
345
}
346

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

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

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

363
  *msg = pBuf;
43,264✔
364
  *msgLen = bufLen;
43,264✔
365

366
  return TSDB_CODE_SUCCESS;
43,264✔
367
}
368

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

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

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

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

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

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

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

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

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

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

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

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

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

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

475
  *msg = pBuf;
4,856✔
476
  *msgLen = bufLen;
4,856✔
477

478
  return TSDB_CODE_SUCCESS;
4,856✔
479
}
480

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

486
  if (NULL == output || NULL == msg || msgSize <= 0) {
141,609!
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) {
141,609!
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) {
141,608!
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);
141,608✔
505
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
454,077✔
506
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
312,469✔
507
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
312,469✔
508
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
632,885✔
509
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
320,416✔
510
    }
511
  }
512

513
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
141,608✔
514

515
PROCESS_USEDB_OVER:
141,609✔
516

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

529
static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) {
84,769✔
530
  QUERY_PARAM_CHECK(pMetaMsg);
84,769!
531
  if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) {
84,769!
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) {
84,769!
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 &&
84,769✔
542
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
36,305✔
543
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
129!
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) {
84,769!
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) {
84,769!
554
    qError("invalid tversion[%d] in table meta rsp msg", pMetaMsg->tversion);
×
555
    return TSDB_CODE_TSC_INVALID_VALUE;
×
556
  }
557

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

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

568
  return TSDB_CODE_SUCCESS;
84,769✔
569
}
570

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

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

582
  return TSDB_CODE_SUCCESS;
126,621✔
583
}
584

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

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

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

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

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

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

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

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

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

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

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

655
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
110,466✔
656
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
110,466!
657
    pTableMeta->schemaExt = pSchemaExt;
107,559✔
658
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
107,559✔
659
  } else {
660
    pTableMeta->schemaExt = NULL;
2,907✔
661
  }
662

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

670
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
110,466!
671
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
3,396,834✔
672
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
3,286,368✔
673
    if (hasPK && (i > 0)) {
3,286,368✔
674
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
1,262✔
675
        ++pTableMeta->tableInfo.numOfPKs;
650✔
676
      } else {
677
        hasPK = false;
612✔
678
      }
679
    }
680
  }
681

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

689
  *pMeta = pTableMeta;
110,466✔
690
  return TSDB_CODE_SUCCESS;
110,466✔
691
}
692

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

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

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

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

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

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

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

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

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

761
  *pMeta = pTableMeta;
402✔
762
  return TSDB_CODE_SUCCESS;
402✔
763
}
764

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

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

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

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

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

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

795
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
84,366✔
796
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
15,182✔
797

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

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

806
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
15,182✔
807
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
69,184✔
808
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
66✔
809

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

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

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

829
  tFreeSTableMetaRsp(&metaRsp);
84,367✔
830
  return code;
84,367✔
831
}
832

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

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

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

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

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

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

863
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
402✔
864
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
22✔
865

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

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

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

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

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

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

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

898
  tFreeSTableMetaRsp(&metaRsp);
402✔
899
  return code;
402✔
900
}
901

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

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

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

919
  return code;
11,742✔
920
}
921

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

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

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

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

940
  return code;
123✔
941
}
942

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

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

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

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

964
  return code;
×
965
}
966

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

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

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

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

982
  return TSDB_CODE_SUCCESS;
5,289✔
983
}
984

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

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

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

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

1000
  return TSDB_CODE_SUCCESS;
×
1001
}
1002

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

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

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

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

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

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

1027
  return TSDB_CODE_SUCCESS;
1,264✔
1028
}
1029

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

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

1041
  return TSDB_CODE_SUCCESS;
21,775✔
1042
}
1043

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

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

1056
  return TSDB_CODE_SUCCESS;
×
1057
}
1058

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

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

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

1078
  return TSDB_CODE_SUCCESS;
253✔
1079
}
1080

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

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

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

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

1102
  return TSDB_CODE_SUCCESS;
331✔
1103
}
1104

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

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

1116
  return TSDB_CODE_SUCCESS;
1,032✔
1117
}
1118

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

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

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

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

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

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

1161
  return TSDB_CODE_SUCCESS;
4,853✔
1162
}
1163

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

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

1208
#pragma GCC diagnostic pop
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc