diff --git a/include/common/tmsg.h b/include/common/tmsg.h index a6dd51b035e02c6aef9db1c0c0732178063f3dee..14b64d64b413da8d8753c1eac4f860306a5a83bb 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -438,6 +438,7 @@ typedef struct { int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp); int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp); +void tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp); typedef struct { int16_t colId; // column id diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index dc52afb3828caf3a71b9e8b4a28f25c6aa77183c..6c84fe6be7a76f73f13c94e28a16b1ee9bf96b0b 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1302,6 +1302,11 @@ int32_t tDeserializeSGetUserAuthRsp(void *buf, int32_t bufLen, SGetUserAuthRsp * return 0; } +void tFreeSGetUserAuthRsp(SGetUserAuthRsp *pRsp) { + taosHashCleanup(pRsp->readDbs); + taosHashCleanup(pRsp->writeDbs); +} + int32_t tSerializeSCreateDropMQSBNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index 2b46fc9274dae5407deccc7a362672db1005f8f0..7d38e1752ac74b3ac60bf0aa5e3696282dce65c1 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -164,7 +164,6 @@ static const SInfosTableSchema userUsersSchema[] = { {.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "account", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; static const SInfosTableSchema grantsSchema[] = { diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 1500b3d7d84b19d9511143a6c1d9c603e8fdf03c..de6c76e0746f4344d843d26cb633de5494339415 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -165,8 +165,9 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { int32_t numOfWriteDbs = 0; SDB_GET_INT32(pRaw, dataPos, &numOfReadDbs, _OVER) SDB_GET_INT32(pRaw, dataPos, &numOfWriteDbs, _OVER) - pUser->readDbs = taosHashInit(numOfReadDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, true); - pUser->writeDbs = taosHashInit(numOfWriteDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, true); + pUser->readDbs = taosHashInit(numOfReadDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); + pUser->writeDbs = + taosHashInit(numOfWriteDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (pUser->readDbs == NULL || pUser->writeDbs == NULL) goto _OVER; for (int32_t i = 0; i < numOfReadDbs; ++i) { @@ -340,13 +341,13 @@ _OVER: return code; } -static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNodeMsg *pReq) { +static int32_t mndAlterUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNodeMsg *pReq) { STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_ALTER_USER, &pReq->rpcMsg); if (pTrans == NULL) { - mError("user:%s, failed to update since %s", pOld->user, terrstr()); + mError("user:%s, failed to alter since %s", pOld->user, terrstr()); return -1; } - mDebug("trans:%d, used to update user:%s", pTrans->id, pOld->user); + mDebug("trans:%d, used to alter user:%s", pTrans->id, pOld->user); SSdbRaw *pRedoRaw = mndUserActionEncode(pNew); if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { @@ -367,7 +368,8 @@ static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNo } static SHashObj *mndDupDbHash(SHashObj *pOld) { - SHashObj *pNew = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, true); + SHashObj *pNew = + taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (pNew == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -378,8 +380,8 @@ static SHashObj *mndDupDbHash(SHashObj *pOld) { int32_t len = strlen(db) + 1; if (taosHashPut(pNew, db, len, db, TSDB_DB_FNAME_LEN) != 0) { taosHashCancelIterate(pOld, db); - terrno = TSDB_CODE_OUT_OF_MEMORY; taosHashCleanup(pNew); + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } db = taosHashIterate(pOld, db); @@ -485,7 +487,7 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) { goto _OVER; } - code = mndUpdateUser(pMnode, pUser, &newUser, pReq); + code = mndAlterUser(pMnode, pUser, &newUser, pReq); if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; _OVER: @@ -632,8 +634,7 @@ static int32_t mndProcessGetUserAuthReq(SNodeMsg *pReq) { _OVER: mndReleaseUser(pMnode, pUser); - taosHashCleanup(authRsp.readDbs); - taosHashCleanup(authRsp.writeDbs); + tFreeSGetUserAuthRsp(&authRsp); return code; } @@ -670,11 +671,6 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB pColInfo = taosArrayGet(pBlock->pDataBlock, cols); colDataAppend(pColInfo, numOfRows, (const char *)&pUser->createdTime, false); - cols++; - pColInfo = taosArrayGet(pBlock->pDataBlock, cols); - STR_WITH_MAXSIZE_TO_VARSTR(name, pUser->acct, pShow->bytes[cols]); - colDataAppend(pColInfo, numOfRows, (const char *)name, false); - numOfRows++; sdbRelease(pSdb, pUser); }