From db21aead7637fa328425f18ebd0f7a38f7d24c64 Mon Sep 17 00:00:00 2001 From: slguan Date: Tue, 21 Apr 2020 11:45:49 +0800 Subject: [PATCH] [TD-148] fix redirect message --- src/client/src/tscServer.c | 18 ++++++++++-------- src/client/src/tscSystem.c | 2 ++ src/mnode/src/mgmtShell.c | 16 +++++++++++++--- tests/script/sh/deploy.sh | 2 +- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index ad5f9cd0af..9bfac58cf4 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -68,11 +68,11 @@ void tscPrintMgmtIp() { } void tscSetMgmtIpListFromCluster(SRpcIpSet *pIpList) { - tscMgmtIpList.numOfIps = htons(pIpList->numOfIps); - tscMgmtIpList.inUse = htons(pIpList->inUse); + tscMgmtIpList.numOfIps = pIpList->numOfIps; + tscMgmtIpList.inUse = pIpList->inUse; tscMgmtIpList.port = htons(pIpList->port); - for (int32_t i = 0; i ip[i]; + for (int32_t i = 0; i < tscMgmtIpList.numOfIps; ++i) { + tscMgmtIpList.ip[i] = htonl(pIpList->ip[i]); } } @@ -87,6 +87,11 @@ void tscSetMgmtIpListFromEdge() { } } +void tscUpdateIpSet(void *ahandle, SRpcIpSet *pIpSet) { + tscTrace("mgmt IP list is changed for ufp is called"); + tscSetMgmtIpListFromCluster(pIpSet); +} + void tscSetMgmtIpList(SRpcIpSet *pIpList) { /* * The iplist returned by the cluster edition is the current management nodes @@ -2224,10 +2229,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) { assert(len <= tListLen(pObj->db)); strncpy(pObj->db, temp, tListLen(pObj->db)); -// SIpList * pIpList; -// char *rsp = pRes->pRsp + sizeof(SCMConnectRsp); -// pIpList = (SIpList *)rsp; -// tscSetMgmtIpList(pIpList); + tscSetMgmtIpList(&pConnect->ipList); strcpy(pObj->sversion, pConnect->serverVersion); pObj->writeAuth = pConnect->writeAuth; diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index a24ca4d045..093890bbdc 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -47,6 +47,7 @@ int tscNumOfThreads; static pthread_once_t tscinit = PTHREAD_ONCE_INIT; void taosInitNote(int numOfNoteLines, int maxNotes, char* lable); +void tscUpdateIpSet(void *ahandle, SRpcIpSet *pIpSet); void tscCheckDiskUsage(void *para, void *unused) { taosGetDisk(); @@ -65,6 +66,7 @@ int32_t tscInitRpc(const char *user, const char *secret) { rpcInit.label = "TSC-vnode"; rpcInit.numOfThreads = tscNumOfThreads; rpcInit.cfp = tscProcessMsgFromServer; + rpcInit.ufp = tscUpdateIpSet; rpcInit.sessions = tsMaxVnodeConnections; rpcInit.connType = TAOS_CONN_CLIENT; rpcInit.user = (char*)user; diff --git a/src/mnode/src/mgmtShell.c b/src/mnode/src/mgmtShell.c index 522968895e..f12240a766 100644 --- a/src/mnode/src/mgmtShell.c +++ b/src/mnode/src/mgmtShell.c @@ -145,9 +145,14 @@ static void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg) { } if (!sdbIsMaster()) { - // rpcSendRedirectRsp(rpcMsg->handle, mgmtGetMnodeIpListForRedirect()); - mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_NO_MASTER); - rpcFreeCont(rpcMsg->pCont); + SRpcConnInfo connInfo; + rpcGetConnInfo(rpcMsg->handle, &connInfo); + bool usePublicIp = (connInfo.serverIp == tsPublicIpInt); + + SRpcIpSet ipSet = {0}; + mgmtGetMnodeIpList(&ipSet, usePublicIp); + mTrace("conn from ip:%s user:%s redirect msg", taosIpStr(connInfo.clientIp), connInfo.user); + rpcSendRedirectRsp(rpcMsg->handle, &ipSet); return; } @@ -357,6 +362,11 @@ static int mgmtShellRetriveAuth(char *user, char *spi, char *encrypt, char *secr *encrypt = 0; *ckey = 0; + if (!sdbIsMaster()) { + *secret = 0; + return TSDB_CODE_SUCCESS; + } + SUserObj *pUser = mgmtGetUser(user); if (pUser == NULL) { *secret = 0; diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 12f9689fd3..6c4ada50fe 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -93,7 +93,7 @@ echo "privateIp $NODE_IP" >> $TAOS_CFG echo "dDebugFlag 199" >> $TAOS_CFG echo "mDebugFlag 199" >> $TAOS_CFG echo "sdbDebugFlag 199" >> $TAOS_CFG -echo "rpcDebugFlag 131" >> $TAOS_CFG +echo "rpcDebugFlag 135" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG echo "cDebugFlag 135" >> $TAOS_CFG echo "httpDebugFlag 131" >> $TAOS_CFG -- GitLab