You need to sign in or sign up before continuing.
clientMsgHandler.c 14.3 KB
Newer Older
H
Haojun Liao 已提交
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/>.
 */

L
Liu Jicong 已提交
16
#include "catalog.h"
H
Haojun Liao 已提交
17
#include "clientInt.h"
18
#include "clientLog.h"
L
Liu Jicong 已提交
19
#include "os.h"
D
dapan1121 已提交
20
#include "query.h"
L
Liu Jicong 已提交
21 22
#include "tdef.h"
#include "tname.h"
H
Haojun Liao 已提交
23

H
Haojun Liao 已提交
24 25 26 27 28
static void setErrno(SRequestObj* pRequest, int32_t code) {
  pRequest->code = code;
  terrno = code;
}

D
dapan1121 已提交
29
int32_t genericRspCallback(void* param, SDataBuf* pMsg, int32_t code) {
30
  SRequestObj* pRequest = param;
H
Haojun Liao 已提交
31 32
  setErrno(pRequest, code);

33 34 35 36
  if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) {
    removeMeta(pRequest->pTscObj, pRequest->targetTableList);
  }

dengyihao's avatar
dengyihao 已提交
37
  taosMemoryFree(pMsg->pEpSet);
wafwerar's avatar
wafwerar 已提交
38
  taosMemoryFree(pMsg->pData);
39 40 41 42 43
  if (pRequest->body.queryFp != NULL) {
    pRequest->body.queryFp(pRequest->body.param, pRequest, code);
  } else {
    tsem_post(&pRequest->body.rspSem);
  }
H
Haojun Liao 已提交
44
  return code;
45 46
}

D
dapan1121 已提交
47
int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) {
48
  SRequestObj* pRequest = param;
H
Haojun Liao 已提交
49
  if (code != TSDB_CODE_SUCCESS) {
dengyihao's avatar
dengyihao 已提交
50
    taosMemoryFree(pMsg->pEpSet);
wafwerar's avatar
wafwerar 已提交
51
    taosMemoryFree(pMsg->pData);
H
Haojun Liao 已提交
52
    setErrno(pRequest, code);
53
    tsem_post(&pRequest->body.rspSem);
H
Haojun Liao 已提交
54 55
    return code;
  }
56

S
Shengliang Guan 已提交
57
  STscObj* pTscObj = pRequest->pTscObj;
H
Haojun Liao 已提交
58

S
Shengliang Guan 已提交
59 60
  SConnectRsp connectRsp = {0};
  tDeserializeSConnectRsp(pMsg->pData, pMsg->len, &connectRsp);
dengyihao's avatar
dengyihao 已提交
61 62 63 64 65

  int32_t now = taosGetTimestampSec();
  int32_t delta = abs(now - connectRsp.svrTimestamp);
  if (delta > timestampDeltaLimit) {
    code = TSDB_CODE_TIME_UNSYNCED;
dengyihao's avatar
dengyihao 已提交
66
    tscError("time diff:%ds is too big", delta);
dengyihao's avatar
dengyihao 已提交
67
    taosMemoryFree(pMsg->pEpSet);
dengyihao's avatar
dengyihao 已提交
68 69 70 71 72 73
    taosMemoryFree(pMsg->pData);
    setErrno(pRequest, code);
    tsem_post(&pRequest->body.rspSem);
    return code;
  }

L
Liu Jicong 已提交
74 75
  /*assert(connectRsp.epSet.numOfEps > 0);*/
  if (connectRsp.epSet.numOfEps == 0) {
dengyihao's avatar
dengyihao 已提交
76
    taosMemoryFree(pMsg->pEpSet);
L
Liu Jicong 已提交
77 78 79 80 81
    taosMemoryFree(pMsg->pData);
    setErrno(pRequest, TSDB_CODE_MND_APP_ERROR);
    tsem_post(&pRequest->body.rspSem);
    return code;
  }
H
Haojun Liao 已提交
82

D
dapan1121 已提交
83
  if (connectRsp.dnodeNum == 1) {
dengyihao's avatar
dengyihao 已提交
84 85 86 87
    SEpSet srcEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
    SEpSet dstEpSet = connectRsp.epSet;
    rpcSetDefaultAddr(pTscObj->pAppInfo->pTransporter, srcEpSet.eps[srcEpSet.inUse].fqdn,
                      dstEpSet.eps[dstEpSet.inUse].fqdn);
D
dapan1121 已提交
88
  } else if (connectRsp.dnodeNum > 1 && !isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, &connectRsp.epSet)) {
D
dapan1121 已提交
89
    SEpSet* pOrig = &pTscObj->pAppInfo->mgmtEp.epSet;
90 91 92 93 94
    SEp*    pOrigEp = &pOrig->eps[pOrig->inUse];
    SEp*    pNewEp = &connectRsp.epSet.eps[connectRsp.epSet.inUse];
    tscDebug("mnode epset updated from %d/%d=>%s:%d to %d/%d=>%s:%d in connRsp", pOrig->inUse, pOrig->numOfEps,
             pOrigEp->fqdn, pOrigEp->port, connectRsp.epSet.inUse, connectRsp.epSet.numOfEps, pNewEp->fqdn,
             pNewEp->port);
S
Shengliang Guan 已提交
95
    updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &connectRsp.epSet);
96 97
  }

S
Shengliang Guan 已提交
98
  for (int32_t i = 0; i < connectRsp.epSet.numOfEps; ++i) {
S
Shengliang Guan 已提交
99
    tscDebug("0x%" PRIx64 " epSet.fqdn[%d]:%s port:%d, connObj:0x%" PRIx64, pRequest->requestId, i,
D
dapan1121 已提交
100
             connectRsp.epSet.eps[i].fqdn, connectRsp.epSet.eps[i].port, pTscObj->id);
H
Haojun Liao 已提交
101 102
  }

103
  pTscObj->sysInfo = connectRsp.sysInfo;
S
Shengliang Guan 已提交
104 105
  pTscObj->connId = connectRsp.connId;
  pTscObj->acctId = connectRsp.acctId;
D
dapan1121 已提交
106 107
  tstrncpy(pTscObj->sVer, connectRsp.sVer, tListLen(pTscObj->sVer));
  tstrncpy(pTscObj->sDetailVer, connectRsp.sDetailVer, tListLen(pTscObj->sDetailVer));
H
Haojun Liao 已提交
108 109

  // update the appInstInfo
S
Shengliang Guan 已提交
110
  pTscObj->pAppInfo->clusterId = connectRsp.clusterId;
H
Haojun Liao 已提交
111

L
Liu Jicong 已提交
112
  pTscObj->connType = connectRsp.connType;
113

D
dapan1121 已提交
114
  hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType);
L
Liu Jicong 已提交
115

116
  //  pRequest->body.resInfo.pRspMsg = pMsg->pData;
S
Shengliang Guan 已提交
117
  tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId,
118
           pTscObj->pAppInfo->numOfConns);
119

wafwerar's avatar
wafwerar 已提交
120
  taosMemoryFree(pMsg->pData);
dengyihao's avatar
dengyihao 已提交
121
  taosMemoryFree(pMsg->pEpSet);
122
  tsem_post(&pRequest->body.rspSem);
123 124
  return 0;
}
H
Haojun Liao 已提交
125

L
Liu Jicong 已提交
126
SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pRequest) {
wafwerar's avatar
wafwerar 已提交
127
  SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
128

H
Haojun Liao 已提交
129
  pMsgSendInfo->requestObjRefId = pRequest->self;
L
Liu Jicong 已提交
130 131 132
  pMsgSendInfo->requestId = pRequest->requestId;
  pMsgSendInfo->param = pRequest;
  pMsgSendInfo->msgType = pRequest->type;
D
dapan1121 已提交
133
  pMsgSendInfo->target.type = TARGET_TYPE_MNODE;
134

H
Haojun Liao 已提交
135 136
  assert(pRequest != NULL);
  pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
H
Haojun Liao 已提交
137
  pMsgSendInfo->fp = getMsgRspHandle(pRequest->type);
138
  return pMsgSendInfo;
139 140
}

D
dapan1121 已提交
141
int32_t processCreateDbRsp(void* param, SDataBuf* pMsg, int32_t code) {
H
Haojun Liao 已提交
142
  // todo rsp with the vnode id list
143
  SRequestObj* pRequest = param;
wafwerar's avatar
wafwerar 已提交
144
  taosMemoryFree(pMsg->pData);
dengyihao's avatar
dengyihao 已提交
145
  taosMemoryFree(pMsg->pEpSet);
X
Xiaoyu Wang 已提交
146 147 148
  if (code != TSDB_CODE_SUCCESS) {
    setErrno(pRequest, code);
  }
149 150 151 152 153 154

  if (pRequest->body.queryFp) {
    pRequest->body.queryFp(pRequest->body.param, pRequest, code);
  } else {
    tsem_post(&pRequest->body.rspSem);
  }
X
Xiaoyu Wang 已提交
155
  return code;
H
Haojun Liao 已提交
156
}
H
Haojun Liao 已提交
157

D
dapan1121 已提交
158
int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) {
H
Haojun Liao 已提交
159 160
  SRequestObj* pRequest = param;

D
dapan1121 已提交
161 162 163
  if (TSDB_CODE_MND_DB_NOT_EXIST == code) {
    SUseDbRsp usedbRsp = {0};
    tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp);
L
Liu Jicong 已提交
164
    struct SCatalog* pCatalog = NULL;
D
dapan1121 已提交
165 166

    if (usedbRsp.vgVersion >= 0) {
167
      uint64_t clusterId = pRequest->pTscObj->pAppInfo->clusterId;
dengyihao's avatar
dengyihao 已提交
168
      int32_t  code1 = catalogGetHandle(clusterId, &pCatalog);
169
      if (code1 != TSDB_CODE_SUCCESS) {
dengyihao's avatar
dengyihao 已提交
170 171
        tscWarn("0x%" PRIx64 "catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->requestId, clusterId,
                tstrerror(code1));
D
dapan1121 已提交
172 173 174 175 176
      } else {
        catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid);
      }
    }

L
Liu Jicong 已提交
177
    tFreeSUsedbRsp(&usedbRsp);
D
dapan1121 已提交
178 179
  }

H
Haojun Liao 已提交
180
  if (code != TSDB_CODE_SUCCESS) {
wafwerar's avatar
wafwerar 已提交
181
    taosMemoryFree(pMsg->pData);
dengyihao's avatar
dengyihao 已提交
182
    taosMemoryFree(pMsg->pEpSet);
H
Haojun Liao 已提交
183
    setErrno(pRequest, code);
184 185 186 187 188 189 190

    if (pRequest->body.queryFp != NULL) {
      pRequest->body.queryFp(pRequest->body.param, pRequest, pRequest->code);
    } else {
      tsem_post(&pRequest->body.rspSem);
    }

H
Haojun Liao 已提交
191 192 193
    return code;
  }

S
Shengliang Guan 已提交
194 195 196
  SUseDbRsp usedbRsp = {0};
  tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp);

197
  SName name = {0};
L
Liu Jicong 已提交
198
  tNameFromString(&name, usedbRsp.db, T_NAME_ACCT | T_NAME_DB);
S
Shengliang Guan 已提交
199

D
dapan1121 已提交
200 201 202 203 204 205 206
  SUseDbOutput output = {0};
  code = queryBuildUseDbOutput(&output, &usedbRsp);

  if (code != 0) {
    terrno = code;
    if (output.dbVgroup) taosHashCleanup(output.dbVgroup->vgHash);

dengyihao's avatar
dengyihao 已提交
207
    tscError("0x%" PRIx64 " failed to build use db output since %s", pRequest->requestId, terrstr());
D
dapan1121 已提交
208
  } else if (output.dbVgroup && output.dbVgroup->vgHash) {
L
Liu Jicong 已提交
209 210
    struct SCatalog* pCatalog = NULL;

211 212
    int32_t code1 = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
    if (code1 != TSDB_CODE_SUCCESS) {
L
Liu Jicong 已提交
213
      tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId,
214
              tstrerror(code1));
D
dapan1121 已提交
215 216
    } else {
      catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup);
D
dapan1121 已提交
217
      output.dbVgroup = NULL;
D
dapan1121 已提交
218 219 220
    }
  }

D
dapan1121 已提交
221 222
  taosMemoryFreeClear(output.dbVgroup);

S
Shengliang Guan 已提交
223
  tFreeSUsedbRsp(&usedbRsp);
224 225 226

  char db[TSDB_DB_NAME_LEN] = {0};
  tNameGetDbName(&name, db);
227

228
  setConnectionDB(pRequest->pTscObj, db);
wafwerar's avatar
wafwerar 已提交
229
  taosMemoryFree(pMsg->pData);
dengyihao's avatar
dengyihao 已提交
230
  taosMemoryFree(pMsg->pEpSet);
231 232 233 234 235 236

  if (pRequest->body.queryFp != NULL) {
    pRequest->body.queryFp(pRequest->body.param, pRequest, pRequest->code);
  } else {
    tsem_post(&pRequest->body.rspSem);
  }
237
  return 0;
238 239
}

D
dapan1121 已提交
240
int32_t processCreateSTableRsp(void* param, SDataBuf* pMsg, int32_t code) {
H
Haojun Liao 已提交
241
  assert(pMsg != NULL && param != NULL);
242
  SRequestObj* pRequest = param;
H
Haojun Liao 已提交
243 244 245

  if (code != TSDB_CODE_SUCCESS) {
    setErrno(pRequest, code);
246 247
  } else {
    SMCreateStbRsp createRsp = {0};
dengyihao's avatar
dengyihao 已提交
248
    SDecoder       coder = {0};
249 250 251 252 253 254
    tDecoderInit(&coder, pMsg->pData, pMsg->len);
    tDecodeSMCreateStbRsp(&coder, &createRsp);
    tDecoderClear(&coder);

    pRequest->body.resInfo.execRes.msgType = TDMT_MND_CREATE_STB;
    pRequest->body.resInfo.execRes.res = createRsp.pMeta;
H
Haojun Liao 已提交
255 256
  }

dengyihao's avatar
dengyihao 已提交
257
  taosMemoryFree(pMsg->pEpSet);
258 259
  taosMemoryFree(pMsg->pData);

260
  if (pRequest->body.queryFp != NULL) {
261 262 263 264 265 266 267 268 269 270 271 272 273
    SExecResult* pRes = &pRequest->body.resInfo.execRes;

    if (code == TSDB_CODE_SUCCESS) {
      SCatalog* pCatalog = NULL;
      int32_t   ret = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
      if (pRes->res != NULL) {
        ret = handleCreateTbExecRes(pRes->res, pCatalog);
      }

      if (ret != TSDB_CODE_SUCCESS) {
        code = ret;
      }
    }
dengyihao's avatar
dengyihao 已提交
274

275 276 277 278
    pRequest->body.queryFp(pRequest->body.param, pRequest, code);
  } else {
    tsem_post(&pRequest->body.rspSem);
  }
H
Haojun Liao 已提交
279
  return code;
280 281
}

D
dapan1121 已提交
282
int32_t processDropDbRsp(void* param, SDataBuf* pMsg, int32_t code) {
283
  SRequestObj* pRequest = param;
H
Haojun Liao 已提交
284 285
  if (code != TSDB_CODE_SUCCESS) {
    setErrno(pRequest, code);
286 287 288
  } else {
    SDropDbRsp dropdbRsp = {0};
    tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp);
D
dapan1121 已提交
289

290
    struct SCatalog* pCatalog = NULL;
D
dapan1121 已提交
291 292 293 294
    int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
    if (TSDB_CODE_SUCCESS == code) {
      catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid);
    }
295
  }
D
dapan1121 已提交
296

D
dapan1121 已提交
297
  taosMemoryFree(pMsg->pData);
dengyihao's avatar
dengyihao 已提交
298
  taosMemoryFree(pMsg->pEpSet);
D
dapan1121 已提交
299

300 301 302 303 304
  if (pRequest->body.queryFp != NULL) {
    pRequest->body.queryFp(pRequest->body.param, pRequest, code);
  } else {
    tsem_post(&pRequest->body.rspSem);
  }
H
Haojun Liao 已提交
305
  return code;
306 307
}

D
dapan1121 已提交
308
int32_t processAlterStbRsp(void* param, SDataBuf* pMsg, int32_t code) {
D
dapan1121 已提交
309 310 311
  SRequestObj* pRequest = param;
  if (code != TSDB_CODE_SUCCESS) {
    setErrno(pRequest, code);
312 313 314 315 316 317 318 319 320
  } else {
    SMAlterStbRsp alterRsp = {0};
    SDecoder      coder = {0};
    tDecoderInit(&coder, pMsg->pData, pMsg->len);
    tDecodeSMAlterStbRsp(&coder, &alterRsp);
    tDecoderClear(&coder);

    pRequest->body.resInfo.execRes.msgType = TDMT_MND_ALTER_STB;
    pRequest->body.resInfo.execRes.res = alterRsp.pMeta;
D
dapan1121 已提交
321 322
  }

D
dapan1121 已提交
323
  taosMemoryFree(pMsg->pData);
dengyihao's avatar
dengyihao 已提交
324
  taosMemoryFree(pMsg->pEpSet);
D
dapan1121 已提交
325

326
  if (pRequest->body.queryFp != NULL) {
D
dapan1121 已提交
327
    SExecResult* pRes = &pRequest->body.resInfo.execRes;
328 329 330 331 332 333 334 335 336 337 338 339 340

    if (code == TSDB_CODE_SUCCESS) {
      SCatalog* pCatalog = NULL;
      int32_t   ret = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
      if (pRes->res != NULL) {
        ret = handleAlterTbExecRes(pRes->res, pCatalog);
      }

      if (ret != TSDB_CODE_SUCCESS) {
        code = ret;
      }
    }

341 342 343 344
    pRequest->body.queryFp(pRequest->body.param, pRequest, code);
  } else {
    tsem_post(&pRequest->body.rspSem);
  }
D
dapan1121 已提交
345 346 347
  return code;
}

D
dapan1121 已提交
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
static int32_t buildShowVariablesBlock(SArray* pVars, SSDataBlock** block) {
  SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
  pBlock->info.hasVarCol = true;

  pBlock->pDataBlock = taosArrayInit(SHOW_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData));

  SColumnInfoData infoData = {0};
  infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
  infoData.info.bytes = SHOW_VARIABLES_RESULT_FIELD1_LEN;

  taosArrayPush(pBlock->pDataBlock, &infoData);

  infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
  infoData.info.bytes = SHOW_VARIABLES_RESULT_FIELD2_LEN;
  taosArrayPush(pBlock->pDataBlock, &infoData);

  int32_t numOfCfg = taosArrayGetSize(pVars);
  blockDataEnsureCapacity(pBlock, numOfCfg);

  for (int32_t i = 0, c = 0; i < numOfCfg; ++i, c = 0) {
368
    SVariablesInfo* pInfo = taosArrayGet(pVars, i);
D
dapan1121 已提交
369 370 371

    char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
    STR_WITH_MAXSIZE_TO_VARSTR(name, pInfo->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE);
372
    SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, c++);
D
dapan1121 已提交
373
    colDataAppend(pColInfo, i, name, false);
374

D
dapan1121 已提交
375 376 377 378 379 380 381 382 383
    char value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0};
    STR_WITH_MAXSIZE_TO_VARSTR(value, pInfo->value, TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE);
    pColInfo = taosArrayGet(pBlock->pDataBlock, c++);
    colDataAppend(pColInfo, i, value, false);
  }

  pBlock->info.rows = numOfCfg;

  *block = pBlock;
384

D
dapan1121 已提交
385 386 387 388 389
  return TSDB_CODE_SUCCESS;
}

static int32_t buildShowVariablesRsp(SArray* pVars, SRetrieveTableRsp** pRsp) {
  SSDataBlock* pBlock = NULL;
390
  int32_t      code = buildShowVariablesBlock(pVars, &pBlock);
D
dapan1121 已提交
391 392 393 394 395 396 397
  if (code) {
    return code;
  }

  size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
  *pRsp = taosMemoryCalloc(1, rspSize);
  if (NULL == *pRsp) {
D
dapan1121 已提交
398
    blockDataDestroy(pBlock);
D
dapan1121 已提交
399 400 401 402 403 404 405 406 407 408 409 410
    return TSDB_CODE_OUT_OF_MEMORY;
  }

  (*pRsp)->useconds = 0;
  (*pRsp)->completed = 1;
  (*pRsp)->precision = 0;
  (*pRsp)->compressed = 0;
  (*pRsp)->compLen = 0;
  (*pRsp)->numOfRows = htonl(pBlock->info.rows);
  (*pRsp)->numOfCols = htonl(SHOW_VARIABLES_RESULT_COLS);

  int32_t len = 0;
411
  blockEncode(pBlock, (*pRsp)->data, &len, SHOW_VARIABLES_RESULT_COLS, false);
D
dapan1121 已提交
412 413 414 415 416 417
  ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));

  blockDataDestroy(pBlock);
  return TSDB_CODE_SUCCESS;
}

D
dapan1121 已提交
418
int32_t processShowVariablesRsp(void* param, SDataBuf* pMsg, int32_t code) {
D
dapan1121 已提交
419 420 421 422
  SRequestObj* pRequest = param;
  if (code != TSDB_CODE_SUCCESS) {
    setErrno(pRequest, code);
  } else {
423
    SShowVariablesRsp  rsp = {0};
D
dapan1121 已提交
424 425 426 427 428 429
    SRetrieveTableRsp* pRes = NULL;
    code = tDeserializeSShowVariablesRsp(pMsg->pData, pMsg->len, &rsp);
    if (TSDB_CODE_SUCCESS == code) {
      code = buildShowVariablesRsp(rsp.variables, &pRes);
    }
    if (TSDB_CODE_SUCCESS == code) {
D
dapan1121 已提交
430
      code = setQueryResultFromRsp(&pRequest->body.resInfo, pRes, false, true);
D
dapan1121 已提交
431
    }
432

D
dapan1121 已提交
433 434 435
    tFreeSShowVariablesRsp(&rsp);
  }

D
dapan1121 已提交
436
  taosMemoryFree(pMsg->pData);
dengyihao's avatar
dengyihao 已提交
437
  taosMemoryFree(pMsg->pEpSet);
D
dapan1121 已提交
438

D
dapan1121 已提交
439 440 441 442 443 444 445 446
  if (pRequest->body.queryFp != NULL) {
    pRequest->body.queryFp(pRequest->body.param, pRequest, code);
  } else {
    tsem_post(&pRequest->body.rspSem);
  }
  return code;
}

H
Haojun Liao 已提交
447 448 449 450 451 452 453 454 455 456 457 458 459 460
__async_send_cb_fn_t getMsgRspHandle(int32_t msgType) {
  switch (msgType) {
    case TDMT_MND_CONNECT:
      return processConnectRsp;
    case TDMT_MND_CREATE_DB:
      return processCreateDbRsp;
    case TDMT_MND_USE_DB:
      return processUseDbRsp;
    case TDMT_MND_CREATE_STB:
      return processCreateSTableRsp;
    case TDMT_MND_DROP_DB:
      return processDropDbRsp;
    case TDMT_MND_ALTER_STB:
      return processAlterStbRsp;
D
dapan1121 已提交
461 462
    case TDMT_MND_SHOW_VARIABLES:
      return processShowVariablesRsp;
H
Haojun Liao 已提交
463 464 465
    default:
      return genericRspCallback;
  }
L
Liu Jicong 已提交
466
}