enh: return with code
This commit is contained in:
parent
7aff15c49e
commit
1547b7ba88
|
@ -172,6 +172,18 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define TAOS_CHECK_EXEC_GOTO(CMD, LINO, EXEC, LABEL) \
|
||||||
|
do { \
|
||||||
|
code = (CMD); \
|
||||||
|
if (code != TSDB_CODE_SUCCESS) { \
|
||||||
|
if (LINO) { \
|
||||||
|
*((int32_t *)(LINO)) = __LINE__; \
|
||||||
|
} \
|
||||||
|
(EXEC); \
|
||||||
|
goto LABEL; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,14 +29,14 @@ enum {
|
||||||
};
|
};
|
||||||
int32_t mndInitUser(SMnode *pMnode);
|
int32_t mndInitUser(SMnode *pMnode);
|
||||||
void mndCleanupUser(SMnode *pMnode);
|
void mndCleanupUser(SMnode *pMnode);
|
||||||
SUserObj *mndAcquireUser(SMnode *pMnode, const char *userName);
|
int32_t mndAcquireUser(SMnode *pMnode, const char *userName, SUserObj **ppUser);
|
||||||
void mndReleaseUser(SMnode *pMnode, SUserObj *pUser);
|
void mndReleaseUser(SMnode *pMnode, SUserObj *pUser);
|
||||||
|
|
||||||
// for trans test
|
// for trans test
|
||||||
SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
||||||
SHashObj *mndDupDbHash(SHashObj *pOld);
|
int32_t mndDupDbHash(SHashObj *pOld, SHashObj **ppNew);
|
||||||
SHashObj *mndDupTableHash(SHashObj *pOld);
|
int32_t mndDupTableHash(SHashObj *pOld, SHashObj **ppNew);
|
||||||
SHashObj *mndDupTopicHash(SHashObj *pOld);
|
int32_t mndDupTopicHash(SHashObj *pOld, SHashObj **ppNew);
|
||||||
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
||||||
int32_t *pRspLen, int64_t ipWhiteListVer);
|
int32_t *pRspLen, int64_t ipWhiteListVer);
|
||||||
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db);
|
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db);
|
||||||
|
|
|
@ -871,6 +871,7 @@ _exit:
|
||||||
static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
|
static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
|
int32_t lino = 0;
|
||||||
SDbObj *pDb = NULL;
|
SDbObj *pDb = NULL;
|
||||||
SUserObj *pUser = NULL;
|
SUserObj *pUser = NULL;
|
||||||
SCreateDbReq createReq = {0};
|
SCreateDbReq createReq = {0};
|
||||||
|
@ -931,10 +932,7 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
TAOS_CHECK_GOTO(mndAcquireUser(pMnode, pReq->info.conn.user, &pUser), &lino, _OVER);
|
||||||
if (pUser == NULL) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndCreateDb(pMnode, pReq, &createReq, pUser);
|
code = mndCreateDb(pMnode, pReq, &createReq, pUser);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
@ -946,7 +944,7 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||||
mError("db:%s, failed to create since %s", createReq.db, terrstr());
|
mError("db:%s, failed to create at line %d since %s", createReq.db, lino, terrstr());
|
||||||
}
|
}
|
||||||
|
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
|
@ -2397,9 +2395,10 @@ static int32_t mndRetrieveDbs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
SDbObj *pDb = NULL;
|
SDbObj *pDb = NULL;
|
||||||
|
SUserObj *pUser = NULL;
|
||||||
ESdbStatus objStatus = 0;
|
ESdbStatus objStatus = 0;
|
||||||
|
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
(void)mndAcquireUser(pMnode, pReq->info.conn.user, &pUser);
|
||||||
if (pUser == NULL) return 0;
|
if (pUser == NULL) return 0;
|
||||||
bool sysinfo = pUser->sysInfo;
|
bool sysinfo = pUser->sysInfo;
|
||||||
|
|
||||||
|
|
|
@ -251,9 +251,9 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
code = mndAcquireUser(pMnode, pReq->info.conn.user, &pUser);
|
||||||
if (pUser == NULL) {
|
if (pUser == NULL) {
|
||||||
mGError("user:%s, failed to login from %s while acquire user since %s", pReq->info.conn.user, ip, terrstr());
|
mGError("user:%s, failed to login from %s while acquire user since %s", pReq->info.conn.user, ip, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2851,8 +2851,9 @@ static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
STableInfoReq infoReq = {0};
|
STableInfoReq infoReq = {0};
|
||||||
STableMetaRsp metaRsp = {0};
|
STableMetaRsp metaRsp = {0};
|
||||||
|
SUserObj *pUser = NULL;
|
||||||
|
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
code = mndAcquireUser(pMnode, pReq->info.conn.user, &pUser);
|
||||||
if (pUser == NULL) return 0;
|
if (pUser == NULL) return 0;
|
||||||
bool sysinfo = pUser->sysInfo;
|
bool sysinfo = pUser->sysInfo;
|
||||||
|
|
||||||
|
|
|
@ -1305,12 +1305,13 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHashObj *mndDupTableHash(SHashObj *pOld) {
|
int32_t mndDupTableHash(SHashObj *pOld, SHashObj **ppNew) {
|
||||||
SHashObj *pNew =
|
*ppNew =
|
||||||
taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||||
if (pNew == NULL) {
|
if (*ppNew == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
TAOS_CHECK_RETURN(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *tb = taosHashIterate(pOld, NULL);
|
char *tb = taosHashIterate(pOld, NULL);
|
||||||
|
@ -1443,17 +1444,18 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SUserObj *mndAcquireUser(SMnode *pMnode, const char *userName) {
|
int32_t mndAcquireUser(SMnode *pMnode, const char *userName, SUserObj **ppUser) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
SUserObj *pUser = sdbAcquire(pSdb, SDB_USER, userName);
|
SUserObj *pUser = sdbAcquire(pSdb, SDB_USER, userName);
|
||||||
if (pUser == NULL) {
|
if (pUser == NULL) {
|
||||||
if (terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
|
if (code == TSDB_CODE_SDB_OBJ_NOT_THERE) {
|
||||||
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
|
code = TSDB_CODE_MND_USER_NOT_EXIST;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_MND_USER_NOT_AVAILABLE;
|
code = TSDB_CODE_MND_USER_NOT_AVAILABLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pUser;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mndReleaseUser(SMnode *pMnode, SUserObj *pUser) {
|
void mndReleaseUser(SMnode *pMnode, SUserObj *pUser) {
|
||||||
|
@ -1552,21 +1554,21 @@ _OVER:
|
||||||
|
|
||||||
static int32_t mndProcessCreateUserReq(SRpcMsg *pReq) {
|
static int32_t mndProcessCreateUserReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = 0;
|
||||||
|
int32_t lino = 0;
|
||||||
SUserObj *pUser = NULL;
|
SUserObj *pUser = NULL;
|
||||||
SUserObj *pOperUser = NULL;
|
SUserObj *pOperUser = NULL;
|
||||||
SCreateUserReq createReq = {0};
|
SCreateUserReq createReq = {0};
|
||||||
|
|
||||||
if (tDeserializeSCreateUserReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
if (tDeserializeSCreateUserReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
TAOS_CHECK_GOTO(TSDB_CODE_INVALID_MSG, &lino, _OVER);
|
||||||
goto _OVER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("user:%s, start to create, createdb:%d, is_import:%d", createReq.user, createReq.isImport, createReq.createDb);
|
mInfo("user:%s, start to create, createdb:%d, is_import:%d", createReq.user, createReq.isImport, createReq.createDb);
|
||||||
|
|
||||||
#ifndef TD_ENTERPRISE
|
#ifndef TD_ENTERPRISE
|
||||||
if (createReq.isImport == 1) {
|
if (createReq.isImport == 1) {
|
||||||
goto _OVER;
|
TAOS_CHECK_GOTO(TSDB_CODE_OPS_NOT_SUPPORT, &lino, _OVER); // enterprise feature
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1599,15 +1601,15 @@ static int32_t mndProcessCreateUserReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pUser = mndAcquireUser(pMnode, createReq.user);
|
code = mndAcquireUser(pMnode, createReq.user, &pUser);
|
||||||
if (pUser != NULL) {
|
if (pUser != NULL) {
|
||||||
terrno = TSDB_CODE_MND_USER_ALREADY_EXIST;
|
terrno = TSDB_CODE_MND_USER_ALREADY_EXIST;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pOperUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
code = mndAcquireUser(pMnode, pReq->info.conn.user, &pOperUser);
|
||||||
if (pOperUser == NULL) {
|
if (pOperUser == NULL) {
|
||||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
code = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1615,6 +1617,7 @@ static int32_t mndProcessCreateUserReq(SRpcMsg *pReq) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
TAOS_CHECK_GOTO(grantCheck(TSDB_GRANT_USER), &lino, _OVER);
|
||||||
|
|
||||||
code = mndCreateUser(pMnode, pOperUser->acct, &createReq, pReq);
|
code = mndCreateUser(pMnode, pOperUser->acct, &createReq, pReq);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
@ -1640,7 +1643,7 @@ _OVER:
|
||||||
mndReleaseUser(pMnode, pOperUser);
|
mndReleaseUser(pMnode, pOperUser);
|
||||||
tFreeSCreateUserReq(&createReq);
|
tFreeSCreateUserReq(&createReq);
|
||||||
|
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndProcessGetUserWhiteListReq(SRpcMsg *pReq) {
|
int32_t mndProcessGetUserWhiteListReq(SRpcMsg *pReq) {
|
||||||
|
@ -1681,7 +1684,7 @@ int32_t mndProcessGetUserWhiteListReq(SRpcMsg *pReq) {
|
||||||
_OVER:
|
_OVER:
|
||||||
mndReleaseUser(pMnode, pUser);
|
mndReleaseUser(pMnode, pUser);
|
||||||
tFreeSGetUserWhiteListRsp(&wlRsp);
|
tFreeSGetUserWhiteListRsp(&wlRsp);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndProcesSRetrieveIpWhiteReq(SRpcMsg *pReq) {
|
int32_t mndProcesSRetrieveIpWhiteReq(SRpcMsg *pReq) {
|
||||||
|
@ -1736,32 +1739,34 @@ static int32_t mndAlterUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SRpc
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHashObj *mndDupObjHash(SHashObj *pOld, int32_t dataLen) {
|
static int32_t mndDupObjHash(SHashObj *pOld, int32_t dataLen, SHashObj **ppNew) {
|
||||||
SHashObj *pNew =
|
int32_t code = 0;
|
||||||
|
|
||||||
|
*ppNew =
|
||||||
taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||||
if (pNew == NULL) {
|
if (*ppNew == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno ? terrno : TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *db = taosHashIterate(pOld, NULL);
|
char *db = taosHashIterate(pOld, NULL);
|
||||||
while (db != NULL) {
|
while (db != NULL) {
|
||||||
int32_t len = strlen(db) + 1;
|
int32_t len = strlen(db) + 1;
|
||||||
if (taosHashPut(pNew, db, len, db, dataLen) != 0) {
|
if ((code = taosHashPut(*ppNew, db, len, db, dataLen)) != 0) {
|
||||||
|
if (terrno != 0) code = terrno; // TODO: remove this line after terrno is removed
|
||||||
taosHashCancelIterate(pOld, db);
|
taosHashCancelIterate(pOld, db);
|
||||||
taosHashCleanup(pNew);
|
taosHashCleanup(*ppNew);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
TAOS_RETURN(code);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
db = taosHashIterate(pOld, db);
|
db = taosHashIterate(pOld, db);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pNew;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
SHashObj *mndDupDbHash(SHashObj *pOld) { return mndDupObjHash(pOld, TSDB_DB_FNAME_LEN); }
|
int32_t mndDupDbHash(SHashObj *pOld, SHashObj **ppNew) { return mndDupObjHash(pOld, TSDB_DB_FNAME_LEN, ppNew); }
|
||||||
|
|
||||||
SHashObj *mndDupTopicHash(SHashObj *pOld) { return mndDupObjHash(pOld, TSDB_TOPIC_FNAME_LEN); }
|
int32_t mndDupTopicHash(SHashObj *pOld, SHashObj **ppNew) { return mndDupObjHash(pOld, TSDB_TOPIC_FNAME_LEN, ppNew); }
|
||||||
|
|
||||||
static int32_t mndTablePriviledge(SMnode *pMnode, SHashObj *hash, SHashObj *useDbHash, SAlterUserReq *alterReq,
|
static int32_t mndTablePriviledge(SMnode *pMnode, SHashObj *hash, SHashObj *useDbHash, SAlterUserReq *alterReq,
|
||||||
SSdb *pSdb) {
|
SSdb *pSdb) {
|
||||||
|
@ -2300,7 +2305,7 @@ _OVER:
|
||||||
|
|
||||||
static int32_t mndProcessGetUserAuthReq(SRpcMsg *pReq) {
|
static int32_t mndProcessGetUserAuthReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = 0;
|
||||||
SUserObj *pUser = NULL;
|
SUserObj *pUser = NULL;
|
||||||
SGetUserAuthReq authReq = {0};
|
SGetUserAuthReq authReq = {0};
|
||||||
SGetUserAuthRsp authRsp = {0};
|
SGetUserAuthRsp authRsp = {0};
|
||||||
|
@ -2312,25 +2317,17 @@ static int32_t mndProcessGetUserAuthReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
mTrace("user:%s, start to get auth", authReq.user);
|
mTrace("user:%s, start to get auth", authReq.user);
|
||||||
|
|
||||||
pUser = mndAcquireUser(pMnode, authReq.user);
|
TAOS_CHECK_GOTO(mndAcquireUser(pMnode, authReq.user, &pUser), NULL, _OVER);
|
||||||
if (pUser == NULL) {
|
|
||||||
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndSetUserAuthRsp(pMnode, pUser, &authRsp);
|
TAOS_CHECK_GOTO(mndSetUserAuthRsp(pMnode, pUser, &authRsp), NULL, _OVER);
|
||||||
if (code) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t contLen = tSerializeSGetUserAuthRsp(NULL, 0, &authRsp);
|
int32_t contLen = tSerializeSGetUserAuthRsp(NULL, 0, &authRsp);
|
||||||
void *pRsp = rpcMallocCont(contLen);
|
void *pRsp = rpcMallocCont(contLen);
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
|
||||||
goto _OVER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tSerializeSGetUserAuthRsp(pRsp, contLen, &authRsp);
|
TAOS_CHECK_GOTO(tSerializeSGetUserAuthRsp(pRsp, contLen, &authRsp), NULL, _OVER);
|
||||||
|
|
||||||
pReq->info.rsp = pRsp;
|
pReq->info.rsp = pRsp;
|
||||||
pReq->info.rspLen = contLen;
|
pReq->info.rspLen = contLen;
|
||||||
|
@ -2341,7 +2338,7 @@ _OVER:
|
||||||
mndReleaseUser(pMnode, pUser);
|
mndReleaseUser(pMnode, pUser);
|
||||||
tFreeSGetUserAuthRsp(&authRsp);
|
tFreeSGetUserAuthRsp(&authRsp);
|
||||||
|
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndRetrieveUsers(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
static int32_t mndRetrieveUsers(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||||
|
|
Loading…
Reference in New Issue