From c71ab49d6bc8a595fb7ef62efbadbfaa27bb5ec9 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 14 Aug 2020 06:00:25 +0000 Subject: [PATCH 1/4] TD-1143 --- src/plugins/monitor/src/monitorMain.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index 55c242763b..d76bb4bd82 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -234,17 +234,22 @@ static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) { } void monitorStopSystem() { - monitorInfo("monitor module is stopped"); - monitorExecuteSQLFp = NULL; + if (tsMonitorConn.state == MONITOR_STATE_STOPPED) return; tsMonitorConn.state = MONITOR_STATE_STOPPED; + monitorExecuteSQLFp = NULL; + + monitorInfo("monitor module is stopped"); + if (tsMonitorConn.initTimer != NULL) { taosTmrStopA(&(tsMonitorConn.initTimer)); } if (tsMonitorConn.timer != NULL) { taosTmrStopA(&(tsMonitorConn.timer)); } - - taos_close(tsMonitorConn.conn); + if (tsMonitorConn.conn != NULL) { + taos_close(tsMonitorConn.conn); + tsMonitorConn.conn = NULL; + } } void monitorCleanUpSystem() { From faabd6e5cbdf02564c4c62ba81ff6e82c6a8e69d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 14 Aug 2020 16:59:41 +0800 Subject: [PATCH 2/4] TD-1057 compile error in vs2019 --- src/client/src/TSDBJNIConnector.c | 2 +- src/client/src/tscSQLParser.c | 2 +- src/common/src/ttimezone.c | 2 +- src/kit/taosnetwork/client.c | 4 ++-- src/kit/taosnetwork/server.c | 6 +++--- src/os/inc/osSocket.h | 4 ++++ src/os/inc/osWindows.h | 22 +++++++++++++++++++--- src/os/src/detail/osSocket.c | 12 ++++++++++++ src/os/src/detail/osTime.c | 7 +++++++ src/os/src/windows/w64Socket.c | 22 +++++++++++++++++++++- src/plugins/http/src/httpServer.c | 6 +++--- src/rpc/src/rpcTcp.c | 4 ++-- src/util/src/tconfig.c | 2 +- 13 files changed, 77 insertions(+), 18 deletions(-) diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index 5036983424..34204f96bf 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -583,7 +583,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_consumeImp(JNIEn return 0l; } - return (long)res; + return (jlong)res; } JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_unsubscribeImp(JNIEnv *env, jobject jobj, jlong sub, diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index f933366711..e5bb516ee6 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2390,7 +2390,7 @@ bool validateIpAddress(const char* ip, size_t size) { strncpy(tmp, ip, size); - in_addr_t epAddr = inet_addr(tmp); + in_addr_t epAddr = taosInetAddr(tmp); return epAddr != INADDR_NONE; } diff --git a/src/common/src/ttimezone.c b/src/common/src/ttimezone.c index edb6aea7f9..62b1e0bb5c 100644 --- a/src/common/src/ttimezone.c +++ b/src/common/src/ttimezone.c @@ -50,7 +50,7 @@ void tsSetTimeZone() { #endif #endif - int32_t tz = (-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR; + int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR); tz += daylight; /* diff --git a/src/kit/taosnetwork/client.c b/src/kit/taosnetwork/client.c index 102f9b9d89..74c161bf67 100644 --- a/src/kit/taosnetwork/client.c +++ b/src/kit/taosnetwork/client.c @@ -91,7 +91,7 @@ int checkTcpPort(info_s *info) { serverAddr.sin_family = AF_INET; serverAddr.sin_port = htons(port); - serverAddr.sin_addr.s_addr = inet_addr(host); + serverAddr.sin_addr.s_addr = taosInetAddr(host); //printf("=================================\n"); if (connect(clientSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) < 0) { @@ -157,7 +157,7 @@ int checkUdpPort(info_s *info) { serverAddr.sin_family = AF_INET; serverAddr.sin_port = htons(port); - serverAddr.sin_addr.s_addr = inet_addr(host); + serverAddr.sin_addr.s_addr = taosInetAddr(host); memset(sendbuf, 0, BUFFER_SIZE); memset(recvbuf, 0, BUFFER_SIZE); diff --git a/src/kit/taosnetwork/server.c b/src/kit/taosnetwork/server.c index 1c3bc6fa09..a2bb2b2b65 100644 --- a/src/kit/taosnetwork/server.c +++ b/src/kit/taosnetwork/server.c @@ -128,7 +128,7 @@ static void *bindTcpPort(void *sarg) { if (errno == EINTR) { continue; } else { - printf("recv Client: %s pkg from TCP port: %d fail:%s.\n", inet_ntoa(clientAddr.sin_addr), port, strerror(errno)); + printf("recv Client: %s pkg from TCP port: %d fail:%s.\n", taosInetNtoa(clientAddr.sin_addr), port, strerror(errno)); close(serverSocket); return NULL; } @@ -139,7 +139,7 @@ static void *bindTcpPort(void *sarg) { } } - printf("recv Client: %s pkg from TCP port: %d, pkg len: %d\n", inet_ntoa(clientAddr.sin_addr), port, iDataNum); + printf("recv Client: %s pkg from TCP port: %d, pkg len: %d\n", taosInetNtoa(clientAddr.sin_addr), port, iDataNum); if (iDataNum > 0) { send(client, buffer, iDataNum, 0); break; @@ -188,7 +188,7 @@ static void *bindUdpPort(void *sarg) { continue; } if (iDataNum > 0) { - printf("recv Client: %s pkg from UDP port: %d, pkg len: %d\n", inet_ntoa(clientAddr.sin_addr), port, iDataNum); + printf("recv Client: %s pkg from UDP port: %d, pkg len: %d\n", taosInetNtoa(clientAddr.sin_addr), port, iDataNum); //printf("Read msg from udp:%s ... %s\n", buffer, buffer+iDataNum-16); sendto(serverSocket, buffer, iDataNum, 0, (struct sockaddr *)&clientAddr, (int)sin_size); diff --git a/src/os/inc/osSocket.h b/src/os/inc/osSocket.h index 58f95c3c2d..e5c3806d1b 100644 --- a/src/os/inc/osSocket.h +++ b/src/os/inc/osSocket.h @@ -65,6 +65,10 @@ void taosBlockSIGPIPE(); // TAOS_OS_FUNC_SOCKET_SETSOCKETOPT int taosSetSockOpt(SOCKET socketfd, int level, int optname, void *optval, int optlen); +// TAOS_OS_FUNC_SOCKET_INET +uint32_t taosInetAddr(char *ipAddr); +const char *taosInetNtoa(IN_ADDR ipInt); + #ifdef __cplusplus } #endif diff --git a/src/os/inc/osWindows.h b/src/os/inc/osWindows.h index 6665dcd920..994e3b991c 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -164,9 +164,25 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone); #define MSG_NOSIGNAL 0 #define SO_NO_CHECK 0x1234 #define SOL_TCP 0x1234 -#define TCP_KEEPCNT 0x1234 -#define TCP_KEEPIDLE 0x1234 -#define TCP_KEEPINTVL 0x1234 + +#ifndef TCP_KEEPCNT + #define TCP_KEEPCNT 0x1234 +#endif + +#ifndef TCP_KEEPIDLE + #define TCP_KEEPIDLE 0x1234 +#endif + +#ifndef TCP_KEEPINTVL + #define TCP_KEEPINTVL 0x1234 +#endif + +#ifdef _MSC_VER +#if _MSC_VER >= 1900 + #define TAOS_OS_FUNC_SOCKET_INET +#endif +#endif + #define SHUT_RDWR SD_BOTH #define SHUT_RD SD_RECEIVE #define SHUT_WR SD_SEND diff --git a/src/os/src/detail/osSocket.c b/src/os/src/detail/osSocket.c index c8ad6a5acc..bcacd8575a 100644 --- a/src/os/src/detail/osSocket.c +++ b/src/os/src/detail/osSocket.c @@ -57,4 +57,16 @@ int taosSetSockOpt(SOCKET socketfd, int level, int optname, void *optval, int op return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen); } +#endif + +#ifndef TAOS_OS_FUNC_SOCKET_INET + +uint32_t taosInetAddr(char *ipAddr) { + return inet_addr(ipAddr); +} + +const char *taosInetNtoa(IN_ADDR ipInt) { + return inet_ntoa(ipInt); +} + #endif \ No newline at end of file diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index ced1643d2b..57634e468a 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -61,8 +61,15 @@ int64_t user_mktime64(const unsigned int year0, const unsigned int mon0, res = res*24; res = ((res + hour) * 60 + min) * 60 + sec; +#ifdef _MSC_VER +#if _MSC_VER >= 1900 + int64_t timezone = _timezone; +#endif +#endif + return (res + timezone); } + // ==== mktime() kernel code =================// static int64_t m_deltaUtc = 0; void deltaToUtcInitOnce() { diff --git a/src/os/src/windows/w64Socket.c b/src/os/src/windows/w64Socket.c index dd8961da40..6514c2f851 100644 --- a/src/os/src/windows/w64Socket.c +++ b/src/os/src/windows/w64Socket.c @@ -62,4 +62,24 @@ int taosSetSockOpt(SOCKET socketfd, int level, int optname, void *optval, int op } return setsockopt(socketfd, level, optname, optval, optlen); -} \ No newline at end of file +} + +#ifdef TAOS_OS_FUNC_SOCKET_INET + +uint32_t taosInetAddr(char *ipAddr) { + uint32_t value; + int ret = inet_pton(AF_INET, ipAddr, &value); + if (ret <= 0) { + return INADDR_NONE; + } else { + return value; + } +} + +const char *taosInetNtoa(IN_ADDR ipInt) { + // not thread safe, only for debug usage while print log + static char tmpDstStr[16]; + return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN); +} + +#endif \ No newline at end of file diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index 8ee92be31c..21949e93af 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -302,7 +302,7 @@ static void *httpAcceptHttpConnection(void *arg) { #if 0 if (totalFds > tsHttpCacheSessions * 100) { httpError("fd:%d, ip:%s:%u, totalFds:%d larger than httpCacheSessions:%d*100, refuse connection", connFd, - inet_ntoa(clientAddr.sin_addr), htons(clientAddr.sin_port), totalFds, tsHttpCacheSessions); + taosInetNtoa(clientAddr.sin_addr), htons(clientAddr.sin_port), totalFds, tsHttpCacheSessions); taosCloseSocket(connFd); continue; } @@ -316,14 +316,14 @@ static void *httpAcceptHttpConnection(void *arg) { pContext = httpCreateContext(connFd); if (pContext == NULL) { - httpError("fd:%d, ip:%s:%u, no enough resource to allocate http context", connFd, inet_ntoa(clientAddr.sin_addr), + httpError("fd:%d, ip:%s:%u, no enough resource to allocate http context", connFd, taosInetNtoa(clientAddr.sin_addr), htons(clientAddr.sin_port)); taosCloseSocket(connFd); continue; } pContext->pThread = pThread; - sprintf(pContext->ipstr, "%s:%u", inet_ntoa(clientAddr.sin_addr), htons(clientAddr.sin_port)); + sprintf(pContext->ipstr, "%s:%u", taosInetAddr(clientAddr.sin_addr), htons(clientAddr.sin_port)); struct epoll_event event; event.events = EPOLLIN | EPOLLPRI | EPOLLWAKEUP | EPOLLERR | EPOLLHUP | EPOLLRDHUP; diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 9da11831e5..3475e0f317 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -254,11 +254,11 @@ static void *taosAcceptTcpConnection(void *arg) { pFdObj->ip = caddr.sin_addr.s_addr; pFdObj->port = htons(caddr.sin_port); tDebug("%s new TCP connection from %s:%hu, fd:%d FD:%p numOfFds:%d", pServerObj->label, - inet_ntoa(caddr.sin_addr), pFdObj->port, connFd, pFdObj, pThreadObj->numOfFds); + taosInetNtoa(caddr.sin_addr), pFdObj->port, connFd, pFdObj, pThreadObj->numOfFds); } else { taosCloseSocket(connFd); tError("%s failed to malloc FdObj(%s) for connection from:%s:%hu", pServerObj->label, strerror(errno), - inet_ntoa(caddr.sin_addr), htons(caddr.sin_port)); + taosInetNtoa(caddr.sin_addr), htons(caddr.sin_port)); } // pick up next thread for next connection diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index ccf4ea7317..704af2017e 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -133,7 +133,7 @@ static void taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { } static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) { - uint32_t value = inet_addr(input_value); + uint32_t value = taosInetAddr(input_value); char * option = (char *)cfg->ptr; if (value == INADDR_NONE) { uError("config option:%s, input value:%s, is not a valid ip address, use default value:%s", From 8ac389c675802a81e6048d5e77aaa640ca3e3f74 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 14 Aug 2020 17:08:04 +0800 Subject: [PATCH 3/4] TD-1057 compile error after merge feature/query --- src/client/src/tscLocalMerge.c | 2 +- tests/tsim/src/simExe.c | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/client/src/tscLocalMerge.c b/src/client/src/tscLocalMerge.c index 186c2871a1..99c3bc4fb3 100644 --- a/src/client/src/tscLocalMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -972,7 +972,7 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO } if (pRes->numOfRows > 0) { - int32_t currentTotal = pRes->numOfRowsGroup + pRes->numOfRows; + int32_t currentTotal = (int32_t)(pRes->numOfRowsGroup + pRes->numOfRows); if (pQueryInfo->limit.limit >= 0 && currentTotal > pQueryInfo->limit.limit) { int32_t overflow = (int32_t)(currentTotal - pQueryInfo->limit.limit); diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 50d1a9b5be..0529808b6b 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -748,11 +748,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { sprintf(value, "%d", *((int *)row[i])); break; case TSDB_DATA_TYPE_BIGINT: -#ifdef _TD_ARM_32_ - sprintf(value, "%lld", *((int64_t *)row[i])); -#else - sprintf(value, "%ld", *((int64_t *)row[i])); -#endif + sprintf(value, "%" PRId64, *((int64_t *)row[i])); break; case TSDB_DATA_TYPE_FLOAT:{ #ifdef _TD_ARM_32_ From 7f885cb3b3f137ef0b3a13eeb91f448793d59bdc Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 14 Aug 2020 09:39:56 +0000 Subject: [PATCH 4/4] TD-1057 --- src/kit/taosnetwork/client.c | 4 ++-- src/kit/taosnetwork/server.c | 6 +++--- src/os/inc/osSocket.h | 2 +- src/os/src/detail/osSocket.c | 2 +- src/os/src/windows/w64Socket.c | 2 +- src/plugins/http/src/httpServer.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/kit/taosnetwork/client.c b/src/kit/taosnetwork/client.c index 74c161bf67..102f9b9d89 100644 --- a/src/kit/taosnetwork/client.c +++ b/src/kit/taosnetwork/client.c @@ -91,7 +91,7 @@ int checkTcpPort(info_s *info) { serverAddr.sin_family = AF_INET; serverAddr.sin_port = htons(port); - serverAddr.sin_addr.s_addr = taosInetAddr(host); + serverAddr.sin_addr.s_addr = inet_addr(host); //printf("=================================\n"); if (connect(clientSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) < 0) { @@ -157,7 +157,7 @@ int checkUdpPort(info_s *info) { serverAddr.sin_family = AF_INET; serverAddr.sin_port = htons(port); - serverAddr.sin_addr.s_addr = taosInetAddr(host); + serverAddr.sin_addr.s_addr = inet_addr(host); memset(sendbuf, 0, BUFFER_SIZE); memset(recvbuf, 0, BUFFER_SIZE); diff --git a/src/kit/taosnetwork/server.c b/src/kit/taosnetwork/server.c index a2bb2b2b65..1c3bc6fa09 100644 --- a/src/kit/taosnetwork/server.c +++ b/src/kit/taosnetwork/server.c @@ -128,7 +128,7 @@ static void *bindTcpPort(void *sarg) { if (errno == EINTR) { continue; } else { - printf("recv Client: %s pkg from TCP port: %d fail:%s.\n", taosInetNtoa(clientAddr.sin_addr), port, strerror(errno)); + printf("recv Client: %s pkg from TCP port: %d fail:%s.\n", inet_ntoa(clientAddr.sin_addr), port, strerror(errno)); close(serverSocket); return NULL; } @@ -139,7 +139,7 @@ static void *bindTcpPort(void *sarg) { } } - printf("recv Client: %s pkg from TCP port: %d, pkg len: %d\n", taosInetNtoa(clientAddr.sin_addr), port, iDataNum); + printf("recv Client: %s pkg from TCP port: %d, pkg len: %d\n", inet_ntoa(clientAddr.sin_addr), port, iDataNum); if (iDataNum > 0) { send(client, buffer, iDataNum, 0); break; @@ -188,7 +188,7 @@ static void *bindUdpPort(void *sarg) { continue; } if (iDataNum > 0) { - printf("recv Client: %s pkg from UDP port: %d, pkg len: %d\n", taosInetNtoa(clientAddr.sin_addr), port, iDataNum); + printf("recv Client: %s pkg from UDP port: %d, pkg len: %d\n", inet_ntoa(clientAddr.sin_addr), port, iDataNum); //printf("Read msg from udp:%s ... %s\n", buffer, buffer+iDataNum-16); sendto(serverSocket, buffer, iDataNum, 0, (struct sockaddr *)&clientAddr, (int)sin_size); diff --git a/src/os/inc/osSocket.h b/src/os/inc/osSocket.h index e5c3806d1b..ecc69ec3d3 100644 --- a/src/os/inc/osSocket.h +++ b/src/os/inc/osSocket.h @@ -67,7 +67,7 @@ int taosSetSockOpt(SOCKET socketfd, int level, int optname, void *optval, int op // TAOS_OS_FUNC_SOCKET_INET uint32_t taosInetAddr(char *ipAddr); -const char *taosInetNtoa(IN_ADDR ipInt); +const char *taosInetNtoa(struct in_addr ipInt); #ifdef __cplusplus } diff --git a/src/os/src/detail/osSocket.c b/src/os/src/detail/osSocket.c index bcacd8575a..8a51c389e9 100644 --- a/src/os/src/detail/osSocket.c +++ b/src/os/src/detail/osSocket.c @@ -65,7 +65,7 @@ uint32_t taosInetAddr(char *ipAddr) { return inet_addr(ipAddr); } -const char *taosInetNtoa(IN_ADDR ipInt) { +const char *taosInetNtoa(struct in_addr ipInt) { return inet_ntoa(ipInt); } diff --git a/src/os/src/windows/w64Socket.c b/src/os/src/windows/w64Socket.c index 6514c2f851..8fd198ba80 100644 --- a/src/os/src/windows/w64Socket.c +++ b/src/os/src/windows/w64Socket.c @@ -76,7 +76,7 @@ uint32_t taosInetAddr(char *ipAddr) { } } -const char *taosInetNtoa(IN_ADDR ipInt) { +const char *taosInetNtoa(struct in_addr ipInt) { // not thread safe, only for debug usage while print log static char tmpDstStr[16]; return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN); diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index 21949e93af..f4aca91cba 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -323,7 +323,7 @@ static void *httpAcceptHttpConnection(void *arg) { } pContext->pThread = pThread; - sprintf(pContext->ipstr, "%s:%u", taosInetAddr(clientAddr.sin_addr), htons(clientAddr.sin_port)); + sprintf(pContext->ipstr, "%s:%u", taosInetNtoa(clientAddr.sin_addr), htons(clientAddr.sin_port)); struct epoll_event event; event.events = EPOLLIN | EPOLLPRI | EPOLLWAKEUP | EPOLLERR | EPOLLHUP | EPOLLRDHUP;