TDengine/source/client/src/clientMsgHandler.c

546 lines
17 KiB
C
Raw Normal View History

2021-12-14 07:08:56 +00:00
/*
* 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/>.
*/
2022-04-24 10:02:57 +00:00
#include "catalog.h"
2021-12-14 07:08:56 +00:00
#include "clientInt.h"
2021-12-14 07:51:57 +00:00
#include "clientLog.h"
2022-04-24 10:02:57 +00:00
#include "os.h"
2022-03-01 11:48:21 +00:00
#include "query.h"
#include "systable.h"
#include "tdatablock.h"
2022-04-24 10:02:57 +00:00
#include "tdef.h"
#include "tglobal.h"
2022-04-24 10:02:57 +00:00
#include "tname.h"
#include "tversion.h"
2021-12-14 07:08:56 +00:00
2021-12-30 02:37:39 +00:00
static void setErrno(SRequestObj* pRequest, int32_t code) {
pRequest->code = code;
terrno = code;
}
2022-06-29 09:15:08 +00:00
int32_t genericRspCallback(void* param, SDataBuf* pMsg, int32_t code) {
SRequestObj* pRequest = param;
2021-12-30 02:37:39 +00:00
setErrno(pRequest, code);
if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) {
removeMeta(pRequest->pTscObj, pRequest->targetTableList);
}
2022-09-15 12:51:14 +00:00
taosMemoryFree(pMsg->pEpSet);
2022-03-25 16:29:53 +00:00
taosMemoryFree(pMsg->pData);
if (pRequest->body.queryFp != NULL) {
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
} else {
tsem_post(&pRequest->body.rspSem);
}
2021-12-30 02:37:39 +00:00
return code;
}
2022-06-29 09:15:08 +00:00
int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) {
SRequestObj* pRequest = acquireRequest(*(int64_t*)param);
2022-11-02 07:18:32 +00:00
if (NULL == pRequest) {
goto End;
}
2021-12-27 07:19:10 +00:00
if (code != TSDB_CODE_SUCCESS) {
2021-12-30 02:37:39 +00:00
setErrno(pRequest, code);
tsem_post(&pRequest->body.rspSem);
2022-10-21 12:05:29 +00:00
goto End;
2021-12-27 07:19:10 +00:00
}
2022-02-16 03:45:44 +00:00
STscObj* pTscObj = pRequest->pTscObj;
2021-12-14 07:08:56 +00:00
2022-11-03 00:42:56 +00:00
if (NULL == pTscObj->pAppInfo || NULL == pTscObj->pAppInfo->pAppHbMgr) {
setErrno(pRequest, TSDB_CODE_TSC_DISCONNECTED);
tsem_post(&pRequest->body.rspSem);
goto End;
}
2022-02-16 03:45:44 +00:00
SConnectRsp connectRsp = {0};
2022-10-21 11:59:44 +00:00
if (tDeserializeSConnectRsp(pMsg->pData, pMsg->len, &connectRsp) != 0) {
code = TSDB_CODE_TSC_INVALID_VERSION;
setErrno(pRequest, code);
tsem_post(&pRequest->body.rspSem);
2022-10-21 12:05:29 +00:00
goto End;
2022-10-21 11:59:44 +00:00
}
2022-07-15 06:51:20 +00:00
2023-03-29 03:10:15 +00:00
if ((code = taosCheckVersionCompatibleFromStr(version, connectRsp.sVer, 3)) != 0) {
setErrno(pRequest, code);
tsem_post(&pRequest->body.rspSem);
goto End;
}
2022-07-15 06:51:20 +00:00
int32_t now = taosGetTimestampSec();
int32_t delta = abs(now - connectRsp.svrTimestamp);
if (delta > timestampDeltaLimit) {
code = TSDB_CODE_TIME_UNSYNCED;
2022-07-15 06:56:23 +00:00
tscError("time diff:%ds is too big", delta);
2022-07-15 06:51:20 +00:00
setErrno(pRequest, code);
tsem_post(&pRequest->body.rspSem);
2022-10-21 12:05:29 +00:00
goto End;
2022-07-15 06:51:20 +00:00
}
2022-04-24 10:02:57 +00:00
if (connectRsp.epSet.numOfEps == 0) {
2022-12-03 02:03:18 +00:00
setErrno(pRequest, TSDB_CODE_APP_ERROR);
2022-04-24 10:02:57 +00:00
tsem_post(&pRequest->body.rspSem);
2022-10-21 12:05:29 +00:00
goto End;
2022-04-24 10:02:57 +00:00
}
2021-12-14 07:08:56 +00:00
2022-05-25 06:46:34 +00:00
if (connectRsp.dnodeNum == 1) {
2022-05-26 03:29:31 +00:00
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);
2022-05-25 06:46:34 +00:00
} else if (connectRsp.dnodeNum > 1 && !isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, &connectRsp.epSet)) {
2022-06-10 09:07:24 +00:00
SEpSet* pOrig = &pTscObj->pAppInfo->mgmtEp.epSet;
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);
2022-02-16 03:45:44 +00:00
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &connectRsp.epSet);
}
2022-02-16 03:45:44 +00:00
for (int32_t i = 0; i < connectRsp.epSet.numOfEps; ++i) {
2022-02-15 08:56:07 +00:00
tscDebug("0x%" PRIx64 " epSet.fqdn[%d]:%s port:%d, connObj:0x%" PRIx64, pRequest->requestId, i,
2022-06-27 01:50:42 +00:00
connectRsp.epSet.eps[i].fqdn, connectRsp.epSet.eps[i].port, pTscObj->id);
2021-12-14 07:08:56 +00:00
}
2022-08-24 09:36:10 +00:00
pTscObj->sysInfo = connectRsp.sysInfo;
2022-02-16 03:45:44 +00:00
pTscObj->connId = connectRsp.connId;
pTscObj->acctId = connectRsp.acctId;
2022-06-24 07:18:40 +00:00
tstrncpy(pTscObj->sVer, connectRsp.sVer, tListLen(pTscObj->sVer));
tstrncpy(pTscObj->sDetailVer, connectRsp.sDetailVer, tListLen(pTscObj->sDetailVer));
2021-12-14 07:08:56 +00:00
// update the appInstInfo
2022-02-16 03:45:44 +00:00
pTscObj->pAppInfo->clusterId = connectRsp.clusterId;
2022-12-30 05:30:54 +00:00
lastClusterId = connectRsp.clusterId;
2021-12-14 07:08:56 +00:00
2022-04-14 06:42:51 +00:00
pTscObj->connType = connectRsp.connType;
pTscObj->passInfo.ver = connectRsp.passVer;
2022-06-27 01:50:42 +00:00
hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType);
2022-01-14 02:48:05 +00:00
2022-02-16 03:45:44 +00:00
tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId,
2021-12-27 02:57:31 +00:00
pTscObj->pAppInfo->numOfConns);
tsem_post(&pRequest->body.rspSem);
2022-10-21 12:05:29 +00:00
End:
2022-11-02 07:18:32 +00:00
if (pRequest) {
releaseRequest(pRequest->self);
}
2022-11-02 07:18:32 +00:00
taosMemoryFree(param);
2022-10-21 12:05:29 +00:00
taosMemoryFree(pMsg->pEpSet);
taosMemoryFree(pMsg->pData);
return code;
}
2021-12-14 07:08:56 +00:00
2022-04-24 10:02:57 +00:00
SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pRequest) {
2022-03-25 16:29:53 +00:00
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
2021-12-29 15:07:01 +00:00
pMsgSendInfo->requestObjRefId = pRequest->self;
2022-04-24 10:02:57 +00:00
pMsgSendInfo->requestId = pRequest->requestId;
pMsgSendInfo->param = pRequest;
pMsgSendInfo->msgType = pRequest->type;
2022-06-10 09:07:24 +00:00
pMsgSendInfo->target.type = TARGET_TYPE_MNODE;
2022-04-12 10:57:57 +00:00
pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
2022-06-06 11:27:51 +00:00
pMsgSendInfo->fp = getMsgRspHandle(pRequest->type);
return pMsgSendInfo;
}
2022-06-29 09:15:08 +00:00
int32_t processCreateDbRsp(void* param, SDataBuf* pMsg, int32_t code) {
2021-12-17 08:42:26 +00:00
// todo rsp with the vnode id list
SRequestObj* pRequest = param;
2022-03-25 16:29:53 +00:00
taosMemoryFree(pMsg->pData);
2022-09-15 12:51:14 +00:00
taosMemoryFree(pMsg->pEpSet);
2022-03-21 09:39:28 +00:00
if (code != TSDB_CODE_SUCCESS) {
setErrno(pRequest, code);
} else {
struct SCatalog* pCatalog = NULL;
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
if (TSDB_CODE_SUCCESS == code) {
STscObj* pTscObj = pRequest->pTscObj;
SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter,
.requestId = pRequest->requestId,
.requestObjRefId = pRequest->self,
.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)};
char dbFName[TSDB_DB_FNAME_LEN];
snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_INFORMATION_SCHEMA_DB);
catalogRefreshDBVgInfo(pCatalog, &conn, dbFName);
snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_PERFORMANCE_SCHEMA_DB);
catalogRefreshDBVgInfo(pCatalog, &conn, dbFName);
}
2022-03-21 09:39:28 +00:00
}
if (pRequest->body.queryFp) {
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
} else {
tsem_post(&pRequest->body.rspSem);
}
2022-03-21 09:39:28 +00:00
return code;
2021-12-17 08:42:26 +00:00
}
2021-12-17 03:22:31 +00:00
2022-06-29 09:15:08 +00:00
int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) {
2021-12-30 02:37:39 +00:00
SRequestObj* pRequest = param;
if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code ||
TSDB_CODE_MND_DB_IN_DROPPING == code) {
2022-03-01 11:48:21 +00:00
SUseDbRsp usedbRsp = {0};
tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp);
2022-04-24 10:02:57 +00:00
struct SCatalog* pCatalog = NULL;
2022-03-01 11:48:21 +00:00
if (usedbRsp.vgVersion >= 0) { // cached in local
uint64_t clusterId = pRequest->pTscObj->pAppInfo->clusterId;
2022-05-26 03:29:31 +00:00
int32_t code1 = catalogGetHandle(clusterId, &pCatalog);
2022-04-15 04:09:27 +00:00
if (code1 != TSDB_CODE_SUCCESS) {
2022-05-26 03:29:31 +00:00
tscWarn("0x%" PRIx64 "catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->requestId, clusterId,
tstrerror(code1));
2022-03-01 11:48:21 +00:00
} else {
catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid);
}
}
2022-04-14 06:42:51 +00:00
tFreeSUsedbRsp(&usedbRsp);
2022-03-01 11:48:21 +00:00
}
2021-12-30 02:37:39 +00:00
if (code != TSDB_CODE_SUCCESS) {
2022-03-25 16:29:53 +00:00
taosMemoryFree(pMsg->pData);
2022-09-15 12:51:14 +00:00
taosMemoryFree(pMsg->pEpSet);
2021-12-30 02:37:39 +00:00
setErrno(pRequest, code);
if (pRequest->body.queryFp != NULL) {
pRequest->body.queryFp(pRequest->body.param, pRequest, pRequest->code);
} else {
tsem_post(&pRequest->body.rspSem);
}
2021-12-30 02:37:39 +00:00
return code;
}
2022-02-14 09:39:08 +00:00
SUseDbRsp usedbRsp = {0};
tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp);
2022-10-21 11:59:44 +00:00
if (strlen(usedbRsp.db) == 0) {
if (usedbRsp.errCode != 0) {
return usedbRsp.errCode;
} else {
return TSDB_CODE_APP_ERROR;
}
2022-10-18 06:47:02 +00:00
}
2022-11-08 05:46:18 +00:00
tscTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum);
for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
SVgroupInfo* pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
tscTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
tscTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
}
}
SName name = {0};
2022-04-14 06:42:51 +00:00
tNameFromString(&name, usedbRsp.db, T_NAME_ACCT | T_NAME_DB);
2022-02-14 09:39:08 +00:00
2022-03-01 11:48:21 +00:00
SUseDbOutput output = {0};
code = queryBuildUseDbOutput(&output, &usedbRsp);
if (code != 0) {
terrno = code;
if (output.dbVgroup) taosHashCleanup(output.dbVgroup->vgHash);
2022-05-26 03:29:31 +00:00
tscError("0x%" PRIx64 " failed to build use db output since %s", pRequest->requestId, terrstr());
2022-06-04 07:59:41 +00:00
} else if (output.dbVgroup && output.dbVgroup->vgHash) {
2022-04-14 06:42:51 +00:00
struct SCatalog* pCatalog = NULL;
2022-04-15 04:09:27 +00:00
int32_t code1 = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
if (code1 != TSDB_CODE_SUCCESS) {
2022-04-14 06:42:51 +00:00
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId,
2022-04-15 04:09:27 +00:00
tstrerror(code1));
2022-03-01 11:48:21 +00:00
} else {
catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup);
2022-07-12 12:53:42 +00:00
output.dbVgroup = NULL;
2022-03-01 11:48:21 +00:00
}
}
2022-07-12 12:53:42 +00:00
taosMemoryFreeClear(output.dbVgroup);
2022-02-14 09:39:08 +00:00
tFreeSUsedbRsp(&usedbRsp);
char db[TSDB_DB_NAME_LEN] = {0};
tNameGetDbName(&name, db);
setConnectionDB(pRequest->pTscObj, db);
2022-03-25 16:29:53 +00:00
taosMemoryFree(pMsg->pData);
2022-09-15 12:51:14 +00:00
taosMemoryFree(pMsg->pEpSet);
if (pRequest->body.queryFp != NULL) {
pRequest->body.queryFp(pRequest->body.param, pRequest, pRequest->code);
} else {
tsem_post(&pRequest->body.rspSem);
}
return 0;
}
2022-06-29 09:15:08 +00:00
int32_t processCreateSTableRsp(void* param, SDataBuf* pMsg, int32_t code) {
if (pMsg == NULL || param == NULL) {
return TSDB_CODE_TSC_INVALID_INPUT;
}
SRequestObj* pRequest = param;
2021-12-30 02:37:39 +00:00
if (code != TSDB_CODE_SUCCESS) {
setErrno(pRequest, code);
} else {
SMCreateStbRsp createRsp = {0};
2022-09-15 12:51:14 +00:00
SDecoder coder = {0};
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;
2021-12-30 02:37:39 +00:00
}
2022-09-15 12:51:14 +00:00
taosMemoryFree(pMsg->pEpSet);
taosMemoryFree(pMsg->pData);
if (pRequest->body.queryFp != NULL) {
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;
}
}
2022-09-15 12:51:14 +00:00
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
} else {
tsem_post(&pRequest->body.rspSem);
}
2021-12-30 02:37:39 +00:00
return code;
}
2022-06-29 09:15:08 +00:00
int32_t processDropDbRsp(void* param, SDataBuf* pMsg, int32_t code) {
SRequestObj* pRequest = param;
2021-12-30 02:38:32 +00:00
if (code != TSDB_CODE_SUCCESS) {
setErrno(pRequest, code);
} else {
SDropDbRsp dropdbRsp = {0};
tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp);
2022-01-26 09:42:31 +00:00
struct SCatalog* pCatalog = NULL;
2022-10-21 11:59:44 +00:00
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
2022-10-18 08:33:27 +00:00
if (TSDB_CODE_SUCCESS == code) {
catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid);
STscObj* pTscObj = pRequest->pTscObj;
SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter,
.requestId = pRequest->requestId,
.requestObjRefId = pRequest->self,
.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)};
char dbFName[TSDB_DB_FNAME_LEN];
2022-11-24 08:57:41 +00:00
snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_INFORMATION_SCHEMA_DB);
catalogRefreshDBVgInfo(pCatalog, &conn, dbFName);
snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_PERFORMANCE_SCHEMA_DB);
catalogRefreshDBVgInfo(pCatalog, &conn, dbFName);
2022-10-18 08:33:27 +00:00
}
}
2022-01-26 09:42:31 +00:00
2022-07-18 05:32:17 +00:00
taosMemoryFree(pMsg->pData);
2022-09-15 12:51:14 +00:00
taosMemoryFree(pMsg->pEpSet);
2022-07-18 05:32:17 +00:00
if (pRequest->body.queryFp != NULL) {
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
} else {
tsem_post(&pRequest->body.rspSem);
}
2021-12-30 02:38:32 +00:00
return code;
}
2022-06-29 09:15:08 +00:00
int32_t processAlterStbRsp(void* param, SDataBuf* pMsg, int32_t code) {
2022-06-01 12:28:29 +00:00
SRequestObj* pRequest = param;
if (code != TSDB_CODE_SUCCESS) {
setErrno(pRequest, code);
2022-06-06 02:35:19 +00:00
} 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;
2022-06-01 12:28:29 +00:00
}
2022-07-18 05:32:17 +00:00
taosMemoryFree(pMsg->pData);
2022-09-15 12:51:14 +00:00
taosMemoryFree(pMsg->pEpSet);
2022-07-18 05:32:17 +00:00
2022-06-06 02:35:19 +00:00
if (pRequest->body.queryFp != NULL) {
2022-07-04 01:08:57 +00:00
SExecResult* pRes = &pRequest->body.resInfo.execRes;
2022-06-06 09:29:43 +00:00
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;
}
}
2022-06-06 02:35:19 +00:00
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
} else {
tsem_post(&pRequest->body.rspSem);
}
2022-06-01 12:28:29 +00:00
return code;
}
2022-06-24 07:18:40 +00:00
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) {
SVariablesInfo* pInfo = taosArrayGet(pVars, i);
2022-06-24 07:18:40 +00:00
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);
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, c++);
2023-02-20 02:04:08 +00:00
colDataSetVal(pColInfo, i, name, false);
2022-06-24 07:18:40 +00:00
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++);
2023-02-20 02:04:08 +00:00
colDataSetVal(pColInfo, i, value, false);
2022-06-24 07:18:40 +00:00
}
pBlock->info.rows = numOfCfg;
*block = pBlock;
2022-06-24 07:18:40 +00:00
return TSDB_CODE_SUCCESS;
}
static int32_t buildShowVariablesRsp(SArray* pVars, SRetrieveTableRsp** pRsp) {
SSDataBlock* pBlock = NULL;
int32_t code = buildShowVariablesBlock(pVars, &pBlock);
2022-06-24 07:18:40 +00:00
if (code) {
return code;
}
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
*pRsp = taosMemoryCalloc(1, rspSize);
if (NULL == *pRsp) {
2022-10-18 08:33:27 +00:00
blockDataDestroy(pBlock);
2022-06-24 07:18:40 +00:00
return TSDB_CODE_OUT_OF_MEMORY;
}
(*pRsp)->useconds = 0;
(*pRsp)->completed = 1;
(*pRsp)->precision = 0;
(*pRsp)->compressed = 0;
(*pRsp)->compLen = 0;
(*pRsp)->numOfRows = htobe64((int64_t)pBlock->info.rows);
2022-06-24 07:18:40 +00:00
(*pRsp)->numOfCols = htonl(SHOW_VARIABLES_RESULT_COLS);
2022-11-09 05:45:46 +00:00
int32_t len = blockEncode(pBlock, (*pRsp)->data, SHOW_VARIABLES_RESULT_COLS);
blockDataDestroy(pBlock);
if (len != rspSize - sizeof(SRetrieveTableRsp)) {
uError("buildShowVariablesRsp error, len:%d != rspSize - sizeof(SRetrieveTableRsp):%" PRIu64, len,
(uint64_t)(rspSize - sizeof(SRetrieveTableRsp)));
return TSDB_CODE_TSC_INVALID_INPUT;
}
2022-06-24 07:18:40 +00:00
return TSDB_CODE_SUCCESS;
}
2022-06-29 09:15:08 +00:00
int32_t processShowVariablesRsp(void* param, SDataBuf* pMsg, int32_t code) {
2022-06-24 07:18:40 +00:00
SRequestObj* pRequest = param;
if (code != TSDB_CODE_SUCCESS) {
setErrno(pRequest, code);
} else {
SShowVariablesRsp rsp = {0};
2022-06-24 07:18:40 +00:00
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) {
2022-08-08 12:15:21 +00:00
code = setQueryResultFromRsp(&pRequest->body.resInfo, pRes, false, true);
2022-06-24 07:18:40 +00:00
}
2023-03-29 03:10:15 +00:00
if (code != 0) {
2023-03-17 06:54:27 +00:00
taosMemoryFree(pRes);
}
2022-06-24 07:18:40 +00:00
tFreeSShowVariablesRsp(&rsp);
}
2022-07-18 05:32:17 +00:00
taosMemoryFree(pMsg->pData);
2022-09-15 12:51:14 +00:00
taosMemoryFree(pMsg->pEpSet);
2022-07-18 05:32:17 +00:00
2022-06-24 07:18:40 +00:00
if (pRequest->body.queryFp != NULL) {
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
} else {
tsem_post(&pRequest->body.rspSem);
}
return code;
}
2022-06-06 11:27:51 +00:00
__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;
2022-06-24 07:18:40 +00:00
case TDMT_MND_SHOW_VARIABLES:
return processShowVariablesRsp;
2022-06-06 11:27:51 +00:00
default:
return genericRspCallback;
}
2022-01-14 02:48:05 +00:00
}