enh: remove user cache in catalog when user dropped
This commit is contained in:
parent
e7dd0caeb9
commit
2ff0748022
|
@ -975,6 +975,7 @@ void ctgFreeQNode(SCtgQNode* node);
|
|||
void ctgClearHandle(SCatalog* pCtg);
|
||||
void ctgFreeTbCacheImpl(SCtgTbCache* pCache, bool lock);
|
||||
int32_t ctgRemoveTbMeta(SCatalog* pCtg, SName* pTableName);
|
||||
int32_t ctgRemoveCacheUser(SCatalog* pCtg, const char* user);
|
||||
int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup,
|
||||
bool* exists);
|
||||
SName* ctgGetFetchName(SArray* pNames, SCtgFetch* pFetch);
|
||||
|
|
|
@ -2241,8 +2241,15 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
|
|||
goto _return;
|
||||
}
|
||||
|
||||
int8_t userDropped = msg->userAuth.dropped;
|
||||
|
||||
SCtgUserAuth *pUser = (SCtgUserAuth *)taosHashGet(pCtg->userCache, msg->userAuth.user, strlen(msg->userAuth.user));
|
||||
if (NULL == pUser) {
|
||||
if (userDropped) {
|
||||
taosMemoryFreeClear(msg);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SCtgUserAuth userAuth = {0};
|
||||
|
||||
memcpy(&userAuth.userAuth, &msg->userAuth, sizeof(msg->userAuth));
|
||||
|
@ -2258,6 +2265,9 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
|
|||
CTG_CACHE_NUM_INC(CTG_CI_USER, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else if(userDropped) {
|
||||
ctgRemoveCacheUser(pCtg, msg->userAuth.user);
|
||||
goto _return;
|
||||
}
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &pUser->lock);
|
||||
|
|
|
@ -311,6 +311,18 @@ void ctgFreeHandleImpl(SCatalog* pCtg) {
|
|||
taosMemoryFree(pCtg);
|
||||
}
|
||||
|
||||
int32_t ctgRemoveCacheUser(SCatalog* pCtg, const char* user) {
|
||||
if (!pCtg || !user) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SCtgUserAuth* pUser = (SCtgUserAuth*)taosHashGet(pCtg->userCache, user, strlen(user));
|
||||
ctgFreeSCtgUserAuth(pUser);
|
||||
taosHashRemove(pCtg->userCache, user, strlen(user));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ctgFreeHandle(SCatalog* pCtg) {
|
||||
if (NULL == pCtg) {
|
||||
return;
|
||||
|
|
|
@ -208,7 +208,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
createUsers(taos, argv[1], qstr);
|
||||
passVerTestMulti(argv[1], qstr);
|
||||
// sysInfoTest(taos, argv[1], qstr);
|
||||
sysInfoTest(taos, argv[1], qstr);
|
||||
userDroppedTest(taos, argv[1], qstr);
|
||||
|
||||
taos_close(taos);
|
||||
|
@ -236,13 +236,6 @@ void createUsers(TAOS *taos, const char *host, char *qstr) {
|
|||
fprintf(stderr, "success to run: taos_set_notify_cb(TAOS_NOTIFY_PASSVER) for user:%s\n", users[i]);
|
||||
}
|
||||
|
||||
code = taos_set_notify_cb(taosu[i], __taos_notify_cb, users[i], TAOS_NOTIFY_USER_DROPPED);
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "failed to run: taos_set_notify_cb(TAOS_NOTIFY_USER_DROPPED) for user:%s since %d\n", users[i], code);
|
||||
} else {
|
||||
fprintf(stderr, "success to run: taos_set_notify_cb(TAOS_NOTIFY_USER_DROPPED) for user:%s\n", users[i]);
|
||||
}
|
||||
|
||||
// alter pass for users
|
||||
sprintf(qstr, "alter user %s pass 'taos'", users[i]);
|
||||
queryDB(taos, qstr);
|
||||
|
@ -396,7 +389,7 @@ _REP:
|
|||
|
||||
void userDroppedTest(TAOS *taos, const char *host, char *qstr) {
|
||||
// users
|
||||
int nTestUsers = 1; // nUser
|
||||
int nTestUsers = nUser;
|
||||
for (int i = 0; i < nTestUsers; ++i) {
|
||||
// sprintf(users[i], "user%d", i);
|
||||
taosu[i] = taos_connect(host, users[i], "taos", NULL, 0);
|
||||
|
@ -404,6 +397,13 @@ void userDroppedTest(TAOS *taos, const char *host, char *qstr) {
|
|||
printf("failed to connect to server, user:%s, reason:%s\n", users[i], "null taos" /*taos_errstr(taos)*/);
|
||||
exit(1);
|
||||
}
|
||||
int code = taos_set_notify_cb(taosu[i], __taos_notify_cb, users[i], TAOS_NOTIFY_USER_DROPPED);
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "failed to run: taos_set_notify_cb:%d for user:%s since %d\n", TAOS_NOTIFY_USER_DROPPED, users[i],
|
||||
code);
|
||||
} else {
|
||||
fprintf(stderr, "success to run: taos_set_notify_cb:%d for user:%s\n", TAOS_NOTIFY_USER_DROPPED, users[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < nTestUsers; ++i) {
|
||||
|
@ -435,5 +435,5 @@ void userDroppedTest(TAOS *taos, const char *host, char *qstr) {
|
|||
fprintf(stderr, ">>> failed to get user dropped notification since nNotify %d < nConn %d\n", nUserDropped, nConn);
|
||||
}
|
||||
fprintf(stderr, "######## %s #########\n", __func__);
|
||||
sleep(300);
|
||||
// sleep(300);
|
||||
}
|
Loading…
Reference in New Issue