enh: remove user cache when user dropped

This commit is contained in:
kailixu 2023-09-21 14:09:50 +08:00
parent 2ff0748022
commit eb6b6ec882
4 changed files with 36 additions and 31 deletions

View File

@ -144,22 +144,22 @@ typedef struct {
} SWhiteListInfo;
typedef struct STscObj {
char user[TSDB_USER_LEN];
char pass[TSDB_PASSWORD_LEN];
char db[TSDB_DB_FNAME_LEN];
char sVer[TSDB_VERSION_LEN];
char sDetailVer[128];
int8_t sysInfo;
int8_t connType;
int32_t acctId;
uint32_t connId;
int64_t id; // ref ID returned by taosAddRef
TdThreadMutex mutex; // used to protect the operation on db
int32_t numOfReqs; // number of sqlObj bound to this connection
int32_t authVer;
SAppInstInfo* pAppInfo;
SHashObj* pRequests;
SPassInfo passInfo;
char user[TSDB_USER_LEN];
char pass[TSDB_PASSWORD_LEN];
char db[TSDB_DB_FNAME_LEN];
char sVer[TSDB_VERSION_LEN];
char sDetailVer[128];
int8_t sysInfo;
int8_t connType;
int32_t acctId;
uint32_t connId;
int64_t id; // ref ID returned by taosAddRef
TdThreadMutex mutex; // used to protect the operation on db
int32_t numOfReqs; // number of sqlObj bound to this connection
int32_t authVer;
SAppInstInfo* pAppInfo;
SHashObj* pRequests;
SPassInfo passInfo;
SWhiteListInfo whiteListInfo;
STscNotifyInfo userDroppedInfo;
} STscObj;

View File

@ -104,8 +104,6 @@ static int32_t hbUpdateUserAuthInfo(SAppHbMgr *pAppHbMgr, SUserAuthBatchRsp *bat
}
}
releaseTscObj(pReq->connKey.tscRid);
// delete the tscObj
releaseTscObj(pReq->connKey.tscRid);
continue;
}
@ -579,6 +577,10 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient
return TSDB_CODE_APP_ERROR;
}
// if(pTscObj->dropped == 1) {
// releaseTscObj(connKey->tscRid);
// }
int32_t code = 0;
SKv kv = {.key = HEARTBEAT_KEY_USER_AUTHINFO};

View File

@ -2241,20 +2241,17 @@ 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;
if (msg->userAuth.dropped == 1) {
goto _return;
}
SCtgUserAuth userAuth = {0};
memcpy(&userAuth.userAuth, &msg->userAuth, sizeof(msg->userAuth));
userAuth.userCacheSize = ctgGetUserCacheSize(&userAuth.userAuth);
if (taosHashPut(pCtg->userCache, msg->userAuth.user, strlen(msg->userAuth.user), &userAuth, sizeof(userAuth))) {
ctgError("taosHashPut user %s to cache failed", msg->userAuth.user);
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
@ -2265,8 +2262,10 @@ 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);
} else if (msg->userAuth.dropped == 1) {
if (ctgRemoveCacheUser(pCtg, msg->userAuth.user) == 0) {
CTG_CACHE_NUM_DEC(CTG_CI_USER, 1);
}
goto _return;
}

View File

@ -315,12 +315,16 @@ 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;
SCtgUserAuth* pUser = (SCtgUserAuth*)taosHashGet(pCtg->userCache, user, strlen(user));
if (pUser) {
ctgFreeSCtgUserAuth(pUser);
if (taosHashRemove(pCtg->userCache, user, strlen(user)) == 0) {
return 0; // user found and removed
}
}
return -1;
}
void ctgFreeHandle(SCatalog* pCtg) {