enh: remove user cache when user dropped
This commit is contained in:
parent
2ff0748022
commit
eb6b6ec882
|
@ -144,22 +144,22 @@ typedef struct {
|
||||||
} SWhiteListInfo;
|
} SWhiteListInfo;
|
||||||
|
|
||||||
typedef struct STscObj {
|
typedef struct STscObj {
|
||||||
char user[TSDB_USER_LEN];
|
char user[TSDB_USER_LEN];
|
||||||
char pass[TSDB_PASSWORD_LEN];
|
char pass[TSDB_PASSWORD_LEN];
|
||||||
char db[TSDB_DB_FNAME_LEN];
|
char db[TSDB_DB_FNAME_LEN];
|
||||||
char sVer[TSDB_VERSION_LEN];
|
char sVer[TSDB_VERSION_LEN];
|
||||||
char sDetailVer[128];
|
char sDetailVer[128];
|
||||||
int8_t sysInfo;
|
int8_t sysInfo;
|
||||||
int8_t connType;
|
int8_t connType;
|
||||||
int32_t acctId;
|
int32_t acctId;
|
||||||
uint32_t connId;
|
uint32_t connId;
|
||||||
int64_t id; // ref ID returned by taosAddRef
|
int64_t id; // ref ID returned by taosAddRef
|
||||||
TdThreadMutex mutex; // used to protect the operation on db
|
TdThreadMutex mutex; // used to protect the operation on db
|
||||||
int32_t numOfReqs; // number of sqlObj bound to this connection
|
int32_t numOfReqs; // number of sqlObj bound to this connection
|
||||||
int32_t authVer;
|
int32_t authVer;
|
||||||
SAppInstInfo* pAppInfo;
|
SAppInstInfo* pAppInfo;
|
||||||
SHashObj* pRequests;
|
SHashObj* pRequests;
|
||||||
SPassInfo passInfo;
|
SPassInfo passInfo;
|
||||||
SWhiteListInfo whiteListInfo;
|
SWhiteListInfo whiteListInfo;
|
||||||
STscNotifyInfo userDroppedInfo;
|
STscNotifyInfo userDroppedInfo;
|
||||||
} STscObj;
|
} STscObj;
|
||||||
|
|
|
@ -104,8 +104,6 @@ static int32_t hbUpdateUserAuthInfo(SAppHbMgr *pAppHbMgr, SUserAuthBatchRsp *bat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
releaseTscObj(pReq->connKey.tscRid);
|
releaseTscObj(pReq->connKey.tscRid);
|
||||||
// delete the tscObj
|
|
||||||
releaseTscObj(pReq->connKey.tscRid);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,6 +577,10 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient
|
||||||
return TSDB_CODE_APP_ERROR;
|
return TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if(pTscObj->dropped == 1) {
|
||||||
|
// releaseTscObj(connKey->tscRid);
|
||||||
|
// }
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
SKv kv = {.key = HEARTBEAT_KEY_USER_AUTHINFO};
|
SKv kv = {.key = HEARTBEAT_KEY_USER_AUTHINFO};
|
||||||
|
|
|
@ -2241,20 +2241,17 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t userDropped = msg->userAuth.dropped;
|
|
||||||
|
|
||||||
SCtgUserAuth *pUser = (SCtgUserAuth *)taosHashGet(pCtg->userCache, msg->userAuth.user, strlen(msg->userAuth.user));
|
SCtgUserAuth *pUser = (SCtgUserAuth *)taosHashGet(pCtg->userCache, msg->userAuth.user, strlen(msg->userAuth.user));
|
||||||
if (NULL == pUser) {
|
if (NULL == pUser) {
|
||||||
if (userDropped) {
|
if (msg->userAuth.dropped == 1) {
|
||||||
taosMemoryFreeClear(msg);
|
goto _return;
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SCtgUserAuth userAuth = {0};
|
SCtgUserAuth userAuth = {0};
|
||||||
|
|
||||||
memcpy(&userAuth.userAuth, &msg->userAuth, sizeof(msg->userAuth));
|
memcpy(&userAuth.userAuth, &msg->userAuth, sizeof(msg->userAuth));
|
||||||
userAuth.userCacheSize = ctgGetUserCacheSize(&userAuth.userAuth);
|
userAuth.userCacheSize = ctgGetUserCacheSize(&userAuth.userAuth);
|
||||||
|
|
||||||
if (taosHashPut(pCtg->userCache, msg->userAuth.user, strlen(msg->userAuth.user), &userAuth, sizeof(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);
|
ctgError("taosHashPut user %s to cache failed", msg->userAuth.user);
|
||||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
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);
|
CTG_CACHE_NUM_INC(CTG_CI_USER, 1);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else if(userDropped) {
|
} else if (msg->userAuth.dropped == 1) {
|
||||||
ctgRemoveCacheUser(pCtg, msg->userAuth.user);
|
if (ctgRemoveCacheUser(pCtg, msg->userAuth.user) == 0) {
|
||||||
|
CTG_CACHE_NUM_DEC(CTG_CI_USER, 1);
|
||||||
|
}
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -315,12 +315,16 @@ int32_t ctgRemoveCacheUser(SCatalog* pCtg, const char* user) {
|
||||||
if (!pCtg || !user) {
|
if (!pCtg || !user) {
|
||||||
return -1;
|
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) {
|
void ctgFreeHandle(SCatalog* pCtg) {
|
||||||
|
|
Loading…
Reference in New Issue