update test case
This commit is contained in:
parent
f29b3b27ac
commit
e7815229ca
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue