From e7815229ca472810c8460855795c8cccf176954c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 13 Sep 2023 19:54:45 +0800 Subject: [PATCH] update test case --- source/dnode/mnode/impl/inc/mndUser.h | 2 ++ source/dnode/mnode/impl/src/mndSync.c | 4 ++- source/dnode/mnode/impl/src/mndUser.c | 37 +++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndUser.h b/source/dnode/mnode/impl/inc/mndUser.h index f4dfb58cb8..fab8ee4707 100644 --- a/source/dnode/mnode/impl/inc/mndUser.h +++ b/source/dnode/mnode/impl/inc/mndUser.h @@ -49,6 +49,8 @@ int64_t mndGetIpWhiteVer(SMnode *pMnode); void mndUpdateIpWhite(SMnode *pMnode, char *user, char *fqdn, int8_t type, int8_t lock); +int32_t mndRefreshUserIpWhiteList(SMnode *pMnode); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index a601d3c121..5759737a6a 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -17,6 +17,7 @@ #include "mndSync.h" #include "mndCluster.h" #include "mndTrans.h" +#include "mndUser.h" static int32_t mndSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { if (pMsg == NULL || pMsg->pCont == NULL) { @@ -167,7 +168,7 @@ int32_t mndProcessWriteMsg(SMnode *pMnode, SRpcMsg *pMsg, SFsmCbMeta *pMeta) { SSdbRaw *pRaw = pMsg->pCont; STrans *pTrans = NULL; int32_t code = -1; - int32_t transId = sdbGetIdFromRaw(pMnode->pSdb, pRaw); + int32_t transId = sdbGetIdFromRaw(pMnode->pSdb, pRaw); if (transId <= 0) { mError("trans:%d, invalid commit msg, cache transId:%d seq:%" PRId64, transId, pMgmt->transId, pMgmt->transSeq); @@ -304,6 +305,7 @@ void mndRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx) { } else { mInfo("vgId:1, sync restore finished"); } + mndRefreshUserIpWhiteList(pMnode); ASSERT(commitIdx == mndSyncAppliedIndex(pFsm)); } diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index a8847e71ad..9ca4b24681 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -57,6 +57,7 @@ static void mndCancelGetNextPrivileges(SMnode *pMnode, void *pIter); SHashObj *mndFetchAllIpWhite(SMnode *pMnode); static int32_t mndProcesSRetrieveIpWhiteReq(SRpcMsg *pReq); +void ipWhiteMgtUpdateAll(SMnode *pMnode); typedef struct { SHashObj *pIpWhiteTab; int64_t ver; @@ -188,6 +189,7 @@ int64_t mndGetIpWhiteVer(SMnode *pMnode) { int64_t ver = 0; taosThreadRwlockWrlock(&ipWhiteMgt.rw); if (ipWhiteMgt.ver == 0) { + // user and dnode r ipWhiteMgtUpdateAll(pMnode); ipWhiteMgt.ver = taosGetTimestampMs(); } @@ -204,7 +206,7 @@ int64_t mndGetIpWhiteVer(SMnode *pMnode) { bool mndUpdateIpWhiteImpl(SHashObj *pIpWhiteTab, char *user, char *fqdn, int8_t type) { bool update = false; SIpV4Range range = {.ip = taosGetIpv4FromFqdn(fqdn), .mask = 32}; - + mDebug("ip-white-list may update for user: %s, fqdn: %s", user, fqdn); SIpWhiteList **ppList = taosHashGet(pIpWhiteTab, user, strlen(user)); SIpWhiteList *pList = NULL; if (ppList != NULL && *ppList != NULL) { @@ -260,16 +262,29 @@ bool mndUpdateIpWhiteImpl(SHashObj *pIpWhiteTab, char *user, char *fqdn, int8_t } } } + if (update) { + mDebug("ip-white-list update for user: %s, fqdn: %s", user, fqdn); + } return update; } + +int32_t mndRefreshUserIpWhiteList(SMnode *pMnode) { + taosThreadRwlockWrlock(&ipWhiteMgt.rw); + + ipWhiteMgtUpdateAll(pMnode); + ipWhiteMgt.ver = taosGetTimestampMs(); + taosThreadRwlockUnlock(&ipWhiteMgt.rw); + + return 0; +} void mndUpdateIpWhite(SMnode *pMnode, char *user, char *fqdn, int8_t type, int8_t lock) { if (lock) { taosThreadRwlockWrlock(&ipWhiteMgt.rw); if (ipWhiteMgt.ver == 0) { ipWhiteMgtUpdateAll(pMnode); ipWhiteMgt.ver = taosGetTimestampMs(); - mInfo("ip-white-mnode ver, %" PRId64 "", ipWhiteMgt.ver); + mInfo("ip-white-list, user: %" PRId64 "", ipWhiteMgt.ver); } } @@ -422,14 +437,22 @@ static void ipRangeToStr(SIpV4Range *range, char *buf) { } return; } -static void ipRangeListToStr(SIpV4Range *range, int32_t num, char *buf) { +static bool isDefualtRange(SIpV4Range *pRange) { + static SIpV4Range val = {.ip = 16777343, .mask = 32}; + return pRange->ip == val.ip && pRange->mask == val.mask; +} +static int32_t ipRangeListToStr(SIpV4Range *range, int32_t num, char *buf) { int32_t len = 0; for (int i = 0; i < num; i++) { - char tbuf[36] = {0}; + char tbuf[36] = {0}; + SIpV4Range *pRange = &range[i]; + if (isDefualtRange(pRange)) continue; + ipRangeToStr(&range[i], tbuf); len += sprintf(buf + len, "%s,", tbuf); } if (len > 0) buf[len - 1] = 0; + return len; } static bool isIpRangeEqual(SIpV4Range *a, SIpV4Range *b) { @@ -459,7 +482,11 @@ int32_t convertIpWhiteListToStr(SIpWhiteList *pList, char **buf) { return 0; } *buf = taosMemoryCalloc(1, pList->num * 36); - ipRangeListToStr(pList->pIpRange, pList->num, *buf); + int32_t len = ipRangeListToStr(pList->pIpRange, pList->num, *buf); + if (len == 0) { + taosMemoryFree(*buf); + return 0; + } return strlen(*buf); } int32_t tSerializeIpWhiteList(void *buf, int32_t len, SIpWhiteList *pList) {