From 2fa55f04e13995c7c7366b28c8692e33c5057137 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Sun, 7 Apr 2024 15:08:04 +0800 Subject: [PATCH] enh: check validity of commit actions of trans --- source/dnode/mnode/impl/src/mndTrans.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 3b6043479c..41ff45038f 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -894,6 +894,21 @@ static int32_t mndTransCheckParallelActions(SMnode *pMnode, STrans *pTrans) { return 0; } +static int32_t mndTransCheckCommitActions(SMnode *pMnode, STrans *pTrans) { + if (!pTrans->changeless && taosArrayGetSize(pTrans->commitActions) <= 0) { + terrno = TSDB_CODE_MND_TRANS_CLOG_IS_NULL; + mError("trans:%d, commit actions of non-changeless trans are empty", pTrans->id); + return -1; + } + if (mndTransActionsOfSameType(pTrans->commitActions) == false) { + terrno = TSDB_CODE_MND_TRANS_INVALID_STAGE; + mError("trans:%d, types of commit actions are not the same", pTrans->id); + return -1; + } + + return 0; +} + int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { if (pTrans == NULL) return -1; @@ -905,9 +920,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { return -1; } - if (!pTrans->changeless && taosArrayGetSize(pTrans->commitActions) <= 0) { - terrno = TSDB_CODE_MND_TRANS_CLOG_IS_NULL; - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + if (mndTransCheckCommitActions(pMnode, pTrans) != 0) { return -1; }