diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 9e99d6a9ba..1bd347fc24 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -570,6 +570,9 @@ typedef struct { int8_t ignoreExist; } SCreateDbReq; +int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq); +int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq); + typedef struct { char db[TSDB_DB_FNAME_LEN]; int32_t totalBlocks; @@ -582,28 +585,39 @@ typedef struct { int8_t cacheLastRow; } SAlterDbReq; +int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq); +int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq); + typedef struct { char db[TSDB_DB_FNAME_LEN]; int8_t ignoreNotExists; } SDropDbReq; +int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq); +int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq); + typedef struct { char db[TSDB_DB_FNAME_LEN]; uint64_t uid; } SDropDbRsp; +int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp); +int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp); + typedef struct { char db[TSDB_DB_FNAME_LEN]; int32_t vgVersion; } SUseDbReq; -typedef struct { - char db[TSDB_DB_FNAME_LEN]; -} SSyncDbReq; +int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq); +int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq); typedef struct { char db[TSDB_DB_FNAME_LEN]; -} SCompactDbReq; +} SSyncDbReq, SCompactDbReq; + +int32_t tSerializeSSyncDbReq(void* buf, int32_t bufLen, SSyncDbReq* pReq); +int32_t tDeserializeSSyncDbReq(void* buf, int32_t bufLen, SSyncDbReq* pReq); typedef struct { char name[TSDB_FUNC_NAME_LEN]; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index c6096ac4b8..20e1da9d07 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1097,3 +1097,213 @@ int32_t tDeserializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp tCoderClear(&decoder); return 0; } + +int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; + if (tEncodeI32(&encoder, pReq->numOfVgroups) < 0) return -1; + if (tEncodeI32(&encoder, pReq->cacheBlockSize) < 0) return -1; + if (tEncodeI32(&encoder, pReq->totalBlocks) < 0) return -1; + if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1; + if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; + if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; + if (tEncodeI32(&encoder, pReq->daysToKeep2) < 0) return -1; + if (tEncodeI32(&encoder, pReq->minRows) < 0) return -1; + if (tEncodeI32(&encoder, pReq->maxRows) < 0) return -1; + if (tEncodeI32(&encoder, pReq->commitTime) < 0) return -1; + if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1; + if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1; + if (tEncodeI8(&encoder, pReq->precision) < 0) return -1; + if (tEncodeI8(&encoder, pReq->compression) < 0) return -1; + if (tEncodeI8(&encoder, pReq->replications) < 0) return -1; + if (tEncodeI8(&encoder, pReq->quorum) < 0) return -1; + if (tEncodeI8(&encoder, pReq->update) < 0) return -1; + if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pReq->ignoreExist) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->numOfVgroups) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->cacheBlockSize) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->totalBlocks) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->daysToKeep2) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->minRows) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->maxRows) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->commitTime) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->compression) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->replications) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->quorum) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->update) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->ignoreExist) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +int32_t tSerializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; + if (tEncodeI32(&encoder, pReq->totalBlocks) < 0) return -1; + if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; + if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; + if (tEncodeI32(&encoder, pReq->daysToKeep2) < 0) return -1; + if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1; + if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1; + if (tEncodeI8(&encoder, pReq->quorum) < 0) return -1; + if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->totalBlocks) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->daysToKeep2) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->quorum) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +int32_t tSerializeSDropDbReq(void *buf, int32_t bufLen, SDropDbReq *pReq) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; + if (tEncodeI8(&encoder, pReq->ignoreNotExists) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSDropDbReq(void *buf, int32_t bufLen, SDropDbReq *pReq) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->ignoreNotExists) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +int32_t tSerializeSDropDbRsp(void *buf, int32_t bufLen, SDropDbRsp *pRsp) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pRsp->db) < 0) return -1; + if (tEncodeU64(&encoder, pRsp->uid) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSDropDbRsp(void *buf, int32_t bufLen, SDropDbRsp *pRsp) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pRsp->db) < 0) return -1; + if (tDecodeU64(&decoder, &pRsp->uid) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +int32_t tSerializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; + if (tEncodeI32(&encoder, pReq->vgVersion) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->vgVersion) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +int32_t tSerializeSSyncDbReq(void *buf, int32_t bufLen, SSyncDbReq *pReq) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSSyncDbReq(void *buf, int32_t bufLen, SSyncDbReq *pReq) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/inc/mndAuth.h b/source/dnode/mnode/impl/inc/mndAuth.h index ca196f69be..c2c69f000b 100644 --- a/source/dnode/mnode/impl/inc/mndAuth.h +++ b/source/dnode/mnode/impl/inc/mndAuth.h @@ -29,8 +29,12 @@ int32_t mndCheckCreateUserAuth(SUserObj *pOperUser); int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SDbObj *pDb, SAlterUserReq *pAlter); int32_t mndCheckDropUserAuth(SUserObj *pOperUser); -int32_t mndCheckOperateNodeAuth(SUserObj *pOperUser); -int32_t mndCheckOperateFuncAuth(SUserObj *pOperUser); +int32_t mndCheckNodeAuth(SUserObj *pOperUser); +int32_t mndCheckFuncAuth(SUserObj *pOperUser); + +int32_t mndCheckCreateDbAuth(SUserObj *pOperUser); +int32_t mndCheckAlterDropCompactSyncDbAuth(SUserObj *pOperUser, SDbObj *pDb); +int32_t mndCheckUseDbAuth(SUserObj *pOperUser, SDbObj *pDb); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndAuth.c b/source/dnode/mnode/impl/src/mndAuth.c index 14dc451686..84c8b7476c 100644 --- a/source/dnode/mnode/impl/src/mndAuth.c +++ b/source/dnode/mnode/impl/src/mndAuth.c @@ -111,7 +111,7 @@ int32_t mndCheckDropUserAuth(SUserObj *pOperUser) { return -1; } -int32_t mndCheckOperateNodeAuth(SUserObj *pOperUser) { +int32_t mndCheckNodeAuth(SUserObj *pOperUser) { if (pOperUser->superUser) { return 0; } @@ -120,7 +120,7 @@ int32_t mndCheckOperateNodeAuth(SUserObj *pOperUser) { return -1; } -int32_t mndCheckOperateFuncAuth(SUserObj *pOperUser) { +int32_t mndCheckFuncAuth(SUserObj *pOperUser) { if (pOperUser->superUser) { return 0; } @@ -128,3 +128,16 @@ int32_t mndCheckOperateFuncAuth(SUserObj *pOperUser) { terrno = TSDB_CODE_MND_NO_RIGHTS; return -1; } + +int32_t mndCheckCreateDbAuth(SUserObj *pOperUser) { return 0; } + +int32_t mndCheckAlterDropCompactSyncDbAuth(SUserObj *pOperUser, SDbObj *pDb) { + if (pOperUser->superUser || strcmp(pOperUser->user, pDb->createUser) == 0) { + return 0; + } + + terrno = TSDB_CODE_MND_NO_RIGHTS; + return -1; +} + +int32_t mndCheckUseDbAuth(SUserObj *pOperUser, SDbObj *pDb) { return 0; } diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index 7bffc482bb..eb9af7b358 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -293,7 +293,7 @@ static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pReq) { goto CREATE_BNODE_OVER; } - if (mndCheckOperateNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser)) { goto CREATE_BNODE_OVER; } @@ -400,7 +400,7 @@ static int32_t mndProcessDropBnodeReq(SMnodeMsg *pReq) { goto DROP_BNODE_OVER; } - if (mndCheckOperateNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser)) { goto DROP_BNODE_OVER; } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 3f4213064a..5126ca9db3 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -496,7 +496,7 @@ static int32_t mndProcessCreateDnodeReq(SMnodeMsg *pReq) { goto CREATE_DNODE_OVER; } - if (mndCheckOperateNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser)) { goto CREATE_DNODE_OVER; } @@ -570,7 +570,7 @@ static int32_t mndProcessDropDnodeReq(SMnodeMsg *pReq) { goto DROP_DNODE_OVER; } - if (mndCheckOperateNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser)) { goto DROP_DNODE_OVER; } diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index cd5eaca638..3527f103db 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -321,7 +321,7 @@ static int32_t mndProcessCreateFuncReq(SMnodeMsg *pReq) { goto CREATE_FUNC_OVER; } - if (mndCheckOperateFuncAuth(pUser)) { + if (mndCheckFuncAuth(pUser)) { goto CREATE_FUNC_OVER; } @@ -376,7 +376,7 @@ static int32_t mndProcessDropFuncReq(SMnodeMsg *pReq) { goto DROP_FUNC_OVER; } - if (mndCheckOperateFuncAuth(pUser)) { + if (mndCheckFuncAuth(pUser)) { goto DROP_FUNC_OVER; } diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 0f27ebdd71..eb9ba49dd2 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -415,7 +415,7 @@ static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pReq) { goto CREATE_MNODE_OVER; } - if (mndCheckOperateNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser)) { goto CREATE_MNODE_OVER; } @@ -582,7 +582,7 @@ static int32_t mndProcessDropMnodeReq(SMnodeMsg *pReq) { goto DROP_MNODE_OVER; } - if (mndCheckOperateNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser)) { goto DROP_MNODE_OVER; } diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index cdb2b79e0f..db1ea2ab17 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -293,7 +293,7 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pReq) { goto CREATE_QNODE_OVER; } - if (mndCheckOperateNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser)) { goto CREATE_QNODE_OVER; } @@ -400,7 +400,7 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pReq) { goto DROP_QNODE_OVER; } - if (mndCheckOperateNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser)) { goto DROP_QNODE_OVER; } diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index a239564fe6..dd699364c0 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -294,7 +294,7 @@ static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pReq) { goto CREATE_SNODE_OVER; } - if (mndCheckOperateNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser)) { goto CREATE_SNODE_OVER; } @@ -403,7 +403,7 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pReq) { goto DROP_SNODE_OVER; } - if (mndCheckOperateNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser)) { goto DROP_SNODE_OVER; }