From 5444fe6beb99a9c6739bf19fc8f981d77e9b078c Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 24 Dec 2020 10:12:00 +0800 Subject: [PATCH 1/6] tsVersion: refactor to correct format --- src/common/inc/tglobal.h | 2 +- src/common/src/tglobal.c | 15 ++++++++++----- src/util/inc/buildInfo.h | 7 ------- 3 files changed, 11 insertions(+), 13 deletions(-) delete mode 100644 src/util/inc/buildInfo.h diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index bf1f22a4ee..e971a9c957 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -161,7 +161,7 @@ extern float tsMinimalLogDirGB; extern float tsReservedTmpDirectorySpace; extern float tsMinimalDataDirGB; extern int32_t tsTotalMemoryMB; -extern int32_t tsVersion; +extern uint32_t tsVersion; // build info extern char version[]; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index f007a82f84..cab234c787 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -201,7 +201,7 @@ float tsAvailDataDirGB = 0; float tsReservedTmpDirectorySpace = 0.1f; float tsMinimalDataDirGB = 0.5f; int32_t tsTotalMemoryMB = 0; -int32_t tsVersion = 0; +uint32_t tsVersion = 0; // log int32_t tsNumOfLogLines = 10000000; @@ -1451,15 +1451,20 @@ int32_t taosCheckGlobalCfg() { // todo refactor tsVersion = 0; - for (int i = 0; i < 10; i++) { + for (int ver = 0, i = 0; i < TSDB_VERSION_LEN; ++i) { if (version[i] >= '0' && version[i] <= '9') { - tsVersion = tsVersion * 10 + (version[i] - '0'); + ver = ver * 10 + (version[i] - '0'); + } else if (version[i] == '.') { + tsVersion |= ver & 0xFF; + tsVersion <<= 8; + + ver = 0; } else if (version[i] == 0) { + tsVersion |= ver & 0xFF; + break; } } - - tsVersion = 10 * tsVersion; tsDnodeShellPort = tsServerPort + TSDB_PORT_DNODESHELL; // udp[6035-6039] tcp[6035] tsDnodeDnodePort = tsServerPort + TSDB_PORT_DNODEDNODE; // udp/tcp diff --git a/src/util/inc/buildInfo.h b/src/util/inc/buildInfo.h deleted file mode 100644 index 8d169d618d..0000000000 --- a/src/util/inc/buildInfo.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef _TS_BUILD_H_ -#define _TS_BUILD_H_ - -extern const char tsVersion[]; -extern const char tsBuildInfo[]; - -#endif From eef2d8f05e9aa51f4899eaa05095776325ccc966 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 24 Dec 2020 10:49:29 +0800 Subject: [PATCH 2/6] [TD-2502]: force version checking with rpc request messages --- src/inc/taoserror.h | 1 + src/rpc/inc/rpcHead.h | 1 + src/rpc/src/rpcMain.c | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index 7c7e7ec31a..69c01e6763 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -67,6 +67,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_RESPONSE_TYPE, 0, 0x0012, "Invalid re TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_TIME_STAMP, 0, 0x0013, "Client and server's time is not synchronized") TAOS_DEFINE_ERROR(TSDB_CODE_APP_NOT_READY, 0, 0x0014, "Database not ready") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_FQDN_ERROR, 0, 0x0015, "Unable to resolve FQDN") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_VERSION, 0, 0x0016, "Invalid app version") //common & util TAOS_DEFINE_ERROR(TSDB_CODE_COM_OPS_NOT_SUPPORT, 0, 0x0100, "Operation not supported") diff --git a/src/rpc/inc/rpcHead.h b/src/rpc/inc/rpcHead.h index 520edadc7d..95204f72f6 100644 --- a/src/rpc/inc/rpcHead.h +++ b/src/rpc/inc/rpcHead.h @@ -58,6 +58,7 @@ typedef struct { char empty[1]; // reserved uint8_t msgType; // message type int32_t msgLen; // message length including the header iteslf + uint32_t msgVer; int32_t code; // code in response message uint8_t content[0]; // message body starts from here } SRpcHead; diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 1d394d8795..8226620c1b 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -959,6 +959,11 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv, SRpcReqCont terrno = TSDB_CODE_RPC_INVALID_SESSION_ID; return NULL; } + if (rpcIsReq(pHead->msgType) && htonl(pHead->msgVer) != tsVersion >> 8) { + tDebug("%s sid:%d, invalid client version:%d", pRpc->label, sid, htonl(pHead->msgVer)); + terrno = TSDB_CODE_RPC_INVALID_VERSION; return NULL; + } + pConn = rpcGetConnObj(pRpc, sid, pRecv); if (pConn == NULL) { tDebug("%s %p, failed to get connection obj(%s)", pRpc->label, (void *)pHead->ahandle, tstrerror(terrno)); @@ -1282,6 +1287,7 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) { // set the message header pHead->version = 1; + pHead->msgVer = htonl(tsVersion >> 8); pHead->msgType = msgType; pHead->encrypt = 0; pConn->tranId++; From c7c4572c15b41a0384d7e4d2cb3723a8fcded6fb Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Fri, 25 Dec 2020 13:06:22 +0800 Subject: [PATCH 3/6] rpc: remove duplicate macro definitions --- src/rpc/inc/rpcHead.h | 1 + src/rpc/src/rpcMain.c | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/rpc/inc/rpcHead.h b/src/rpc/inc/rpcHead.h index 95204f72f6..dc0cac0143 100644 --- a/src/rpc/inc/rpcHead.h +++ b/src/rpc/inc/rpcHead.h @@ -20,6 +20,7 @@ extern "C" { #endif +// server:0 client:1 tcp:2 udp:0 #define RPC_CONN_UDPS 0 #define RPC_CONN_UDPC 1 #define RPC_CONN_TCPS 2 diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 8226620c1b..deaf30f42e 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -137,13 +137,6 @@ static int tsRpcRefId = -1; static int32_t tsRpcNum = 0; //static pthread_once_t tsRpcInit = PTHREAD_ONCE_INIT; -// server:0 client:1 tcp:2 udp:0 -#define RPC_CONN_UDPS 0 -#define RPC_CONN_UDPC 1 -#define RPC_CONN_TCPS 2 -#define RPC_CONN_TCPC 3 -#define RPC_CONN_TCP 2 - void *(*taosInitConn[])(uint32_t ip, uint16_t port, char *label, int threads, void *fp, void *shandle) = { taosInitUdpConnection, taosInitUdpConnection, From 76f75ba806f53bb39b0f17a2d3f35f4023102bfb Mon Sep 17 00:00:00 2001 From: stephenkgu Date: Sun, 27 Dec 2020 06:54:04 +0800 Subject: [PATCH 4/6] rpc: refactor macro definitions --- src/rpc/inc/rpcHead.h | 5 ----- src/rpc/src/rpcMain.c | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/rpc/inc/rpcHead.h b/src/rpc/inc/rpcHead.h index dc0cac0143..5b401ac54b 100644 --- a/src/rpc/inc/rpcHead.h +++ b/src/rpc/inc/rpcHead.h @@ -20,11 +20,6 @@ extern "C" { #endif -// server:0 client:1 tcp:2 udp:0 -#define RPC_CONN_UDPS 0 -#define RPC_CONN_UDPC 1 -#define RPC_CONN_TCPS 2 -#define RPC_CONN_TCPC 3 #define RPC_CONN_TCP 2 extern int tsRpcOverhead; diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index deaf30f42e..22838a3f7b 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -137,6 +137,12 @@ static int tsRpcRefId = -1; static int32_t tsRpcNum = 0; //static pthread_once_t tsRpcInit = PTHREAD_ONCE_INIT; +// server:0 client:1 tcp:2 udp:0 +#define RPC_CONN_UDPS 0 +#define RPC_CONN_UDPC 1 +#define RPC_CONN_TCPS 2 +#define RPC_CONN_TCPC 3 + void *(*taosInitConn[])(uint32_t ip, uint16_t port, char *label, int threads, void *fp, void *shandle) = { taosInitUdpConnection, taosInitUdpConnection, From 2be8db9d421301f0510760f76d1536a7123a99f6 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 28 Dec 2020 02:10:29 +0800 Subject: [PATCH 5/6] rpc/log: refactor invalid client version log --- src/rpc/src/rpcMain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index deaf30f42e..bdefecfba3 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -953,7 +953,7 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv, SRpcReqCont } if (rpcIsReq(pHead->msgType) && htonl(pHead->msgVer) != tsVersion >> 8) { - tDebug("%s sid:%d, invalid client version:%d", pRpc->label, sid, htonl(pHead->msgVer)); + tDebug("%s sid:%d, invalid client version:%x/%x %s", pRpc->label, sid, htonl(pHead->msgVer), tsVersion, taosMsg[pHead->msgType]); terrno = TSDB_CODE_RPC_INVALID_VERSION; return NULL; } From 4e8a37ed982fcb129d9f338de06c6772c8f49871 Mon Sep 17 00:00:00 2001 From: stephenkgu Date: Mon, 28 Dec 2020 02:45:11 +0800 Subject: [PATCH 6/6] rpcMain/fix: fix version checking with rpcSendReqHead --- src/rpc/src/rpcMain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index a9346f55d3..fbc59d8ddf 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -1216,6 +1216,7 @@ static void rpcSendReqHead(SRpcConn *pConn) { pHead = (SRpcHead *)msg; pHead->version = 1; pHead->msgType = pConn->outType; + pHead->msgVer = htonl(tsVersion >> 8); pHead->spi = pConn->spi; pHead->encrypt = 0; pHead->tranId = pConn->outTranId;