From ec8cd0c6b8783dacf39e384e52fabf3e9cee6de8 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 9 Apr 2023 18:44:46 +0800 Subject: [PATCH 01/25] enh: support passwd version --- include/client/taos.h | 3 + include/common/tmsg.h | 16 +++ include/libs/catalog/catalog.h | 7 ++ source/client/inc/clientInt.h | 6 ++ source/client/src/clientHb.c | 89 ++++++++++++++++ source/client/src/clientMain.c | 17 ++++ source/common/src/tmsg.c | 58 ++++++++++- source/dnode/mnode/impl/inc/mndDef.h | 1 + source/dnode/mnode/impl/inc/mndUser.h | 2 + source/dnode/mnode/impl/src/mndDump.c | 1 + source/dnode/mnode/impl/src/mndProfile.c | 10 ++ source/dnode/mnode/impl/src/mndUser.c | 123 ++++++++++++++++++++++- 12 files changed, 330 insertions(+), 3 deletions(-) diff --git a/include/client/taos.h b/include/client/taos.h index cf410a42da..bfb29456be 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -101,6 +101,7 @@ typedef struct TAOS_FIELD_E { #endif typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *res, int code); +typedef void (*__taos_notify_fn_t)(void *param); typedef struct TAOS_MULTI_BIND { int buffer_type; @@ -225,6 +226,8 @@ DLL_EXPORT int taos_get_tables_vgId(TAOS *taos, const char *db, const char *tabl DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList); +DLL_EXPORT int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param); + /* --------------------------schemaless INTERFACE------------------------------- */ DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision); diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 999cc17767..9e2ef087e0 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -106,6 +106,7 @@ enum { HEARTBEAT_KEY_DBINFO, HEARTBEAT_KEY_STBINFO, HEARTBEAT_KEY_TMQ, + HEARTBEAT_KEY_USER_PASSINFO, }; typedef enum _mgmt_table { @@ -704,6 +705,13 @@ int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pR int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp); void tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp); +typedef SGetUserAuthReq SGetUserPassReq; + +typedef struct { + char user[TSDB_USER_LEN]; + int32_t version; +} SGetUserPassRsp; + /* * for client side struct, only column id, type, bytes are necessary * But for data in vnode side, we need all the following information. @@ -1034,6 +1042,14 @@ int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp); void tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp); +typedef struct { + SArray* pArray; // Array of SGetUserPassRsp +} SUserPassBatchRsp; + +int32_t tSerializeSUserPassBatchRsp(void* buf, int32_t bufLen, SUserPassBatchRsp* pRsp); +int32_t tDeserializeSUserPassBatchRsp(void* buf, int32_t bufLen, SUserPassBatchRsp* pRsp); +void tFreeSUserPassBatchRsp(SUserPassBatchRsp* pRsp); + typedef struct { char db[TSDB_DB_FNAME_LEN]; STimeWindow timeRange; diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index fbb24d2862..498a6e4c7d 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -140,6 +140,11 @@ typedef struct SUserAuthVersion { int32_t version; } SUserAuthVersion; +typedef struct SUserPassVersion { + char user[TSDB_USER_LEN]; + int32_t version; +} SUserPassVersion; + typedef SDbCfgRsp SDbCfgInfo; typedef SUserIndexRsp SIndexInfo; @@ -320,6 +325,8 @@ int32_t catalogChkAuthFromCache(SCatalog* pCtg, const char* user, const char* db int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth); +// int32_t catalogUpdateUserPassInfo(SCatalog* pCtg, SGetUserPassRsp* pPass); + int32_t catalogUpdateVgEpSet(SCatalog* pCtg, const char* dbFName, int32_t vgId, SEpSet* epSet); int32_t catalogGetServerVersion(SCatalog* pCtg, SRequestConnInfo* pConn, char** pVersion); diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 86db35b412..8878275d68 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -133,6 +133,11 @@ typedef struct SAppInfo { TdThreadMutex mutex; } SAppInfo; +typedef struct { + int32_t ver; + __taos_notify_fn_t* fp; +} SPassInfo; + typedef struct STscObj { char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; @@ -148,6 +153,7 @@ typedef struct STscObj { int32_t numOfReqs; // number of sqlObj bound to this connection SAppInstInfo* pAppInfo; SHashObj* pRequests; + SPassInfo passInfo; } STscObj; typedef struct STscDbg { diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index c9c2e7a5f8..f547f9123c 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -49,6 +49,42 @@ static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SC return TSDB_CODE_SUCCESS; } +static int32_t hbProcessUserPassInfoRsp(void *value, int32_t valueLen, SClientHbKey *connKey) { + int32_t code = 0; + STscObj *pTscObj = (STscObj *)acquireTscObj(connKey->tscRid); + if (NULL == pTscObj) { + tscWarn("tscObj rid %" PRIx64 " not exist", connKey->tscRid); + return TSDB_CODE_SUCCESS; + } + + SUserPassBatchRsp batchRsp = {0}; + if (tDeserializeSUserPassBatchRsp(value, valueLen, &batchRsp) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + releaseTscObj(connKey->tscRid); + assert(0); + return -1; + } + + SPassInfo *passInfo = &pTscObj->passInfo; + int32_t numOfBatchs = taosArrayGetSize(batchRsp.pArray); + for (int32_t i = 0; i < numOfBatchs; ++i) { + SGetUserPassRsp *rsp = taosArrayGet(batchRsp.pArray, i); + if (0 == strncmp(rsp->user, pTscObj->user, TSDB_USER_LEN)) { + tscError("update user:%s passVer from %d to %d", rsp->user, passInfo->ver, rsp->version); + if (atomic_load_32(&passInfo->ver) < rsp->version) { + atomic_store_32(&passInfo->ver, rsp->version); + if (passInfo->fp) { + (*passInfo->fp)(NULL); + } + } + } + } + + taosArrayDestroy(batchRsp.pArray); + releaseTscObj(connKey->tscRid); + return TSDB_CODE_SUCCESS; +} + static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) { int32_t code = 0; SDBVgInfo *vgInfo = taosMemoryCalloc(1, sizeof(SDBVgInfo)); @@ -291,6 +327,15 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { hbProcessStbInfoRsp(kv->value, kv->valueLen, pCatalog); break; } + case HEARTBEAT_KEY_USER_PASSINFO: { + if (kv->valueLen <= 0 || NULL == kv->value) { + tscError("invalid hb user pass info, len:%d, value:%p", kv->valueLen, kv->value); + break; + } + + hbProcessUserPassInfoRsp(kv->value, kv->valueLen, &pRsp->connKey); + break; + } default: tscError("invalid hb key type:%d", kv->key); break; @@ -472,6 +517,48 @@ int32_t hbGetQueryBasicInfo(SClientHbKey *connKey, SClientHbReq *req) { return TSDB_CODE_SUCCESS; } +static int32_t hbGetUserBasicInfo(SClientHbKey *connKey, SClientHbReq *req) { + STscObj *pTscObj = (STscObj *)acquireTscObj(connKey->tscRid); + if (!pTscObj) { + tscWarn("tscObj rid %" PRIx64 " not exist", connKey->tscRid); + return TSDB_CODE_APP_ERROR; + } + + int32_t code = 0; + SUserPassVersion *user = taosMemoryMalloc(sizeof(SUserPassVersion)); + if (!user) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _return; + } + strncpy(user->user, pTscObj->user, TSDB_USER_LEN); + user->version = htonl(pTscObj->passInfo.ver); + + SKv kv = { + .key = HEARTBEAT_KEY_USER_PASSINFO, + .valueLen = sizeof(SUserPassVersion), + .value = user, + }; + + tscDebug("hb got user basic info, valueLen:%d", kv.valueLen); + + if (!req->info) { + req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK); + } + + if (taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv)) < 0) { + code = terrno ? terrno : TSDB_CODE_APP_ERROR; + goto _return; + } + +_return: + releaseTscObj(connKey->tscRid); + if (code) { + tscError("hb got user basic info failed since %s", terrstr(code)); + } + + return code; +} + int32_t hbGetExpiredUserInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SClientHbReq *req) { SUserAuthVersion *users = NULL; uint32_t userNum = 0; @@ -620,6 +707,8 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req hbGetQueryBasicInfo(connKey, req); + hbGetUserBasicInfo(connKey, req); + code = hbGetExpiredUserInfo(connKey, pCatalog, req); if (TSDB_CODE_SUCCESS != code) { return code; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 60c7b44b3d..182750b821 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -119,6 +119,23 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha return NULL; } +int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param) { + if (taos == NULL) { + return 0; + } + + STscObj *pObj = acquireTscObj(*(int64_t *)taos); + if (NULL == pObj) { + tscError("invalid parameter for %s", __func__); + terrno = TSDB_CODE_TSC_DISCONNECTED; + return -1; + } + + pObj->passInfo.fp = fp; + + return 0; +} + void taos_close_internal(void *taos) { if (taos == NULL) { return; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index c37c0e830a..edde771e03 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -192,6 +192,8 @@ void *taosDecodeSEpSet(const void *buf, SEpSet *pEp) { static int32_t tSerializeSClientHbReq(SEncoder *pEncoder, const SClientHbReq *pReq) { if (tEncodeSClientHbKey(pEncoder, &pReq->connKey) < 0) return -1; + + if (pReq->connKey.connType == CONN_TYPE__QUERY) { if (tEncodeI64(pEncoder, pReq->app.appId) < 0) return -1; if (tEncodeI32(pEncoder, pReq->app.pid) < 0) return -1; @@ -212,6 +214,7 @@ static int32_t tSerializeSClientHbReq(SEncoder *pEncoder, const SClientHbReq *pR queryNum = 1; if (tEncodeI32(pEncoder, queryNum) < 0) return -1; if (tEncodeU32(pEncoder, pReq->query->connId) < 0) return -1; + if (tEncodeI64(pEncoder, pReq->clusterId) < 0) return -1; int32_t num = taosArrayGetSize(pReq->query->queryDesc); if (tEncodeI32(pEncoder, num) < 0) return -1; @@ -276,7 +279,7 @@ static int32_t tDeserializeSClientHbReq(SDecoder *pDecoder, SClientHbReq *pReq) pReq->query = taosMemoryCalloc(1, sizeof(*pReq->query)); if (NULL == pReq->query) return -1; if (tDecodeU32(pDecoder, &pReq->query->connId) < 0) return -1; - + if (tDecodeI64(pDecoder, &pReq->clusterId) < 0) return -1; int32_t num = 0; if (tDecodeI32(pDecoder, &num) < 0) return -1; if (num > 0) { @@ -2781,6 +2784,59 @@ void tFreeSUserAuthBatchRsp(SUserAuthBatchRsp *pRsp) { taosArrayDestroy(pRsp->pArray); } +int32_t tSerializeSUserPassBatchRsp(void *buf, int32_t bufLen, SUserPassBatchRsp *pRsp) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + + int32_t numOfBatch = taosArrayGetSize(pRsp->pArray); + if (tEncodeI32(&encoder, numOfBatch) < 0) return -1; + for (int32_t i = 0; i < numOfBatch; ++i) { + SGetUserPassRsp *pUserPassRsp = taosArrayGet(pRsp->pArray, i); + if (tEncodeCStr(&encoder, pUserPassRsp->user) < 0) return -1; + if (tEncodeI32(&encoder, pUserPassRsp->version) < 0) return -1; + } + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSUserPassBatchRsp(void *buf, int32_t bufLen, SUserPassBatchRsp *pRsp) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + + int32_t numOfBatch = taosArrayGetSize(pRsp->pArray); + if (tDecodeI32(&decoder, &numOfBatch) < 0) return -1; + + pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SGetUserPassRsp)); + if (pRsp->pArray == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + for (int32_t i = 0; i < numOfBatch; ++i) { + SGetUserPassRsp rsp = {0}; + if (tDecodeCStrTo(&decoder, rsp.user) < 0) return -1; + if (tDecodeI32(&decoder, &rsp.version) < 0) return -1; + taosArrayPush(pRsp->pArray, &rsp); + } + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + +void tFreeSUserPassBatchRsp(SUserPassBatchRsp *pRsp) { + if(pRsp) { + taosArrayDestroy(pRsp->pArray); + } +} + int32_t tSerializeSDbCfgReq(void *buf, int32_t bufLen, SDbCfgReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 876f2651bc..de7eafae46 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -278,6 +278,7 @@ typedef struct { int8_t reserve; int32_t acctId; int32_t authVersion; + int32_t passVersion; SHashObj* readDbs; SHashObj* writeDbs; SHashObj* topics; diff --git a/source/dnode/mnode/impl/inc/mndUser.h b/source/dnode/mnode/impl/inc/mndUser.h index 8943ba703e..8a1561ca20 100644 --- a/source/dnode/mnode/impl/inc/mndUser.h +++ b/source/dnode/mnode/impl/inc/mndUser.h @@ -34,6 +34,8 @@ SHashObj *mndDupDbHash(SHashObj *pOld); SHashObj *mndDupTopicHash(SHashObj *pOld); int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp, int32_t *pRspLen); +int32_t mndValidateUserPassInfo(SMnode *pMnode, SUserPassVersion *pUsers, int32_t numOfUses, void **ppRsp, + int32_t *pRspLen); int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db); int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic); diff --git a/source/dnode/mnode/impl/src/mndDump.c b/source/dnode/mnode/impl/src/mndDump.c index 44a7d49fff..a991bddda8 100644 --- a/source/dnode/mnode/impl/src/mndDump.c +++ b/source/dnode/mnode/impl/src/mndDump.c @@ -421,6 +421,7 @@ void dumpUser(SSdb *pSdb, SJson *json) { tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); tjsonAddStringToObject(item, "superUser", i642str(pObj->superUser)); tjsonAddStringToObject(item, "authVersion", i642str(pObj->authVersion)); + tjsonAddStringToObject(item, "passVersion", i642str(pObj->passVersion)); tjsonAddStringToObject(item, "numOfReadDbs", i642str(taosHashGetSize(pObj->readDbs))); tjsonAddStringToObject(item, "numOfWriteDbs", i642str(taosHashGetSize(pObj->writeDbs))); sdbRelease(pSdb, pObj); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 50e502f4ab..6e78982b03 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -547,6 +547,16 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb } break; } + case HEARTBEAT_KEY_USER_PASSINFO: { + void *rspMsg = NULL; + int32_t rspLen = 0; + mndValidateUserPassInfo(pMnode, kv->value, kv->valueLen / sizeof(SUserPassVersion), &rspMsg, &rspLen); + if (rspMsg && rspLen > 0) { + SKv kv1 = {.key = HEARTBEAT_KEY_USER_PASSINFO, .valueLen = rspLen, .value = rspMsg}; + taosArrayPush(hbRsp.info, &kv1); + } + break; + } default: mError("invalid kv key:%d", kv->key); hbRsp.status = TSDB_CODE_APP_ERROR; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 92b73aed96..2245e09187 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -22,7 +22,7 @@ #include "mndTrans.h" #include "tbase64.h" -#define USER_VER_NUMBER 2 +#define USER_VER_NUMBER 3 #define USER_RESERVE_SIZE 64 static int32_t mndCreateDefaultUsers(SMnode *pMnode); @@ -142,6 +142,7 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) { SDB_SET_INT8(pRaw, dataPos, pUser->enable, _OVER) SDB_SET_INT8(pRaw, dataPos, pUser->reserve, _OVER) SDB_SET_INT32(pRaw, dataPos, pUser->authVersion, _OVER) + SDB_SET_INT32(pRaw, dataPos, pUser->passVersion, _OVER) SDB_SET_INT32(pRaw, dataPos, numOfReadDbs, _OVER) SDB_SET_INT32(pRaw, dataPos, numOfWriteDbs, _OVER) SDB_SET_INT32(pRaw, dataPos, numOfTopics, _OVER) @@ -188,7 +189,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { int8_t sver = 0; if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER; - if (sver != 1 && sver != 2) { + if (sver < 1 || sver > USER_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; goto _OVER; } @@ -210,6 +211,9 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { SDB_GET_INT8(pRaw, dataPos, &pUser->enable, _OVER) SDB_GET_INT8(pRaw, dataPos, &pUser->reserve, _OVER) SDB_GET_INT32(pRaw, dataPos, &pUser->authVersion, _OVER) + if (sver >= 3) { + SDB_GET_INT32(pRaw, dataPos, &pUser->passVersion, _OVER) + } int32_t numOfReadDbs = 0; int32_t numOfWriteDbs = 0; @@ -322,6 +326,7 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) { taosWLockLatch(&pOld->lock); pOld->updateTime = pNew->updateTime; pOld->authVersion = pNew->authVersion; + pOld->passVersion = pNew->passVersion; pOld->sysInfo = pNew->sysInfo; pOld->enable = pNew->enable; memcpy(pOld->pass, pNew->pass, TSDB_PASSWORD_LEN); @@ -543,10 +548,14 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) { if (mndUserDupObj(pUser, &newUser) != 0) goto _OVER; + newUser.passVersion = pUser->passVersion; if (alterReq.alterType == TSDB_ALTER_USER_PASSWD) { char pass[TSDB_PASSWORD_LEN + 1] = {0}; taosEncryptPass_c((uint8_t *)alterReq.pass, strlen(alterReq.pass), pass); memcpy(newUser.pass, pass, TSDB_PASSWORD_LEN); + if (0 != strncmp(pUser->pass, pass, TSDB_PASSWORD_LEN)) { + ++newUser.passVersion; + } } if (alterReq.alterType == TSDB_ALTER_USER_SUPERUSER) { @@ -782,6 +791,50 @@ _OVER: return code; } +#if 0 +static int32_t mndProcessGetUserPassReq(SRpcMsg *pReq) { + SMnode *pMnode = pReq->info.node; + int32_t code = -1; + SUserObj *pUser = NULL; + SGetUserPassReq req = {0}; + SGetUserPassRsp rsp = {0}; + + if (tDeserializeSGetUserPassReq(pReq->pCont, pReq->contLen, &req) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + goto _OVER; + } + + mTrace("user:%s, start to get pass", req.user); + + pUser = mndAcquireUser(pMnode, req.user); + if (pUser == NULL) { + terrno = TSDB_CODE_MND_USER_NOT_EXIST; + goto _OVER; + } + + memcpy(rsp.user, pUser->user, TSDB_USER_LEN); + rsp.version = pUser->passVersion; + + int32_t contLen = tSerializeSGetUserPassRsp(NULL, 0, &rsp); + void *pRsp = rpcMallocCont(contLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _OVER; + } + + tSerializeSGetUserPassRsp(pRsp, contLen, &rsp); + + pReq->info.rsp = pRsp; + pReq->info.rspLen = contLen; + code = 0; + +_OVER: + + mndReleaseUser(pMnode, pUser); + + return code; +} +#endif static int32_t mndRetrieveUsers(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->info.node; @@ -1019,6 +1072,72 @@ _OVER: return code; } +int32_t mndValidateUserPassInfo(SMnode *pMnode, SUserPassVersion *pUsers, int32_t numOfUses, void **ppRsp, + int32_t *pRspLen) { + int32_t code = 0; + SUserPassBatchRsp batchRsp = {0}; + + for (int32_t i = 0; i < numOfUses; ++i) { + SUserObj *pUser = mndAcquireUser(pMnode, pUsers[i].user); + if (pUser == NULL) { + mError("user:%s, failed to validate user pass since %s", pUsers[i].user, terrstr()); + continue; + } + + pUsers[i].version = ntohl(pUsers[i].version); + if (pUser->passVersion <= pUsers[i].version) { + mDebug("user:%s, not update since mnd passVer %d <= client passVer %d", pUsers[i].user, pUser->passVersion, + pUsers[i].version); + mndReleaseUser(pMnode, pUser); + continue; + } + + SGetUserPassRsp rsp = {0}; + memcpy(rsp.user, pUser->user, TSDB_USER_LEN); + rsp.version = pUser->passVersion; + + if (!batchRsp.pArray && !(batchRsp.pArray = taosArrayInit(numOfUses, sizeof(SGetUserPassRsp)))) { + code = TSDB_CODE_OUT_OF_MEMORY; + assert(0); + goto _OVER; + } + + taosArrayPush(batchRsp.pArray, &rsp); + mndReleaseUser(pMnode, pUser); + } + + if (taosArrayGetSize(batchRsp.pArray) <= 0) { + goto _OVER; + } + + int32_t rspLen = tSerializeSUserPassBatchRsp(NULL, 0, &batchRsp); + if (rspLen < 0) { + assert(0); + code = TSDB_CODE_OUT_OF_MEMORY; + goto _OVER; + } + void *pRsp = taosMemoryMalloc(rspLen); + if (pRsp == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + assert(0); + goto _OVER; + } + tSerializeSUserPassBatchRsp(pRsp, rspLen, &batchRsp); + + *ppRsp = pRsp; + *pRspLen = rspLen; + +_OVER: + if (code) { + *ppRsp = NULL; + *pRspLen = 0; + assert(0); + } + + tFreeSUserPassBatchRsp(&batchRsp); + return code; +} + int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db) { int32_t code = 0; SSdb *pSdb = pMnode->pSdb; From b30d90355aeef51a6a85fd0086a902677b97a9c8 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 9 Apr 2023 18:55:05 +0800 Subject: [PATCH 02/25] chore: more code --- include/libs/catalog/catalog.h | 2 -- source/client/src/clientMain.c | 1 + source/common/src/tmsg.c | 4 --- source/dnode/mnode/impl/src/mndUser.c | 44 --------------------------- 4 files changed, 1 insertion(+), 50 deletions(-) diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 498a6e4c7d..5895d9404d 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -325,8 +325,6 @@ int32_t catalogChkAuthFromCache(SCatalog* pCtg, const char* user, const char* db int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth); -// int32_t catalogUpdateUserPassInfo(SCatalog* pCtg, SGetUserPassRsp* pPass); - int32_t catalogUpdateVgEpSet(SCatalog* pCtg, const char* dbFName, int32_t vgId, SEpSet* epSet); int32_t catalogGetServerVersion(SCatalog* pCtg, SRequestConnInfo* pConn, char** pVersion); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 182750b821..3969e7e771 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -133,6 +133,7 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param) { pObj->passInfo.fp = fp; + releaseTscObj(*(int64_t *)taos); return 0; } diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index edde771e03..2943de116d 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -192,8 +192,6 @@ void *taosDecodeSEpSet(const void *buf, SEpSet *pEp) { static int32_t tSerializeSClientHbReq(SEncoder *pEncoder, const SClientHbReq *pReq) { if (tEncodeSClientHbKey(pEncoder, &pReq->connKey) < 0) return -1; - - if (pReq->connKey.connType == CONN_TYPE__QUERY) { if (tEncodeI64(pEncoder, pReq->app.appId) < 0) return -1; if (tEncodeI32(pEncoder, pReq->app.pid) < 0) return -1; @@ -214,7 +212,6 @@ static int32_t tSerializeSClientHbReq(SEncoder *pEncoder, const SClientHbReq *pR queryNum = 1; if (tEncodeI32(pEncoder, queryNum) < 0) return -1; if (tEncodeU32(pEncoder, pReq->query->connId) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->clusterId) < 0) return -1; int32_t num = taosArrayGetSize(pReq->query->queryDesc); if (tEncodeI32(pEncoder, num) < 0) return -1; @@ -279,7 +276,6 @@ static int32_t tDeserializeSClientHbReq(SDecoder *pDecoder, SClientHbReq *pReq) pReq->query = taosMemoryCalloc(1, sizeof(*pReq->query)); if (NULL == pReq->query) return -1; if (tDecodeU32(pDecoder, &pReq->query->connId) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->clusterId) < 0) return -1; int32_t num = 0; if (tDecodeI32(pDecoder, &num) < 0) return -1; if (num > 0) { diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 2245e09187..54e5eac20e 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -791,50 +791,6 @@ _OVER: return code; } -#if 0 -static int32_t mndProcessGetUserPassReq(SRpcMsg *pReq) { - SMnode *pMnode = pReq->info.node; - int32_t code = -1; - SUserObj *pUser = NULL; - SGetUserPassReq req = {0}; - SGetUserPassRsp rsp = {0}; - - if (tDeserializeSGetUserPassReq(pReq->pCont, pReq->contLen, &req) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - goto _OVER; - } - - mTrace("user:%s, start to get pass", req.user); - - pUser = mndAcquireUser(pMnode, req.user); - if (pUser == NULL) { - terrno = TSDB_CODE_MND_USER_NOT_EXIST; - goto _OVER; - } - - memcpy(rsp.user, pUser->user, TSDB_USER_LEN); - rsp.version = pUser->passVersion; - - int32_t contLen = tSerializeSGetUserPassRsp(NULL, 0, &rsp); - void *pRsp = rpcMallocCont(contLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - goto _OVER; - } - - tSerializeSGetUserPassRsp(pRsp, contLen, &rsp); - - pReq->info.rsp = pRsp; - pReq->info.rspLen = contLen; - code = 0; - -_OVER: - - mndReleaseUser(pMnode, pUser); - - return code; -} -#endif static int32_t mndRetrieveUsers(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->info.node; From 7eb7cb72637b6f4215a3274396e44c4bc7486e15 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 9 Apr 2023 18:57:04 +0800 Subject: [PATCH 03/25] chore: more code --- source/libs/transport/src/transCli.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c23d6d0a1f..50ed9fa61b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -462,7 +462,6 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { if (transQueueEmpty(&pConn->cliMsgs)) { if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) { tTrace("%s conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn); - if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); transUnrefCliHandle(pConn); return; } @@ -522,7 +521,6 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { destroyCmsg(pMsg); tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn)); } while (!transQueueEmpty(&pConn->cliMsgs)); - if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); transUnrefCliHandle(pConn); } void cliHandleExcept(SCliConn* conn) { From e689356c6583646048e63ee5e3685103c46a9150 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 9 Apr 2023 19:01:51 +0800 Subject: [PATCH 04/25] chore: more code --- include/common/tmsg.h | 9 +++++---- include/libs/catalog/catalog.h | 5 ----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 9e2ef087e0..1ea12c3a10 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -705,12 +705,13 @@ int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pR int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp); void tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp); -typedef SGetUserAuthReq SGetUserPassReq; - -typedef struct { +typedef struct SUserPassVersion { char user[TSDB_USER_LEN]; int32_t version; -} SGetUserPassRsp; +} SUserPassVersion; + +typedef SGetUserAuthReq SGetUserPassReq; +typedef SUserPassVersion SGetUserPassRsp; /* * for client side struct, only column id, type, bytes are necessary diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 5895d9404d..fbb24d2862 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -140,11 +140,6 @@ typedef struct SUserAuthVersion { int32_t version; } SUserAuthVersion; -typedef struct SUserPassVersion { - char user[TSDB_USER_LEN]; - int32_t version; -} SUserPassVersion; - typedef SDbCfgRsp SDbCfgInfo; typedef SUserIndexRsp SIndexInfo; From 8c70dca4a9095430809f881ea46a32545a1d2634 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 9 Apr 2023 19:04:11 +0800 Subject: [PATCH 05/25] chore: more code --- source/common/src/tmsg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 2943de116d..a59fa7a2d6 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -276,6 +276,7 @@ static int32_t tDeserializeSClientHbReq(SDecoder *pDecoder, SClientHbReq *pReq) pReq->query = taosMemoryCalloc(1, sizeof(*pReq->query)); if (NULL == pReq->query) return -1; if (tDecodeU32(pDecoder, &pReq->query->connId) < 0) return -1; + int32_t num = 0; if (tDecodeI32(pDecoder, &num) < 0) return -1; if (num > 0) { From 76386b9fad07e4c78620bddd64166df87c826f68 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 10 Apr 2023 13:07:18 +0800 Subject: [PATCH 06/25] enh: assign passVer during taos_connect --- include/client/taos.h | 6 +++++- include/common/tmsg.h | 1 + source/client/src/clientHb.c | 13 ++++++------- source/client/src/clientMsgHandler.c | 1 + source/common/src/tmsg.c | 8 ++++++++ source/dnode/mnode/impl/src/mndProfile.c | 1 + source/dnode/mnode/impl/src/mndUser.c | 2 +- 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/client/taos.h b/include/client/taos.h index bfb29456be..530b40f5aa 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -101,7 +101,7 @@ typedef struct TAOS_FIELD_E { #endif typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *res, int code); -typedef void (*__taos_notify_fn_t)(void *param); +typedef void (*__taos_notify_fn_t)(void *param, void *ext, int type); typedef struct TAOS_MULTI_BIND { int buffer_type; @@ -122,6 +122,10 @@ typedef enum { SET_CONF_RET_ERR_TOO_LONG = -6 } SET_CONF_RET_CODE; +typedef enum { + TAOS_NOTIFY_PASSVER = 1, +} TAOS_NOTIFY_TYPE; + #define RET_MSG_LENGTH 1024 typedef struct setConfRet { SET_CONF_RET_CODE retCode; diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 1ea12c3a10..b7332dd1cc 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -629,6 +629,7 @@ typedef struct { int8_t connType; SEpSet epSet; int32_t svrTimestamp; + int32_t passVer; char sVer[TSDB_VERSION_LEN]; char sDetailVer[128]; } SConnectRsp; diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index f547f9123c..6596bc4bb3 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -54,15 +54,14 @@ static int32_t hbProcessUserPassInfoRsp(void *value, int32_t valueLen, SClientHb STscObj *pTscObj = (STscObj *)acquireTscObj(connKey->tscRid); if (NULL == pTscObj) { tscWarn("tscObj rid %" PRIx64 " not exist", connKey->tscRid); - return TSDB_CODE_SUCCESS; + return code; } SUserPassBatchRsp batchRsp = {0}; if (tDeserializeSUserPassBatchRsp(value, valueLen, &batchRsp) != 0) { - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; releaseTscObj(connKey->tscRid); - assert(0); - return -1; + return code; } SPassInfo *passInfo = &pTscObj->passInfo; @@ -70,11 +69,11 @@ static int32_t hbProcessUserPassInfoRsp(void *value, int32_t valueLen, SClientHb for (int32_t i = 0; i < numOfBatchs; ++i) { SGetUserPassRsp *rsp = taosArrayGet(batchRsp.pArray, i); if (0 == strncmp(rsp->user, pTscObj->user, TSDB_USER_LEN)) { - tscError("update user:%s passVer from %d to %d", rsp->user, passInfo->ver, rsp->version); + tscDebug("update passVer of user %s from %d to %d", rsp->user, passInfo->ver, rsp->version); if (atomic_load_32(&passInfo->ver) < rsp->version) { atomic_store_32(&passInfo->ver, rsp->version); if (passInfo->fp) { - (*passInfo->fp)(NULL); + (*passInfo->fp)(&pTscObj->id, NULL, TAOS_NOTIFY_PASSVER); } } } @@ -82,7 +81,7 @@ static int32_t hbProcessUserPassInfoRsp(void *value, int32_t valueLen, SClientHb taosArrayDestroy(batchRsp.pArray); releaseTscObj(connKey->tscRid); - return TSDB_CODE_SUCCESS; + return code; } static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) { diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index a0146cfa39..52c5fc7940 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -130,6 +130,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { lastClusterId = connectRsp.clusterId; pTscObj->connType = connectRsp.connType; + pTscObj->passInfo.ver = connectRsp.passVer; hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index a59fa7a2d6..1f9a44b1f4 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -3874,6 +3874,7 @@ int32_t tSerializeSConnectRsp(void *buf, int32_t bufLen, SConnectRsp *pRsp) { if (tEncodeI32(&encoder, pRsp->svrTimestamp) < 0) return -1; if (tEncodeCStr(&encoder, pRsp->sVer) < 0) return -1; if (tEncodeCStr(&encoder, pRsp->sDetailVer) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->passVer) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -3897,6 +3898,13 @@ int32_t tDeserializeSConnectRsp(void *buf, int32_t bufLen, SConnectRsp *pRsp) { if (tDecodeI32(&decoder, &pRsp->svrTimestamp) < 0) return -1; if (tDecodeCStrTo(&decoder, pRsp->sVer) < 0) return -1; if (tDecodeCStrTo(&decoder, pRsp->sDetailVer) < 0) return -1; + + if (!tDecodeIsEnd(&decoder)) { + if (tDecodeI32(&decoder, &pRsp->passVer) < 0) return -1; + } else { + pRsp->passVer = 0; + } + tEndDecode(&decoder); tDecoderClear(&decoder); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 6e78982b03..2ebb5aeb99 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -283,6 +283,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { connectRsp.connType = connReq.connType; connectRsp.dnodeNum = mndGetDnodeSize(pMnode); connectRsp.svrTimestamp = taosGetTimestampSec(); + connectRsp.passVer = pUser->passVersion; strcpy(connectRsp.sVer, version); snprintf(connectRsp.sDetailVer, sizeof(connectRsp.sDetailVer), "ver:%s\nbuild:%s\ngitinfo:%s", version, buildinfo, diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 54e5eac20e..de4768d746 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -1042,7 +1042,7 @@ int32_t mndValidateUserPassInfo(SMnode *pMnode, SUserPassVersion *pUsers, int32_ pUsers[i].version = ntohl(pUsers[i].version); if (pUser->passVersion <= pUsers[i].version) { - mDebug("user:%s, not update since mnd passVer %d <= client passVer %d", pUsers[i].user, pUser->passVersion, + mTrace("user:%s, not update since mnd passVer %d <= client passVer %d", pUsers[i].user, pUser->passVersion, pUsers[i].version); mndReleaseUser(pMnode, pUser); continue; From f6078dc27e07c2c0263a50ef244988e93402b908 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 10 Apr 2023 15:11:54 +0800 Subject: [PATCH 07/25] chore: more code --- include/client/taos.h | 2 +- source/client/src/clientMain.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/client/taos.h b/include/client/taos.h index 530b40f5aa..73086ce666 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -123,7 +123,7 @@ typedef enum { } SET_CONF_RET_CODE; typedef enum { - TAOS_NOTIFY_PASSVER = 1, + TAOS_NOTIFY_PASSVER = 0, } TAOS_NOTIFY_TYPE; #define RET_MSG_LENGTH 1024 diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 3969e7e771..a216b2afb2 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -131,7 +131,15 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param) { return -1; } - pObj->passInfo.fp = fp; + int32_t type = param ? *(int32_t *)param : 0; + switch (type) { + case TAOS_NOTIFY_PASSVER: { + pObj->passInfo.fp = fp; + break; + } + default: + break; + } releaseTscObj(*(int64_t *)taos); return 0; From 539337ca0be0a2d91962cf83212757600c0d1e15 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 10 Apr 2023 16:12:54 +0800 Subject: [PATCH 08/25] chore: code optimization --- source/client/src/clientMain.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index a216b2afb2..2491f5d70a 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -121,14 +121,13 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param) { if (taos == NULL) { - return 0; + return TSDB_CODE_INVALID_PARA; } STscObj *pObj = acquireTscObj(*(int64_t *)taos); if (NULL == pObj) { tscError("invalid parameter for %s", __func__); - terrno = TSDB_CODE_TSC_DISCONNECTED; - return -1; + return TSDB_CODE_TSC_DISCONNECTED; } int32_t type = param ? *(int32_t *)param : 0; From 5889ea12615b73c4fef2446037ea43d6316c740c Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 17 Apr 2023 14:19:44 +0800 Subject: [PATCH 09/25] chore: support specify param by app --- include/client/taos.h | 2 +- source/client/inc/clientInt.h | 1 + source/client/src/clientHb.c | 2 +- source/client/src/clientMain.c | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/client/taos.h b/include/client/taos.h index 73086ce666..bca93f611f 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -230,7 +230,7 @@ DLL_EXPORT int taos_get_tables_vgId(TAOS *taos, const char *db, const char *tabl DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList); -DLL_EXPORT int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param); +DLL_EXPORT int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param, int type); /* --------------------------schemaless INTERFACE------------------------------- */ diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 8878275d68..93ea433723 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -135,6 +135,7 @@ typedef struct SAppInfo { typedef struct { int32_t ver; + void* param; __taos_notify_fn_t* fp; } SPassInfo; diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 6596bc4bb3..dd40a18c88 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -73,7 +73,7 @@ static int32_t hbProcessUserPassInfoRsp(void *value, int32_t valueLen, SClientHb if (atomic_load_32(&passInfo->ver) < rsp->version) { atomic_store_32(&passInfo->ver, rsp->version); if (passInfo->fp) { - (*passInfo->fp)(&pTscObj->id, NULL, TAOS_NOTIFY_PASSVER); + (*passInfo->fp)(&pTscObj->id, passInfo->param, TAOS_NOTIFY_PASSVER); } } } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 2491f5d70a..b47e5bf53b 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -119,7 +119,7 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha return NULL; } -int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param) { +int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param, int type) { if (taos == NULL) { return TSDB_CODE_INVALID_PARA; } @@ -130,10 +130,10 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param) { return TSDB_CODE_TSC_DISCONNECTED; } - int32_t type = param ? *(int32_t *)param : 0; switch (type) { case TAOS_NOTIFY_PASSVER: { pObj->passInfo.fp = fp; + pObj->passInfo.param = param; break; } default: From 97aa8aede20394b5d90f819df02cead3532b143e Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 17 Apr 2023 14:26:02 +0800 Subject: [PATCH 10/25] chore: revert --- source/common/src/tmsg.c | 2 +- source/dnode/mnode/impl/src/mndStb.c | 2 +- source/libs/transport/src/transCli.c | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 0ce46d1cd0..1b0b4b1e4b 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -276,7 +276,7 @@ static int32_t tDeserializeSClientHbReq(SDecoder *pDecoder, SClientHbReq *pReq) pReq->query = taosMemoryCalloc(1, sizeof(*pReq->query)); if (NULL == pReq->query) return -1; if (tDecodeU32(pDecoder, &pReq->query->connId) < 0) return -1; - + int32_t num = 0; if (tDecodeI32(pDecoder, &num) < 0) return -1; if (num > 0) { diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 3f2f4062f1..63bcef2a5b 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -2929,7 +2929,7 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc if (pDb != NULL && pStb->dbUid != pDb->uid) { sdbRelease(pSdb, pStb); - continue; + continue; } cols = 0; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 50ed9fa61b..c23d6d0a1f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -462,6 +462,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { if (transQueueEmpty(&pConn->cliMsgs)) { if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) { tTrace("%s conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn); + if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); transUnrefCliHandle(pConn); return; } @@ -521,6 +522,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { destroyCmsg(pMsg); tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn)); } while (!transQueueEmpty(&pConn->cliMsgs)); + if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); transUnrefCliHandle(pConn); } void cliHandleExcept(SCliConn* conn) { From c0148ed5e195670e22be1c2e74305340c00b73db Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 18 Apr 2023 11:11:44 +0800 Subject: [PATCH 11/25] chore: remove the assertion --- source/dnode/mnode/impl/src/mndUser.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 635aa6326a..1c64024eac 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -1455,7 +1455,6 @@ int32_t mndValidateUserPassInfo(SMnode *pMnode, SUserPassVersion *pUsers, int32_ if (!batchRsp.pArray && !(batchRsp.pArray = taosArrayInit(numOfUses, sizeof(SGetUserPassRsp)))) { code = TSDB_CODE_OUT_OF_MEMORY; - assert(0); goto _OVER; } @@ -1469,14 +1468,12 @@ int32_t mndValidateUserPassInfo(SMnode *pMnode, SUserPassVersion *pUsers, int32_ int32_t rspLen = tSerializeSUserPassBatchRsp(NULL, 0, &batchRsp); if (rspLen < 0) { - assert(0); code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } void *pRsp = taosMemoryMalloc(rspLen); if (pRsp == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - assert(0); goto _OVER; } tSerializeSUserPassBatchRsp(pRsp, rspLen, &batchRsp); @@ -1488,7 +1485,6 @@ _OVER: if (code) { *ppRsp = NULL; *pRspLen = 0; - assert(0); } tFreeSUserPassBatchRsp(&batchRsp); From 696d294f02cdebf8eb8efb99c99e9de04edaa9a5 Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 18 Apr 2023 19:58:02 +0800 Subject: [PATCH 12/25] chore: code optimization --- source/client/src/clientHb.c | 7 ++++++- source/client/src/clientMain.c | 13 +++++++++---- source/dnode/mnode/impl/src/mndUser.c | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index dd40a18c88..04e45609e6 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -523,7 +523,12 @@ static int32_t hbGetUserBasicInfo(SClientHbKey *connKey, SClientHbReq *req) { return TSDB_CODE_APP_ERROR; } - int32_t code = 0; + int32_t code = 0; + + if (!pTscObj->passInfo.fp) { + goto _return; + } + SUserPassVersion *user = taosMemoryMalloc(sizeof(SUserPassVersion)); if (!user) { code = TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index b47e5bf53b..4de8c408c7 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -121,13 +121,15 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param, int type) { if (taos == NULL) { - return TSDB_CODE_INVALID_PARA; + terrno = TSDB_CODE_INVALID_PARA; + return terrno; } STscObj *pObj = acquireTscObj(*(int64_t *)taos); if (NULL == pObj) { + terrno = TSDB_CODE_TSC_DISCONNECTED; tscError("invalid parameter for %s", __func__); - return TSDB_CODE_TSC_DISCONNECTED; + return terrno; } switch (type) { @@ -136,8 +138,11 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param, int type pObj->passInfo.param = param; break; } - default: - break; + default: { + terrno = TSDB_CODE_INVALID_PARA; + releaseTscObj(*(int64_t *)taos); + return terrno; + } } releaseTscObj(*(int64_t *)taos); diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 1c64024eac..f6e5895cda 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -1455,6 +1455,7 @@ int32_t mndValidateUserPassInfo(SMnode *pMnode, SUserPassVersion *pUsers, int32_ if (!batchRsp.pArray && !(batchRsp.pArray = taosArrayInit(numOfUses, sizeof(SGetUserPassRsp)))) { code = TSDB_CODE_OUT_OF_MEMORY; + mndReleaseUser(pMnode, pUser); goto _OVER; } From dd85357b399786f5ac19fc3a4066e3fa5915aaec Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 19 Apr 2023 14:19:36 +0800 Subject: [PATCH 13/25] chore: more code --- source/client/src/clientHb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 04e45609e6..7f6356284a 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -73,7 +73,7 @@ static int32_t hbProcessUserPassInfoRsp(void *value, int32_t valueLen, SClientHb if (atomic_load_32(&passInfo->ver) < rsp->version) { atomic_store_32(&passInfo->ver, rsp->version); if (passInfo->fp) { - (*passInfo->fp)(&pTscObj->id, passInfo->param, TAOS_NOTIFY_PASSVER); + (*passInfo->fp)(passInfo->param, &passInfo->ver, TAOS_NOTIFY_PASSVER); } } } From 9549c1d929e262dfdc29f6b9d6cfaf5204e826c1 Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 19 Apr 2023 14:47:06 +0800 Subject: [PATCH 14/25] chore: fix --- include/client/taos.h | 2 +- source/client/inc/clientInt.h | 6 +++--- source/client/src/clientMain.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/client/taos.h b/include/client/taos.h index bca93f611f..2bc705a041 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -230,7 +230,7 @@ DLL_EXPORT int taos_get_tables_vgId(TAOS *taos, const char *db, const char *tabl DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList); -DLL_EXPORT int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param, int type); +DLL_EXPORT int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type); /* --------------------------schemaless INTERFACE------------------------------- */ diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 93ea433723..e34385bc24 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -134,9 +134,9 @@ typedef struct SAppInfo { } SAppInfo; typedef struct { - int32_t ver; - void* param; - __taos_notify_fn_t* fp; + int32_t ver; + void* param; + __taos_notify_fn_t fp; } SPassInfo; typedef struct STscObj { diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 4de8c408c7..b3f7c844e9 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -119,7 +119,7 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha return NULL; } -int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t *fp, void *param, int type) { +int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type) { if (taos == NULL) { terrno = TSDB_CODE_INVALID_PARA; return terrno; From fb99654899dc31a4f35fb9faf76e443bd5db6007 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 21 Apr 2023 18:22:44 +0800 Subject: [PATCH 15/25] chore: add UT --- tests/script/api/makefile | 3 + tests/script/api/passwdTest.c | 144 ++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 tests/script/api/passwdTest.c diff --git a/tests/script/api/makefile b/tests/script/api/makefile index 6739794cc8..6d55d8a75f 100644 --- a/tests/script/api/makefile +++ b/tests/script/api/makefile @@ -15,8 +15,11 @@ exe: gcc $(CFLAGS) ./stopquery.c -o $(ROOT)stopquery $(LFLAGS) gcc $(CFLAGS) ./dbTableRoute.c -o $(ROOT)dbTableRoute $(LFLAGS) gcc $(CFLAGS) ./insertSameTs.c -o $(ROOT)insertSameTs $(LFLAGS) + gcc $(CFLAGS) ./passwdTest.c -o $(ROOT)passwdTest $(LFLAGS) clean: rm $(ROOT)batchprepare rm $(ROOT)stopquery rm $(ROOT)dbTableRoute + rm $(ROOT)insertSameTs + rm $(ROOT)passwdTest diff --git a/tests/script/api/passwdTest.c b/tests/script/api/passwdTest.c new file mode 100644 index 0000000000..f3161047e8 --- /dev/null +++ b/tests/script/api/passwdTest.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +// TAOS standard API example. The same syntax as MySQL, but only a subset +// to compile: gcc -o demo demo.c -ltaos + +#include +#include +#include +#include +#include +#include "taos.h" // TAOS header file + +#define nRepetition 1 +#define nTaos 10 + +void Test(TAOS *taos, char *qstr); +void passVerTestMulti(const char *host, char *qstr); + +int nPassVerNotifiedMulti = 0; + +void __taos_notify_cb(void *param, void *ext, int type) { + switch (type) { + case TAOS_NOTIFY_PASSVER: { + ++nPassVerNotifiedMulti; + printf("%s:%d type:%d user:%s ver:%d\n", __func__, __LINE__, type, param ? (char *)param : "NULL", *(int *)ext); + break; + } + default: + printf("%s:%d unknown type:%d\n", __func__, __LINE__, type); + break; + } +} + +static void queryDB(TAOS *taos, char *command) { + int i; + TAOS_RES *pSql = NULL; + int32_t code = -1; + + for (i = 0; i < nRepetition; ++i) { + if (NULL != pSql) { + taos_free_result(pSql); + pSql = NULL; + } + + pSql = taos_query(taos, command); + code = taos_errno(pSql); + if (0 == code) { + break; + } + } + + if (code != 0) { + fprintf(stderr, "failed to run: %s, reason: %s\n", command, taos_errstr(pSql)); + taos_free_result(pSql); + taos_close(taos); + exit(EXIT_FAILURE); + } else { + fprintf(stderr, "success to run: %s\n", command); + } + + taos_free_result(pSql); +} + +int main(int argc, char *argv[]) { + char qstr[1024]; + + // connect to server + if (argc < 2) { + printf("please input server-ip \n"); + return 0; + } + + TAOS *taos = taos_connect(argv[1], "root", "taosdata", NULL, 0); + if (taos == NULL) { + printf("failed to connect to server, reason:%s\n", "null taos" /*taos_errstr(taos)*/); + exit(1); + } + + passVerTestMulti(argv[1], qstr); + + taos_close(taos); + taos_cleanup(); +} + +void passVerTestMulti(const char *host, char *qstr) { + TAOS *taos[nTaos] = {0}; + char *userName = calloc(1, 24); + strcpy(userName, "root"); + + for (int i = 0; i < nTaos; ++i) { + taos[i] = taos_connect(host, "root", "taosdata", NULL, 0); + if (taos[i] == NULL) { + printf("failed to connect to server, reason:%s\n", "null taos" /*taos_errstr(taos)*/); + exit(1); + } + + int code = taos_set_notify_cb(taos[i], __taos_notify_cb, userName, TAOS_NOTIFY_PASSVER); + + if (code != 0) { + fprintf(stderr, "failed to run: taos_set_notify_cb since %d\n", code); + } else { + fprintf(stderr, "success to run: taos_set_notify_cb\n"); + } + } + + queryDB(taos[0], "create database if not exists demo1 vgroups 1 minrows 10"); + queryDB(taos[0], "create database if not exists demo2 vgroups 1 minrows 10"); + queryDB(taos[0], "create database if not exists demo3 vgroups 1 minrows 10"); + + queryDB(taos[0], "create table demo1.stb (ts timestamp, c1 int) tags(t1 int)"); + queryDB(taos[0], "create table demo2.stb (ts timestamp, c1 int) tags(t1 int)"); + queryDB(taos[0], "create table demo3.stb (ts timestamp, c1 int) tags(t1 int)"); + + strcpy(qstr, "alter user root pass 'taos'"); + queryDB(taos[0], qstr); + + for (int i = 0; i < 10; ++i) { + if (nPassVerNotifiedMulti >= nTaos) break; + sleep(1); + } + + if (nPassVerNotifiedMulti >= nTaos) { + fprintf(stderr, "success to get passVer notification\n"); + } else { + fprintf(stderr, "failed to get passVer notification\n"); + } + + // sleep(1000); + + free(userName); +} \ No newline at end of file From 0256b44be8b7acf9e61daa656016544683cdf773 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 23 Apr 2023 17:45:03 +0800 Subject: [PATCH 16/25] chore: code optimization --- source/client/inc/clientInt.h | 5 +- source/client/src/clientEnv.c | 2 +- source/client/src/clientHb.c | 85 ++++++++++++++++++-------------- source/client/src/clientMain.c | 3 ++ tests/script/api/passwdTest.c | 88 ++++++++++++++++++++++++++-------- 5 files changed, 126 insertions(+), 57 deletions(-) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index f131bb9aa1..7cd5354240 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -63,6 +63,7 @@ typedef struct { // statistics int32_t reportCnt; int32_t connKeyCnt; + int32_t nPassVerCb; int64_t reportBytes; // not implemented int64_t startTime; // ctl @@ -73,7 +74,7 @@ typedef struct { typedef int32_t (*FHbRspHandle)(SAppHbMgr* pAppHbMgr, SClientHbRsp* pRsp); -typedef int32_t (*FHbReqHandle)(SClientHbKey* connKey, void* param, SClientHbReq* req); +typedef int32_t (*FHbReqHandle)(SClientHbKey* connKey, void* param, SClientHbReq* req, int32_t cb); typedef struct { int8_t inited; @@ -360,7 +361,7 @@ void stopAllRequests(SHashObj* pRequests); // conn level int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType); -void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey); +void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* cb); typedef struct SSqlCallbackWrapper { SParseContext* pParseCtx; diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 418103f2a6..99569fdb57 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -239,7 +239,7 @@ void destroyTscObj(void *pObj) { tscTrace("begin to destroy tscObj %" PRIx64 " p:%p", tscId, pTscObj); SClientHbKey connKey = {.tscRid = pTscObj->id, .connType = pTscObj->connType}; - hbDeregisterConn(pTscObj->pAppInfo->pAppHbMgr, connKey); + hbDeregisterConn(pTscObj->pAppInfo->pAppHbMgr, connKey, pTscObj->passInfo.fp); destroyAllRequests(pTscObj->pRequests); taosHashCleanup(pTscObj->pRequests); diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 7f6356284a..49fa2d6a7d 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -24,7 +24,7 @@ static SClientHbMgr clientHbMgr = {0}; static int32_t hbCreateThread(); static void hbStopThread(); -static int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) { return 0; } +static int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req, int32_t cb) { return 0; } static int32_t hbMqHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { return 0; } @@ -49,38 +49,48 @@ static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SC return TSDB_CODE_SUCCESS; } -static int32_t hbProcessUserPassInfoRsp(void *value, int32_t valueLen, SClientHbKey *connKey) { - int32_t code = 0; - STscObj *pTscObj = (STscObj *)acquireTscObj(connKey->tscRid); - if (NULL == pTscObj) { - tscWarn("tscObj rid %" PRIx64 " not exist", connKey->tscRid); - return code; - } - +static int32_t hbProcessUserPassInfoRsp(void *value, int32_t valueLen, SClientHbKey *connKey, SAppHbMgr *pAppHbMgr) { + int32_t code = 0; + int32_t numOfBatchs = 0; SUserPassBatchRsp batchRsp = {0}; if (tDeserializeSUserPassBatchRsp(value, valueLen, &batchRsp) != 0) { code = TSDB_CODE_INVALID_MSG; - releaseTscObj(connKey->tscRid); return code; } - SPassInfo *passInfo = &pTscObj->passInfo; - int32_t numOfBatchs = taosArrayGetSize(batchRsp.pArray); - for (int32_t i = 0; i < numOfBatchs; ++i) { - SGetUserPassRsp *rsp = taosArrayGet(batchRsp.pArray, i); - if (0 == strncmp(rsp->user, pTscObj->user, TSDB_USER_LEN)) { - tscDebug("update passVer of user %s from %d to %d", rsp->user, passInfo->ver, rsp->version); - if (atomic_load_32(&passInfo->ver) < rsp->version) { - atomic_store_32(&passInfo->ver, rsp->version); - if (passInfo->fp) { - (*passInfo->fp)(passInfo->param, &passInfo->ver, TAOS_NOTIFY_PASSVER); + numOfBatchs = taosArrayGetSize(batchRsp.pArray); + + SClientHbReq *pReq = NULL; + while ((pReq = taosHashIterate(pAppHbMgr->activeInfo, pReq))) { + STscObj *pTscObj = (STscObj *)acquireTscObj(pReq->connKey.tscRid); + if (!pTscObj) { + continue; + } + SPassInfo *passInfo = &pTscObj->passInfo; + if (!passInfo->fp) { + continue; + } + + for (int32_t i = 0; i < numOfBatchs; ++i) { + SGetUserPassRsp *rsp = taosArrayGet(batchRsp.pArray, i); + if (0 == strncmp(rsp->user, pTscObj->user, TSDB_USER_LEN)) { + int32_t oldVer = atomic_load_32(&passInfo->ver); + if (oldVer < rsp->version) { + atomic_store_32(&passInfo->ver, rsp->version); + tscDebug("update passVer of user %s from %d to %d, tscRid:%" PRIi64 "\n", rsp->user, oldVer, + atomic_load_32(&passInfo->ver), pTscObj->id); + if (passInfo->fp) { + (*passInfo->fp)(passInfo->param, &passInfo->ver, TAOS_NOTIFY_PASSVER); + } } + break; } } + releaseTscObj(pReq->connKey.tscRid); } taosArrayDestroy(batchRsp.pArray); - releaseTscObj(connKey->tscRid); + return code; } @@ -91,7 +101,7 @@ static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) { code = TSDB_CODE_OUT_OF_MEMORY; return code; } - + vgInfo->vgVersion = rsp->vgVersion; vgInfo->stateTs = rsp->stateTs; vgInfo->hashMethod = rsp->hashMethod; @@ -104,7 +114,7 @@ static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) { code = TSDB_CODE_OUT_OF_MEMORY; goto _return; } - + for (int32_t j = 0; j < rsp->vgNum; ++j) { SVgroupInfo *pInfo = taosArrayGet(rsp->pVgroupInfos, j); if (taosHashPut(vgInfo->vgHash, &pInfo->vgId, sizeof(int32_t), pInfo, sizeof(SVgroupInfo)) != 0) { @@ -332,7 +342,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { break; } - hbProcessUserPassInfoRsp(kv->value, kv->valueLen, &pRsp->connKey); + hbProcessUserPassInfoRsp(kv->value, kv->valueLen, &pRsp->connKey, pAppHbMgr); break; } default: @@ -523,12 +533,7 @@ static int32_t hbGetUserBasicInfo(SClientHbKey *connKey, SClientHbReq *req) { return TSDB_CODE_APP_ERROR; } - int32_t code = 0; - - if (!pTscObj->passInfo.fp) { - goto _return; - } - + int32_t code = 0; SUserPassVersion *user = taosMemoryMalloc(sizeof(SUserPassVersion)); if (!user) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -543,7 +548,8 @@ static int32_t hbGetUserBasicInfo(SClientHbKey *connKey, SClientHbReq *req) { .value = user, }; - tscDebug("hb got user basic info, valueLen:%d", kv.valueLen); + tscDebug("hb got user basic info, valueLen:%d, user:%s, passVer:%d, tscRid:%" PRIi64, kv.valueLen, user->user, + pTscObj->passInfo.ver, connKey->tscRid); if (!req->info) { req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK); @@ -697,7 +703,7 @@ int32_t hbGetAppInfo(int64_t clusterId, SClientHbReq *req) { return TSDB_CODE_SUCCESS; } -int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) { +int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req, int32_t cb) { int64_t *clusterId = (int64_t *)param; struct SCatalog *pCatalog = NULL; @@ -711,7 +717,7 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req hbGetQueryBasicInfo(connKey, req); - hbGetUserBasicInfo(connKey, req); + if (cb) hbGetUserBasicInfo(connKey, req); code = hbGetExpiredUserInfo(connKey, pCatalog, req); if (TSDB_CODE_SUCCESS != code) { @@ -764,9 +770,14 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) { return NULL; } + int32_t nPassVerCb = atomic_load_32(&pAppHbMgr->nPassVerCb); while (pIter != NULL) { pOneReq = taosArrayPush(pBatchReq->reqs, pOneReq); - code = (*clientHbMgr.reqHandle[pOneReq->connKey.connType])(&pOneReq->connKey, &pOneReq->clusterId, pOneReq); + code = (*clientHbMgr.reqHandle[pOneReq->connKey.connType])(&pOneReq->connKey, &pOneReq->clusterId, pOneReq, + nPassVerCb); + break; + +#if 0 if (code) { pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter); pOneReq = pIter; @@ -775,6 +786,7 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) { pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter); pOneReq = pIter; +#endif } releaseTscObj(rid); @@ -1116,7 +1128,7 @@ int hbRegisterConn(SAppHbMgr *pAppHbMgr, int64_t tscRefId, int64_t clusterId, in } } -void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey) { +void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, void *cb) { SClientHbReq *pReq = taosHashAcquire(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey)); if (pReq) { tFreeClientHbReq(pReq); @@ -1129,4 +1141,7 @@ void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey) { } atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1); + if (cb) { + atomic_sub_fetch_32(&pAppHbMgr->nPassVerCb, 1); + } } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index b3f7c844e9..3f29249e52 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -136,6 +136,9 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type) case TAOS_NOTIFY_PASSVER: { pObj->passInfo.fp = fp; pObj->passInfo.param = param; + if (fp) { + atomic_add_fetch_32(&pObj->pAppInfo->pAppHbMgr->nPassVerCb, 1); + } break; } default: { diff --git a/tests/script/api/passwdTest.c b/tests/script/api/passwdTest.c index f3161047e8..c788851044 100644 --- a/tests/script/api/passwdTest.c +++ b/tests/script/api/passwdTest.c @@ -16,6 +16,11 @@ // TAOS standard API example. The same syntax as MySQL, but only a subset // to compile: gcc -o demo demo.c -ltaos +/** + * passwdTest.c + * - Run the test case in clear TDengine environment with default root passwd 'taosdata' + */ + #include #include #include @@ -23,18 +28,23 @@ #include #include "taos.h" // TAOS header file -#define nRepetition 1 -#define nTaos 10 +#define nDup 1 +#define nRoot 10 +#define nUser 10 +#define USER_LEN 30 void Test(TAOS *taos, char *qstr); +void createUers(TAOS *taos, const char *host, char *qstr); void passVerTestMulti(const char *host, char *qstr); -int nPassVerNotifiedMulti = 0; +int nPassVerNotified = 0; +TAOS *taosu[nRoot] = {0}; +char users[nUser][USER_LEN] = {0}; void __taos_notify_cb(void *param, void *ext, int type) { switch (type) { case TAOS_NOTIFY_PASSVER: { - ++nPassVerNotifiedMulti; + ++nPassVerNotified; printf("%s:%d type:%d user:%s ver:%d\n", __func__, __LINE__, type, param ? (char *)param : "NULL", *(int *)ext); break; } @@ -49,7 +59,7 @@ static void queryDB(TAOS *taos, char *command) { TAOS_RES *pSql = NULL; int32_t code = -1; - for (i = 0; i < nRepetition; ++i) { + for (i = 0; i < nDup; ++i) { if (NULL != pSql) { taos_free_result(pSql); pSql = NULL; @@ -88,19 +98,46 @@ int main(int argc, char *argv[]) { printf("failed to connect to server, reason:%s\n", "null taos" /*taos_errstr(taos)*/); exit(1); } - + createUers(taos, argv[1], qstr); passVerTestMulti(argv[1], qstr); taos_close(taos); taos_cleanup(); } -void passVerTestMulti(const char *host, char *qstr) { - TAOS *taos[nTaos] = {0}; - char *userName = calloc(1, 24); - strcpy(userName, "root"); +void createUers(TAOS *taos, const char *host, char *qstr) { + // users + for (int i = 0; i < nUser; ++i) { + sprintf(users[i], "user%d", i); + sprintf(qstr, "CREATE USER %s PASS 'taosdata'", users[i]); + queryDB(taos, qstr); - for (int i = 0; i < nTaos; ++i) { + taosu[i] = taos_connect(host, users[i], "taosdata", NULL, 0); + if (taosu[i] == NULL) { + 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_PASSVER); + + if (code != 0) { + fprintf(stderr, "failed to run: taos_set_notify_cb for user:%s since %d\n", users[i], code); + } else { + fprintf(stderr, "success to run: taos_set_notify_cb for user:%s\n", users[i]); + } + + // alter pass for users + sprintf(qstr, "alter user %s pass 'taos'", users[i]); + queryDB(taos, qstr); + } +} + +void passVerTestMulti(const char *host, char *qstr) { + // root + TAOS *taos[nRoot] = {0}; + char userName[USER_LEN] = "root"; + + for (int i = 0; i < nRoot; ++i) { taos[i] = taos_connect(host, "root", "taosdata", NULL, 0); if (taos[i] == NULL) { printf("failed to connect to server, reason:%s\n", "null taos" /*taos_errstr(taos)*/); @@ -127,18 +164,31 @@ void passVerTestMulti(const char *host, char *qstr) { strcpy(qstr, "alter user root pass 'taos'"); queryDB(taos[0], qstr); - for (int i = 0; i < 10; ++i) { - if (nPassVerNotifiedMulti >= nTaos) break; + // calculate the nPassVerNotified for root and users + int nConn = nRoot + nUser; + + for (int i = 0; i < 15; ++i) { + if (nPassVerNotified >= nConn) break; sleep(1); } - if (nPassVerNotifiedMulti >= nTaos) { - fprintf(stderr, "success to get passVer notification\n"); - } else { - fprintf(stderr, "failed to get passVer notification\n"); + // close the taos_conn + for (int i = 0; i < nRoot; ++i) { + taos_close(taos[i]); + printf("%s:%d close taos[%d]\n", __func__, __LINE__, i); + sleep(1); } - // sleep(1000); + for (int i = 0; i < nUser; ++i) { + taos_close(taosu[i]); + printf("%s:%d close taosu[%d]\n", __func__, __LINE__, i); + sleep(1); + } - free(userName); + if (nPassVerNotified >= nConn) { + fprintf(stderr, "succeed to get passVer notification since nNotify %d >= nConn %d\n", nPassVerNotified, nConn); + } else { + fprintf(stderr, "failed to get passVer notification since nNotify %d < nConn %d\n", nPassVerNotified, nConn); + } + // sleep(300); } \ No newline at end of file From ee1a4b665a16f4e47542135094edb5afb683b784 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 23 Apr 2023 17:48:03 +0800 Subject: [PATCH 17/25] chore: more code --- tests/script/api/passwdTest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/script/api/passwdTest.c b/tests/script/api/passwdTest.c index c788851044..8a2b0a0390 100644 --- a/tests/script/api/passwdTest.c +++ b/tests/script/api/passwdTest.c @@ -31,7 +31,7 @@ #define nDup 1 #define nRoot 10 #define nUser 10 -#define USER_LEN 30 +#define USER_LEN 24 void Test(TAOS *taos, char *qstr); void createUers(TAOS *taos, const char *host, char *qstr); From 5d4bc82e17ec75f48649caf2b7f51db8cf7ae098 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 23 Apr 2023 19:53:58 +0800 Subject: [PATCH 18/25] chore: more code --- source/client/inc/clientInt.h | 2 +- source/client/src/clientHb.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 7cd5354240..1df032c498 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -361,7 +361,7 @@ void stopAllRequests(SHashObj* pRequests); // conn level int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType); -void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* cb); +void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* connFp); typedef struct SSqlCallbackWrapper { SParseContext* pParseCtx; diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 49fa2d6a7d..473d7c2e7d 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -101,7 +101,7 @@ static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) { code = TSDB_CODE_OUT_OF_MEMORY; return code; } - + vgInfo->vgVersion = rsp->vgVersion; vgInfo->stateTs = rsp->stateTs; vgInfo->hashMethod = rsp->hashMethod; @@ -114,7 +114,7 @@ static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) { code = TSDB_CODE_OUT_OF_MEMORY; goto _return; } - + for (int32_t j = 0; j < rsp->vgNum; ++j) { SVgroupInfo *pInfo = taosArrayGet(rsp->pVgroupInfos, j); if (taosHashPut(vgInfo->vgHash, &pInfo->vgId, sizeof(int32_t), pInfo, sizeof(SVgroupInfo)) != 0) { @@ -717,7 +717,7 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req hbGetQueryBasicInfo(connKey, req); - if (cb) hbGetUserBasicInfo(connKey, req); + if (cb > 0) hbGetUserBasicInfo(connKey, req); code = hbGetExpiredUserInfo(connKey, pCatalog, req); if (TSDB_CODE_SUCCESS != code) { @@ -1128,7 +1128,7 @@ int hbRegisterConn(SAppHbMgr *pAppHbMgr, int64_t tscRefId, int64_t clusterId, in } } -void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, void *cb) { +void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, void *connFp) { SClientHbReq *pReq = taosHashAcquire(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey)); if (pReq) { tFreeClientHbReq(pReq); @@ -1141,7 +1141,7 @@ void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, void *cb) { } atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1); - if (cb) { + if (connFp) { atomic_sub_fetch_32(&pAppHbMgr->nPassVerCb, 1); } } From 8513a30bfc234e39951802e0a15ac23856181cd2 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 23 Apr 2023 20:01:46 +0800 Subject: [PATCH 19/25] chore: more code --- source/client/inc/clientInt.h | 2 +- source/client/src/clientHb.c | 7 ++++--- source/client/src/clientMain.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 1df032c498..211b47b49c 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -63,7 +63,7 @@ typedef struct { // statistics int32_t reportCnt; int32_t connKeyCnt; - int32_t nPassVerCb; + int32_t passKeyCnt; // with passVer call back int64_t reportBytes; // not implemented int64_t startTime; // ctl diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 473d7c2e7d..277f74c77d 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -68,6 +68,7 @@ static int32_t hbProcessUserPassInfoRsp(void *value, int32_t valueLen, SClientHb } SPassInfo *passInfo = &pTscObj->passInfo; if (!passInfo->fp) { + releaseTscObj(pReq->connKey.tscRid); continue; } @@ -770,11 +771,11 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) { return NULL; } - int32_t nPassVerCb = atomic_load_32(&pAppHbMgr->nPassVerCb); + int32_t passKeyCnt = atomic_load_32(&pAppHbMgr->passKeyCnt); while (pIter != NULL) { pOneReq = taosArrayPush(pBatchReq->reqs, pOneReq); code = (*clientHbMgr.reqHandle[pOneReq->connKey.connType])(&pOneReq->connKey, &pOneReq->clusterId, pOneReq, - nPassVerCb); + passKeyCnt); break; #if 0 @@ -1142,6 +1143,6 @@ void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, void *connFp) atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1); if (connFp) { - atomic_sub_fetch_32(&pAppHbMgr->nPassVerCb, 1); + atomic_sub_fetch_32(&pAppHbMgr->passKeyCnt, 1); } } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 3f29249e52..aed11b4fb1 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -137,7 +137,7 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type) pObj->passInfo.fp = fp; pObj->passInfo.param = param; if (fp) { - atomic_add_fetch_32(&pObj->pAppInfo->pAppHbMgr->nPassVerCb, 1); + atomic_add_fetch_32(&pObj->pAppInfo->pAppHbMgr->passKeyCnt, 1); } break; } From dff62bdccd9ab9e59acceef362d1c6a37c594ef9 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 23 Apr 2023 22:43:29 +0800 Subject: [PATCH 20/25] chore: code optimization --- source/client/inc/clientInt.h | 2 +- source/client/src/clientHb.c | 37 +++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 211b47b49c..c319a6ffa5 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -74,7 +74,7 @@ typedef struct { typedef int32_t (*FHbRspHandle)(SAppHbMgr* pAppHbMgr, SClientHbRsp* pRsp); -typedef int32_t (*FHbReqHandle)(SClientHbKey* connKey, void* param, SClientHbReq* req, int32_t cb); +typedef int32_t (*FHbReqHandle)(SClientHbKey* connKey, void* param, SClientHbReq* req); typedef struct { int8_t inited; diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 277f74c77d..08607b08ea 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -24,7 +24,14 @@ static SClientHbMgr clientHbMgr = {0}; static int32_t hbCreateThread(); static void hbStopThread(); -static int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req, int32_t cb) { return 0; } +typedef struct { + union { + int64_t clusterId; + int32_t passKeyCnt; + }; +} SHbParam; + +static int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) { return 0; } static int32_t hbMqHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { return 0; } @@ -704,21 +711,23 @@ int32_t hbGetAppInfo(int64_t clusterId, SClientHbReq *req) { return TSDB_CODE_SUCCESS; } -int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req, int32_t cb) { - int64_t *clusterId = (int64_t *)param; +int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) { + SHbParam *hbParam = (SHbParam *)param; struct SCatalog *pCatalog = NULL; - int32_t code = catalogGetHandle(*clusterId, &pCatalog); + int32_t code = catalogGetHandle(hbParam->clusterId, &pCatalog); if (code != TSDB_CODE_SUCCESS) { - tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", *clusterId, tstrerror(code)); + tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code)); return code; } - hbGetAppInfo(*clusterId, req); + hbGetAppInfo(hbParam->clusterId, req); hbGetQueryBasicInfo(connKey, req); - if (cb > 0) hbGetUserBasicInfo(connKey, req); + if (hbParam->passKeyCnt > 0) { + hbGetUserBasicInfo(connKey, req); + } code = hbGetExpiredUserInfo(connKey, pCatalog, req); if (TSDB_CODE_SUCCESS != code) { @@ -771,11 +780,19 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) { return NULL; } - int32_t passKeyCnt = atomic_load_32(&pAppHbMgr->passKeyCnt); while (pIter != NULL) { pOneReq = taosArrayPush(pBatchReq->reqs, pOneReq); - code = (*clientHbMgr.reqHandle[pOneReq->connKey.connType])(&pOneReq->connKey, &pOneReq->clusterId, pOneReq, - passKeyCnt); + SHbParam param; + switch (pOneReq->connKey.connType) { + case CONN_TYPE__QUERY: { + param.clusterId = pOneReq->clusterId; + param.passKeyCnt = atomic_load_32(&pAppHbMgr->passKeyCnt); + break; + } + default: + break; + } + code = (*clientHbMgr.reqHandle[pOneReq->connKey.connType])(&pOneReq->connKey, ¶m, pOneReq); break; #if 0 From 16f039a780b9f712fde8b4861e94f4b0f6ed7f27 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 23 Apr 2023 22:52:20 +0800 Subject: [PATCH 21/25] chore: code optimization --- source/client/inc/clientInt.h | 2 +- source/client/src/clientHb.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index c319a6ffa5..8e20d7d275 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -361,7 +361,7 @@ void stopAllRequests(SHashObj* pRequests); // conn level int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType); -void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* connFp); +void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* param); typedef struct SSqlCallbackWrapper { SParseContext* pParseCtx; diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 08607b08ea..3b8739207c 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -1146,7 +1146,7 @@ int hbRegisterConn(SAppHbMgr *pAppHbMgr, int64_t tscRefId, int64_t clusterId, in } } -void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, void *connFp) { +void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, void *param) { SClientHbReq *pReq = taosHashAcquire(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey)); if (pReq) { tFreeClientHbReq(pReq); @@ -1159,7 +1159,7 @@ void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, void *connFp) } atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1); - if (connFp) { + if (param) { atomic_sub_fetch_32(&pAppHbMgr->passKeyCnt, 1); } } From 4701fdfe0606ebf1a3ba9dc8ecd785a7f2fe0521 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 23 Apr 2023 23:11:15 +0800 Subject: [PATCH 22/25] chore: more code --- source/client/src/clientHb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 3b8739207c..555aefc21b 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -19,11 +19,6 @@ #include "scheduler.h" #include "trpc.h" -static SClientHbMgr clientHbMgr = {0}; - -static int32_t hbCreateThread(); -static void hbStopThread(); - typedef struct { union { int64_t clusterId; @@ -31,6 +26,11 @@ typedef struct { }; } SHbParam; +static SClientHbMgr clientHbMgr = {0}; + +static int32_t hbCreateThread(); +static void hbStopThread(); + static int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) { return 0; } static int32_t hbMqHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { return 0; } From 63bad2e4fbb770034dfe03d18306ede786127bef Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Apr 2023 09:57:48 +0800 Subject: [PATCH 23/25] chore: code optimization --- source/client/src/clientHb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 555aefc21b..3b07fcf7ab 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -792,7 +792,13 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) { default: break; } - code = (*clientHbMgr.reqHandle[pOneReq->connKey.connType])(&pOneReq->connKey, ¶m, pOneReq); + if (clientHbMgr.reqHandle[pOneReq->connKey.connType]) { + code = (*clientHbMgr.reqHandle[pOneReq->connKey.connType])(&pOneReq->connKey, ¶m, pOneReq); + if (code) { + tscWarn("hbGatherAllInfo failed since %s, tscRid:%" PRIi64 ", connType:%" PRIi8, tstrerror(code), + pOneReq->connKey.tscRid, pOneReq->connKey.connType); + } + } break; #if 0 From d5d113aed72ec1ce5fa2a7ef3437c43e20955269 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Apr 2023 14:17:13 +0800 Subject: [PATCH 24/25] chore: fix the SHbParam definition --- source/client/src/clientHb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 3b07fcf7ab..dea58f6a30 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -21,8 +21,10 @@ typedef struct { union { - int64_t clusterId; - int32_t passKeyCnt; + struct { + int64_t clusterId; + int32_t passKeyCnt; + }; }; } SHbParam; From 0a405c10b7f3881278642a0ffa1796b939ccb3ed Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 24 Apr 2023 14:59:52 +0800 Subject: [PATCH 25/25] chore: code optimization --- source/client/src/clientHb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index dea58f6a30..79435da89f 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -87,11 +87,11 @@ static int32_t hbProcessUserPassInfoRsp(void *value, int32_t valueLen, SClientHb int32_t oldVer = atomic_load_32(&passInfo->ver); if (oldVer < rsp->version) { atomic_store_32(&passInfo->ver, rsp->version); - tscDebug("update passVer of user %s from %d to %d, tscRid:%" PRIi64 "\n", rsp->user, oldVer, - atomic_load_32(&passInfo->ver), pTscObj->id); if (passInfo->fp) { (*passInfo->fp)(passInfo->param, &passInfo->ver, TAOS_NOTIFY_PASSVER); } + tscDebug("update passVer of user %s from %d to %d, tscRid:%" PRIi64, rsp->user, oldVer, + atomic_load_32(&passInfo->ver), pTscObj->id); } break; }