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

taosdata / TDengine / #4720

08 Sep 2025 08:43AM UTC coverage: 58.139% (-0.6%) from 58.762%
#4720

push

travis-ci

web-flow
Merge pull request #32881 from taosdata/enh/add-new-windows-ci

fix(ci): update workflow reference to use new Windows CI YAML

133181 of 292179 branches covered (45.58%)

Branch coverage included in aggregate %.

201691 of 283811 relevant lines covered (71.07%)

5442780.71 hits per line

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

38.88
/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 "streamMsg.h"
19
#include "systable.h"
20
#include "tmsg.h"
21
#include "trpc.h"
22

23
#pragma GCC diagnostic push
24
#ifdef COMPILER_SUPPORTS_CXX13
25
#pragma GCC diagnostic ignored "-Wformat-truncation"
26
#endif
27

28
int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
29
                                   void *(*mallocFp)(int64_t)) = {0};
30
int32_t (*queryProcessMsgRsp[TDMT_MAX])(void *output, char *msg, int32_t msgSize) = {0};
31

32
int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) {
20,430✔
33
  QUERY_PARAM_CHECK(pOut);
20,430!
34
  QUERY_PARAM_CHECK(usedbRsp);
20,430!
35
  memcpy(pOut->db, usedbRsp->db, TSDB_DB_FNAME_LEN);
20,430✔
36
  pOut->dbId = usedbRsp->uid;
20,430✔
37

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

43
  pOut->dbVgroup->vgVersion = usedbRsp->vgVersion;
20,431✔
44
  pOut->dbVgroup->hashMethod = usedbRsp->hashMethod;
20,431✔
45
  pOut->dbVgroup->hashPrefix = usedbRsp->hashPrefix;
20,431✔
46
  pOut->dbVgroup->hashSuffix = usedbRsp->hashSuffix;
20,431✔
47
  pOut->dbVgroup->stateTs = usedbRsp->stateTs;
20,431✔
48
  pOut->dbVgroup->flags = usedbRsp->flags;
20,431✔
49

50
  qDebug("db:%s, get %d vgroup, vgVersion:%d, stateTs:%" PRId64, usedbRsp->db, usedbRsp->vgNum, usedbRsp->vgVersion,
20,431✔
51
         usedbRsp->stateTs);
52

53
  if (usedbRsp->vgNum <= 0) {
20,431✔
54
    return TSDB_CODE_SUCCESS;
1,871✔
55
  }
56

57
  pOut->dbVgroup->vgHash =
37,119✔
58
      taosHashInit(usedbRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
18,560✔
59
  if (NULL == pOut->dbVgroup->vgHash) {
18,559!
60
    return terrno;
×
61
  }
62

63
  for (int32_t i = 0; i < usedbRsp->vgNum; ++i) {
142,578✔
64
    SVgroupInfo *pVgInfo = taosArrayGet(usedbRsp->pVgroupInfos, i);
124,018✔
65
    pOut->dbVgroup->numOfTable += pVgInfo->numOfTable;
124,017✔
66
    qDebug("db:%s, vgId:%d, epNum:%d, current ep:%s:%u", usedbRsp->db, pVgInfo->vgId, pVgInfo->epSet.numOfEps,
124,017✔
67
           pVgInfo->epSet.eps[pVgInfo->epSet.inUse].fqdn, pVgInfo->epSet.eps[pVgInfo->epSet.inUse].port);
68
    if (0 != taosHashPut(pOut->dbVgroup->vgHash, &pVgInfo->vgId, sizeof(int32_t), pVgInfo, sizeof(SVgroupInfo))) {
124,017!
69
      return terrno;
×
70
    }
71
  }
72

73
  return TSDB_CODE_SUCCESS;
18,560✔
74
}
75

76
int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
12,264✔
77
                                  void *(*mallcFp)(int64_t)) {
78
  QUERY_PARAM_CHECK(input);
12,264!
79
  QUERY_PARAM_CHECK(msg);
12,264!
80
  QUERY_PARAM_CHECK(msgLen);
12,264!
81
  SBuildTableInput *pInput = input;
12,264✔
82

83
  STableInfoReq infoReq = {0};
12,264✔
84
  infoReq.option = pInput->option;
12,264✔
85
  infoReq.header.vgId = pInput->vgId;
12,264✔
86
  infoReq.autoCreateCtb = pInput->autoCreateCtb;
12,264✔
87

88
  if (pInput->dbFName) {
12,264✔
89
    tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
12,261✔
90
  }
91
  tstrncpy(infoReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
12,264✔
92

93
  int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
12,264✔
94
  void   *pBuf = (*mallcFp)(bufLen);
12,263✔
95
  if (NULL == pBuf) {
12,267!
96
    return terrno;
×
97
  }
98
  int32_t ret = tSerializeSTableInfoReq(pBuf, bufLen, &infoReq);
12,267✔
99
  if (ret < 0) return ret;
12,268!
100

101
  *msg = pBuf;
12,268✔
102
  *msgLen = bufLen;
12,268✔
103

104
  return TSDB_CODE_SUCCESS;
12,268✔
105
}
106

107
int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
18,375✔
108
  QUERY_PARAM_CHECK(input);
18,375!
109
  QUERY_PARAM_CHECK(msg);
18,375!
110
  QUERY_PARAM_CHECK(msgLen);
18,375!
111
  SBuildUseDBInput *pInput = input;
18,375✔
112

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

121
  int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
18,375✔
122
  void   *pBuf = (*mallcFp)(bufLen);
18,375✔
123
  if (NULL == pBuf) {
18,376!
124
    return terrno;
×
125
  }
126
  int32_t ret = tSerializeSUseDbReq(pBuf, bufLen, &usedbReq);
18,376✔
127
  if (ret < 0) return ret;
18,376!
128

129
  *msg = pBuf;
18,376✔
130
  *msgLen = bufLen;
18,376✔
131

132
  return TSDB_CODE_SUCCESS;
18,376✔
133
}
134

135
int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
3✔
136
  QUERY_PARAM_CHECK(msg);
3!
137
  QUERY_PARAM_CHECK(msgLen);
3!
138

139
  SQnodeListReq qnodeListReq = {0};
3✔
140
  qnodeListReq.rowNum = -1;
3✔
141

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

148
  int32_t ret = tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq);
3✔
149
  if (ret < 0) return ret;
3!
150

151
  *msg = pBuf;
3✔
152
  *msgLen = bufLen;
3✔
153

154
  return TSDB_CODE_SUCCESS;
3✔
155
}
156

157
int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
3✔
158
  QUERY_PARAM_CHECK(msg);
3!
159
  QUERY_PARAM_CHECK(msgLen);
3!
160

161
  SDnodeListReq dnodeListReq = {0};
3✔
162
  dnodeListReq.rowNum = -1;
3✔
163

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

172
  *msg = pBuf;
3✔
173
  *msgLen = bufLen;
3✔
174

175
  return TSDB_CODE_SUCCESS;
3✔
176
}
177

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

182
  SServerVerReq req = {0};
3✔
183

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

192
  *msg = pBuf;
3✔
193
  *msgLen = bufLen;
3✔
194

195
  return TSDB_CODE_SUCCESS;
3✔
196
}
197

198
int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
1,700✔
199
  QUERY_PARAM_CHECK(input);
1,700!
200
  QUERY_PARAM_CHECK(msg);
1,700!
201
  QUERY_PARAM_CHECK(msgLen);
1,700!
202

203
  SDbCfgReq dbCfgReq = {0};
1,700✔
204
  tstrncpy(dbCfgReq.db, input, TSDB_DB_FNAME_LEN);
1,700✔
205

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

214
  *msg = pBuf;
1,700✔
215
  *msgLen = bufLen;
1,700✔
216

217
  return TSDB_CODE_SUCCESS;
1,700✔
218
}
219

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

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

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

236
  *msg = pBuf;
3✔
237
  *msgLen = bufLen;
3✔
238

239
  return TSDB_CODE_SUCCESS;
3✔
240
}
241

242
int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
11✔
243
                                  void *(*mallcFp)(int64_t)) {
244
  QUERY_PARAM_CHECK(input);
11!
245
  QUERY_PARAM_CHECK(msg);
11!
246
  QUERY_PARAM_CHECK(msgLen);
11!
247

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

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

272
  taosArrayDestroy(funcReq.pFuncNames);
11✔
273

274
  *msg = pBuf;
11✔
275
  *msgLen = bufLen;
11✔
276

277
  return TSDB_CODE_SUCCESS;
11✔
278
}
279

280
int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
1,892✔
281
  QUERY_PARAM_CHECK(input);
1,892!
282
  QUERY_PARAM_CHECK(msg);
1,892!
283
  QUERY_PARAM_CHECK(msgLen);
1,892!
284

285
  SGetUserAuthReq req = {0};
1,892✔
286
  tstrncpy(req.user, input, TSDB_USER_LEN);
1,892✔
287

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

296
  *msg = pBuf;
1,895✔
297
  *msgLen = bufLen;
1,895✔
298

299
  return TSDB_CODE_SUCCESS;
1,895✔
300
}
301

302
int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
3✔
303
  QUERY_PARAM_CHECK(input);
3!
304
  QUERY_PARAM_CHECK(msg);
3!
305
  QUERY_PARAM_CHECK(msgLen);
3!
306

307
  STableIndexReq indexReq = {0};
3✔
308
  tstrncpy(indexReq.tbFName, input, TSDB_TABLE_FNAME_LEN);
3✔
309

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

318
  *msg = pBuf;
3✔
319
  *msgLen = bufLen;
3✔
320

321
  return TSDB_CODE_SUCCESS;
3✔
322
}
323

324
int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
81✔
325
  QUERY_PARAM_CHECK(input);
81!
326
  QUERY_PARAM_CHECK(msg);
81!
327
  QUERY_PARAM_CHECK(msgLen);
81!
328

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

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

343
  *msg = pBuf;
81✔
344
  *msgLen = bufLen;
81✔
345

346
  return TSDB_CODE_SUCCESS;
81✔
347
}
348

349
int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
3,542✔
350
  QUERY_PARAM_CHECK(input);
3,542!
351
  QUERY_PARAM_CHECK(msg);
3,542!
352
  QUERY_PARAM_CHECK(msgLen);
3,542!
353

354
  SViewMetaReq req = {0};
3,542✔
355
  tstrncpy(req.fullname, input, TSDB_VIEW_FNAME_LEN);
3,542✔
356

357
  int32_t bufLen = tSerializeSViewMetaReq(NULL, 0, &req);
3,542✔
358
  void   *pBuf = (*mallcFp)(bufLen);
3,547✔
359
  if (NULL == pBuf) {
3,546!
360
    return terrno;
×
361
  }
362
  int32_t ret = tSerializeSViewMetaReq(pBuf, bufLen, &req);
3,546✔
363
  if (ret < 0) return ret;
3,546!
364

365
  *msg = pBuf;
3,546✔
366
  *msgLen = bufLen;
3,546✔
367

368
  return TSDB_CODE_SUCCESS;
3,546✔
369
}
370

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

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

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

388
  *msg = pBuf;
×
389
  *msgLen = bufLen;
×
390
  return TSDB_CODE_SUCCESS;
×
391
}
392

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

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

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

412
  *msg = pBuf;
×
413
  *msgLen = bufLen;
×
414
  return TSDB_CODE_SUCCESS;
×
415
}
416

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

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

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

431
  *msg = pBuf;
×
432
  *msgLen = len;
×
433
  return TSDB_CODE_SUCCESS;
×
434
}
435

436

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

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

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

454
  *msg = pBuf;
×
455
  *msgLen = bufLen;
×
456

457
  return TSDB_CODE_SUCCESS;
×
458
}
459

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

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

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

477
  *msg = pBuf;
×
478
  *msgLen = bufLen;
×
479

480
  return TSDB_CODE_SUCCESS;
×
481
}
482

483
int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) {
18,363✔
484
  SUseDbOutput *pOut = output;
18,363✔
485
  SUseDbRsp     usedbRsp = {0};
18,363✔
486
  int32_t       code = -1;
18,363✔
487

488
  if (NULL == output || NULL == msg || msgSize <= 0) {
18,363!
489
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
490
    qError("invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
491
    goto PROCESS_USEDB_OVER;
×
492
  }
493

494
  if (tDeserializeSUseDbRsp(msg, msgSize, &usedbRsp) != 0) {
18,363!
495
    qError("invalid use db rsp msg, msgSize:%d", msgSize);
×
496
    code = TSDB_CODE_INVALID_MSG;
×
497
    goto PROCESS_USEDB_OVER;
×
498
  }
499

500
  if (usedbRsp.vgNum < 0) {
18,363!
501
    qError("invalid db[%s] vgroup number[%d]", usedbRsp.db, usedbRsp.vgNum);
×
502
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
503
    goto PROCESS_USEDB_OVER;
×
504
  }
505

506
  qTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum);
18,363✔
507
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
141,133✔
508
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
122,770✔
509
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
122,770✔
510
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
424,950✔
511
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
302,180✔
512
    }
513
  }
514

515
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
18,363✔
516

517
PROCESS_USEDB_OVER:
18,363✔
518

519
  if (code != 0) {
18,363!
520
    if (pOut) {
×
521
      if (pOut->dbVgroup) taosHashCleanup(pOut->dbVgroup->vgHash);
×
522
      taosMemoryFreeClear(pOut->dbVgroup);
×
523
    }
524
    qError("failed to process usedb rsp since %s", terrstr());
×
525
  }
526

527
  tFreeSUsedbRsp(&usedbRsp);
18,363✔
528
  return code;
18,363✔
529
}
530

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

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

543
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
9,184✔
544
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
1,144✔
545
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
59!
546
    qError("invalid tableType[%d] in table meta rsp msg", pMetaMsg->tableType);
×
547
    return TSDB_CODE_TSC_INVALID_VALUE;
×
548
  }
549

550
  if (pMetaMsg->sversion < 0) {
9,184!
551
    qError("invalid sversion[%d] in table meta rsp msg", pMetaMsg->sversion);
×
552
    return TSDB_CODE_TSC_INVALID_VALUE;
×
553
  }
554

555
  if (pMetaMsg->tversion < 0) {
9,184!
556
    qError("invalid tversion[%d] in table meta rsp msg", pMetaMsg->tversion);
×
557
    return TSDB_CODE_TSC_INVALID_VALUE;
×
558
  }
559

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

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

570
  return TSDB_CODE_SUCCESS;
9,184✔
571
}
572

573
int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) {
41,319✔
574
  QUERY_PARAM_CHECK(msg);
41,319!
575
  QUERY_PARAM_CHECK(pMeta);
41,319!
576
  pMeta->vgId = msg->vgId;
41,319✔
577
  pMeta->tableType = msg->tableType;
41,319✔
578
  pMeta->uid = msg->tuid;
41,319✔
579
  pMeta->suid = msg->suid;
41,319✔
580

581
  qDebug("ctb:%s, uid:0x%" PRIx64 " meta returned, type:%d vgId:%d db:%s suid:%" PRIx64, msg->tbName, pMeta->uid,
41,319✔
582
         pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid);
583

584
  return TSDB_CODE_SUCCESS;
41,321✔
585
}
586

587
int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta) {
31✔
588
  QUERY_PARAM_CHECK(msg);
31!
589
  QUERY_PARAM_CHECK(pMeta);
31!
590
  QUERY_PARAM_CHECK(msg->pColRefs);
31!
591

592
  int32_t pColRefSize = sizeof(SColRef) * msg->numOfColRefs;
31✔
593

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

600
  pTableMeta->vgId = msg->vgId;
31✔
601
  pTableMeta->tableType = msg->tableType;
31✔
602
  pTableMeta->uid = msg->tuid;
31✔
603
  pTableMeta->suid = msg->suid;
31✔
604
  pTableMeta->numOfColRefs = msg->numOfColRefs;
31✔
605
  pTableMeta->rversion = msg->rversion;
31✔
606

607
  pTableMeta->colRef = (SColRef *)((char *)pTableMeta + sizeof(SVCTableMeta));
31✔
608
  memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
31✔
609

610
  qDebug("ctable %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s suid %" PRIx64, msg->tbName, (pTableMeta)->uid,
31✔
611
         (pTableMeta)->tableType, (pTableMeta)->vgId, msg->dbFName, (pTableMeta)->suid);
612

613
  *pMeta = pTableMeta;
31✔
614
  return TSDB_CODE_SUCCESS;
31✔
615
}
616

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

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

633
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
12,193✔
634
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
12,193✔
635
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
12,193✔
636
  pTableMeta->suid = msg->suid;
12,193✔
637
  pTableMeta->sversion = msg->sversion;
12,193✔
638
  pTableMeta->tversion = msg->tversion;
12,193✔
639
  pTableMeta->rversion = msg->rversion;
12,193✔
640
  if (msg->virtualStb) {
12,193✔
641
    pTableMeta->virtualStb = 1;
27✔
642
    pTableMeta->numOfColRefs = 0;
27✔
643
  } else {
644
    if (msg->tableType == TSDB_VIRTUAL_CHILD_TABLE && isStb) {
12,166!
645
      pTableMeta->virtualStb = 1;
30✔
646
      pTableMeta->numOfColRefs = 0;
30✔
647
    } else {
648
      pTableMeta->virtualStb = 0;
12,136✔
649
      pTableMeta->numOfColRefs = msg->numOfColRefs;
12,136✔
650
    }
651
  }
652

653
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
12,193✔
654
  pTableMeta->tableInfo.precision = msg->precision;
12,193✔
655
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
12,193✔
656

657
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
12,193✔
658
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
12,193✔
659
    pTableMeta->schemaExt = pSchemaExt;
11,553✔
660
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
11,553✔
661
  } else {
662
    pTableMeta->schemaExt = NULL;
640✔
663
  }
664

665
  if (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) {
12,193!
666
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
30✔
667
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
30✔
668
  } else {
669
    pTableMeta->colRef = NULL;
12,162✔
670
  }
671

672
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
12,192!
673
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
280,114✔
674
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
267,922✔
675
    if (hasPK && (i > 0)) {
267,922✔
676
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
61✔
677
        ++pTableMeta->tableInfo.numOfPKs;
48✔
678
      } else {
679
        hasPK = false;
13✔
680
      }
681
    }
682
  }
683

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

691
  *pMeta = pTableMeta;
12,192✔
692
  return TSDB_CODE_SUCCESS;
12,192✔
693
}
694

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

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

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

722
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
×
723
  pTableMeta->tableInfo.precision = msg->precision;
×
724
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
×
725

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

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

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

753
  char *pTbName = (char *)pTableMeta + metaSize + schemaExtSize + pColRefSize;
×
754
  tstrncpy(pTbName, msg->tbName, tbNameSize);
×
755

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

763
  *pMeta = pTableMeta;
×
764
  return TSDB_CODE_SUCCESS;
×
765
}
766

767
int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) {
9,184✔
768
  int32_t       code = 0;
9,184✔
769
  STableMetaRsp metaRsp = {0};
9,184✔
770

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

777
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
9,184!
778
    code = TSDB_CODE_INVALID_MSG;
×
779
    goto PROCESS_META_OVER;
×
780
  }
781

782
  code = queryConvertTableMetaMsg(&metaRsp);
9,184✔
783
  if (code != TSDB_CODE_SUCCESS) {
9,184!
784
    goto PROCESS_META_OVER;
×
785
  }
786

787
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
9,184!
788
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
8,610!
789
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
790
    goto PROCESS_META_OVER;
×
791
  }
792

793
  STableMetaOutput *pOut = output;
9,184✔
794
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
9,184✔
795
  pOut->dbId = metaRsp.dbId;
9,184✔
796

797
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
9,184✔
798
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
1,355✔
799

800
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
1,355✔
801
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
1,355✔
802

803
    pOut->ctbMeta.vgId = metaRsp.vgId;
1,355✔
804
    pOut->ctbMeta.tableType = metaRsp.tableType;
1,355✔
805
    pOut->ctbMeta.uid = metaRsp.tuid;
1,355✔
806
    pOut->ctbMeta.suid = metaRsp.suid;
1,355✔
807

808
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
1,355✔
809
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
7,829✔
810
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
30✔
811

812
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
30✔
813
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
30✔
814

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

826
PROCESS_META_OVER:
9,183✔
827
  if (code != 0) {
9,183!
828
    qError("failed to process table meta rsp since %s", tstrerror(code));
×
829
  }
830

831
  tFreeSTableMetaRsp(&metaRsp);
9,183✔
832
  return code;
9,184✔
833
}
834

835
static int32_t queryProcessTableNameRsp(void *output, char *msg, int32_t msgSize) {
×
836
  int32_t       code = 0;
×
837
  STableMetaRsp metaRsp = {0};
×
838

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

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

850
  code = queryConvertTableMetaMsg(&metaRsp);
×
851
  if (code != TSDB_CODE_SUCCESS) {
×
852
    goto PROCESS_NAME_OVER;
×
853
  }
854

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

861
  STableMetaOutput *pOut = output;
×
862
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
×
863
  pOut->dbId = metaRsp.dbId;
×
864

865
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
×
866
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
×
867

868
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
869
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
×
870

871
    pOut->ctbMeta.vgId = metaRsp.vgId;
×
872
    pOut->ctbMeta.tableType = metaRsp.tableType;
×
873
    pOut->ctbMeta.uid = metaRsp.tuid;
×
874
    pOut->ctbMeta.suid = metaRsp.suid;
×
875

876
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
×
877
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
×
878
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
879

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

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

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

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

900
  tFreeSTableMetaRsp(&metaRsp);
×
901
  return code;
×
902
}
903

904
int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) {
3✔
905
  SQnodeListRsp out = {0};
3✔
906
  int32_t       code = 0;
3✔
907

908
  if (NULL == output || NULL == msg || msgSize <= 0) {
3!
909
    qError("queryProcessQnodeListRsp: 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
  out.qnodeList = (SArray *)output;
3✔
915
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
3!
916
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
×
917
    code = TSDB_CODE_INVALID_MSG;
×
918
    return code;
×
919
  }
920

921
  return code;
3✔
922
}
923

924
int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) {
3✔
925
  SDnodeListRsp out = {0};
3✔
926
  int32_t       code = 0;
3✔
927

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

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

940
  *(SArray **)output = out.dnodeList;
3✔
941

942
  return code;
3✔
943
}
944

945
int32_t queryProcessGetSerVerRsp(void *output, char *msg, int32_t msgSize) {
3✔
946
  SServerVerRsp out = {0};
3✔
947
  int32_t       code = 0;
3✔
948

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

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

961
  *(char **)output = taosStrdup(out.ver);
3!
962
  if (NULL == *(char **)output) {
3!
963
    return terrno;
×
964
  }
965

966
  return code;
3✔
967
}
968

969
int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) {
1,687✔
970
  SDbCfgRsp out = {0};
1,687✔
971

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

977
  if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) {
1,691!
978
    qError("tDeserializeSDbCfgRsp failed, msgSize:%d, dbCfgRsp:%lu", msgSize, sizeof(out));
×
979
    return TSDB_CODE_INVALID_MSG;
×
980
  }
981

982
  memcpy(output, &out, sizeof(out));
1,690✔
983

984
  return TSDB_CODE_SUCCESS;
1,690✔
985
}
986

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

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

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

1000
  memcpy(output, &out, sizeof(out));
×
1001

1002
  return TSDB_CODE_SUCCESS;
×
1003
}
1004

1005
int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
11✔
1006
  SRetrieveFuncRsp out = {0};
11✔
1007

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

1013
  if (tDeserializeSRetrieveFuncRsp(msg, msgSize, &out) != 0) {
11!
1014
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
×
1015
    return TSDB_CODE_INVALID_MSG;
×
1016
  }
1017

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

1023
  SFuncInfo *funcInfo = taosArrayGet(out.pFuncInfos, 0);
11✔
1024

1025
  memcpy(output, funcInfo, sizeof(*funcInfo));
11✔
1026
  taosArrayDestroy(out.pFuncInfos);
11✔
1027
  taosArrayDestroy(out.pFuncExtraInfos);
11✔
1028

1029
  return TSDB_CODE_SUCCESS;
11✔
1030
}
1031

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

1038
  if (tDeserializeSGetUserAuthRsp(msg, msgSize, (SGetUserAuthRsp *)output) != 0) {
1,894!
1039
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
1040
    return TSDB_CODE_INVALID_MSG;
×
1041
  }
1042

1043
  return TSDB_CODE_SUCCESS;
1,894✔
1044
}
1045

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

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

1058
  return TSDB_CODE_SUCCESS;
3✔
1059
}
1060

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

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

1078
  *(STableCfgRsp **)output = out;
81✔
1079

1080
  return TSDB_CODE_SUCCESS;
81✔
1081
}
1082

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

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

1100
  qDebugL("view meta recved, dbFName:%s, view:%s, querySQL:%s", out->dbFName, out->name, out->querySql);
1!
1101

1102
  *(SViewMetaRsp **)output = out;
1✔
1103

1104
  return TSDB_CODE_SUCCESS;
1✔
1105
}
1106

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

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

1118
  return TSDB_CODE_SUCCESS;
×
1119
}
1120

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

1127
  if (tDeserializeSStreamProgressRsp(msg, msgSize, output) != 0) {
×
1128
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1129
    return TSDB_CODE_INVALID_MSG;
×
1130
  }
1131
  return TSDB_CODE_SUCCESS;
×
1132
}
1133

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

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

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

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

1163
  return TSDB_CODE_SUCCESS;
×
1164
}
1165

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

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

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

© 2025 Coveralls, Inc