From fe4fb35392798a86663519883d39f7013fc9901c Mon Sep 17 00:00:00 2001 From: slguan Date: Mon, 9 Dec 2019 22:08:17 +0800 Subject: [PATCH 01/10] [TBASE-1241] --- src/inc/tglobalcfg.h | 2 +- src/modules/monitor/src/monitorSystem.c | 20 +------------------- src/os/linux/src/tsystem.c | 4 ++-- src/system/detail/src/dnodeSystem.c | 2 +- src/system/detail/src/mgmtShell.c | 7 ++----- src/system/detail/src/vnodeShell.c | 8 +++----- src/system/lite/src/mgmtDnode.spec.c | 2 +- src/util/src/tglobalcfg.c | 21 +++++++++------------ 8 files changed, 20 insertions(+), 46 deletions(-) diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h index ede3c97ce9..99bc3431d6 100644 --- a/src/inc/tglobalcfg.h +++ b/src/inc/tglobalcfg.h @@ -74,7 +74,6 @@ extern int tsMetricMetaKeepTimer; extern float tsNumOfThreadsPerCore; extern float tsRatioOfQueryThreads; extern char tsPublicIp[]; -extern char tsInternalIp[]; extern char tsPrivateIp[]; extern char tsServerIpStr[]; extern short tsNumOfVnodesPerCore; @@ -151,6 +150,7 @@ extern int tsTelegrafUseFieldNum; extern int tsAdminRowLimit; extern int tsTscEnableRecordSql; +extern int tsAnyIp; extern char tsMonitorDbName[]; extern char tsInternalPass[]; diff --git a/src/modules/monitor/src/monitorSystem.c b/src/modules/monitor/src/monitorSystem.c index c5f65eef36..86f075cb2f 100644 --- a/src/modules/monitor/src/monitorSystem.c +++ b/src/modules/monitor/src/monitorSystem.c @@ -113,11 +113,7 @@ void monitorInitConn(void *para, void *unused) { monitor->state = MONITOR_STATE_INITIALIZING; if (monitor->privateIpStr[0] == 0) { -#ifdef CLUSTER strcpy(monitor->privateIpStr, tsPrivateIp); -#else - strcpy(monitor->privateIpStr, tsInternalIp); -#endif for (int i = 0; i < TSDB_IPv4ADDR_LEN; ++i) { if (monitor->privateIpStr[i] == '.') { monitor->privateIpStr[i] = '_'; @@ -167,11 +163,7 @@ void dnodeBuildMonitorSql(char *sql, int cmd) { tsMonitorDbName, IP_LEN_STR + 1); } else if (cmd == MONITOR_CMD_CREATE_TB_DN) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.dn_%s using %s.dn tags('%s')", tsMonitorDbName, -#ifdef CLUSTER monitor->privateIpStr, tsMonitorDbName, tsPrivateIp); -#else - monitor->privateIpStr, tsMonitorDbName, tsInternalIp); -#endif } else if (cmd == MONITOR_CMD_CREATE_MT_ACCT) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.acct(ts timestamp " @@ -226,10 +218,8 @@ void monitorInitDatabaseCb(void *param, TAOS_RES *result, int code) { taosLogSqlFp = monitorExecuteSQL; #ifdef CLUSTER taosLogAcctFp = monitorSaveAcctLog; - monitorLPrint("dnode:%s is started", tsPrivateIp); -#else - monitorLPrint("dnode:%s is started", tsInternalIp); #endif + monitorLPrint("dnode:%s is started", tsPrivateIp); } monitor->cmdIndex++; monitorInitDatabase(); @@ -245,11 +235,7 @@ void monitorStopSystem() { return; } -#ifdef CLUSTER monitorLPrint("dnode:%s monitor module is stopped", tsPrivateIp); -#else - monitorLPrint("dnode:%s monitor module is stopped", tsInternalIp); -#endif monitor->state = MONITOR_STATE_STOPPED; taosLogFp = NULL; if (monitor->initTimer != NULL) { @@ -439,11 +425,7 @@ void monitorSaveLog(int level, const char *const format, ...) { va_end(argpointer); if (len > max_length) len = max_length; -#ifdef CLUSTER len += sprintf(sql + len, "', '%s')", tsPrivateIp); -#else - len += sprintf(sql + len, "', '%s')", tsInternalIp); -#endif sql[len++] = 0; monitorTrace("monitor:%p, save log, sql: %s", monitor->conn, sql); diff --git a/src/os/linux/src/tsystem.c b/src/os/linux/src/tsystem.c index 03192bb9cc..3b46a559a1 100644 --- a/src/os/linux/src/tsystem.c +++ b/src/os/linux/src/tsystem.c @@ -381,8 +381,8 @@ bool taosGetCardName(char *ip, char *name) { bool taosGetCardInfo(int64_t *bytes) { static char tsPublicCard[1000] = {0}; if (tsPublicCard[0] == 0) { - if (!taosGetCardName(tsInternalIp, tsPublicCard)) { - pError("can't get card name from ip:%s", tsInternalIp); + if (!taosGetCardName(tsPrivateIp, tsPublicCard)) { + pError("can't get card name from ip:%s", tsPrivateIp); return false; } int cardNameLen = (int)strlen(tsPublicCard); diff --git a/src/system/detail/src/dnodeSystem.c b/src/system/detail/src/dnodeSystem.c index 05a7bef486..f4bea50fc7 100644 --- a/src/system/detail/src/dnodeSystem.c +++ b/src/system/detail/src/dnodeSystem.c @@ -139,7 +139,7 @@ int dnodeInitSystem() { vnodeInitMgmtIp(); tsPrintGlobalConfig(); - dPrint("Server IP address is:%s", tsInternalIp); + dPrint("Server IP address is:%s", tsPrivateIp); taosSetCoreDump(); diff --git a/src/system/detail/src/mgmtShell.c b/src/system/detail/src/mgmtShell.c index 6084c5489d..e6afe11855 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -79,11 +79,8 @@ int mgmtInitShell() { if (numOfThreads < 1) numOfThreads = 1; memset(&rpcInit, 0, sizeof(rpcInit)); -#ifdef CLUSTER - rpcInit.localIp = tsInternalIp; -#else - rpcInit.localIp = "0.0.0.0"; -#endif + + rpcInit.localIp = tsAnyIp ? "0.0.0.0" : tsPrivateIp;; rpcInit.localPort = tsMgmtShellPort; rpcInit.label = "MND-shell"; rpcInit.numOfThreads = numOfThreads; diff --git a/src/system/detail/src/vnodeShell.c b/src/system/detail/src/vnodeShell.c index 66bede89b7..45d6cc64b5 100644 --- a/src/system/detail/src/vnodeShell.c +++ b/src/system/detail/src/vnodeShell.c @@ -143,11 +143,9 @@ int vnodeInitShell() { if (numOfThreads < 1) numOfThreads = 1; memset(&rpcInit, 0, sizeof(rpcInit)); -#ifdef CLUSTER - rpcInit.localIp = tsInternalIp; -#else - rpcInit.localIp = "0.0.0.0"; -#endif + + rpcInit.localIp = tsAnyIp ? "0.0.0.0" : tsPrivateIp; + rpcInit.localPort = tsVnodeShellPort; rpcInit.label = "DND-shell"; rpcInit.numOfThreads = numOfThreads; diff --git a/src/system/lite/src/mgmtDnode.spec.c b/src/system/lite/src/mgmtDnode.spec.c index dc7dd7d472..170683a998 100644 --- a/src/system/lite/src/mgmtDnode.spec.c +++ b/src/system/lite/src/mgmtDnode.spec.c @@ -27,7 +27,7 @@ int mgmtUpdateDnode(SDnodeObj *pDnode) { return 0; } void mgmtCleanUpDnodes() {} int mgmtInitDnodes() { - dnodeObj.privateIp = inet_addr(tsInternalIp);; + dnodeObj.privateIp = inet_addr(tsPrivateIp);; dnodeObj.createdTime = (int64_t)tsRebootTime * 1000; dnodeObj.lastReboot = tsRebootTime; dnodeObj.numOfCores = (uint16_t)tsNumOfCores; diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index cef11d30cb..aabc722519 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -75,7 +75,6 @@ int tsMetricMetaKeepTimer = 600; // second float tsNumOfThreadsPerCore = 1.0; float tsRatioOfQueryThreads = 0.5; char tsPublicIp[TSDB_IPv4ADDR_LEN] = {0}; -char tsInternalIp[TSDB_IPv4ADDR_LEN] = {0}; char tsPrivateIp[TSDB_IPv4ADDR_LEN] = {0}; char tsServerIpStr[TSDB_IPv4ADDR_LEN] = "127.0.0.1"; short tsNumOfVnodesPerCore = 8; @@ -164,6 +163,7 @@ int tsAdminRowLimit = 10240; int tsTscEnableRecordSql = 0; int tsEnableCoreFile = 0; +int tsAnyIp = 1; int tsRpcTimer = 300; int tsRpcMaxTime = 600; // seconds; @@ -448,9 +448,6 @@ static void doInitGlobalConfig() { tsInitConfigOption(cfg++, "privateIp", tsPrivateIp, TSDB_CFG_VTYPE_IPSTR, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLUSTER, 0, 0, TSDB_IPv4ADDR_LEN, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "internalIp", tsInternalIp, TSDB_CFG_VTYPE_IPSTR, - TSDB_CFG_CTYPE_B_CONFIG, - 0, 0, TSDB_IPv4ADDR_LEN, TSDB_CFG_UTYPE_NONE); tsInitConfigOption(cfg++, "localIp", tsLocalIp, TSDB_CFG_VTYPE_IPSTR, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, 0, 0, TSDB_IPv4ADDR_LEN, TSDB_CFG_UTYPE_NONE); @@ -709,7 +706,7 @@ static void doInitGlobalConfig() { 1, 100000, 0, TSDB_CFG_UTYPE_NONE); tsInitConfigOption(cfg++, "httpEnableRecordSql", &tsHttpEnableRecordSql, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG, - 1, 100000, 0, TSDB_CFG_UTYPE_NONE); + 0, 1, 0, TSDB_CFG_UTYPE_NONE); tsInitConfigOption(cfg++, "telegrafUseFieldNum", &tsTelegrafUseFieldNum, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, 0, 1, 1, TSDB_CFG_UTYPE_NONE); @@ -773,12 +770,16 @@ static void doInitGlobalConfig() { tsInitConfigOption(cfg++, "tscEnableRecordSql", &tsTscEnableRecordSql, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG, - 1, 100000, 0, TSDB_CFG_UTYPE_NONE); + 0, 1, 0, TSDB_CFG_UTYPE_NONE); tsInitConfigOption(cfg++, "enableCoreFile", &tsEnableCoreFile, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG, - 1, 100000, 0, TSDB_CFG_UTYPE_NONE); - + 0, 1, 0, TSDB_CFG_UTYPE_NONE); + + tsInitConfigOption(cfg++, "anyIp", &tsAnyIp, TSDB_CFG_VTYPE_INT, + TSDB_CFG_CTYPE_B_CONFIG, + 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, @@ -904,10 +905,6 @@ bool tsReadGlobalConfig() { strcpy(tsPublicIp, tsPrivateIp); } - if (tsInternalIp[0] == 0) { - strcpy(tsInternalIp, tsPrivateIp); - } - if (tsLocalIp[0] == 0) { strcpy(tsLocalIp, tsPrivateIp); } From 2bf71e71079ed55d68aecad4040afcde1914313f Mon Sep 17 00:00:00 2001 From: slguan Date: Tue, 10 Dec 2019 13:00:00 +0800 Subject: [PATCH 02/10] [TBASE-1241] --- src/client/src/tscServer.c | 5 +++ src/client/src/tscSql.c | 32 ++------------- src/inc/taosmsg.h | 4 ++ src/inc/tglobalcfg.h | 2 + src/inc/tutil.h | 2 + src/system/detail/inc/mgmt.h | 4 +- src/system/detail/src/dnodeService.c | 8 +--- src/system/detail/src/mgmtMeter.c | 22 ++++++---- src/system/detail/src/mgmtShell.c | 61 ++++++++++++++++++++++------ src/system/detail/src/mgmtVgroup.c | 16 +++++--- src/util/src/tglobalcfg.c | 10 +++++ src/util/src/tutil.c | 36 ++++++++++++++-- 12 files changed, 136 insertions(+), 66 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index d25b2dde53..3fac0c74f2 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2642,6 +2642,11 @@ int tscBuildConnectMsg(SSqlObj *pSql) { db = (db == NULL) ? pObj->db : db + 1; strcpy(pConnect->db, db); + strcpy(pConnect->clientVersion, version); + pConnect->usePublicIp = (int8_t)tsUsePublicIp; + pConnect->isCluster = (int8_t)tsIsCluster; + memset(pConnect->reserved, 0, sizeof(pConnect->reserved)); + pMsg += sizeof(SConnectMsg); msgLen = pMsg - pStart; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 233a37dc59..381b342fdc 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -165,38 +165,12 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha STscObj* pObj = (STscObj*) taos; // version compare only requires the first 3 segments of the version string - int32_t comparedSegments = 3; - char client_version[64] = {0}; - char server_version[64] = {0}; - int clientVersionNumber[4] = {0}; - int serverVersionNumber[4] = {0}; - - strcpy(client_version, version); - strcpy(server_version, taos_get_server_info(taos)); - - if (!taosGetVersionNumber(client_version, clientVersionNumber)) { - tscError("taos:%p, invalid client version:%s", taos, client_version); - pObj->pSql->res.code = TSDB_CODE_INVALID_CLIENT_VERSION; + int code = taosCheckVersion(version, taos_get_server_info(taos), 3); + if (code != 0) { + pObj->pSql->res.code = code; taos_close(taos); return NULL; } - - if (!taosGetVersionNumber(server_version, serverVersionNumber)) { - tscError("taos:%p, invalid server version:%s", taos, server_version); - pObj->pSql->res.code = TSDB_CODE_INVALID_CLIENT_VERSION; - taos_close(taos); - return NULL; - } - - for(int32_t i = 0; i < comparedSegments; ++i) { - if (clientVersionNumber[i] != serverVersionNumber[i]) { - tscError("taos:%p, the %d-th number of server version:%s not matched with client version:%s, close connection", - taos, i, server_version, version); - pObj->pSql->res.code = TSDB_CODE_INVALID_CLIENT_VERSION; - taos_close(taos); - return NULL; - } - } } return taos; diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index c1820a5b9c..ae58c43477 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -350,7 +350,11 @@ typedef struct { } SAlterTableMsg; typedef struct { + char clientVersion[TSDB_VERSION_LEN]; char db[TSDB_METER_ID_LEN]; + int8_t usePublicIp; + int8_t isCluster; + int8_t reserved[14]; } SConnectMsg; typedef struct { diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h index 99bc3431d6..0bf47d75ad 100644 --- a/src/inc/tglobalcfg.h +++ b/src/inc/tglobalcfg.h @@ -151,6 +151,8 @@ extern int tsAdminRowLimit; extern int tsTscEnableRecordSql; extern int tsAnyIp; +extern int tsUsePublicIp; +extern int tsIsCluster; extern char tsMonitorDbName[]; extern char tsInternalPass[]; diff --git a/src/inc/tutil.h b/src/inc/tutil.h index bdf9df63ee..df82c2113a 100644 --- a/src/inc/tutil.h +++ b/src/inc/tutil.h @@ -187,6 +187,8 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, cha memcpy(target, context.digest, TSDB_KEY_LEN); } +int taosCheckVersion(char *input_client_version, char *input_server_version, int compared_segments); + char *taosIpStr(uint32_t ipInt); #define TAOS_ALLOC_MODE_DEFAULT 0 diff --git a/src/system/detail/inc/mgmt.h b/src/system/detail/inc/mgmt.h index 75ec841076..b59c5cf61c 100644 --- a/src/system/detail/inc/mgmt.h +++ b/src/system/detail/inc/mgmt.h @@ -222,6 +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 reserved : 4; uint32_t queryId; // query ID to be killed uint32_t streamId; // stream ID to be killed uint32_t ip; // shell IP @@ -343,7 +345,7 @@ void mgmtCleanUpVgroups(); int mgmtInitMeters(); STabObj *mgmtGetMeter(char *meterId); STabObj *mgmtGetMeterInfo(char *src, char *tags[]); -int mgmtRetrieveMetricMeta(void *thandle, char **pStart, SMetricMetaMsg *pInfo); +int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pInfo); int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate); int mgmtDropMeter(SDbObj *pDb, char *meterId, int ignore); int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter); diff --git a/src/system/detail/src/dnodeService.c b/src/system/detail/src/dnodeService.c index f03bd5f3bb..eec918acd0 100644 --- a/src/system/detail/src/dnodeService.c +++ b/src/system/detail/src/dnodeService.c @@ -55,12 +55,8 @@ int main(int argc, char *argv[]) { exit(EXIT_FAILURE); } } else if (strcmp(argv[i], "-V") == 0) { - #ifdef CLUSTER - printf("enterprise version: %s compatible_version: %s\n", version, compatible_version); - #else - printf("community version: %s compatible_version: %s\n", version, compatible_version); - #endif - + char *versionStr = tsIsCluster ? "enterprise" : "community"; + printf("%s version: %s compatible_version: %s\n", versionStr, version, compatible_version); printf("gitinfo: %s\n", gitinfo); printf("buildinfo: %s\n", buildinfo); return 0; diff --git a/src/system/detail/src/mgmtMeter.c b/src/system/detail/src/mgmtMeter.c index 4e1d62e60e..9acd4f1326 100644 --- a/src/system/detail/src/mgmtMeter.c +++ b/src/system/detail/src/mgmtMeter.c @@ -987,7 +987,7 @@ SSchema *mgmtGetMeterSchema(STabObj *pMeter) { /* * serialize SVnodeSidList to byte array */ -static char *mgmtBuildMetricMetaMsg(STabObj *pMeter, int32_t *ovgId, SVnodeSidList **pList, SMetricMeta *pMeta, +static char *mgmtBuildMetricMetaMsg(SConnObj *pConn, STabObj *pMeter, int32_t *ovgId, SVnodeSidList **pList, SMetricMeta *pMeta, int32_t tagLen, int16_t numOfTags, int16_t *tagsId, int32_t maxNumOfMeters, char *pMsg) { if (pMeter->gid.vgId != *ovgId || ((*pList) != NULL && (*pList)->numOfSids >= maxNumOfMeters)) { @@ -1004,8 +1004,13 @@ static char *mgmtBuildMetricMetaMsg(STabObj *pMeter, int32_t *ovgId, SVnodeSidLi SVgObj *pVgroup = mgmtGetVgroup(pMeter->gid.vgId); for (int i = 0; i < TSDB_VNODES_SUPPORT; ++i) { - (*pList)->vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; - (*pList)->vpeerDesc[i].vnode = pVgroup->vnodeGid[i].vnode; + if (pConn->usePublicIp) { + (*pList)->vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; + (*pList)->vpeerDesc[i].vnode = pVgroup->vnodeGid[i].vnode; + } else { + (*pList)->vpeerDesc[i].ip = pVgroup->vnodeGid[i].ip; + (*pList)->vpeerDesc[i].vnode = pVgroup->vnodeGid[i].vnode; + } } pMsg += sizeof(SVnodeSidList); @@ -1102,10 +1107,10 @@ static SMetricMetaElemMsg *doConvertMetricMetaMsg(SMetricMetaMsg *pMetricMetaMsg return pElem; } -static int32_t mgmtBuildMetricMetaRspMsg(void *thandle, SMetricMetaMsg *pMetricMetaMsg, tQueryResultset *pResult, +static int32_t mgmtBuildMetricMetaRspMsg(SConnObj *pConn, SMetricMetaMsg *pMetricMetaMsg, tQueryResultset *pResult, char **pStart, int32_t *tagLen, int32_t rspMsgSize, int32_t maxTablePerVnode, int32_t code) { - *pStart = taosBuildRspMsgWithSize(thandle, TSDB_MSG_TYPE_METRIC_META_RSP, rspMsgSize); + *pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_METRIC_META_RSP, rspMsgSize); if (*pStart == NULL) { return 0; } @@ -1143,7 +1148,7 @@ static int32_t mgmtBuildMetricMetaRspMsg(void *thandle, SMetricMetaMsg *pMetricM for (int32_t i = 0; i < pResult[j].num; ++i) { STabObj *pMeter = pResult[j].pRes[i]; - pMsg = mgmtBuildMetricMetaMsg(pMeter, &ovgId, &pList, pMeta, tagLen[j], pElem->numOfTags, pElem->tagCols, + pMsg = mgmtBuildMetricMetaMsg(pConn, pMeter, &ovgId, &pList, pMeta, tagLen[j], pElem->numOfTags, pElem->tagCols, maxTablePerVnode, pMsg); } @@ -1159,7 +1164,7 @@ static int32_t mgmtBuildMetricMetaRspMsg(void *thandle, SMetricMetaMsg *pMetricM return msgLen; } -int mgmtRetrieveMetricMeta(void *thandle, char **pStart, SMetricMetaMsg *pMetricMetaMsg) { +int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetricMetaMsg) { /* * naive method: Do not limit the maximum number of meters in each * vnode(subquery), split the result according to vnodes @@ -1233,8 +1238,7 @@ int mgmtRetrieveMetricMeta(void *thandle, char **pStart, SMetricMetaMsg *pMetric msgLen = 512; } - msgLen = mgmtBuildMetricMetaRspMsg(thandle, pMetricMetaMsg, result, pStart, tagLen, msgLen, maxMetersPerVNodeForQuery, - ret); + msgLen = mgmtBuildMetricMetaRspMsg(pConn, pMetricMetaMsg, result, pStart, tagLen, msgLen, maxMetersPerVNodeForQuery, ret); for (int32_t i = 0; i < pMetricMetaMsg->numOfMeters; ++i) { tQueryResultClean(&result[i]); diff --git a/src/system/detail/src/mgmtShell.c b/src/system/detail/src/mgmtShell.c index e6afe11855..576353d758 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -314,8 +314,13 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { goto _exit_code; } for (int i = 0; i < TSDB_VNODES_SUPPORT; ++i) { - pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; - pMeta->vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); + if (pConn->usePublicIp) { + pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; + pMeta->vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); + } else { + pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].ip; + pMeta->vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); + } } } } @@ -453,8 +458,13 @@ int mgmtProcessMultiMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { } for (int i = 0; i < TSDB_VNODES_SUPPORT; ++i) { - pMeta->meta.vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; - pMeta->meta.vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); + if (pConn->usePublicIp) { + pMeta->meta.vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; + pMeta->meta.vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); + } else { + pMeta->meta.vpeerDesc[i].ip = pVgroup->vnodeGid[i].ip; + pMeta->meta.vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode); + } } } } @@ -526,7 +536,7 @@ int mgmtProcessMetricMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { msgLen = pMsg - pStart; } else { - msgLen = mgmtRetrieveMetricMeta(pConn->thandle, &pStart, pMetricMetaMsg); + msgLen = mgmtRetrieveMetricMeta(pConn, &pStart, pMetricMetaMsg); if (msgLen <= 0) { taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_METRIC_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); return 0; @@ -1099,10 +1109,17 @@ int mgmtProcessHeartBeatMsg(char *cont, int contLen, SConnObj *pConn) { pHBRsp->killConnection = pConn->killConnection; #ifdef CLUSTER - int size = pSdbPublicIpList->numOfIps * 4; - pHBRsp->ipList.numOfIps = pSdbPublicIpList->numOfIps; - memcpy(pHBRsp->ipList.ip, pSdbPublicIpList->ip, size); - pMsg += sizeof(SHeartBeatRsp) + size; + if (pConn->usePublicIp) { + int size = pSdbPublicIpList->numOfIps * 4; + pHBRsp->ipList.numOfIps = pSdbPublicIpList->numOfIps; + memcpy(pHBRsp->ipList.ip, pSdbPublicIpList->ip, size); + pMsg += sizeof(SHeartBeatRsp) + size; + } else { + int size = pSdbIpList->numOfIps * 4; + pHBRsp->ipList.numOfIps = pSdbIpList->numOfIps; + memcpy(pHBRsp->ipList.ip, pSdbIpList->ip, size); + pMsg += sizeof(SHeartBeatRsp) + size; + } #else pMsg += sizeof(SHeartBeatRsp); #endif @@ -1178,6 +1195,18 @@ int mgmtProcessConnectMsg(char *pMsg, int msgLen, SConnObj *pConn) { pAcct = mgmtGetAcct(pUser->acct); + code = taosCheckVersion(pConnectMsg->clientVersion, version, 3); + if (code != 0) { + mError("invalid client version:%s", pConnectMsg->clientVersion); + goto _rsp; + } + + if (pConnectMsg->isCluster != tsIsCluster) { + mError("Cluster Edition and lite Edition cannot be interconnected, client:%d server:%d", pConnectMsg->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); @@ -1217,9 +1246,17 @@ _rsp: pMsg += sizeof(SConnectRsp); #ifdef CLUSTER - int size = pSdbPublicIpList->numOfIps * 4 + sizeof(SIpList); - memcpy(pMsg, pSdbPublicIpList, size); - pMsg += size; + if (pConnectMsg->usePublicIp) { + pConn->usePublicIp = 1; + int size = pSdbPublicIpList->numOfIps * 4 + sizeof(SIpList); + memcpy(pMsg, pSdbPublicIpList, size); + pMsg += size; + } + else { + int size = pSdbIpList->numOfIps * 4 + sizeof(SIpList); + memcpy(pMsg, pSdbIpList, size); + pMsg += size; + } #endif // set the time resolution: millisecond or microsecond diff --git a/src/system/detail/src/mgmtVgroup.c b/src/system/detail/src/mgmtVgroup.c index e3bed57b33..d7e935241a 100644 --- a/src/system/detail/src/mgmtVgroup.c +++ b/src/system/detail/src/mgmtVgroup.c @@ -102,13 +102,17 @@ int mgmtInitVgroups() { } taosIdPoolReinit(pVgroup->idPool); -#ifdef CLUSTER - if (pVgroup->vnodeGid[0].publicIp == 0) { - pVgroup->vnodeGid[0].publicIp = inet_addr(tsPublicIp); - pVgroup->vnodeGid[0].ip = inet_addr(tsPrivateIp); - sdbUpdateRow(vgSdb, pVgroup, tsVgUpdateSize, 1); + + if (tsIsCluster) { + /* + * Upgrade from open source version to cluster version for the first time + */ + if (pVgroup->vnodeGid[0].publicIp == 0) { + pVgroup->vnodeGid[0].publicIp = inet_addr(tsPublicIp); + pVgroup->vnodeGid[0].ip = inet_addr(tsPrivateIp); + sdbUpdateRow(vgSdb, pVgroup, tsVgUpdateSize, 1); + } } -#endif mgmtSetDnodeVgid(pVgroup->vnodeGid, pVgroup->numOfVnodes, pVgroup->vgId); } diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index aabc722519..345dbdd4db 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -164,6 +164,13 @@ int tsAdminRowLimit = 10240; int tsTscEnableRecordSql = 0; int tsEnableCoreFile = 0; int tsAnyIp = 1; +int tsUsePublicIp = 0; + +#ifdef CLUSTER +int tsIsCluster = 1; +#else +int tsIsCluster = 0; +#endif int tsRpcTimer = 300; int tsRpcMaxTime = 600; // seconds; @@ -780,6 +787,9 @@ static void doInitGlobalConfig() { TSDB_CFG_CTYPE_B_CONFIG, 0, 1, 0, TSDB_CFG_UTYPE_NONE); + 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, diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index e0dcb0aa3f..f21ca96a81 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -24,6 +24,8 @@ #include "ttime.h" #include "ttypes.h" #include "tutil.h" +#include "tlog.h" +#include "taoserror.h" int32_t strdequote(char *z) { if (z == NULL) { @@ -450,10 +452,8 @@ bool taosValidateEncodec(char *encodec) { return false; } iconv_close(cd); - return true; -#else - return true; #endif + return true; } bool taosGetVersionNumber(char *versionStr, int *versionNubmer) { @@ -485,6 +485,36 @@ bool taosGetVersionNumber(char *versionStr, int *versionNubmer) { return true; } +int taosCheckVersion(char *input_client_version, char *input_server_version, int comparedSegments) { + char client_version[64] = {0}; + char server_version[64] = {0}; + int clientVersionNumber[4] = {0}; + int serverVersionNumber[4] = {0}; + + strcpy(client_version, input_client_version); + strcpy(server_version, input_server_version); + + if (!taosGetVersionNumber(client_version, clientVersionNumber)) { + pError("invalid client version:%s", client_version); + return TSDB_CODE_INVALID_CLIENT_VERSION; + } + + if (!taosGetVersionNumber(server_version, serverVersionNumber)) { + pError("invalid server version:%s", server_version); + return TSDB_CODE_INVALID_CLIENT_VERSION; + return NULL; + } + + for(int32_t i = 0; i < comparedSegments; ++i) { + if (clientVersionNumber[i] != serverVersionNumber[i]) { + tscError("the %d-th number of server version:%s not matched with client version:%s", i, server_version, version); + return TSDB_CODE_INVALID_CLIENT_VERSION; + } + } + + return 0; +} + char *taosIpStr(uint32_t ipInt) { static char ipStrArray[3][30]; static int ipStrIndex = 0; From b07e3dfd070d4563f513f6df4a673ddc895afe15 Mon Sep 17 00:00:00 2001 From: slguan Date: Tue, 10 Dec 2019 14:52:16 +0800 Subject: [PATCH 03/10] [TBASE-1241] --- src/util/src/tglobalcfg.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index 345dbdd4db..d1a61633ae 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -783,9 +783,12 @@ static void doInitGlobalConfig() { TSDB_CFG_CTYPE_B_CONFIG, 0, 1, 0, TSDB_CFG_UTYPE_NONE); +#ifdef CLUSTER tsInitConfigOption(cfg++, "anyIp", &tsAnyIp, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG, 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, From 1475d520a95e1a5ccb0e778d9d54fc87f7a1b303 Mon Sep 17 00:00:00 2001 From: slguan Date: Tue, 10 Dec 2019 17:36:43 +0800 Subject: [PATCH 04/10] [TBASE-1241] --- src/util/src/tglobalcfg.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index d1a61633ae..edff1c432b 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -787,7 +787,6 @@ static void doInitGlobalConfig() { tsInitConfigOption(cfg++, "anyIp", &tsAnyIp, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG, 0, 1, 0, TSDB_CFG_UTYPE_NONE); - } #endif tsInitConfigOption(cfg++, "usePublicIp", &tsUsePublicIp, TSDB_CFG_VTYPE_INT, From d774aa3993542766e3551e93212000d7923ac48f Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 11 Dec 2019 14:39:48 +0800 Subject: [PATCH 05/10] [TBASE-1241] --- src/client/src/tscServer.c | 3 --- src/inc/taosmsg.h | 14 ++++++++------ src/rpc/src/trpc.c | 2 ++ src/system/detail/inc/mgmt.h | 3 ++- src/system/detail/src/mgmtShell.c | 24 ++++++++++++++---------- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 3fac0c74f2..801256644c 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2643,9 +2643,6 @@ int tscBuildConnectMsg(SSqlObj *pSql) { strcpy(pConnect->db, db); strcpy(pConnect->clientVersion, version); - pConnect->usePublicIp = (int8_t)tsUsePublicIp; - pConnect->isCluster = (int8_t)tsIsCluster; - memset(pConnect->reserved, 0, sizeof(pConnect->reserved)); pMsg += sizeof(SConnectMsg); diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index ae58c43477..1d20ad76ed 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -224,7 +224,9 @@ typedef struct { uint32_t destId; char meterId[TSDB_UNI_LEN]; uint16_t port; // for UDP only - char empty[1]; + uint8_t usePublicIp : 1; + uint8_t isCluster : 1; + uint8_t empty : 6; uint8_t msgType; int32_t msgLen; uint8_t content[0]; @@ -352,9 +354,6 @@ typedef struct { typedef struct { char clientVersion[TSDB_VERSION_LEN]; char db[TSDB_METER_ID_LEN]; - int8_t usePublicIp; - int8_t isCluster; - int8_t reserved[14]; } SConnectMsg; typedef struct { @@ -667,8 +666,11 @@ typedef struct { typedef struct { uint32_t destId; char meterId[TSDB_UNI_LEN]; - char empty[3]; - char msgType; + uint16_t port; // for UDP only + uint8_t usePublicIp : 1; + uint8_t isCluster : 1; + uint8_t empty : 6; + uint8_t msgType; int32_t msgLen; uint8_t content[0]; } SIntMsg; diff --git a/src/rpc/src/trpc.c b/src/rpc/src/trpc.c index 9f006ab05a..7b5229ddc7 100755 --- a/src/rpc/src/trpc.c +++ b/src/rpc/src/trpc.c @@ -246,6 +246,8 @@ 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)); diff --git a/src/system/detail/inc/mgmt.h b/src/system/detail/inc/mgmt.h index b59c5cf61c..e339274025 100644 --- a/src/system/detail/inc/mgmt.h +++ b/src/system/detail/inc/mgmt.h @@ -223,7 +223,8 @@ typedef struct _connObj { char writeAuth : 1; // write flag char killConnection : 1; // kill the connection flag char usePublicIp : 1; // if the connection request is publicIp - char reserved : 4; + char isCluster : 1; + char reserved : 3; 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 576353d758..4334218530 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -1201,8 +1201,8 @@ int mgmtProcessConnectMsg(char *pMsg, int msgLen, SConnObj *pConn) { goto _rsp; } - if (pConnectMsg->isCluster != tsIsCluster) { - mError("Cluster Edition and lite Edition cannot be interconnected, client:%d server:%d", pConnectMsg->isCluster, tsIsCluster); + 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; } @@ -1246,17 +1246,13 @@ _rsp: pMsg += sizeof(SConnectRsp); #ifdef CLUSTER - if (pConnectMsg->usePublicIp) { - pConn->usePublicIp = 1; - int size = pSdbPublicIpList->numOfIps * 4 + sizeof(SIpList); + int size = pSdbPublicIpList->numOfIps * 4 + sizeof(SIpList); + if (pConn->usePublicIp) { memcpy(pMsg, pSdbPublicIpList, size); - pMsg += size; - } - else { - int size = pSdbIpList->numOfIps * 4 + sizeof(SIpList); + } else { memcpy(pMsg, pSdbIpList, size); - pMsg += size; } + pMsg += size; #endif // set the time resolution: millisecond or microsecond @@ -1305,8 +1301,16 @@ void *mgmtProcessMsgFromShell(char *msg, void *ahandle, void *thandle) { pConn = connList + pMsg->destId; pConn->thandle = thandle; strcpy(pConn->user, pMsg->meterId); + + uint32_t ip = taosGetRpcLocalIp(thandle); + if (ip == tsPublicIp) { + pConn->usePublicIp = true; + } } + 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 { From 04b5df6273da6ed9fa307bf3cfc494da9a984478 Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 11 Dec 2019 15:12:17 +0800 Subject: [PATCH 06/10] [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); From 8314e22328d5872f763522aa0d7d49a31c19099c Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 11 Dec 2019 15:23:08 +0800 Subject: [PATCH 07/10] [TBASE-1241] --- src/system/detail/src/mgmtShell.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/system/detail/src/mgmtShell.c b/src/system/detail/src/mgmtShell.c index d94c205625..f78791ea75 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -1224,9 +1224,7 @@ int mgmtProcessConnectMsg(char *pMsg, int msgLen, SConnObj *pConn) { 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); if (pStart == NULL) return 0; From 7d6db536d0f16b61eaf99e377f08b8464b0d5d06 Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 11 Dec 2019 16:19:44 +0800 Subject: [PATCH 08/10] [TBASE-1241] --- src/inc/taosmsg.h | 2 ++ src/rpc/src/trpc.c | 1 + src/system/detail/src/mgmtShell.c | 11 +++++------ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index b4baaff745..db36309222 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -222,6 +222,7 @@ typedef struct { // internal part uint32_t destId; + uint32_t destIp; char meterId[TSDB_UNI_LEN]; uint16_t port; // for UDP only char empty[1]; @@ -663,6 +664,7 @@ typedef struct { // internal message typedef struct { uint32_t destId; + uint32_t destIp; char meterId[TSDB_UNI_LEN]; char empty[3]; char msgType; diff --git a/src/rpc/src/trpc.c b/src/rpc/src/trpc.c index 35740acc14..21f2ae4dc0 100755 --- a/src/rpc/src/trpc.c +++ b/src/rpc/src/trpc.c @@ -1219,6 +1219,7 @@ int taosSendMsgToPeerH(void *thandle, char *pCont, int contLen, void *ahandle) { pServer = pConn->pServer; pChann = pServer->channList + pConn->chann; pHeader = (STaosHeader *)(pCont - sizeof(STaosHeader)); + pHeader->destIp = pConn->peerIp; msg = (char *)pHeader; if ((pHeader->msgType & 1U) == 0 && pConn->localPort) pHeader->port = pConn->localPort; diff --git a/src/system/detail/src/mgmtShell.c b/src/system/detail/src/mgmtShell.c index f78791ea75..c56939e0dd 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -1224,7 +1224,7 @@ int mgmtProcessConnectMsg(char *pMsg, int msgLen, SConnObj *pConn) { uint32_t peerIp = taosGetRpcLocalIp(pConn->thandle); pConn->usePublicIp = (peerIp == tsPublicIpInt ? 1 : 0); mgmtEstablishConn(pConn); - + _rsp: pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_CONNECT_RSP, 128); if (pStart == NULL) return 0; @@ -1298,13 +1298,12 @@ void *mgmtProcessMsgFromShell(char *msg, void *ahandle, void *thandle) { pConn = connList + pMsg->destId; pConn->thandle = thandle; strcpy(pConn->user, pMsg->meterId); - - 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->destIp == tsPublicIpInt ? 1 : 0); + mTrace("pConn:%p, destIp:%s publicIp:%s usePublicIp:%u", + pConn, taosIpStr(pMsg->destIp), taosIpStr(tsPublicIpInt), pConn->usePublicIp); + if (pMsg->msgType == TSDB_MSG_TYPE_CONNECT) { (*mgmtProcessShellMsg[pMsg->msgType])((char *)pMsg->content, pMsg->msgLen - sizeof(SIntMsg), pConn); } else { From a3c0c50d9000078c6657f3db4a5bff4669f97123 Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 11 Dec 2019 16:22:11 +0800 Subject: [PATCH 09/10] [TBASE-1241] --- src/system/detail/src/mgmtShell.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/system/detail/src/mgmtShell.c b/src/system/detail/src/mgmtShell.c index c56939e0dd..c5fb87bcdb 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -1298,11 +1298,11 @@ void *mgmtProcessMsgFromShell(char *msg, void *ahandle, void *thandle) { pConn = connList + pMsg->destId; pConn->thandle = thandle; strcpy(pConn->user, pMsg->meterId); - } - pConn->usePublicIp = (pMsg->destIp == tsPublicIpInt ? 1 : 0); - mTrace("pConn:%p, destIp:%s publicIp:%s usePublicIp:%u", - pConn, taosIpStr(pMsg->destIp), taosIpStr(tsPublicIpInt), pConn->usePublicIp); + pConn->usePublicIp = (pMsg->destIp == tsPublicIpInt ? 1 : 0); + mPrint("pConn:%p is rebuild, destIp:%s publicIp:%s usePublicIp:%u", + pConn, taosIpStr(pMsg->destIp), taosIpStr(tsPublicIpInt), pConn->usePublicIp); + } if (pMsg->msgType == TSDB_MSG_TYPE_CONNECT) { (*mgmtProcessShellMsg[pMsg->msgType])((char *)pMsg->content, pMsg->msgLen - sizeof(SIntMsg), pConn); From 6dfc958cf4a36dcf07f042aaf559b38437eb6763 Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 11 Dec 2019 16:30:40 +0800 Subject: [PATCH 10/10] [TBASE-1241] --- src/inc/trpc.h | 2 -- src/rpc/src/trpc.c | 5 ----- src/system/detail/src/mgmtShell.c | 10 +++------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/inc/trpc.h b/src/inc/trpc.h index 6554d0d201..97a0c905f8 100644 --- a/src/inc/trpc.h +++ b/src/inc/trpc.h @@ -109,8 +109,6 @@ 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 21f2ae4dc0..88bfbc2c2d 100755 --- a/src/rpc/src/trpc.c +++ b/src/rpc/src/trpc.c @@ -1411,11 +1411,6 @@ 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/src/mgmtShell.c b/src/system/detail/src/mgmtShell.c index c5fb87bcdb..b738c0dab3 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -1220,11 +1220,8 @@ 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); - + _rsp: pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_CONNECT_RSP, 128); if (pStart == NULL) return 0; @@ -1298,10 +1295,9 @@ void *mgmtProcessMsgFromShell(char *msg, void *ahandle, void *thandle) { pConn = connList + pMsg->destId; pConn->thandle = thandle; strcpy(pConn->user, pMsg->meterId); - pConn->usePublicIp = (pMsg->destIp == tsPublicIpInt ? 1 : 0); - mPrint("pConn:%p is rebuild, destIp:%s publicIp:%s usePublicIp:%u", - pConn, taosIpStr(pMsg->destIp), taosIpStr(tsPublicIpInt), pConn->usePublicIp); + mTrace("pConn:%p is rebuild, destIp:%s publicIp:%s usePublicIp:%u", + pConn, taosIpStr(pMsg->destIp), taosIpStr(tsPublicIpInt), pConn->usePublicIp); } if (pMsg->msgType == TSDB_MSG_TYPE_CONNECT) {