update test case

This commit is contained in:
yihaoDeng 2023-09-13 19:54:45 +08:00
parent f29b3b27ac
commit e7815229ca
3 changed files with 37 additions and 6 deletions

View File

@ -49,6 +49,8 @@ int64_t mndGetIpWhiteVer(SMnode *pMnode);
void mndUpdateIpWhite(SMnode *pMnode, char *user, char *fqdn, int8_t type, int8_t lock); void mndUpdateIpWhite(SMnode *pMnode, char *user, char *fqdn, int8_t type, int8_t lock);
int32_t mndRefreshUserIpWhiteList(SMnode *pMnode);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -17,6 +17,7 @@
#include "mndSync.h" #include "mndSync.h"
#include "mndCluster.h" #include "mndCluster.h"
#include "mndTrans.h" #include "mndTrans.h"
#include "mndUser.h"
static int32_t mndSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { static int32_t mndSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
if (pMsg == NULL || pMsg->pCont == NULL) { if (pMsg == NULL || pMsg->pCont == NULL) {
@ -304,6 +305,7 @@ void mndRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx) {
} else { } else {
mInfo("vgId:1, sync restore finished"); mInfo("vgId:1, sync restore finished");
} }
mndRefreshUserIpWhiteList(pMnode);
ASSERT(commitIdx == mndSyncAppliedIndex(pFsm)); ASSERT(commitIdx == mndSyncAppliedIndex(pFsm));
} }

View File

@ -57,6 +57,7 @@ static void mndCancelGetNextPrivileges(SMnode *pMnode, void *pIter);
SHashObj *mndFetchAllIpWhite(SMnode *pMnode); SHashObj *mndFetchAllIpWhite(SMnode *pMnode);
static int32_t mndProcesSRetrieveIpWhiteReq(SRpcMsg *pReq); static int32_t mndProcesSRetrieveIpWhiteReq(SRpcMsg *pReq);
void ipWhiteMgtUpdateAll(SMnode *pMnode);
typedef struct { typedef struct {
SHashObj *pIpWhiteTab; SHashObj *pIpWhiteTab;
int64_t ver; int64_t ver;
@ -188,6 +189,7 @@ int64_t mndGetIpWhiteVer(SMnode *pMnode) {
int64_t ver = 0; int64_t ver = 0;
taosThreadRwlockWrlock(&ipWhiteMgt.rw); taosThreadRwlockWrlock(&ipWhiteMgt.rw);
if (ipWhiteMgt.ver == 0) { if (ipWhiteMgt.ver == 0) {
// user and dnode r
ipWhiteMgtUpdateAll(pMnode); ipWhiteMgtUpdateAll(pMnode);
ipWhiteMgt.ver = taosGetTimestampMs(); ipWhiteMgt.ver = taosGetTimestampMs();
} }
@ -204,7 +206,7 @@ int64_t mndGetIpWhiteVer(SMnode *pMnode) {
bool mndUpdateIpWhiteImpl(SHashObj *pIpWhiteTab, char *user, char *fqdn, int8_t type) { bool mndUpdateIpWhiteImpl(SHashObj *pIpWhiteTab, char *user, char *fqdn, int8_t type) {
bool update = false; bool update = false;
SIpV4Range range = {.ip = taosGetIpv4FromFqdn(fqdn), .mask = 32}; 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 **ppList = taosHashGet(pIpWhiteTab, user, strlen(user));
SIpWhiteList *pList = NULL; SIpWhiteList *pList = NULL;
if (ppList != NULL && *ppList != 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; 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) { void mndUpdateIpWhite(SMnode *pMnode, char *user, char *fqdn, int8_t type, int8_t lock) {
if (lock) { if (lock) {
taosThreadRwlockWrlock(&ipWhiteMgt.rw); taosThreadRwlockWrlock(&ipWhiteMgt.rw);
if (ipWhiteMgt.ver == 0) { if (ipWhiteMgt.ver == 0) {
ipWhiteMgtUpdateAll(pMnode); ipWhiteMgtUpdateAll(pMnode);
ipWhiteMgt.ver = taosGetTimestampMs(); 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; 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; int32_t len = 0;
for (int i = 0; i < num; i++) { 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); ipRangeToStr(&range[i], tbuf);
len += sprintf(buf + len, "%s,", tbuf); len += sprintf(buf + len, "%s,", tbuf);
} }
if (len > 0) buf[len - 1] = 0; if (len > 0) buf[len - 1] = 0;
return len;
} }
static bool isIpRangeEqual(SIpV4Range *a, SIpV4Range *b) { static bool isIpRangeEqual(SIpV4Range *a, SIpV4Range *b) {
@ -459,7 +482,11 @@ int32_t convertIpWhiteListToStr(SIpWhiteList *pList, char **buf) {
return 0; return 0;
} }
*buf = taosMemoryCalloc(1, pList->num * 36); *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); return strlen(*buf);
} }
int32_t tSerializeIpWhiteList(void *buf, int32_t len, SIpWhiteList *pList) { int32_t tSerializeIpWhiteList(void *buf, int32_t len, SIpWhiteList *pList) {