diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index bde98052af..e09b5670d3 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -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; diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index a4fa1e0c41..7ce2858adf 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -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}; diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c index 0ddce15fed..b541cdd411 100644 --- a/source/libs/catalog/src/ctgCache.c +++ b/source/libs/catalog/src/ctgCache.c @@ -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; } diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index a26263d685..ef1fb18cb4 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -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) {