From 30eb8d50b000a84d8ad62a8316c63cfef612eede Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Mar 2022 19:44:53 +0800 Subject: [PATCH] shm --- include/libs/transport/trpc.h | 12 +++++---- source/dnode/mgmt/container/src/dndMsg.c | 2 ++ source/dnode/mnode/impl/src/mndProfile.c | 31 +++++++++++------------- source/util/src/tprocess.c | 6 ++++- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 8125de7647..54813a77a3 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -49,11 +49,13 @@ typedef struct SRpcMsg { } SRpcMsg; typedef struct { - char user[TSDB_USER_LEN]; - SRpcMsg rpcMsg; - int32_t rspLen; - void * pRsp; - void * pNode; + char user[TSDB_USER_LEN]; + uint32_t clientIp; + uint16_t clientPort; + SRpcMsg rpcMsg; + int32_t rspLen; + void *pRsp; + void *pNode; } SNodeMsg; typedef struct SRpcInit { diff --git a/source/dnode/mgmt/container/src/dndMsg.c b/source/dnode/mgmt/container/src/dndMsg.c index 5da1d73034..e4ecbe6af8 100644 --- a/source/dnode/mgmt/container/src/dndMsg.c +++ b/source/dnode/mgmt/container/src/dndMsg.c @@ -42,6 +42,8 @@ static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) { } memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN); + pMsg->clientIp = connInfo.clientIp; + pMsg->clientPort = connInfo.clientPort; memcpy(&pMsg->rpcMsg, pRpc, sizeof(SRpcMsg)); return 0; } diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index bf378a4d43..6c38d8626c 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -44,7 +44,8 @@ typedef struct { SQueryDesc *pQueries; } SConnObj; -static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, const char *app, int64_t startTime); +static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, uint32_t ip, uint16_t port, int32_t pid, + const char *app, int64_t startTime); static void mndFreeConn(SConnObj *pConn); static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId); static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn); @@ -94,7 +95,8 @@ void mndCleanupProfile(SMnode *pMnode) { } } -static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, const char *app, int64_t startTime) { +static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, uint32_t ip, uint16_t port, int32_t pid, + const char *app, int64_t startTime) { SProfileMgmt *pMgmt = &pMnode->profileMgmt; int32_t connId = atomic_add_fetch_32(&pMgmt->connId, 1); @@ -104,8 +106,8 @@ static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, SConnObj connObj = {.id = connId, .appStartTimeMs = startTime, .pid = pid, - .ip = pInfo->clientIp, - .port = pInfo->clientPort, + .ip = ip, + .port = port, .killed = 0, .loginTimeMs = taosGetTimestampMs(), .lastAccessTimeMs = 0, @@ -114,17 +116,17 @@ static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, .pQueries = NULL}; connObj.lastAccessTimeMs = connObj.loginTimeMs; - tstrncpy(connObj.user, pInfo->user, TSDB_USER_LEN); + tstrncpy(connObj.user, user, TSDB_USER_LEN); tstrncpy(connObj.app, app, TSDB_APP_NAME_LEN); int32_t keepTime = tsShellActivityTimer * 3; SConnObj *pConn = taosCachePut(pMgmt->cache, &connId, sizeof(int32_t), &connObj, sizeof(connObj), keepTime * 1000); if (pConn == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("conn:%d, failed to put into cache since %s, user:%s", connId, pInfo->user, terrstr()); + mError("conn:%d, failed to put into cache since %s, user:%s", connId, user, terrstr()); return NULL; } else { - mTrace("conn:%d, is created, data:%p user:%s", pConn->id, pConn, pInfo->user); + mTrace("conn:%d, is created, data:%p user:%s", pConn->id, pConn, user); return pConn; } } @@ -184,20 +186,14 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) { SConnObj *pConn = NULL; int32_t code = -1; SConnectReq connReq = {0}; + char ip[30] = {0}; if (tDeserializeSConnectReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &connReq) != 0) { terrno = TSDB_CODE_INVALID_MSG; goto CONN_OVER; } - SRpcConnInfo info = {0}; - if (rpcGetConnInfo(pReq->rpcMsg.handle, &info) != 0) { - mError("user:%s, failed to login while get connection info since %s", pReq->user, terrstr()); - goto CONN_OVER; - } - - char ip[30]; - taosIp2String(info.clientIp, ip); + taosIp2String(pReq->clientIp, ip); pUser = mndAcquireUser(pMnode, pReq->user); if (pUser == NULL) { @@ -216,7 +212,8 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) { } } - pConn = mndCreateConn(pMnode, &info, connReq.pid, connReq.app, connReq.startTime); + pConn = + mndCreateConn(pMnode, pReq->user, pReq->clientIp, pReq->clientPort, connReq.pid, connReq.app, connReq.startTime); if (pConn == NULL) { mError("user:%s, failed to login from %s while create connection since %s", pReq->user, ip, terrstr()); goto CONN_OVER; @@ -241,7 +238,7 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) { pReq->rspLen = contLen; pReq->pRsp = pRsp; - mDebug("user:%s, login from %s, conn:%d, app:%s", info.user, ip, pConn->id, connReq.app); + mDebug("user:%s, login from %s, conn:%d, app:%s", pReq->user, ip, pConn->id, connReq.app); code = 0; diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index d06aab6fda..650794971c 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -24,7 +24,6 @@ #include #define SHM_DEFAULT_SIZE (20 * 1024 * 1024) -#define CEIL8(n) (ceil((float)(n) / 8) * 8) typedef void *(*ProcThreadFp)(void *param); typedef struct SProcQueue { @@ -58,6 +57,11 @@ typedef struct SProcObj { bool stopFlag; } SProcObj; +static inline int32_t CEIL8(int32_t v) { + const int32_t c = ceil((float)(v) / 8) * 8; + return c < 8 ? 8 : c; +} + static int32_t taosProcInitMutex(TdThreadMutex **ppMutex, int32_t *pShmid) { TdThreadMutex *pMutex = NULL; TdThreadMutexAttr mattr = {0}; -- GitLab