From 1b19b963c8284f974a76e8eed8d7cd433a536024 Mon Sep 17 00:00:00 2001 From: "Haolin.song" <403438485@qq.com> Date: Tue, 20 Mar 2018 15:31:31 +0000 Subject: [PATCH 1/2] [TRAFODION-3003]Trafodion keepalive support Keepalive could be configured by modifying file src/main/java/org/trafodion/dcs/Constants.java Modify variable DCS_SERVER_PROGRAM_TCP_KEEPALIVE_STATUS/IDLETIME/INTERVAL/RETRYCOUNT; DCS_SERVER_PROGRAM_TCP_KEEPALIVE_STATUS has three value:enable,default,unenable; Default value is enable,300,3,20(Only effective when value configured is set incorrectly) The value will be read in when mxosrvr start. Mxosrvr will set the socket after getting a connection. --- core/conn/odbc/src/odbc/Common/Global.h | 15 +++- core/conn/odbc/src/odbc/Common/Listener.h | 9 +- .../odbc/nsksrvr/Interface/Listener_srvr.cpp | 47 ++++++++++- .../odbc/nsksrvr/Interface/Listener_srvr.h | 4 +- .../Interface/linux/Listener_srvr_ps.cpp | 7 +- core/conn/odbc/src/odbc/nsksrvr/SrvrMain.cpp | 83 ++++++++++++++++++- core/conn/odbc/src/odbc/nsksrvrcore/Makefile | 2 +- .../java/org/trafodion/dcs/Constants.java | 25 +++++- .../trafodion/dcs/server/ServerManager.java | 24 ++++++ dcs/src/main/resources/dcs-default.xml | 29 +++++++ 10 files changed, 234 insertions(+), 11 deletions(-) diff --git a/core/conn/odbc/src/odbc/Common/Global.h b/core/conn/odbc/src/odbc/Common/Global.h index 09f39bc24e..8dc22cf8f9 100644 --- a/core/conn/odbc/src/odbc/Common/Global.h +++ b/core/conn/odbc/src/odbc/Common/Global.h @@ -139,10 +139,16 @@ class ODBCMXTraceMsg; #define DEFAULT_REFRESH_RATE_SECS 60 #define DEFAULT_SRVR_IDLE_TIMEOUT 0 #define DEFAULT_CONN_IDLE_TIMEOUT 0 +#define DEFAULT_KEEPALIVE 1 //OPEN KEEPALIVE +#define DEFAULT_KEEPALIVE_TIMESEC 3600 +#define DEFAULT_KEEPALIVE_COUNT 3 +#define DEFAULT_KEEPALIVE_INTVL 20 #define INFINITE_SRVR_IDLE_TIMEOUT -1 #define INFINITE_CONN_IDLE_TIMEOUT -1 #define STATE_TRANSITION_TIMEOUT_SECS 300 +#define CLIENT_KEEPALIVE_ATTR_TIMEOUT 3001 + #define JDBC_ATTR_CONN_IDLE_TIMEOUT 3000 #define JDBC_DATASOURCE_CONN_IDLE_TIMEOUT -1L #define JDBC_INFINITE_CONN_IDLE_TIMEOUT 0 @@ -935,7 +941,10 @@ typedef struct _SRVR_GLOBAL_Def bzero(m_ProcName,sizeof(m_ProcName)); m_bNewConnection = false; m_bNewService = false; - + bzero(clientKeepaliveStatus, sizeof(clientKeepaliveStatus)); + clientKeepaliveIdletime = 0; + clientKeepaliveIntervaltime = 0; + clientKeepaliveRetrycount = 0; m_rule_wms_off = false; // perf m_rule_endstats_off = false;// perf @@ -1053,6 +1062,10 @@ typedef struct _SRVR_GLOBAL_Def tip_handle_t tip_gateway; + char clientKeepaliveStatus[64]; + int clientKeepaliveIdletime; + int clientKeepaliveIntervaltime; + int clientKeepaliveRetrycount; char *pxid_url; IDL_long_long local_xid; UINT xid_length; diff --git a/core/conn/odbc/src/odbc/Common/Listener.h b/core/conn/odbc/src/odbc/Common/Listener.h index 028f437ecf..670161b896 100644 --- a/core/conn/odbc/src/odbc/Common/Listener.h +++ b/core/conn/odbc/src/odbc/Common/Listener.h @@ -26,7 +26,7 @@ #include #include #include - +#include enum CURR_TCPIP_OPER{ CURR_UNDEFINED, CURR_OPEN, @@ -34,6 +34,13 @@ enum CURR_TCPIP_OPER{ CURR_OTHER }; +typedef struct KEEPALIVE_OPT{ + int isKeepalive; + int keepaliveIdle; + int keepaliveInterval; + int keepCount; +}; + #define INITIALIZE_TRACE(TransportTrace) \ m_TransportTrace = TransportTrace; \ if (m_TransportTrace) { \ diff --git a/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp b/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp index a7d358d9fa..bdd40ce639 100644 --- a/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp +++ b/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp @@ -27,7 +27,7 @@ #include "Global.h" -//extern SRVR_GLOBAL_Def *srvrGlobal; // needed in the platform specific implementation file +extern SRVR_GLOBAL_Def *srvrGlobal; // needed in the platform specific implementation file //extern void flushCollectors(); // needed in the platform specific implementation file CNSKListenerSrvr::CNSKListenerSrvr() @@ -81,4 +81,49 @@ void CNSKListenerSrvr::TCP_PROCESSNAME_PORT(FILE* fp) fprintf(fp,"<==========TCP/PORT (%s/%d)==========>\n",m_TcpProcessName, m_port); } +void CNSKListenerSrvr::TCP_SetKeepalive(int socketnum, + char *keepaliveStatus, + int idleTime, + int intervalTime, + int retryCount) +{ + //all need to be configured + if(NULL == keepaliveStatus){ + return; + } + if(0 == strcmp(keepaliveStatus,"default")){ + keepaliveOpt.isKeepalive = DEFAULT_KEEPALIVE; + keepaliveOpt.keepaliveIdle = DEFAULT_KEEPALIVE_TIMESEC; + keepaliveOpt.keepaliveInterval = DEFAULT_KEEPALIVE_INTVL; + keepaliveOpt.keepCount = DEFAULT_KEEPALIVE_COUNT; + }else + if(0 == strcmp(keepaliveStatus,"unenable")){ + keepaliveOpt.isKeepalive = 0; + keepaliveOpt.keepaliveIdle = DEFAULT_KEEPALIVE_TIMESEC; + keepaliveOpt.keepaliveInterval = DEFAULT_KEEPALIVE_INTVL; + keepaliveOpt.keepCount = DEFAULT_KEEPALIVE_COUNT; + }else + if(0 == strcmp(keepaliveStatus, "enable")){ + keepaliveOpt.isKeepalive = 1; + keepaliveOpt.keepaliveIdle = idleTime; + keepaliveOpt.keepaliveInterval = intervalTime; + keepaliveOpt.keepCount = retryCount; + + }else{ + keepaliveOpt.isKeepalive = 0; + keepaliveOpt.keepaliveIdle = DEFAULT_KEEPALIVE_TIMESEC; + keepaliveOpt.keepaliveInterval = DEFAULT_KEEPALIVE_INTVL; + keepaliveOpt.keepCount = DEFAULT_KEEPALIVE_COUNT; + } + int error; + error += setsockopt(socketnum, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepaliveOpt.isKeepalive , sizeof(keepaliveOpt.isKeepalive)); + error += setsockopt(socketnum, SOL_TCP, TCP_KEEPIDLE, (void*)&keepaliveOpt.keepaliveIdle , sizeof(keepaliveOpt.keepaliveIdle )); + error += setsockopt(socketnum, SOL_TCP, TCP_KEEPINTVL, (void *)&keepaliveOpt.keepaliveInterval , sizeof(keepaliveOpt.keepaliveInterval )); + error += setsockopt(socketnum, SOL_TCP, TCP_KEEPCNT, (void *)&keepaliveOpt.keepCount , sizeof(keepaliveOpt.keepCount )); + + if (error != 0){ + SET_WARNING((long)0, NSK, TCPIP, UNKNOWN_API, errorType_, + "set socket keepalive opt error", O_INIT_PROCESS, F_SOCKET, 0, 0); + } +} diff --git a/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.h b/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.h index aab35d6018..9a5d01078f 100644 --- a/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.h +++ b/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.h @@ -47,8 +47,8 @@ class CNSKListenerSrvr: public CNSKListener long getPort() { return m_port; }; void closeTCPIPSession(int fnum); - - + KEEPALIVE_OPT keepaliveOpt; + void TCP_SetKeepalive(int socketnum, char *keepaliveStatus, int idleTime, int intervalTime, int retryCount); protected: long m_port; CURR_TCPIP_OPER m_tcpip_operation; diff --git a/core/conn/odbc/src/odbc/nsksrvr/Interface/linux/Listener_srvr_ps.cpp b/core/conn/odbc/src/odbc/nsksrvr/Interface/linux/Listener_srvr_ps.cpp index 96553491f8..b4cbcff6dd 100644 --- a/core/conn/odbc/src/odbc/nsksrvr/Interface/linux/Listener_srvr_ps.cpp +++ b/core/conn/odbc/src/odbc/nsksrvr/Interface/linux/Listener_srvr_ps.cpp @@ -263,7 +263,11 @@ void* CNSKListenerSrvr::OpenTCPIPSession() //LCOV_EXCL_STOP } - + TCP_SetKeepalive(nSocketFnum, + srvrGlobal->clientKeepaliveStatus, + srvrGlobal->clientKeepaliveIdletime, + srvrGlobal->clientKeepaliveIntervaltime, + srvrGlobal->clientKeepaliveRetrycount); pnode = GTransport.m_TCPIPSystemSrvr_list->ins_node(nSocketFnum); if (pnode == NULL) @@ -444,6 +448,7 @@ void * CNSKListenerSrvr::tcpip_listener(void *arg) { GTransport.m_TCPIPSystemSrvr_list->del_node(pnode->m_nSocketFnum); + SET_ERROR((long)0, NSK, TCPIP, UNKNOWN_API, E_SERVER,"tcpip_listener", O_SELECT, F_SELECT,errno, pnode->m_nSocketFnum); SRVR::BreakDialogue(NULL); } else diff --git a/core/conn/odbc/src/odbc/nsksrvr/SrvrMain.cpp b/core/conn/odbc/src/odbc/nsksrvr/SrvrMain.cpp index 20ebd2a78f..52e4ce1727 100644 --- a/core/conn/odbc/src/odbc/nsksrvr/SrvrMain.cpp +++ b/core/conn/odbc/src/odbc/nsksrvr/SrvrMain.cpp @@ -95,7 +95,10 @@ long initSessMemSize; int portMapToSecs = -1; int portBindToSecs = -1; bool bPlanEnabled = false; - +char keepaliveStatus[256]; +int keepaliveIdletime; +int keepaliveIntervaltime; +int keepaliveRetrycount; void watcher(zhandle_t *zzh, int type, int state, const char *path, void *watcherCtx); bool verifyPortAvailable(const char * idForPort, int portNumber); BOOL getInitParamSrvr(int argc, char *argv[], SRVR_INIT_PARAM_Def &initParam, char* strName, char* strValue); @@ -791,7 +794,14 @@ catch(SB_Fatal_Excep sbfe) //LCOV_EXCL_STOP } } - + if( strlen(keepaliveStatus) > 0){ + strncpy( srvrGlobal->clientKeepaliveStatus, keepaliveStatus, strlen(keepaliveStatus)); + srvrGlobal->clientKeepaliveIntervaltime = keepaliveIntervaltime; + srvrGlobal->clientKeepaliveIdletime = keepaliveIdletime; + srvrGlobal->clientKeepaliveRetrycount = keepaliveRetrycount; + }else{ + strncpy( srvrGlobal->clientKeepaliveStatus, "unenable", strlen("unenable")); + } // TCPADD and RZ are required parameters. // The address is passed in with TCPADD parameter . // The hostname is passed in with RZ parameter. @@ -1427,7 +1437,74 @@ BOOL getInitParamSrvr(int argc, char *argv[], SRVR_INIT_PARAM_Def &initParam, ch argEmpty = TRUE; break; } - } + }else + if (strcmp(arg, "-TCPKEEPALIVESTATUS") == 0){ + if (++count < argc && argv[count][0] != '-') + { + if (strlen(argv[count]) < sizeof(keepaliveStatus) - 1) + { + memset(keepaliveStatus, 0, sizeof(keepaliveStatus) - 1); + strncpy(keepaliveStatus, argv[count], sizeof(keepaliveStatus) - 1); + } + else + { + argWrong = TRUE; + } + } + else + { + argEmpty = TRUE; + break; + } + }else + if (strcmp(arg, "-TCPKEEPALIVEIDLETIME") == 0){ + if (++count < argc ) + { + if(strspn(argv[count], "0123456789")==strlen(argv[count])){ + keepaliveIdletime = atoi(argv[count]); + }else + { + argWrong = TRUE; + } + } + else + { + argEmpty = TRUE; + break; + } + }else + if (strcmp(arg, "-TCPKEEPALIVEINTERVAL") == 0){ + if (++count < argc ) + { + if(strspn(argv[count], "0123456789")==strlen(argv[count])){ + keepaliveIntervaltime = atoi(argv[count]); + }else + { + argWrong = TRUE; + } + } + else + { + argEmpty = TRUE; + break; + } + }else + if (strcmp(arg, "-TCPKEEPALIVERETRYCOUNT") == 0){ + if (++count < argc ) + { + if(strspn(argv[count], "0123456789")==strlen(argv[count])){ + keepaliveRetrycount = atoi(argv[count]); + }else + { + argWrong = TRUE; + } + } + else + { + argEmpty = TRUE; + break; + } + } count++; } diff --git a/core/conn/odbc/src/odbc/nsksrvrcore/Makefile b/core/conn/odbc/src/odbc/nsksrvrcore/Makefile index ea7af7fc42..1de3061d68 100644 --- a/core/conn/odbc/src/odbc/nsksrvrcore/Makefile +++ b/core/conn/odbc/src/odbc/nsksrvrcore/Makefile @@ -64,7 +64,7 @@ OBJS = $(OUTDIR)/CommonDiags.o \ $(OUTDIR)/srvrothers.o \ $(OUTDIR)/libmxocore_version.o -INCLUDES = -I. -I../Common -I../EventMsgs -I../SrvrMsg -I../dependencies/include -I../dependencies/linux -I../Krypton/generated_incs -I$(TRAF_HOME)/export/include/sql -I$(TRAF_HOME)/inc/tmf_tipapi -I$(TRAF_HOME)/inc -I$(TRAF_HOME)/export/include -I$(TRAF_HOME)/sql/nq_w/common -I../OssCfgCl/src -I../CmdCfgDll -I$(PROTOBUFS_INC) -I$(TRAF_HOME)/../sql/cli -I$(TRAF_HOME)/commonLogger -I$(TRAF_HOME)/../dbsecurity/cert/inc -I$(TRAF_HOME)/../dbsecurity/auth/inc -I$(LOG4CXX_INC_DIR) -I$(TRAF_HOME)/../mpi/src/include/intern +INCLUDES = -I. -I ../nsksrvr/Interface/ -I../Common -I../EventMsgs -I../SrvrMsg -I../dependencies/include -I../dependencies/linux -I../Krypton/generated_incs -I$(TRAF_HOME)/export/include/sql -I$(TRAF_HOME)/inc/tmf_tipapi -I$(TRAF_HOME)/inc -I$(TRAF_HOME)/export/include -I$(TRAF_HOME)/sql/nq_w/common -I../OssCfgCl/src -I../CmdCfgDll -I$(PROTOBUFS_INC) -I$(TRAF_HOME)/../sql/cli -I$(TRAF_HOME)/commonLogger -I$(TRAF_HOME)/../dbsecurity/cert/inc -I$(TRAF_HOME)/../dbsecurity/auth/inc -I$(LOG4CXX_INC_DIR) -I$(TRAF_HOME)/../mpi/src/include/intern DEFINES = -DNA_LINUX -DSIZEOF_LONG_INT=4 -DUSE_NEW_PHANDLE -DSQ_GUARDIAN_CALL -D_M_DG -DINC_QPID_EVENT -w diff --git a/dcs/src/main/java/org/trafodion/dcs/Constants.java b/dcs/src/main/java/org/trafodion/dcs/Constants.java index 3f8843737e..de51773518 100644 --- a/dcs/src/main/java/org/trafodion/dcs/Constants.java +++ b/dcs/src/main/java/org/trafodion/dcs/Constants.java @@ -92,7 +92,7 @@ public final class Constants { public static final String DCS_SERVER_USER_PROGRAM_COMMAND = "dcs.server.user.program.command"; /** Default value for DCS server user program command */ - public static final String DEFAULT_DCS_SERVER_USER_PROGRAM_COMMAND = "cd ${dcs.user.program.home};. ./sqenv.sh;mxosrvr -ZKHOST -RZ -ZKPNODE -CNGTO -ZKSTO -EADSCO -TCPADD -MAXHEAPPCT -STATISTICSINTERVAL -STATISTICSLIMIT -STATISTICSTYPE -STATISTICSENABLE -SQLPLAN -PORTMAPTOSECS -PORTBINDTOSECS"; + public static final String DEFAULT_DCS_SERVER_USER_PROGRAM_COMMAND = "cd ${dcs.user.program.home};. ./sqenv.sh;mxosrvr -ZKHOST -RZ -ZKPNODE -CNGTO -ZKSTO -EADSCO -TCPADD -MAXHEAPPCT -STATISTICSINTERVAL -STATISTICSLIMIT -STATISTICSTYPE -STATISTICSENABLE -SQLPLAN -PORTMAPTOSECS -PORTBINDTOSECS -TCPKEEPALIVESTATUS -TCPKEEPALIVEIDLETIME -TCPKEEPALIVEINTERVAL -TCPKEEPALIVERETRYCOUNT"; /** Configuration key for DCS server user program connecting timeout */ public static final String DCS_SERVER_USER_PROGRAM_CONNECTING_TIMEOUT = "dcs.server.user.program.connecting.timeout"; @@ -112,6 +112,29 @@ public final class Constants { /** Default value for DCS server user program exit after disconnect */ public static final int DEFAULT_DCS_SERVER_USER_PROGRAM_EXIT_AFTER_DISCONNECT = 0; + /** Configuration key for DCS server program mxosrvr keepalive STATUS*/ + public static final String DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_STATUS= "dcs.server.user.program.tcp.keepalive.status"; + + /** Default value for DCS server program mxosrvr keepalive STATUS*/ + public static final String DCS_SERVER_PROGRAM_KEEPALIVE_STATUS = "enable"; + + /** Configuration key for DCS server program mxosrvr keepalive IDLETIME*/ + public static final String DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_IDLETIME = "dcs.server.user.program.tcp.keepalive.idletime"; + + /** Default value for DCS server program mxosrvr keepalive IDLETIME*/ + public static final int DCS_SERVER_PROGRAM_KEEPALIVE_IDLETIME = 300; + + /** Configuration key for DCS server program mxosrvr keepalive INTERTIME */ + public static final String DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_INTERVALTIME = "dcs.server.user.program.tcp.keepalive.intervaltime"; + + /** Default value for DCS server program mxosrvr keepalive INTERTIME */ + public static final int DCS_SERVER_PROGRAM_KEEPALIVE_INTERVALTIME = 5; + + /** Configuration key for DCS server program mxosrvr keepalive RETRYCNT*/ + public static final String DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_RETRYCOUNT = "dcs.server.user.program.tcp.keepalive.retrycount"; + + /** Default value for DCS server program mxosrvr keepalive RETRYCNT*/ + public static final int DCS_SERVER_PROGRAM_KEEPALIVE_RETRYCOUNT = 3; /** * Configuration key for DCS server user program exit when heap size becomes * too large diff --git a/dcs/src/main/java/org/trafodion/dcs/server/ServerManager.java b/dcs/src/main/java/org/trafodion/dcs/server/ServerManager.java index 89186d5108..23e572186f 100644 --- a/dcs/src/main/java/org/trafodion/dcs/server/ServerManager.java +++ b/dcs/src/main/java/org/trafodion/dcs/server/ServerManager.java @@ -83,6 +83,10 @@ public final class ServerManager implements Callable { private int maxRestartAttempts; private int retryIntervalMillis; private String nid = null; + private static String mxosrvrKeepaliveStatus; + private static int mxosrvrKeepaliveIdletime; + private static int mxosrvrKeepaliveIntervaltime; + private static int mxosrvrKeepaliveRetrycount; class RegisteredWatcher implements Watcher { CountDownLatch startSignal; @@ -205,6 +209,14 @@ public ServerRunner(int childInstance, String registeredPath) { "-PORTMAPTOSECS " + userProgPortMapToSecs + " ") .replace("-PORTBINDTOSECS", "-PORTBINDTOSECS " + userProgPortBindToSecs) + .replace("-TCPKEEPALIVESTATUS", + "-TCPKEEPALIVESTATUS " + mxosrvrKeepaliveStatus + " ") + .replace("-TCPKEEPALIVEIDLETIME", + "-TCPKEEPALIVEIDLETIME " + mxosrvrKeepaliveIdletime + " ") + .replace("-TCPKEEPALIVEINTERVAL", + "-TCPKEEPALIVEINTERVAL " + mxosrvrKeepaliveIntervaltime + " ") + .replace("-TCPKEEPALIVERETRYCOUNT", + "-TCPKEEPALIVERETRYCOUNT " + mxosrvrKeepaliveRetrycount + " ") .replace("<", "<").replace("&", "&") .replace(">", ">"); scriptContext.setCommand(command); @@ -348,6 +360,18 @@ public ServerManager(Configuration conf, ZkClient zkc, this.retryIntervalMillis = conf .getInt(Constants.DCS_SERVER_USER_PROGRAM_RESTART_HANDLER_RETRY_INTERVAL_MILLIS, Constants.DEFAULT_DCS_SERVER_USER_PROGRAM_RESTART_HANDLER_RETRY_INTERVAL_MILLIS); + this.mxosrvrKeepaliveStatus = conf.get( + Constants.DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_STATUS, + Constants.DCS_SERVER_PROGRAM_KEEPALIVE_STATUS); + this.mxosrvrKeepaliveIdletime = conf.getInt( + Constants.DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_IDLETIME, + Constants.DCS_SERVER_PROGRAM_KEEPALIVE_IDLETIME); + this.mxosrvrKeepaliveIntervaltime = conf.getInt( + Constants.DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_INTERVALTIME, + Constants.DCS_SERVER_PROGRAM_KEEPALIVE_INTERVALTIME); + this.mxosrvrKeepaliveRetrycount = conf.getInt( + Constants.DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_RETRYCOUNT, + Constants.DCS_SERVER_PROGRAM_KEEPALIVE_RETRYCOUNT); serverHandlers = new ServerHandler[this.childServers]; } diff --git a/dcs/src/main/resources/dcs-default.xml b/dcs/src/main/resources/dcs-default.xml index 12a4bf7917..9967b5bcee 100644 --- a/dcs/src/main/resources/dcs-default.xml +++ b/dcs/src/main/resources/dcs-default.xml @@ -386,4 +386,33 @@ Timeout minutes between first and max times (6 default) DCS Server startup MXOSRVR. + + dcs.server.user.program.tcp.keepalive.status + enable + + Used in mxosrvr keepalive , parameter is ENABLE IDLETIME INTERTIME RETRYCNT. + + + + dcs.server.user.program.tcp.keepalive.idletime + 300 + + Used in mxosrvr keepalive , parameter is ENABLE IDLETIME INTERTIME RETRYCNT. + + + + dcs.server.user.program.tcp.keepalive.intervaltime + 5 + + Used in mxosrvr keepalive , parameter is ENABLE IDLETIME INTERTIME RETRYCNT. + + + + dcs.server.user.program.tcp.keepalive.retrycount + 3 + + Used in mxosrvr keepalive , parameter is ENABLE IDLETIME INTERTIME RETRYCNT. + + + From 8cd59bf0146fde470e1484b5a03adefd6647865d Mon Sep 17 00:00:00 2001 From: "Haolin.song" <403438485@qq.com> Date: Wed, 28 Mar 2018 11:15:50 +0000 Subject: [PATCH 2/2] Change some variable. Make the description more detailed. --- core/conn/odbc/src/odbc/Common/Global.h | 12 ++++----- .../odbc/nsksrvr/Interface/Listener_srvr.cpp | 22 +++------------ .../odbc/nsksrvr/Interface/Listener_srvr.h | 4 +-- core/conn/odbc/src/odbc/nsksrvr/SrvrMain.cpp | 27 ++++++++++--------- .../java/org/trafodion/dcs/Constants.java | 2 +- .../trafodion/dcs/server/ServerManager.java | 24 ++++++++--------- dcs/src/main/resources/dcs-default.xml | 14 +++++----- 7 files changed, 47 insertions(+), 58 deletions(-) diff --git a/core/conn/odbc/src/odbc/Common/Global.h b/core/conn/odbc/src/odbc/Common/Global.h index 8dc22cf8f9..0789b1c814 100644 --- a/core/conn/odbc/src/odbc/Common/Global.h +++ b/core/conn/odbc/src/odbc/Common/Global.h @@ -139,7 +139,7 @@ class ODBCMXTraceMsg; #define DEFAULT_REFRESH_RATE_SECS 60 #define DEFAULT_SRVR_IDLE_TIMEOUT 0 #define DEFAULT_CONN_IDLE_TIMEOUT 0 -#define DEFAULT_KEEPALIVE 1 //OPEN KEEPALIVE +#define DEFAULT_KEEPALIVE 0 //OPEN KEEPALIVE #define DEFAULT_KEEPALIVE_TIMESEC 3600 #define DEFAULT_KEEPALIVE_COUNT 3 #define DEFAULT_KEEPALIVE_INTVL 20 @@ -941,7 +941,7 @@ typedef struct _SRVR_GLOBAL_Def bzero(m_ProcName,sizeof(m_ProcName)); m_bNewConnection = false; m_bNewService = false; - bzero(clientKeepaliveStatus, sizeof(clientKeepaliveStatus)); + clientKeepaliveStatus = false; clientKeepaliveIdletime = 0; clientKeepaliveIntervaltime = 0; clientKeepaliveRetrycount = 0; @@ -1062,10 +1062,10 @@ typedef struct _SRVR_GLOBAL_Def tip_handle_t tip_gateway; - char clientKeepaliveStatus[64]; - int clientKeepaliveIdletime; - int clientKeepaliveIntervaltime; - int clientKeepaliveRetrycount; + BOOL clientKeepaliveStatus; + int clientKeepaliveIdletime; + int clientKeepaliveIntervaltime; + int clientKeepaliveRetrycount; char *pxid_url; IDL_long_long local_xid; UINT xid_length; diff --git a/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp b/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp index bdd40ce639..a31b51bf2a 100644 --- a/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp +++ b/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp @@ -82,38 +82,22 @@ void CNSKListenerSrvr::TCP_PROCESSNAME_PORT(FILE* fp) } void CNSKListenerSrvr::TCP_SetKeepalive(int socketnum, - char *keepaliveStatus, + bool keepaliveStatus, int idleTime, int intervalTime, int retryCount) { //all need to be configured - if(NULL == keepaliveStatus){ - return; - } - if(0 == strcmp(keepaliveStatus,"default")){ + if(!keepaliveStatus){ keepaliveOpt.isKeepalive = DEFAULT_KEEPALIVE; keepaliveOpt.keepaliveIdle = DEFAULT_KEEPALIVE_TIMESEC; keepaliveOpt.keepaliveInterval = DEFAULT_KEEPALIVE_INTVL; keepaliveOpt.keepCount = DEFAULT_KEEPALIVE_COUNT; - }else - if(0 == strcmp(keepaliveStatus,"unenable")){ - keepaliveOpt.isKeepalive = 0; - keepaliveOpt.keepaliveIdle = DEFAULT_KEEPALIVE_TIMESEC; - keepaliveOpt.keepaliveInterval = DEFAULT_KEEPALIVE_INTVL; - keepaliveOpt.keepCount = DEFAULT_KEEPALIVE_COUNT; - }else - if(0 == strcmp(keepaliveStatus, "enable")){ + }else{ keepaliveOpt.isKeepalive = 1; keepaliveOpt.keepaliveIdle = idleTime; keepaliveOpt.keepaliveInterval = intervalTime; keepaliveOpt.keepCount = retryCount; - - }else{ - keepaliveOpt.isKeepalive = 0; - keepaliveOpt.keepaliveIdle = DEFAULT_KEEPALIVE_TIMESEC; - keepaliveOpt.keepaliveInterval = DEFAULT_KEEPALIVE_INTVL; - keepaliveOpt.keepCount = DEFAULT_KEEPALIVE_COUNT; } int error; diff --git a/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.h b/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.h index 9a5d01078f..dcf4f4bbb3 100644 --- a/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.h +++ b/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.h @@ -47,8 +47,8 @@ class CNSKListenerSrvr: public CNSKListener long getPort() { return m_port; }; void closeTCPIPSession(int fnum); - KEEPALIVE_OPT keepaliveOpt; - void TCP_SetKeepalive(int socketnum, char *keepaliveStatus, int idleTime, int intervalTime, int retryCount); + KEEPALIVE_OPT keepaliveOpt; + void TCP_SetKeepalive(int socketnum, bool keepaliveStatus, int idleTime, int intervalTime, int retryCount); protected: long m_port; CURR_TCPIP_OPER m_tcpip_operation; diff --git a/core/conn/odbc/src/odbc/nsksrvr/SrvrMain.cpp b/core/conn/odbc/src/odbc/nsksrvr/SrvrMain.cpp index 52e4ce1727..132a0a4869 100644 --- a/core/conn/odbc/src/odbc/nsksrvr/SrvrMain.cpp +++ b/core/conn/odbc/src/odbc/nsksrvr/SrvrMain.cpp @@ -95,7 +95,7 @@ long initSessMemSize; int portMapToSecs = -1; int portBindToSecs = -1; bool bPlanEnabled = false; -char keepaliveStatus[256]; +bool keepaliveStatus = false; int keepaliveIdletime; int keepaliveIntervaltime; int keepaliveRetrycount; @@ -794,14 +794,12 @@ catch(SB_Fatal_Excep sbfe) //LCOV_EXCL_STOP } } - if( strlen(keepaliveStatus) > 0){ - strncpy( srvrGlobal->clientKeepaliveStatus, keepaliveStatus, strlen(keepaliveStatus)); - srvrGlobal->clientKeepaliveIntervaltime = keepaliveIntervaltime; - srvrGlobal->clientKeepaliveIdletime = keepaliveIdletime; - srvrGlobal->clientKeepaliveRetrycount = keepaliveRetrycount; - }else{ - strncpy( srvrGlobal->clientKeepaliveStatus, "unenable", strlen("unenable")); - } + + srvrGlobal->clientKeepaliveStatus = keepaliveStatus; + srvrGlobal->clientKeepaliveIntervaltime = keepaliveIntervaltime; + srvrGlobal->clientKeepaliveIdletime = keepaliveIdletime; + srvrGlobal->clientKeepaliveRetrycount = keepaliveRetrycount; + // TCPADD and RZ are required parameters. // The address is passed in with TCPADD parameter . // The hostname is passed in with RZ parameter. @@ -1441,10 +1439,15 @@ BOOL getInitParamSrvr(int argc, char *argv[], SRVR_INIT_PARAM_Def &initParam, ch if (strcmp(arg, "-TCPKEEPALIVESTATUS") == 0){ if (++count < argc && argv[count][0] != '-') { - if (strlen(argv[count]) < sizeof(keepaliveStatus) - 1) + char keepaliveEnable[20]; + if (strlen(argv[count]) < sizeof(keepaliveEnable) - 1) { - memset(keepaliveStatus, 0, sizeof(keepaliveStatus) - 1); - strncpy(keepaliveStatus, argv[count], sizeof(keepaliveStatus) - 1); + memset(keepaliveEnable, 0, sizeof(keepaliveEnable) - 1); + strncpy(keepaliveEnable, argv[count], sizeof(keepaliveEnable) - 1); + if(stricmp(keepaliveEnable, "true") == 0) + keepaliveStatus = true; + else + keepaliveStatus = false; } else { diff --git a/dcs/src/main/java/org/trafodion/dcs/Constants.java b/dcs/src/main/java/org/trafodion/dcs/Constants.java index de51773518..b3e5f3819e 100644 --- a/dcs/src/main/java/org/trafodion/dcs/Constants.java +++ b/dcs/src/main/java/org/trafodion/dcs/Constants.java @@ -116,7 +116,7 @@ public final class Constants { public static final String DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_STATUS= "dcs.server.user.program.tcp.keepalive.status"; /** Default value for DCS server program mxosrvr keepalive STATUS*/ - public static final String DCS_SERVER_PROGRAM_KEEPALIVE_STATUS = "enable"; + public static final String DCS_SERVER_PROGRAM_KEEPALIVE_STATUS = "true"; /** Configuration key for DCS server program mxosrvr keepalive IDLETIME*/ public static final String DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_IDLETIME = "dcs.server.user.program.tcp.keepalive.idletime"; diff --git a/dcs/src/main/java/org/trafodion/dcs/server/ServerManager.java b/dcs/src/main/java/org/trafodion/dcs/server/ServerManager.java index 23e572186f..e9dc98cb7b 100644 --- a/dcs/src/main/java/org/trafodion/dcs/server/ServerManager.java +++ b/dcs/src/main/java/org/trafodion/dcs/server/ServerManager.java @@ -83,10 +83,10 @@ public final class ServerManager implements Callable { private int maxRestartAttempts; private int retryIntervalMillis; private String nid = null; - private static String mxosrvrKeepaliveStatus; - private static int mxosrvrKeepaliveIdletime; - private static int mxosrvrKeepaliveIntervaltime; - private static int mxosrvrKeepaliveRetrycount; + private static String userProgKeepaliveStatus; + private static int userProgKeepaliveIdletime; + private static int userProgKeepaliveIntervaltime; + private static int userProgKeepaliveRetrycount; class RegisteredWatcher implements Watcher { CountDownLatch startSignal; @@ -210,13 +210,13 @@ public ServerRunner(int childInstance, String registeredPath) { .replace("-PORTBINDTOSECS", "-PORTBINDTOSECS " + userProgPortBindToSecs) .replace("-TCPKEEPALIVESTATUS", - "-TCPKEEPALIVESTATUS " + mxosrvrKeepaliveStatus + " ") + "-TCPKEEPALIVESTATUS " + userProgKeepaliveStatus + " ") .replace("-TCPKEEPALIVEIDLETIME", - "-TCPKEEPALIVEIDLETIME " + mxosrvrKeepaliveIdletime + " ") + "-TCPKEEPALIVEIDLETIME " + userProgKeepaliveIdletime + " ") .replace("-TCPKEEPALIVEINTERVAL", - "-TCPKEEPALIVEINTERVAL " + mxosrvrKeepaliveIntervaltime + " ") + "-TCPKEEPALIVEINTERVAL " + userProgKeepaliveIntervaltime + " ") .replace("-TCPKEEPALIVERETRYCOUNT", - "-TCPKEEPALIVERETRYCOUNT " + mxosrvrKeepaliveRetrycount + " ") + "-TCPKEEPALIVERETRYCOUNT " + userProgKeepaliveRetrycount + " ") .replace("<", "<").replace("&", "&") .replace(">", ">"); scriptContext.setCommand(command); @@ -360,16 +360,16 @@ public ServerManager(Configuration conf, ZkClient zkc, this.retryIntervalMillis = conf .getInt(Constants.DCS_SERVER_USER_PROGRAM_RESTART_HANDLER_RETRY_INTERVAL_MILLIS, Constants.DEFAULT_DCS_SERVER_USER_PROGRAM_RESTART_HANDLER_RETRY_INTERVAL_MILLIS); - this.mxosrvrKeepaliveStatus = conf.get( + this.userProgKeepaliveStatus = conf.get( Constants.DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_STATUS, Constants.DCS_SERVER_PROGRAM_KEEPALIVE_STATUS); - this.mxosrvrKeepaliveIdletime = conf.getInt( + this.userProgKeepaliveIdletime = conf.getInt( Constants.DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_IDLETIME, Constants.DCS_SERVER_PROGRAM_KEEPALIVE_IDLETIME); - this.mxosrvrKeepaliveIntervaltime = conf.getInt( + this.userProgKeepaliveIntervaltime = conf.getInt( Constants.DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_INTERVALTIME, Constants.DCS_SERVER_PROGRAM_KEEPALIVE_INTERVALTIME); - this.mxosrvrKeepaliveRetrycount = conf.getInt( + this.userProgKeepaliveRetrycount = conf.getInt( Constants.DEFAULT_DCS_SERVER_PROGRAM_TCP_KEEPALIVE_RETRYCOUNT, Constants.DCS_SERVER_PROGRAM_KEEPALIVE_RETRYCOUNT); serverHandlers = new ServerHandler[this.childServers]; diff --git a/dcs/src/main/resources/dcs-default.xml b/dcs/src/main/resources/dcs-default.xml index 9967b5bcee..b568d99aa4 100644 --- a/dcs/src/main/resources/dcs-default.xml +++ b/dcs/src/main/resources/dcs-default.xml @@ -388,30 +388,32 @@ dcs.server.user.program.tcp.keepalive.status - enable + true - Used in mxosrvr keepalive , parameter is ENABLE IDLETIME INTERTIME RETRYCNT. + If tcp keepalive is enabled. The default is true. Set false to disable. dcs.server.user.program.tcp.keepalive.idletime 300 - Used in mxosrvr keepalive , parameter is ENABLE IDLETIME INTERTIME RETRYCNT. + Time in seconds for the interval between the last data packet sent and the first keepalive probe. + The default is 300. dcs.server.user.program.tcp.keepalive.intervaltime - 5 + 3 - Used in mxosrvr keepalive , parameter is ENABLE IDLETIME INTERTIME RETRYCNT. + Time in seconds for interval between two keepalive probes . + The default is 3. dcs.server.user.program.tcp.keepalive.retrycount 3 - Used in mxosrvr keepalive , parameter is ENABLE IDLETIME INTERTIME RETRYCNT. + The maximum number of keepalive probes TCP should send before dropping the connection.