add rpc update interface
This commit is contained in:
parent
d9eed32167
commit
f29880fee3
|
@ -1384,6 +1384,8 @@ int32_t tDeserializeSDropUserReq(void *buf, int32_t bufLen, SDropUserReq *pReq)
|
|||
}
|
||||
|
||||
SIpWhiteList *cloneIpWhiteList(SIpWhiteList *pIpWhiteList) {
|
||||
if (pIpWhiteList == NULL) return NULL;
|
||||
|
||||
int32_t sz = sizeof(SIpWhiteList) + pIpWhiteList->num * sizeof(SIpV4Range);
|
||||
SIpWhiteList *pNew = taosMemoryCalloc(1, sz);
|
||||
memcpy(pNew, pIpWhiteList, sz);
|
||||
|
|
|
@ -289,6 +289,7 @@ typedef struct {
|
|||
int32_t acctId;
|
||||
int32_t authVersion;
|
||||
int32_t passVersion;
|
||||
int64_t ipWhiteListVer;
|
||||
SIpWhiteList* pIpWhiteList;
|
||||
|
||||
SHashObj* readDbs;
|
||||
|
|
|
@ -47,7 +47,7 @@ void mndUserFreeObj(SUserObj *pUser);
|
|||
|
||||
int64_t mndGetIpWhiteVer(SMnode *pMnode);
|
||||
|
||||
void mndUpdateIpWhite(char *user, char *fqdn, int8_t type, int8_t lock);
|
||||
void mndUpdateIpWhite(SMnode *pMnode, char *user, char *fqdn, int8_t type, int8_t lock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) {
|
|||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
code = 0;
|
||||
mndUpdateIpWhite(TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD, 1);
|
||||
mndUpdateIpWhite(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD, 1);
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -705,7 +705,7 @@ static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pC
|
|||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
code = 0;
|
||||
|
||||
mndUpdateIpWhite(TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD, 1);
|
||||
mndUpdateIpWhite(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD, 1);
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
sdbFreeRaw(pRaw);
|
||||
|
@ -998,7 +998,7 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM
|
|||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
mndUpdateIpWhite(TSDB_DEFAULT_USER, pDnode->fqdn, IP_WHITE_DROP, 1);
|
||||
mndUpdateIpWhite(pMnode, TSDB_DEFAULT_USER, pDnode->fqdn, IP_WHITE_DROP, 1);
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
|
|
|
@ -262,8 +262,14 @@ bool mndUpdateIpWhiteImpl(SHashObj *pIpWhiteTab, char *user, char *fqdn, int8_t
|
|||
|
||||
return update;
|
||||
}
|
||||
void mndUpdateIpWhite(char *user, char *fqdn, int8_t type, int8_t lock) {
|
||||
if (lock) taosThreadRwlockWrlock(&ipWhiteMgt.rw);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
bool update = mndUpdateIpWhiteImpl(ipWhiteMgt.pIpWhiteTab, user, fqdn, type);
|
||||
if (update) ipWhiteMgt.ver++;
|
||||
|
@ -526,6 +532,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char
|
|||
userObj.updateTime = userObj.createdTime;
|
||||
userObj.sysInfo = 1;
|
||||
userObj.enable = 1;
|
||||
userObj.ipWhiteListVer = taosGetTimestampMs();
|
||||
userObj.pIpWhiteList = createDefaultIpWhiteList();
|
||||
if (strcmp(user, TSDB_DEFAULT_USER) == 0) {
|
||||
userObj.superUser = 1;
|
||||
|
@ -707,6 +714,8 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
|||
SDB_SET_BINARY(pRaw, dataPos, buf, len, _OVER);
|
||||
taosMemoryFree(buf);
|
||||
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->ipWhiteListVer, _OVER);
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, USER_RESERVE_SIZE, _OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||
|
||||
|
@ -875,10 +884,13 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
|||
|
||||
pUser->pIpWhiteList = createIpWhiteList(buf, len);
|
||||
taosMemoryFree(buf);
|
||||
|
||||
SDB_GET_INT64(pRaw, dataPos, &pUser->ipWhiteListVer, _OVER);
|
||||
}
|
||||
|
||||
if (pUser->pIpWhiteList == NULL) {
|
||||
pUser->pIpWhiteList = createDefaultIpWhiteList();
|
||||
pUser->ipWhiteListVer = taosGetTimestampMs();
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, dataPos, USER_RESERVE_SIZE, _OVER)
|
||||
|
@ -896,7 +908,7 @@ _OVER:
|
|||
taosHashCleanup(pUser->readTbs);
|
||||
taosHashCleanup(pUser->writeTbs);
|
||||
taosHashCleanup(pUser->useDbs);
|
||||
taosMemoryFree(pUser->pIpWhiteList);
|
||||
taosMemoryFreeClear(pUser->pIpWhiteList);
|
||||
}
|
||||
taosMemoryFreeClear(pRow);
|
||||
return NULL;
|
||||
|
@ -1001,7 +1013,7 @@ void mndUserFreeObj(SUserObj *pUser) {
|
|||
taosHashCleanup(pUser->readTbs);
|
||||
taosHashCleanup(pUser->writeTbs);
|
||||
taosHashCleanup(pUser->useDbs);
|
||||
taosMemoryFree(pUser->pIpWhiteList);
|
||||
taosMemoryFreeClear(pUser->pIpWhiteList);
|
||||
pUser->readDbs = NULL;
|
||||
pUser->writeDbs = NULL;
|
||||
pUser->topics = NULL;
|
||||
|
@ -1083,6 +1095,8 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate
|
|||
userObj.pIpWhiteList = p;
|
||||
}
|
||||
|
||||
userObj.ipWhiteListVer = taosGetTimestampMs();
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-user");
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
|
@ -1591,6 +1605,7 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
|||
}
|
||||
pNew->num = idx;
|
||||
newUser.pIpWhiteList = pNew;
|
||||
newUser.ipWhiteListVer = pUser->ipWhiteListVer + 1;
|
||||
}
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_DROP_WHITE_LIST) {
|
||||
taosMemoryFree(newUser.pIpWhiteList);
|
||||
|
@ -1617,9 +1632,12 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
|||
}
|
||||
pNew->num = idx;
|
||||
newUser.pIpWhiteList = pNew;
|
||||
newUser.ipWhiteListVer = pUser->ipWhiteListVer + 1;
|
||||
|
||||
} else {
|
||||
pNew->num = 0;
|
||||
newUser.pIpWhiteList = pNew;
|
||||
newUser.ipWhiteListVer = pUser->ipWhiteListVer + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1827,9 +1845,9 @@ static int32_t mndRetrieveUsers(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
|||
|
||||
cols++;
|
||||
|
||||
char *buf = NULL;
|
||||
// int32_t tlen = convertIpWhiteListToStr(pUser->pIpWhiteList, &buf);
|
||||
int32_t tlen = mndFetchIpWhiteList(pUser->pIpWhiteList, &buf);
|
||||
char *buf = NULL;
|
||||
int32_t tlen = convertIpWhiteListToStr(pUser->pIpWhiteList, &buf);
|
||||
// int32_t tlen = mndFetchIpWhiteList(pUser->pIpWhiteList, &buf);
|
||||
if (tlen != 0) {
|
||||
char *varstr = taosMemoryCalloc(1, VARSTR_HEADER_SIZE + tlen);
|
||||
varDataSetLen(varstr, tlen);
|
||||
|
|
Loading…
Reference in New Issue