TDengine/source/dnode/mgmt/node_mgmt/src/dmTransport.c

569 lines
18 KiB
C
Raw Normal View History

2021-11-22 02:03:41 +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/>.
*/
2021-11-22 02:03:41 +00:00
#define _DEFAULT_SOURCE
2022-05-12 09:57:38 +00:00
#include "dmMgmt.h"
2022-05-21 10:10:37 +00:00
#include "qworker.h"
2023-07-05 08:16:25 +00:00
#include "tversion.h"
2024-07-29 11:41:44 +00:00
static inline void dmSendRsp(SRpcMsg *pMsg) { (void)rpcSendResponse(pMsg); }
2022-06-21 07:05:31 +00:00
static inline void dmBuildMnodeRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) {
SEpSet epSet = {0};
dmGetMnodeEpSetForRedirect(&pDnode->data, pMsg, &epSet);
2024-07-30 00:52:28 +00:00
int32_t contLen = tSerializeSEpSet(NULL, 0, &epSet);
2022-06-21 07:05:31 +00:00
pMsg->pCont = rpcMallocCont(contLen);
if (pMsg->pCont == NULL) {
pMsg->code = TSDB_CODE_OUT_OF_MEMORY;
} else {
2024-07-29 11:41:44 +00:00
contLen = tSerializeSEpSet(pMsg->pCont, contLen, &epSet);
if (contLen < 0) {
pMsg->code = contLen;
return;
}
2022-06-21 07:05:31 +00:00
pMsg->contLen = contLen;
}
}
2022-05-16 06:55:31 +00:00
int32_t dmProcessNodeMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
const STraceId *trace = &pMsg->info.traceId;
2022-05-16 06:55:31 +00:00
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pMsg->msgType)];
2022-05-14 15:26:28 +00:00
if (msgFp == NULL) {
2024-07-16 10:01:09 +00:00
// terrno = TSDB_CODE_MSG_NOT_PROCESSED;
2023-01-30 05:54:15 +00:00
dGError("msg:%p, not processed since no handler, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
2024-07-16 10:01:09 +00:00
return TSDB_CODE_MSG_NOT_PROCESSED;
2022-05-14 15:26:28 +00:00
}
2022-05-14 09:41:43 +00:00
2022-06-21 07:05:31 +00:00
dGTrace("msg:%p, will be processed by %s", pMsg, pWrapper->name);
2022-05-18 09:42:50 +00:00
pMsg->info.wrapper = pWrapper;
2022-05-14 15:26:28 +00:00
return (*msgFp)(pWrapper->pMgmt, pMsg);
}
2022-12-06 02:30:14 +00:00
static bool dmFailFastFp(tmsg_t msgType) {
// add more msg type later
2022-12-07 01:30:17 +00:00
return msgType == TDMT_SYNC_HEARTBEAT || msgType == TDMT_SYNC_APPEND_ENTRIES;
2022-12-06 02:30:14 +00:00
}
2024-07-16 10:01:09 +00:00
static int32_t dmConvertErrCode(tmsg_t msgType, int32_t code) {
if (code != TSDB_CODE_APP_IS_STOPPING) {
return code;
2022-12-21 12:13:32 +00:00
}
if ((msgType > TDMT_VND_MSG_MIN && msgType < TDMT_VND_MSG_MAX) ||
(msgType > TDMT_SCH_MSG_MIN && msgType < TDMT_SCH_MSG_MAX)) {
2024-07-16 10:01:09 +00:00
code = TSDB_CODE_VND_STOPPED;
2022-12-21 12:13:32 +00:00
}
2024-07-16 10:01:09 +00:00
return code;
2022-12-21 12:13:32 +00:00
}
static void dmUpdateRpcIpWhite(SDnodeData *pData, void *pTrans, SRpcMsg *pRpc) {
2024-07-29 11:41:44 +00:00
int32_t code = 0;
2023-09-07 12:47:10 +00:00
SUpdateIpWhite ipWhite = {0}; // aosMemoryCalloc(1, sizeof(SUpdateIpWhite));
2024-07-29 11:41:44 +00:00
code = tDeserializeSUpdateIpWhite(pRpc->pCont, pRpc->contLen, &ipWhite);
if (code < 0) {
dError("failed to update rpc ip-white since: %s", tstrerror(code));
return;
}
2024-07-22 09:38:19 +00:00
code = rpcSetIpWhite(pTrans, &ipWhite);
pData->ipWhiteVer = ipWhite.ver;
2023-09-07 08:10:07 +00:00
2024-07-29 11:41:44 +00:00
(void)tFreeSUpdateIpWhiteReq(&ipWhite);
2023-09-07 08:10:07 +00:00
rpcFreeCont(pRpc->pCont);
2023-09-06 13:54:31 +00:00
}
2023-09-11 12:48:24 +00:00
static bool dmIsForbiddenIp(int8_t forbidden, char *user, uint32_t clientIp) {
if (forbidden) {
SIpV4Range range = {.ip = clientIp, .mask = 32};
char buf[36] = {0};
2024-07-29 11:41:44 +00:00
(void)rpcUtilSIpRangeToStr(&range, buf);
2023-09-13 06:27:58 +00:00
dError("User:%s host:%s not in ip white list", user, buf);
2023-09-11 12:48:24 +00:00
return true;
} else {
return false;
}
}
2022-05-14 15:26:28 +00:00
static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
2024-02-29 10:54:35 +00:00
SDnodeTrans *pTrans = &pDnode->trans;
2022-05-14 15:26:28 +00:00
int32_t code = -1;
2024-02-29 10:54:35 +00:00
SRpcMsg *pMsg = NULL;
2022-05-14 15:26:28 +00:00
SMgmtWrapper *pWrapper = NULL;
2022-05-21 05:03:43 +00:00
SDnodeHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(pRpc->msgType)];
2022-05-14 15:26:28 +00:00
2022-06-21 07:05:31 +00:00
const STraceId *trace = &pRpc->info.traceId;
2022-06-18 09:23:55 +00:00
dGTrace("msg:%s is received, handle:%p len:%d code:0x%x app:%p refId:%" PRId64, TMSG_INFO(pRpc->msgType),
pRpc->info.handle, pRpc->contLen, pRpc->code, pRpc->info.ahandle, pRpc->info.refId);
2022-05-15 14:08:43 +00:00
2023-07-05 08:16:25 +00:00
int32_t svrVer = 0;
2024-07-29 11:41:44 +00:00
(void)taosVersionStrToInt(version, &svrVer);
2024-07-16 10:01:09 +00:00
if ((code = taosCheckVersionCompatible(pRpc->info.cliVer, svrVer, 3)) != 0) {
2024-08-07 08:01:28 +00:00
dError("Version not compatible, cli ver: %d, svr ver: %d, ip:0x%x", pRpc->info.cliVer, svrVer, pRpc->info.conn.clientIp);
2023-07-05 08:16:25 +00:00
goto _OVER;
}
2023-09-11 12:48:24 +00:00
bool isForbidden = dmIsForbiddenIp(pRpc->info.forbiddenIp, pRpc->info.conn.user, pRpc->info.conn.clientIp);
if (isForbidden) {
2024-07-16 10:01:09 +00:00
code = TSDB_CODE_IP_NOT_IN_WHITE_LIST;
2023-09-10 06:09:36 +00:00
goto _OVER;
}
2022-06-21 07:05:31 +00:00
switch (pRpc->msgType) {
case TDMT_DND_NET_TEST:
dmProcessNetTestReq(pDnode, pRpc);
return;
case TDMT_MND_SYSTABLE_RETRIEVE_RSP:
2022-06-22 09:17:18 +00:00
case TDMT_DND_SYSTABLE_RETRIEVE_RSP:
2022-06-29 09:15:08 +00:00
case TDMT_SCH_FETCH_RSP:
2022-07-06 12:33:23 +00:00
case TDMT_SCH_MERGE_FETCH_RSP:
2022-07-06 08:29:51 +00:00
case TDMT_VND_SUBMIT_RSP:
2024-07-16 10:01:09 +00:00
code = qWorkerProcessRspMsg(NULL, NULL, pRpc, 0);
2022-06-21 07:05:31 +00:00
return;
case TDMT_MND_STATUS_RSP:
if (pEpSet != NULL) {
dmSetMnodeEpSet(&pDnode->data, pEpSet);
}
2023-09-07 08:10:07 +00:00
break;
2023-09-06 13:54:31 +00:00
case TDMT_MND_RETRIEVE_IP_WHITE_RSP: {
dmUpdateRpcIpWhite(&pDnode->data, pTrans->serverRpc, pRpc);
2023-09-07 08:10:07 +00:00
return;
2023-09-06 13:54:31 +00:00
} break;
2022-06-21 07:05:31 +00:00
default:
break;
2022-05-14 09:41:43 +00:00
}
2023-02-25 10:01:17 +00:00
/*
pDnode is null, TD-22618
at trans.c line 91
before this line, dmProcessRpcMsg callback is set
after this line, parent is set
so when dmProcessRpcMsg is called, pDonde is still null.
*/
if (pDnode != NULL) {
if (pDnode->status != DND_STAT_RUNNING) {
2023-02-21 10:15:32 +00:00
if (pRpc->msgType == TDMT_DND_SERVER_STATUS) {
dmProcessServerStartupStatus(pDnode, pRpc);
return;
} else {
2023-02-21 10:15:32 +00:00
if (pDnode->status == DND_STAT_INIT) {
2024-07-16 10:01:09 +00:00
code = TSDB_CODE_APP_IS_STARTING;
2023-02-21 10:15:32 +00:00
} else {
2024-07-16 10:01:09 +00:00
code = TSDB_CODE_APP_IS_STOPPING;
2023-02-21 10:15:32 +00:00
}
goto _OVER;
}
2023-02-25 10:01:17 +00:00
}
2023-02-21 10:15:32 +00:00
} else {
2024-07-16 10:01:09 +00:00
code = TSDB_CODE_APP_IS_STARTING;
2023-02-21 10:15:32 +00:00
goto _OVER;
2022-05-14 15:26:28 +00:00
}
if (pRpc->pCont == NULL && (IsReq(pRpc) || pRpc->contLen != 0)) {
2022-11-02 07:28:32 +00:00
dGError("msg:%p, type:%s pCont is NULL", pRpc, TMSG_INFO(pRpc->msgType));
2024-07-16 10:01:09 +00:00
code = TSDB_CODE_INVALID_MSG_LEN;
2022-05-21 05:03:43 +00:00
goto _OVER;
2022-12-28 07:19:35 +00:00
} else if ((pRpc->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pRpc->code == TSDB_CODE_RPC_BROKEN_LINK) &&
(!IsReq(pRpc)) && (pRpc->pCont == NULL)) {
dGError("msg:%p, type:%s pCont is NULL, err: %s", pRpc, TMSG_INFO(pRpc->msgType), tstrerror(pRpc->code));
2024-07-16 10:01:09 +00:00
code = pRpc->code;
2022-12-28 07:19:35 +00:00
goto _OVER;
}
2022-05-14 15:26:28 +00:00
if (pHandle->defaultNtype == NODE_END) {
dGError("msg:%p, type:%s not processed since no handle", pRpc, TMSG_INFO(pRpc->msgType));
2024-07-16 10:01:09 +00:00
code = TSDB_CODE_MSG_NOT_PROCESSED;
2022-05-21 05:03:43 +00:00
goto _OVER;
2022-06-21 07:05:31 +00:00
}
pWrapper = &pDnode->wrappers[pHandle->defaultNtype];
if (pHandle->needCheckVgId) {
if (pRpc->contLen > 0) {
const SMsgHead *pHead = pRpc->pCont;
const int32_t vgId = ntohl(pHead->vgId);
switch (vgId) {
case QNODE_HANDLE:
2022-05-15 14:08:43 +00:00
pWrapper = &pDnode->wrappers[QNODE];
2022-06-21 07:05:31 +00:00
break;
case SNODE_HANDLE:
2022-06-07 08:24:50 +00:00
pWrapper = &pDnode->wrappers[SNODE];
2022-06-21 07:05:31 +00:00
break;
case MNODE_HANDLE:
2022-05-15 14:08:43 +00:00
pWrapper = &pDnode->wrappers[MNODE];
2022-06-21 07:05:31 +00:00
break;
default:
break;
2022-05-14 15:26:28 +00:00
}
2022-06-21 07:05:31 +00:00
} else {
2022-11-02 07:28:32 +00:00
dGError("msg:%p, type:%s contLen is 0", pRpc, TMSG_INFO(pRpc->msgType));
2024-07-16 10:01:09 +00:00
code = TSDB_CODE_INVALID_MSG_LEN;
2022-06-21 07:05:31 +00:00
goto _OVER;
2022-05-14 15:26:28 +00:00
}
}
2022-04-02 11:21:20 +00:00
2024-07-16 10:01:09 +00:00
if ((code = dmMarkWrapper(pWrapper)) != 0) {
2022-05-21 05:03:43 +00:00
pWrapper = NULL;
goto _OVER;
2022-05-14 15:26:28 +00:00
}
2022-05-12 05:00:21 +00:00
2022-06-21 07:05:31 +00:00
pRpc->info.wrapper = pWrapper;
2024-07-04 09:11:53 +00:00
2024-07-04 10:19:08 +00:00
EQItype itype = IsReq(pRpc) ? RPC_QITEM : DEF_QITEM; // rsp msg is not restricted by tsRpcQueueMemoryUsed
2024-07-16 09:30:32 +00:00
code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
if (code) goto _OVER;
2022-04-02 11:21:20 +00:00
2022-06-21 07:05:31 +00:00
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
2022-12-13 12:16:45 +00:00
dGTrace("msg:%p, is created, type:%s handle:%p len:%d", pMsg, TMSG_INFO(pRpc->msgType), pMsg->info.handle,
pRpc->contLen);
2022-05-14 15:26:28 +00:00
2022-10-18 10:28:13 +00:00
code = dmProcessNodeMsg(pWrapper, pMsg);
2022-04-02 11:21:20 +00:00
_OVER:
if (code != 0) {
2024-07-16 10:01:09 +00:00
code = dmConvertErrCode(pRpc->msgType, code);
2022-11-03 05:44:34 +00:00
if (pMsg) {
2024-07-16 10:01:09 +00:00
dGTrace("msg:%p, failed to process %s since %s", pMsg, TMSG_INFO(pMsg->msgType), tstrerror(code));
2022-11-03 05:44:34 +00:00
} else {
dGTrace("msg:%p, failed to process empty msg since %s", pMsg, tstrerror(code));
2022-11-03 05:44:34 +00:00
}
2022-05-14 15:26:28 +00:00
2022-05-16 06:55:31 +00:00
if (IsReq(pRpc)) {
SRpcMsg rsp = {.code = code, .info = pRpc->info};
if (code == TSDB_CODE_MNODE_NOT_FOUND) {
dmBuildMnodeRedirectRsp(pDnode, &rsp);
}
if (pWrapper != NULL) {
dmSendRsp(&rsp);
2022-05-21 07:36:18 +00:00
} else {
2024-07-30 02:55:48 +00:00
(void)rpcSendResponse(&rsp);
2022-05-21 07:36:18 +00:00
}
2022-04-02 11:21:20 +00:00
}
2022-05-14 15:26:28 +00:00
2022-06-07 01:59:15 +00:00
if (pMsg != NULL) {
2022-06-21 07:05:31 +00:00
dGTrace("msg:%p, is freed", pMsg);
2022-06-07 01:59:15 +00:00
taosFreeQitem(pMsg);
}
2022-04-02 11:21:20 +00:00
rpcFreeCont(pRpc->pCont);
2022-07-05 09:38:21 +00:00
pRpc->pCont = NULL;
2022-04-02 11:21:20 +00:00
}
2022-05-21 05:03:43 +00:00
dmReleaseWrapper(pWrapper);
2022-04-02 11:21:20 +00:00
}
2023-12-14 10:49:32 +00:00
int32_t dmInitMsgHandle(SDnode *pDnode) {
SDnodeTrans *pTrans = &pDnode->trans;
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
2024-02-29 10:54:35 +00:00
SArray *pArray = (*pWrapper->func.getHandlesFp)();
2023-12-14 10:49:32 +00:00
if (pArray == NULL) return -1;
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
2024-02-29 10:54:35 +00:00
SMgmtHandle *pMgmt = taosArrayGet(pArray, i);
2023-12-14 10:49:32 +00:00
SDnodeHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(pMgmt->msgType)];
if (pMgmt->needCheckVgId) {
pHandle->needCheckVgId = pMgmt->needCheckVgId;
}
if (!pMgmt->needCheckVgId) {
pHandle->defaultNtype = ntype;
}
pWrapper->msgFps[TMSG_INDEX(pMgmt->msgType)] = pMgmt->msgFp;
}
taosArrayDestroy(pArray);
}
return 0;
}
2022-03-14 02:04:56 +00:00
2022-05-19 08:56:50 +00:00
static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
2024-07-16 10:01:09 +00:00
int32_t code = 0;
2022-05-16 15:23:49 +00:00
SDnode *pDnode = dmInstance();
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
2022-05-19 08:56:50 +00:00
rpcFreeCont(pMsg->pCont);
pMsg->pCont = NULL;
if (pDnode->status == DND_STAT_INIT) {
2024-07-16 10:01:09 +00:00
code = TSDB_CODE_APP_IS_STARTING;
} else {
2024-07-16 10:01:09 +00:00
code = TSDB_CODE_APP_IS_STOPPING;
}
2024-07-16 10:01:09 +00:00
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), tstrerror(code),
pMsg->info.handle);
return code;
2022-05-16 15:23:49 +00:00
} else {
2024-06-26 02:32:15 +00:00
pMsg->info.handle = 0;
2024-07-29 11:41:44 +00:00
(void)rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pMsg, NULL);
2024-01-31 01:13:10 +00:00
return 0;
2022-04-01 13:27:47 +00:00
}
}
2024-01-10 09:57:08 +00:00
static inline int32_t dmSendSyncReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
int32_t code = 0;
2024-01-10 09:57:08 +00:00
SDnode *pDnode = dmInstance();
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
2024-01-10 09:57:08 +00:00
rpcFreeCont(pMsg->pCont);
pMsg->pCont = NULL;
if (pDnode->status == DND_STAT_INIT) {
code = TSDB_CODE_APP_IS_STARTING;
2024-01-10 09:57:08 +00:00
} else {
code = TSDB_CODE_APP_IS_STOPPING;
2024-01-10 09:57:08 +00:00
}
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), tstrerror(code),
pMsg->info.handle);
return code;
2024-01-10 09:57:08 +00:00
} else {
2024-07-29 11:41:44 +00:00
return rpcSendRequest(pDnode->trans.syncRpc, pEpSet, pMsg, NULL);
2024-01-10 09:57:08 +00:00
}
}
2022-04-01 13:27:47 +00:00
2024-07-29 11:41:44 +00:00
static inline void dmRegisterBrokenLinkArg(SRpcMsg *pMsg) { (void)rpcRegisterBrokenLinkArg(pMsg); }
2022-03-29 05:39:55 +00:00
2024-07-29 11:41:44 +00:00
static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) { (void)rpcReleaseHandle(pHandle, type); }
2022-03-29 05:39:55 +00:00
2022-06-27 11:34:50 +00:00
static bool rpcRfp(int32_t code, tmsg_t msgType) {
2022-12-02 14:45:11 +00:00
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_MNODE_NOT_FOUND ||
2022-12-28 07:19:35 +00:00
code == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED || code == TSDB_CODE_SYN_NOT_LEADER ||
code == TSDB_CODE_SYN_RESTORING || code == TSDB_CODE_VND_STOPPED || code == TSDB_CODE_APP_IS_STARTING ||
code == TSDB_CODE_APP_IS_STOPPING) {
2022-08-08 11:17:28 +00:00
if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY || msgType == TDMT_SCH_FETCH ||
2024-01-22 11:53:59 +00:00
msgType == TDMT_SCH_MERGE_FETCH || msgType == TDMT_SCH_TASK_NOTIFY || msgType == TDMT_VND_DROP_TTL_TABLE) {
2022-06-27 11:34:50 +00:00
return false;
}
2022-06-25 04:19:52 +00:00
return true;
} else {
return false;
}
}
static bool rpcNoDelayMsg(tmsg_t msgType) {
if (msgType == TDMT_VND_FETCH_TTL_EXPIRED_TBS || msgType == TDMT_VND_S3MIGRATE || msgType == TDMT_VND_S3MIGRATE ||
msgType == TDMT_VND_QUERY_COMPACT_PROGRESS || msgType == TDMT_VND_DROP_TTL_TABLE) {
return true;
}
return false;
}
int32_t dmInitClient(SDnode *pDnode) {
2022-04-12 11:49:19 +00:00
SDnodeTrans *pTrans = &pDnode->trans;
SRpcInit rpcInit = {0};
2024-01-11 07:30:39 +00:00
rpcInit.label = "DNODE-CLI";
2024-01-11 06:01:06 +00:00
rpcInit.numOfThreads = tsNumOfRpcThreads / 2;
2022-05-14 15:26:28 +00:00
rpcInit.cfp = (RpcCfp)dmProcessRpcMsg;
2022-04-12 11:49:19 +00:00
rpcInit.sessions = 1024;
rpcInit.connType = TAOS_CONN_CLIENT;
2023-07-24 06:46:59 +00:00
rpcInit.user = TSDB_DEFAULT_USER;
2022-04-12 11:49:19 +00:00
rpcInit.idleTime = tsShellActivityTimer * 1000;
rpcInit.parent = pDnode;
2022-04-28 08:41:13 +00:00
rpcInit.rfp = rpcRfp;
2022-10-11 14:18:44 +00:00
rpcInit.compressSize = tsCompressMsgSize;
2024-02-29 10:40:21 +00:00
rpcInit.dfp = destroyAhandle;
2022-11-29 02:52:06 +00:00
rpcInit.retryMinInterval = tsRedirectPeriod;
rpcInit.retryStepFactor = tsRedirectFactor;
rpcInit.retryMaxInterval = tsRedirectMaxPeriod;
2023-08-09 00:46:18 +00:00
rpcInit.retryMaxTimeout = tsMaxRetryWaitTime;
2022-04-12 11:49:19 +00:00
2023-02-15 11:24:48 +00:00
rpcInit.failFastInterval = 5000; // interval threshold(ms)
2022-12-06 02:30:14 +00:00
rpcInit.failFastThreshold = 3; // failed threshold
rpcInit.ffp = dmFailFastFp;
rpcInit.noDelayFp = rpcNoDelayMsg;
2024-01-11 06:01:06 +00:00
int32_t connLimitNum = tsNumOfRpcSessions / (tsNumOfRpcThreads * 3) / 2;
2023-02-18 03:37:43 +00:00
connLimitNum = TMAX(connLimitNum, 10);
2023-02-19 10:10:42 +00:00
connLimitNum = TMIN(connLimitNum, 500);
2023-02-15 16:30:26 +00:00
rpcInit.connLimitNum = connLimitNum;
2023-02-15 12:06:04 +00:00
rpcInit.connLimitLock = 1;
2023-02-16 07:09:39 +00:00
rpcInit.supportBatch = 1;
2023-02-19 10:29:11 +00:00
rpcInit.batchSize = 8 * 1024;
2023-02-24 13:20:15 +00:00
rpcInit.timeToGetConn = tsTimeToGetAvailableConn;
2024-07-29 11:41:44 +00:00
(void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
2023-02-15 09:26:11 +00:00
2022-04-12 11:49:19 +00:00
pTrans->clientRpc = rpcOpen(&rpcInit);
if (pTrans->clientRpc == NULL) {
dError("failed to init dnode rpc client");
return -1;
}
dDebug("dnode rpc client is initialized");
return 0;
}
2023-10-18 08:03:55 +00:00
int32_t dmInitStatusClient(SDnode *pDnode) {
SDnodeTrans *pTrans = &pDnode->trans;
SRpcInit rpcInit = {0};
2024-01-11 07:30:03 +00:00
rpcInit.label = "DNODE-STA-CLI";
2023-10-18 08:03:55 +00:00
rpcInit.numOfThreads = 1;
rpcInit.cfp = (RpcCfp)dmProcessRpcMsg;
rpcInit.sessions = 1024;
rpcInit.connType = TAOS_CONN_CLIENT;
rpcInit.user = TSDB_DEFAULT_USER;
rpcInit.idleTime = tsShellActivityTimer * 1000;
rpcInit.parent = pDnode;
rpcInit.rfp = rpcRfp;
rpcInit.compressSize = tsCompressMsgSize;
rpcInit.retryMinInterval = tsRedirectPeriod;
rpcInit.retryStepFactor = tsRedirectFactor;
rpcInit.retryMaxInterval = tsRedirectMaxPeriod;
rpcInit.retryMaxTimeout = tsMaxRetryWaitTime;
rpcInit.failFastInterval = 5000; // interval threshold(ms)
rpcInit.failFastThreshold = 3; // failed threshold
rpcInit.ffp = dmFailFastFp;
int32_t connLimitNum = 100;
connLimitNum = TMAX(connLimitNum, 10);
connLimitNum = TMIN(connLimitNum, 500);
rpcInit.connLimitNum = connLimitNum;
rpcInit.connLimitLock = 1;
rpcInit.supportBatch = 1;
rpcInit.batchSize = 8 * 1024;
rpcInit.timeToGetConn = tsTimeToGetAvailableConn;
2024-07-29 11:41:44 +00:00
(void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
2023-10-18 08:03:55 +00:00
2024-01-10 09:57:08 +00:00
pTrans->statusRpc = rpcOpen(&rpcInit);
if (pTrans->statusRpc == NULL) {
dError("failed to init dnode rpc status client");
2024-07-16 01:04:16 +00:00
return TSDB_CODE_OUT_OF_MEMORY;
2024-01-10 09:57:08 +00:00
}
2023-10-18 08:03:55 +00:00
dDebug("dnode rpc status client is initialized");
return 0;
}
2022-04-12 11:49:19 +00:00
2024-01-10 09:57:08 +00:00
int32_t dmInitSyncClient(SDnode *pDnode) {
SDnodeTrans *pTrans = &pDnode->trans;
SRpcInit rpcInit = {0};
2024-01-11 07:30:03 +00:00
rpcInit.label = "DNODE-SYNC-CLI";
2024-01-11 06:01:06 +00:00
rpcInit.numOfThreads = tsNumOfRpcThreads / 2;
2024-01-10 09:57:08 +00:00
rpcInit.cfp = (RpcCfp)dmProcessRpcMsg;
rpcInit.sessions = 1024;
rpcInit.connType = TAOS_CONN_CLIENT;
rpcInit.user = TSDB_DEFAULT_USER;
rpcInit.idleTime = tsShellActivityTimer * 1000;
rpcInit.parent = pDnode;
rpcInit.rfp = rpcRfp;
rpcInit.compressSize = tsCompressMsgSize;
rpcInit.retryMinInterval = tsRedirectPeriod;
rpcInit.retryStepFactor = tsRedirectFactor;
rpcInit.retryMaxInterval = tsRedirectMaxPeriod;
rpcInit.retryMaxTimeout = tsMaxRetryWaitTime;
rpcInit.failFastInterval = 5000; // interval threshold(ms)
rpcInit.failFastThreshold = 3; // failed threshold
rpcInit.ffp = dmFailFastFp;
2024-01-11 06:01:06 +00:00
int32_t connLimitNum = tsNumOfRpcSessions / (tsNumOfRpcThreads * 3) / 2;
2024-01-10 09:57:08 +00:00
connLimitNum = TMAX(connLimitNum, 10);
connLimitNum = TMIN(connLimitNum, 500);
rpcInit.connLimitNum = connLimitNum;
rpcInit.connLimitLock = 1;
rpcInit.supportBatch = 1;
rpcInit.batchSize = 8 * 1024;
rpcInit.timeToGetConn = tsTimeToGetAvailableConn;
2024-07-29 11:41:44 +00:00
(void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
2024-01-10 09:57:08 +00:00
pTrans->syncRpc = rpcOpen(&rpcInit);
if (pTrans->syncRpc == NULL) {
dError("failed to init dnode rpc sync client");
2024-07-16 01:04:16 +00:00
return TSDB_CODE_OUT_OF_MEMORY;
2024-01-10 09:57:08 +00:00
}
dDebug("dnode rpc sync client is initialized");
return 0;
}
void dmCleanupClient(SDnode *pDnode) {
2022-04-12 11:49:19 +00:00
SDnodeTrans *pTrans = &pDnode->trans;
if (pTrans->clientRpc) {
rpcClose(pTrans->clientRpc);
pTrans->clientRpc = NULL;
dDebug("dnode rpc client is closed");
}
}
2023-10-18 08:03:55 +00:00
void dmCleanupStatusClient(SDnode *pDnode) {
SDnodeTrans *pTrans = &pDnode->trans;
2024-01-10 09:57:08 +00:00
if (pTrans->statusRpc) {
rpcClose(pTrans->statusRpc);
pTrans->statusRpc = NULL;
dDebug("dnode rpc status client is closed");
}
}
void dmCleanupSyncClient(SDnode *pDnode) {
SDnodeTrans *pTrans = &pDnode->trans;
if (pTrans->syncRpc) {
rpcClose(pTrans->syncRpc);
pTrans->syncRpc = NULL;
dDebug("dnode rpc sync client is closed");
}
2023-10-18 08:03:55 +00:00
}
2022-04-12 11:49:19 +00:00
int32_t dmInitServer(SDnode *pDnode) {
2022-04-12 11:49:19 +00:00
SDnodeTrans *pTrans = &pDnode->trans;
SRpcInit rpcInit = {0};
2022-09-29 11:41:54 +00:00
tstrncpy(rpcInit.localFqdn, tsLocalFqdn, TSDB_FQDN_LEN);
2022-05-16 13:36:29 +00:00
rpcInit.localPort = tsServerPort;
2022-06-28 07:49:33 +00:00
rpcInit.label = "DND-S";
2022-04-12 11:49:19 +00:00
rpcInit.numOfThreads = tsNumOfRpcThreads;
2022-05-14 15:26:28 +00:00
rpcInit.cfp = (RpcCfp)dmProcessRpcMsg;
2022-04-12 11:49:19 +00:00
rpcInit.sessions = tsMaxShellConns;
rpcInit.connType = TAOS_CONN_SERVER;
rpcInit.idleTime = tsShellActivityTimer * 1000;
rpcInit.parent = pDnode;
2022-12-07 10:04:35 +00:00
rpcInit.compressSize = tsCompressMsgSize;
2024-07-29 11:41:44 +00:00
(void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
2022-04-12 11:49:19 +00:00
pTrans->serverRpc = rpcOpen(&rpcInit);
if (pTrans->serverRpc == NULL) {
dError("failed to init dnode rpc server");
2024-07-16 10:01:09 +00:00
return terrno;
2022-04-12 11:49:19 +00:00
}
dDebug("dnode rpc server is initialized");
return 0;
}
void dmCleanupServer(SDnode *pDnode) {
2022-04-12 11:49:19 +00:00
SDnodeTrans *pTrans = &pDnode->trans;
if (pTrans->serverRpc) {
rpcClose(pTrans->serverRpc);
pTrans->serverRpc = NULL;
dDebug("dnode rpc server is closed");
}
}
2022-05-16 15:44:07 +00:00
SMsgCb dmGetMsgcb(SDnode *pDnode) {
SMsgCb msgCb = {
.clientRpc = pDnode->trans.clientRpc,
2023-09-11 12:48:24 +00:00
.serverRpc = pDnode->trans.serverRpc,
2024-01-10 09:57:08 +00:00
.statusRpc = pDnode->trans.statusRpc,
.syncRpc = pDnode->trans.syncRpc,
2022-05-16 15:44:07 +00:00
.sendReqFp = dmSendReq,
2024-01-10 09:57:08 +00:00
.sendSyncReqFp = dmSendSyncReq,
2022-05-16 15:44:07 +00:00
.sendRspFp = dmSendRsp,
.registerBrokenLinkArgFp = dmRegisterBrokenLinkArg,
.releaseHandleFp = dmReleaseHandle,
.reportStartupFp = dmReportStartup,
.updateDnodeInfoFp = dmUpdateDnodeInfo,
.getDnodeEpFp = dmGetDnodeEp,
.data = &pDnode->data,
2022-04-13 07:52:14 +00:00
};
return msgCb;
2022-04-21 06:29:22 +00:00
}