From 654a5061ff631d88dd681c821d67fb386288913f Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Mon, 4 Nov 2019 13:16:31 +0800 Subject: [PATCH] configure the socket type(TCP/UDP) in config file.#671 --- packaging/cfg/taos.cfg | 3 +++ src/client/src/tscSystem.c | 4 ++-- src/inc/tglobalcfg.h | 14 ++++++++------ src/inc/trpc.h | 3 +++ src/system/src/mgmtShell.c | 2 +- src/system/src/vnodeShell.c | 2 +- src/util/src/tglobalcfg.c | 9 ++++++++- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/packaging/cfg/taos.cfg b/packaging/cfg/taos.cfg index d9a9ce32a2..3f7ece8826 100644 --- a/packaging/cfg/taos.cfg +++ b/packaging/cfg/taos.cfg @@ -54,6 +54,9 @@ # interval of system monitor # monitorInterval 60 +# set socket type(UDP by default). if udpsocket is 0, TCP is applied for all connections +# udpsocket 1 + # RPC re-try timer, millisecond # rpcTimer 300 diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 7428399210..ff0c1555ff 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -118,7 +118,7 @@ void taos_init_imp() { rpcInit.sessionsPerChann = tsMaxVnodeConnections / tscNumOfThreads; rpcInit.idMgmt = TAOS_ID_FREE; rpcInit.noFree = 0; - rpcInit.connType = TAOS_CONN_UDP; + rpcInit.connType = TAOS_CONN_SOCKET_TYPE_C(); rpcInit.qhandle = tscQhandle; pVnodeConn = taosOpenRpc(&rpcInit); if (pVnodeConn == NULL) { @@ -139,7 +139,7 @@ void taos_init_imp() { rpcInit.sessionsPerChann = tsMaxMgmtConnections; rpcInit.idMgmt = TAOS_ID_FREE; rpcInit.noFree = 0; - rpcInit.connType = TAOS_CONN_UDP; + rpcInit.connType = TAOS_CONN_SOCKET_TYPE_C(); rpcInit.qhandle = tscQhandle; pTscMgmtConn = taosOpenRpc(&rpcInit); if (pTscMgmtConn == NULL) { diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h index cfc89997d3..054317fcae 100644 --- a/src/inc/tglobalcfg.h +++ b/src/inc/tglobalcfg.h @@ -132,6 +132,8 @@ extern int tsStreamCompRetryDelay; extern int tsProjectExecInterval; extern int64_t tsMaxRetentWindow; +extern int tsUDPSocket; + extern char tsHttpIp[]; extern short tsHttpPort; extern int tsHttpCacheSessions; @@ -182,12 +184,12 @@ void tsSetTimeZone(); void tsSetLocale(); void tsInitGlobalConfig(); -#define TSDB_CFG_CTYPE_B_CONFIG 1 // can be configured from file -#define TSDB_CFG_CTYPE_B_SHOW 2 // can displayed by "show configs" commands -#define TSDB_CFG_CTYPE_B_LOG 4 // is a log type configuration -#define TSDB_CFG_CTYPE_B_CLIENT 8 // can be displayed in the client log -#define TSDB_CFG_CTYPE_B_OPTION 16 // can be configured by taos_options function -#define TSDB_CFG_CTYPE_B_NOT_PRINT 32 +#define TSDB_CFG_CTYPE_B_CONFIG 1U // can be configured from file +#define TSDB_CFG_CTYPE_B_SHOW 2U // can displayed by "show configs" commands +#define TSDB_CFG_CTYPE_B_LOG 4U // is a log type configuration +#define TSDB_CFG_CTYPE_B_CLIENT 8U // can be displayed in the client log +#define TSDB_CFG_CTYPE_B_OPTION 16U // can be configured by taos_options function +#define TSDB_CFG_CTYPE_B_NOT_PRINT 32U #define TSDB_CFG_CSTATUS_NONE 0 // not configured #define TSDB_CFG_CSTATUS_DEFAULT 1 // use system default value diff --git a/src/inc/trpc.h b/src/inc/trpc.h index 70804903e3..0532f1c129 100644 --- a/src/inc/trpc.h +++ b/src/inc/trpc.h @@ -34,6 +34,9 @@ extern "C" { #define TAOS_ID_FREE 1 #define TAOS_ID_REALLOCATE 2 +#define TAOS_CONN_SOCKET_TYPE_S() ((tsUDPSocket == 1)? TAOS_CONN_UDPS:TAOS_CONN_TCPS) +#define TAOS_CONN_SOCKET_TYPE_C() ((tsUDPSocket == 1)? TAOS_CONN_UDP:TAOS_CONN_TCPC) + #define taosSendMsgToPeer(x, y, z) taosSendMsgToPeerH(x, y, z, NULL) #define taosOpenRpcChann(x, y, z) taosOpenRpcChannWithQ(x, y, z, NULL) #define taosBuildReqMsg(x, y) taosBuildReqMsgWithSize(x, y, 512) diff --git a/src/system/src/mgmtShell.c b/src/system/src/mgmtShell.c index 19f706f4a8..9621af763b 100644 --- a/src/system/src/mgmtShell.c +++ b/src/system/src/mgmtShell.c @@ -64,7 +64,7 @@ int mgmtInitShell() { rpcInit.numOfChanns = 1; rpcInit.sessionsPerChann = tsMaxShellConns; rpcInit.idMgmt = TAOS_ID_FREE; - rpcInit.connType = TAOS_CONN_UDPS; + rpcInit.connType = TAOS_CONN_SOCKET_TYPE_S(); rpcInit.idleTime = tsShellActivityTimer * 2000; rpcInit.qhandle = mgmtQhandle; rpcInit.afp = mgmtRetriveUserAuthInfo; diff --git a/src/system/src/vnodeShell.c b/src/system/src/vnodeShell.c index c87c504dcb..66818766d9 100644 --- a/src/system/src/vnodeShell.c +++ b/src/system/src/vnodeShell.c @@ -127,7 +127,7 @@ int vnodeInitShell() { rpcInit.numOfChanns = TSDB_MAX_VNODES; rpcInit.sessionsPerChann = 16; rpcInit.idMgmt = TAOS_ID_FREE; - rpcInit.connType = TAOS_CONN_UDPS; + rpcInit.connType = TAOS_CONN_SOCKET_TYPE_S(); rpcInit.idleTime = tsShellActivityTimer * 2000; rpcInit.qhandle = rpcQhandle[0]; rpcInit.efp = vnodeSendVpeerCfgMsg; diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index 7bdd4df7e5..f26732e688 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -122,6 +122,8 @@ int tsStreamCompRetryDelay = 10; // the stream computing delay int tsProjectExecInterval = 10000; // every 10sec, the projection will be executed once int64_t tsMaxRetentWindow = 24 * 3600L; // maximum time window tolerance +int tsUDPSocket = 1; // use UDP by default, if tsUDPSocket equals to 0, all connection use TCP socket + char tsHttpIp[TSDB_IPv4ADDR_LEN] = "0.0.0.0"; short tsHttpPort = 6020; // only tcp, range tcp[6020] // short tsNginxPort = 6060; //only tcp, range tcp[6060] @@ -494,7 +496,12 @@ void tsInitGlobalConfig() { tsInitConfigOption(cfg++, "defaultUser", tsDefaultUser, TSDB_CFG_VTYPE_STRING, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, 0, 0, TSDB_USER_LEN, TSDB_CFG_UTYPE_NONE); tsInitConfigOption(cfg++, "defaultPass", tsDefaultPass, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_NOT_PRINT, 0, 0, TSDB_PASSWORD_LEN, TSDB_CFG_UTYPE_NONE); + TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_NOT_PRINT, 0, 0, + TSDB_PASSWORD_LEN, TSDB_CFG_UTYPE_NONE); + + // socket type, udp by default + tsInitConfigOption(cfg++, "udpsocket", &tsUDPSocket, TSDB_CFG_VTYPE_INT, + TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW, 0, 1, 1, TSDB_CFG_UTYPE_NONE); // locale & charset tsInitConfigOption(cfg++, "timezone", tsTimezone, TSDB_CFG_VTYPE_STRING, -- GitLab