From 04b5df6273da6ed9fa307bf3cfc494da9a984478 Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 11 Dec 2019 15:12:17 +0800 Subject: [PATCH] [TBASE-1241] --- src/inc/taosmsg.h | 11 +++-------- src/inc/tglobalcfg.h | 2 +- src/inc/trpc.h | 2 ++ src/rpc/src/trpc.c | 7 +++++-- src/system/detail/inc/mgmt.h | 5 ++--- src/system/detail/src/mgmtShell.c | 22 +++++++++------------- src/util/src/tglobalcfg.c | 6 ++---- 7 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 1d20ad76ed..b4baaff745 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -224,9 +224,7 @@ typedef struct { uint32_t destId; char meterId[TSDB_UNI_LEN]; uint16_t port; // for UDP only - uint8_t usePublicIp : 1; - uint8_t isCluster : 1; - uint8_t empty : 6; + char empty[1]; uint8_t msgType; int32_t msgLen; uint8_t content[0]; @@ -666,11 +664,8 @@ typedef struct { typedef struct { uint32_t destId; char meterId[TSDB_UNI_LEN]; - uint16_t port; // for UDP only - uint8_t usePublicIp : 1; - uint8_t isCluster : 1; - uint8_t empty : 6; - uint8_t msgType; + char empty[3]; + char msgType; int32_t msgLen; uint8_t content[0]; } SIntMsg; diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h index 0bf47d75ad..60b18c77dc 100644 --- a/src/inc/tglobalcfg.h +++ b/src/inc/tglobalcfg.h @@ -80,6 +80,7 @@ extern short tsNumOfVnodesPerCore; extern short tsNumOfTotalVnodes; extern short tsCheckHeaderFile; extern uint32_t tsServerIp; +extern uint32_t tsPublicIpInt; extern int tsSessionsPerVnode; extern int tsAverageCacheBlocks; @@ -151,7 +152,6 @@ extern int tsAdminRowLimit; extern int tsTscEnableRecordSql; extern int tsAnyIp; -extern int tsUsePublicIp; extern int tsIsCluster; extern char tsMonitorDbName[]; diff --git a/src/inc/trpc.h b/src/inc/trpc.h index 97a0c905f8..6554d0d201 100644 --- a/src/inc/trpc.h +++ b/src/inc/trpc.h @@ -109,6 +109,8 @@ int taosSetSecurityInfo(int cid, int sid, char *id, int spi, int encrypt, char * void taosGetRpcConnInfo(void *thandle, uint32_t *peerId, uint32_t *peerIp, uint16_t *peerPort, int *cid, int *sid); +uint32_t taosGetRpcLocalIp(void *thandle); + int taosGetOutType(void *thandle); #ifdef __cplusplus diff --git a/src/rpc/src/trpc.c b/src/rpc/src/trpc.c index 7b5229ddc7..35740acc14 100755 --- a/src/rpc/src/trpc.c +++ b/src/rpc/src/trpc.c @@ -246,8 +246,6 @@ char *taosBuildReqHeader(void *param, char type, char *msg) { pHeader->destId = pConn->peerId; pHeader->port = 0; pHeader->uid = (uint32_t)pConn + (uint32_t)getpid(); - pHeader->usePublicIp = (tsUsePublicIp == 0 ? 0 : 1); - pHeader->isCluster = (tsIsCluster == 0 ? 0 : 1); memcpy(pHeader->meterId, pConn->meterId, tListLen(pHeader->meterId)); @@ -1412,6 +1410,11 @@ void taosGetRpcConnInfo(void *thandle, uint32_t *peerId, uint32_t *peerIp, uint1 *sid = pConn->sid; } +uint32_t taosGetRpcLocalIp(void *thandle) { + SRpcConn *pConn = (SRpcConn *)thandle; + return pConn->peerIp; +} + int taosGetOutType(void *thandle) { SRpcConn *pConn = (SRpcConn *)thandle; if (pConn == NULL) return -1; diff --git a/src/system/detail/inc/mgmt.h b/src/system/detail/inc/mgmt.h index e339274025..d5d604e313 100644 --- a/src/system/detail/inc/mgmt.h +++ b/src/system/detail/inc/mgmt.h @@ -222,9 +222,8 @@ typedef struct _connObj { char superAuth : 1; // super user flag char writeAuth : 1; // write flag char killConnection : 1; // kill the connection flag - char usePublicIp : 1; // if the connection request is publicIp - char isCluster : 1; - char reserved : 3; + uint8_t usePublicIp : 1; // if the connection request is publicIp + uint8_t reserved : 4; uint32_t queryId; // query ID to be killed uint32_t streamId; // stream ID to be killed uint32_t ip; // shell IP diff --git a/src/system/detail/src/mgmtShell.c b/src/system/detail/src/mgmtShell.c index 4334218530..d94c205625 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -1201,12 +1201,6 @@ int mgmtProcessConnectMsg(char *pMsg, int msgLen, SConnObj *pConn) { goto _rsp; } - if (pConn->isCluster != tsIsCluster) { - mError("Cluster Edition and lite Edition cannot be interconnected, client:%d server:%d", pConn->isCluster, tsIsCluster); - code = TSDB_CODE_INVALID_CLIENT_VERSION; - goto _rsp; - } - if (pConnectMsg->db[0]) { sprintf(dbName, "%x%s%s", pAcct->acctId, TS_PATH_DELIMITER, pConnectMsg->db); pDb = mgmtGetDb(dbName); @@ -1226,7 +1220,12 @@ int mgmtProcessConnectMsg(char *pMsg, int msgLen, SConnObj *pConn) { pConn->pAcct = pAcct; pConn->pDb = pDb; pConn->pUser = pUser; + + uint32_t peerIp = taosGetRpcLocalIp(pConn->thandle); + pConn->usePublicIp = (peerIp == tsPublicIpInt ? 1 : 0); mgmtEstablishConn(pConn); + mPrint("pConn:%p is created, peerIp:%s publicIp:%s usePublicIp:%u", + pConn, taosIpStr(peerIp), taosIpStr(tsPublicIpInt), pConn->usePublicIp); _rsp: pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_CONNECT_RSP, 128); @@ -1302,15 +1301,12 @@ void *mgmtProcessMsgFromShell(char *msg, void *ahandle, void *thandle) { pConn->thandle = thandle; strcpy(pConn->user, pMsg->meterId); - uint32_t ip = taosGetRpcLocalIp(thandle); - if (ip == tsPublicIp) { - pConn->usePublicIp = true; - } + uint32_t peerIp = taosGetRpcLocalIp(thandle); + pConn->usePublicIp = (peerIp == tsPublicIpInt ? 1 : 0); + mPrint("pConn:%p is rebuild, peerIp:%s publicIp:%s usePublicIp:%u", + pConn, taosIpStr(peerIp), taosIpStr(tsPublicIpInt), pConn->usePublicIp); } - pConn->usePublicIp = pMsg->usePublicIp; - pConn->isCluster = pMsg->isCluster; - if (pMsg->msgType == TSDB_MSG_TYPE_CONNECT) { (*mgmtProcessShellMsg[pMsg->msgType])((char *)pMsg->content, pMsg->msgLen - sizeof(SIntMsg), pConn); } else { diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index edff1c432b..748843cdcc 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -164,7 +164,7 @@ int tsAdminRowLimit = 10240; int tsTscEnableRecordSql = 0; int tsEnableCoreFile = 0; int tsAnyIp = 1; -int tsUsePublicIp = 0; +uint32_t tsPublicIpInt = 0; #ifdef CLUSTER int tsIsCluster = 1; @@ -789,9 +789,6 @@ static void doInitGlobalConfig() { 0, 1, 0, TSDB_CFG_UTYPE_NONE); #endif - tsInitConfigOption(cfg++, "usePublicIp", &tsUsePublicIp, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 1, 0, TSDB_CFG_UTYPE_NONE); // version info tsInitConfigOption(cfg++, "gitinfo", gitinfo, TSDB_CFG_VTYPE_STRING, TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT, @@ -916,6 +913,7 @@ bool tsReadGlobalConfig() { if (tsPublicIp[0] == 0) { strcpy(tsPublicIp, tsPrivateIp); } + tsPublicIpInt = inet_addr(tsPublicIp); if (tsLocalIp[0] == 0) { strcpy(tsLocalIp, tsPrivateIp); -- GitLab