querymsg.c 14.8 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

H
Hongze Cheng 已提交
16
#include "tmsg.h"
D
dapan1121 已提交
17
#include "queryInt.h"
D
dapan1121 已提交
18
#include "query.h"
D
catalog  
dapan1121 已提交
19
#include "trpc.h"
20
#include "systable.h"
D
dapan 已提交
21

S
Shengliang Guan 已提交
22 23 24
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-truncation"

D
dapan1121 已提交
25
int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallocFp)(int32_t)) = {0};
S
Shengliang Guan 已提交
26
int32_t (*queryProcessMsgRsp[TDMT_MAX])(void *output, char *msg, int32_t msgSize) = {0};
D
dapan 已提交
27

X
Xiaoyu Wang 已提交
28 29 30
int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) {
  memcpy(pOut->db, usedbRsp->db, TSDB_DB_FNAME_LEN);
  pOut->dbId = usedbRsp->uid;
D
dapan1121 已提交
31

wafwerar's avatar
wafwerar 已提交
32
  pOut->dbVgroup = taosMemoryCalloc(1, sizeof(SDBVgInfo));
X
Xiaoyu Wang 已提交
33 34 35 36 37 38
  if (NULL == pOut->dbVgroup) {
    return TSDB_CODE_TSC_OUT_OF_MEMORY;
  }

  pOut->dbVgroup->vgVersion = usedbRsp->vgVersion;
  pOut->dbVgroup->hashMethod = usedbRsp->hashMethod;
D
dapan1121 已提交
39 40 41 42 43

  if (usedbRsp->vgNum <= 0) {
    return TSDB_CODE_SUCCESS;
  }
  
X
Xiaoyu Wang 已提交
44 45 46 47 48 49 50 51
  pOut->dbVgroup->vgHash =
      taosHashInit(usedbRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
  if (NULL == pOut->dbVgroup->vgHash) {
    return TSDB_CODE_TSC_OUT_OF_MEMORY;
  }

  for (int32_t i = 0; i < usedbRsp->vgNum; ++i) {
    SVgroupInfo *pVgInfo = taosArrayGet(usedbRsp->pVgroupInfos, i);
D
dapan 已提交
52
    pOut->dbVgroup->numOfTable += pVgInfo->numOfTable;
X
Xiaoyu Wang 已提交
53 54 55 56 57 58 59 60
    if (0 != taosHashPut(pOut->dbVgroup->vgHash, &pVgInfo->vgId, sizeof(int32_t), pVgInfo, sizeof(SVgroupInfo))) {
      return TSDB_CODE_TSC_OUT_OF_MEMORY;
    }
  }

  return TSDB_CODE_SUCCESS;
}

D
dapan1121 已提交
61
int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
S
Shengliang Guan 已提交
62
  SBuildTableMetaInput *pInput = input;
D
dapan1121 已提交
63 64 65 66
  if (NULL == input || NULL == msg || NULL == msgLen) {
    return TSDB_CODE_TSC_INVALID_INPUT;
  }

S
Shengliang Guan 已提交
67 68
  STableInfoReq infoReq = {0};
  infoReq.header.vgId = pInput->vgId;
S
Shengliang Guan 已提交
69
  if (pInput->dbFName) {
S
Shengliang Guan 已提交
70
    tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
D
dapan1121 已提交
71
  }
S
Shengliang Guan 已提交
72
  tstrncpy(infoReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
D
dapan1121 已提交
73

S
Shengliang Guan 已提交
74
  int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
D
dapan1121 已提交
75
  void   *pBuf = (*mallcFp)(bufLen);
S
Shengliang Guan 已提交
76 77 78 79
  tSerializeSTableInfoReq(pBuf, bufLen, &infoReq);

  *msg = pBuf;
  *msgLen = bufLen;
D
dapan1121 已提交
80 81 82 83

  return TSDB_CODE_SUCCESS;
}

D
dapan1121 已提交
84
int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
S
Shengliang Guan 已提交
85 86
  SBuildUseDBInput *pInput = input;
  if (NULL == pInput || NULL == msg || NULL == msgLen) {
D
dapan1121 已提交
87 88 89
    return TSDB_CODE_TSC_INVALID_INPUT;
  }

S
Shengliang Guan 已提交
90
  SUseDbReq usedbReq = {0};
S
Shengliang Guan 已提交
91
  strncpy(usedbReq.db, pInput->db, sizeof(usedbReq.db));
S
Shengliang Guan 已提交
92
  usedbReq.db[sizeof(usedbReq.db) - 1] = 0;
S
Shengliang Guan 已提交
93
  usedbReq.vgVersion = pInput->vgVersion;
X
Xiaoyu Wang 已提交
94
  usedbReq.dbId = pInput->dbId;
D
dapan 已提交
95
  usedbReq.numOfTable = pInput->numOfTable;
D
dapan1121 已提交
96

S
Shengliang Guan 已提交
97
  int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
D
dapan1121 已提交
98
  void   *pBuf = (*mallcFp)(bufLen);
S
Shengliang Guan 已提交
99
  tSerializeSUseDbReq(pBuf, bufLen, &usedbReq);
D
dapan1121 已提交
100

S
Shengliang Guan 已提交
101 102
  *msg = pBuf;
  *msgLen = bufLen;
D
dapan1121 已提交
103

S
Shengliang Guan 已提交
104
  return TSDB_CODE_SUCCESS;
D
dapan1121 已提交
105 106
}

D
dapan1121 已提交
107
int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
D
dapan1121 已提交
108 109 110 111 112 113 114 115
  if (NULL == msg || NULL == msgLen) {
    return TSDB_CODE_TSC_INVALID_INPUT;
  }

  SQnodeListReq qnodeListReq = {0};
  qnodeListReq.rowNum = -1;

  int32_t bufLen = tSerializeSQnodeListReq(NULL, 0, &qnodeListReq);
D
dapan1121 已提交
116
  void   *pBuf = (*mallcFp)(bufLen);
D
dapan1121 已提交
117 118 119 120 121 122 123 124
  tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq);

  *msg = pBuf;
  *msgLen = bufLen;

  return TSDB_CODE_SUCCESS;
}

D
dapan1121 已提交
125
int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
D
dapan1121 已提交
126 127 128 129 130 131 132 133
  if (NULL == msg || NULL == msgLen) {
    return TSDB_CODE_TSC_INVALID_INPUT;
  }

  SDbCfgReq dbCfgReq = {0};
  strcpy(dbCfgReq.db, input);

  int32_t bufLen = tSerializeSDbCfgReq(NULL, 0, &dbCfgReq);
D
dapan1121 已提交
134
  void   *pBuf = (*mallcFp)(bufLen);
D
dapan1121 已提交
135 136 137 138 139 140 141
  tSerializeSDbCfgReq(pBuf, bufLen, &dbCfgReq);

  *msg = pBuf;
  *msgLen = bufLen;

  return TSDB_CODE_SUCCESS;
}
D
dapan1121 已提交
142

D
dapan1121 已提交
143
int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
D
dapan1121 已提交
144 145 146 147 148 149 150 151
  if (NULL == msg || NULL == msgLen) {
    return TSDB_CODE_TSC_INVALID_INPUT;
  }

  SUserIndexReq indexReq = {0};
  strcpy(indexReq.indexFName, input);

  int32_t bufLen = tSerializeSUserIndexReq(NULL, 0, &indexReq);
D
dapan1121 已提交
152
  void   *pBuf = (*mallcFp)(bufLen);
D
dapan1121 已提交
153 154 155 156 157 158 159 160
  tSerializeSUserIndexReq(pBuf, bufLen, &indexReq);

  *msg = pBuf;
  *msgLen = bufLen;

  return TSDB_CODE_SUCCESS;
}

D
dapan1121 已提交
161
int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
D
dapan1121 已提交
162 163 164 165 166 167
  if (NULL == msg || NULL == msgLen) {
    return TSDB_CODE_TSC_INVALID_INPUT;
  }

  SRetrieveFuncReq funcReq = {0};
  funcReq.numOfFuncs = 1;
D
dapan1121 已提交
168
  funcReq.ignoreCodeComment = true;
D
dapan1121 已提交
169 170 171 172
  funcReq.pFuncNames = taosArrayInit(1, strlen(input) + 1);
  taosArrayPush(funcReq.pFuncNames, input);

  int32_t bufLen = tSerializeSRetrieveFuncReq(NULL, 0, &funcReq);
D
dapan1121 已提交
173
  void   *pBuf = (*mallcFp)(bufLen);
D
dapan1121 已提交
174 175 176 177 178 179 180 181 182
  tSerializeSRetrieveFuncReq(pBuf, bufLen, &funcReq);

  taosArrayDestroy(funcReq.pFuncNames);

  *msg = pBuf;
  *msgLen = bufLen;

  return TSDB_CODE_SUCCESS;
}
D
dapan1121 已提交
183

D
dapan1121 已提交
184
int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
D
dapan 已提交
185 186 187 188 189 190 191 192
  if (NULL == msg || NULL == msgLen) {
    return TSDB_CODE_TSC_INVALID_INPUT;
  }

  SGetUserAuthReq req = {0};
  strncpy(req.user, input, sizeof(req.user));

  int32_t bufLen = tSerializeSGetUserAuthReq(NULL, 0, &req);
D
dapan1121 已提交
193
  void   *pBuf = (*mallcFp)(bufLen);
D
dapan 已提交
194 195 196 197 198 199 200 201 202
  tSerializeSGetUserAuthReq(pBuf, bufLen, &req);

  *msg = pBuf;
  *msgLen = bufLen;

  return TSDB_CODE_SUCCESS;
}


S
Shengliang Guan 已提交
203
int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) {
S
Shengliang Guan 已提交
204 205 206 207
  SUseDbOutput *pOut = output;
  SUseDbRsp     usedbRsp = {0};
  int32_t       code = -1;

D
dapan1121 已提交
208
  if (NULL == output || NULL == msg || msgSize <= 0) {
S
Shengliang Guan 已提交
209 210
    code = TSDB_CODE_TSC_INVALID_INPUT;
    goto PROCESS_USEDB_OVER;
D
dapan1121 已提交
211 212
  }

S
Shengliang Guan 已提交
213 214
  if (tDeserializeSUseDbRsp(msg, msgSize, &usedbRsp) != 0) {
    qError("invalid use db rsp msg, msgSize:%d", msgSize);
S
Shengliang Guan 已提交
215 216
    code = TSDB_CODE_INVALID_MSG;
    goto PROCESS_USEDB_OVER;
D
dapan1121 已提交
217 218
  }

S
Shengliang Guan 已提交
219 220
  if (usedbRsp.vgNum < 0) {
    qError("invalid db[%s] vgroup number[%d]", usedbRsp.db, usedbRsp.vgNum);
S
Shengliang Guan 已提交
221 222
    code = TSDB_CODE_TSC_INVALID_VALUE;
    goto PROCESS_USEDB_OVER;
D
dapan1121 已提交
223 224
  }

X
Xiaoyu Wang 已提交
225
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
226

S
Shengliang Guan 已提交
227
PROCESS_USEDB_OVER:
X
Xiaoyu Wang 已提交
228

S
Shengliang Guan 已提交
229 230 231
  if (code != 0) {
    if (pOut) {
      if (pOut->dbVgroup) taosHashCleanup(pOut->dbVgroup->vgHash);
wafwerar's avatar
wafwerar 已提交
232
      taosMemoryFreeClear(pOut->dbVgroup);
S
Shengliang Guan 已提交
233 234
    }
    qError("failed to process usedb rsp since %s", terrstr());
D
dapan1121 已提交
235
  }
S
Shengliang Guan 已提交
236

S
Shengliang Guan 已提交
237
  tFreeSUsedbRsp(&usedbRsp);
D
dapan1121 已提交
238 239 240
  return code;
}

S
Shengliang Guan 已提交
241
static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) {
D
dapan1121 已提交
242 243 244 245 246 247 248 249 250 251
  if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) {
    qError("invalid numOfTags[%d] in table meta rsp msg", pMetaMsg->numOfTags);
    return TSDB_CODE_TSC_INVALID_VALUE;
  }

  if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) {
    qError("invalid numOfColumns[%d] in table meta rsp msg", pMetaMsg->numOfColumns);
    return TSDB_CODE_TSC_INVALID_VALUE;
  }

S
Shengliang Guan 已提交
252
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
X
Xiaoyu Wang 已提交
253
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE) {
D
dapan1121 已提交
254 255 256 257 258 259 260 261 262 263 264 265 266 267
    qError("invalid tableType[%d] in table meta rsp msg", pMetaMsg->tableType);
    return TSDB_CODE_TSC_INVALID_VALUE;
  }

  if (pMetaMsg->sversion < 0) {
    qError("invalid sversion[%d] in table meta rsp msg", pMetaMsg->sversion);
    return TSDB_CODE_TSC_INVALID_VALUE;
  }

  if (pMetaMsg->tversion < 0) {
    qError("invalid tversion[%d] in table meta rsp msg", pMetaMsg->tversion);
    return TSDB_CODE_TSC_INVALID_VALUE;
  }

S
Shengliang Guan 已提交
268
  if (pMetaMsg->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
269
    qError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", pMetaMsg->pSchemas[0].colId);
D
dapan1121 已提交
270 271 272 273 274 275
    return TSDB_CODE_TSC_INVALID_VALUE;
  }

  return TSDB_CODE_SUCCESS;
}

S
Shengliang Guan 已提交
276
int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isSuperTable, STableMeta **pMeta) {
D
dapan1121 已提交
277 278
  int32_t total = msg->numOfColumns + msg->numOfTags;
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
S
Shengliang Guan 已提交
279

wafwerar's avatar
wafwerar 已提交
280
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize);
D
dapan1121 已提交
281 282 283 284
  if (NULL == pTableMeta) {
    qError("calloc size[%d] failed", metaSize);
    return TSDB_CODE_TSC_OUT_OF_MEMORY;
  }
D
dapan1121 已提交
285 286

  pTableMeta->vgId = isSuperTable ? 0 : msg->vgId;
D
dapan1121 已提交
287
  pTableMeta->tableType = isSuperTable ? TSDB_SUPER_TABLE : msg->tableType;
S
Shengliang Guan 已提交
288
  pTableMeta->uid = isSuperTable ? msg->suid : msg->tuid;
D
dapan1121 已提交
289 290 291 292
  pTableMeta->suid = msg->suid;
  pTableMeta->sversion = msg->sversion;
  pTableMeta->tversion = msg->tversion;

D
dapan1121 已提交
293 294 295 296
  if (isSuperTable) {
    qDebug("stable %s meta returned, suid:%" PRIx64, msg->stbName, pTableMeta->suid);
  }

D
dapan1121 已提交
297 298 299 300
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
  pTableMeta->tableInfo.precision = msg->precision;
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;

S
Shengliang Guan 已提交
301
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
D
dapan1121 已提交
302

S
Shengliang Guan 已提交
303
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
D
dapan1121 已提交
304 305 306 307 308 309 310
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
  }

  *pMeta = pTableMeta;
  return TSDB_CODE_SUCCESS;
}

S
Shengliang Guan 已提交
311
int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) {
D
dapan1121 已提交
312
  int32_t       code = 0;
S
Shengliang Guan 已提交
313 314 315 316 317 318
  STableMetaRsp metaRsp = {0};

  if (NULL == output || NULL == msg || msgSize <= 0) {
    code = TSDB_CODE_TSC_INVALID_INPUT;
    goto PROCESS_META_OVER;
  }
D
dapan1121 已提交
319

S
Shengliang Guan 已提交
320 321 322 323 324 325
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
    code = TSDB_CODE_INVALID_MSG;
    goto PROCESS_META_OVER;
  }

  code = queryConvertTableMetaMsg(&metaRsp);
D
dapan1121 已提交
326
  if (code != TSDB_CODE_SUCCESS) {
S
Shengliang Guan 已提交
327
    goto PROCESS_META_OVER;
D
dapan1121 已提交
328 329
  }

D
dapan1121 已提交
330
  if (0 != strcmp(metaRsp.dbFName, TSDB_INFORMATION_SCHEMA_DB) && !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
S
Shengliang Guan 已提交
331 332
    code = TSDB_CODE_TSC_INVALID_VALUE;
    goto PROCESS_META_OVER;
D
dapan1121 已提交
333 334
  }

S
Shengliang Guan 已提交
335 336 337
  STableMetaOutput *pOut = output;
  strcpy(pOut->dbFName, metaRsp.dbFName);
  pOut->dbId = metaRsp.dbId;
D
dapan1121 已提交
338

S
Shengliang Guan 已提交
339
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
D
dapan1121 已提交
340
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
D
dapan1121 已提交
341

S
Shengliang Guan 已提交
342 343
    strcpy(pOut->ctbName, metaRsp.tbName);
    strcpy(pOut->tbName, metaRsp.stbName);
D
dapan1121 已提交
344

S
Shengliang Guan 已提交
345 346 347 348 349 350
    pOut->ctbMeta.vgId = metaRsp.vgId;
    pOut->ctbMeta.tableType = metaRsp.tableType;
    pOut->ctbMeta.uid = metaRsp.tuid;
    pOut->ctbMeta.suid = metaRsp.suid;

    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
D
dapan1121 已提交
351
  } else {
D
dapan1121 已提交
352
    SET_META_TYPE_TABLE(pOut->metaType);
S
Shengliang Guan 已提交
353 354 355 356 357 358
    strcpy(pOut->tbName, metaRsp.tbName);
    code = queryCreateTableMetaFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
  }

PROCESS_META_OVER:
  if (code != 0) {
D
dapan1121 已提交
359
    qError("failed to process table meta rsp since %s", tstrerror(code));
D
dapan1121 已提交
360
  }
S
Shengliang Guan 已提交
361 362

  tFreeSTableMetaRsp(&metaRsp);
D
dapan1121 已提交
363 364 365
  return code;
}

D
dapan1121 已提交
366 367 368

int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) {
  SQnodeListRsp out = {0};
D
dapan 已提交
369
  int32_t       code = 0;
D
dapan1121 已提交
370 371 372

  if (NULL == output || NULL == msg || msgSize <= 0) {
    code = TSDB_CODE_TSC_INVALID_INPUT;
D
dapan 已提交
373
    return code;
D
dapan1121 已提交
374 375
  }

D
dapan1121 已提交
376
  out.qnodeList = (SArray *)output;
D
dapan1121 已提交
377 378 379
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
    code = TSDB_CODE_INVALID_MSG;
D
dapan 已提交
380
    return code;
D
dapan1121 已提交
381 382 383 384 385
  }

  return code;
}

D
dapan1121 已提交
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) {
  SDbCfgRsp out = {0};

  if (NULL == output || NULL == msg || msgSize <= 0) {
    return TSDB_CODE_TSC_INVALID_INPUT;
  }

  if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) {
    qError("tDeserializeSDbCfgRsp failed, msgSize:%d", msgSize);
    return TSDB_CODE_INVALID_MSG;
  }

  memcpy(output, &out, sizeof(out));

  return TSDB_CODE_SUCCESS;
}

D
dapan1121 已提交
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
int32_t queryProcessGetIndexRsp(void *output, char *msg, int32_t msgSize) {
  SUserIndexRsp out = {0};

  if (NULL == output || NULL == msg || msgSize <= 0) {
    return TSDB_CODE_TSC_INVALID_INPUT;
  }

  if (tDeserializeSUserIndexRsp(msg, msgSize, &out) != 0) {
    qError("tDeserializeSUserIndexRsp failed, msgSize:%d", msgSize);
    return TSDB_CODE_INVALID_MSG;
  }

  memcpy(output, &out, sizeof(out));

  return TSDB_CODE_SUCCESS;
}
D
dapan1121 已提交
419

D
dapan1121 已提交
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
  SRetrieveFuncRsp out = {0};

  if (NULL == output || NULL == msg || msgSize <= 0) {
    return TSDB_CODE_TSC_INVALID_INPUT;
  }

  if (tDeserializeSRetrieveFuncRsp(msg, msgSize, &out) != 0) {
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
    return TSDB_CODE_INVALID_MSG;
  }

  if (1 != out.numOfFuncs) {
    qError("invalid func num returned, numOfFuncs:%d", out.numOfFuncs);
    return TSDB_CODE_INVALID_MSG;
  }

  SFuncInfo * funcInfo = taosArrayGet(out.pFuncInfos, 0);

  memcpy(output, funcInfo, sizeof(*funcInfo));
  taosArrayDestroy(out.pFuncInfos);

  return TSDB_CODE_SUCCESS;
}

D
dapan 已提交
445 446 447 448 449 450 451 452 453 454 455 456 457 458
int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) {
  if (NULL == output || NULL == msg || msgSize <= 0) {
    return TSDB_CODE_TSC_INVALID_INPUT;
  }

  if (tDeserializeSGetUserAuthRsp(msg, msgSize, (SGetUserAuthRsp *)output) != 0) {
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
    return TSDB_CODE_INVALID_MSG;
  }

  return TSDB_CODE_SUCCESS;
}


459
void initQueryModuleMsgHandle() {
D
catalog  
dapan1121 已提交
460
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg;
D
dapan1121 已提交
461
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;
D
dapan1121 已提交
462
  queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)]     = queryBuildUseDbMsg;
D
dapan1121 已提交
463
  queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg;
D
dapan1121 已提交
464
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg;
D
dapan1121 已提交
465
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)]  = queryBuildGetIndexMsg;
D
dapan1121 已提交
466
  queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)]  = queryBuildRetrieveFuncMsg;
D
dapan 已提交
467 468
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)]  = queryBuildGetUserAuthMsg;
  
D
dapan1121 已提交
469

D
catalog  
dapan1121 已提交
470
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp;
D
dapan1121 已提交
471
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp;
D
dapan1121 已提交
472
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)]     = queryProcessUseDBRsp;
D
dapan1121 已提交
473
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp;
D
dapan1121 已提交
474
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp;
D
dapan1121 已提交
475
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_INDEX)]  = queryProcessGetIndexRsp;
D
dapan1121 已提交
476
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)]  = queryProcessRetrieveFuncRsp;
D
dapan 已提交
477
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)]  = queryProcessGetUserAuthRsp;
D
dapan 已提交
478 479
}

D
dapan1121 已提交
480
#pragma GCC diagnostic pop