From 9dd5922d150bb6f5c2232ea638201d8d646a37c9 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 22:36:24 -0800 Subject: [PATCH] error returned when trans rollback --- source/dnode/mnode/impl/inc/mndDef.h | 8 ++++---- source/dnode/mnode/impl/src/mndTrans.c | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 267a3f6cf5..93a5722842 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -64,10 +64,10 @@ typedef enum { TRN_STAGE_PREPARE = 0, TRN_STAGE_REDO_LOG = 1, TRN_STAGE_REDO_ACTION = 2, - TRN_STAGE_UNDO_LOG = 3, - TRN_STAGE_UNDO_ACTION = 4, - TRN_STAGE_COMMIT_LOG = 5, - TRN_STAGE_COMMIT = 6, + TRN_STAGE_COMMIT_LOG = 3, + TRN_STAGE_COMMIT = 4, + TRN_STAGE_UNDO_ACTION = 5, + TRN_STAGE_UNDO_LOG = 6, TRN_STAGE_ROLLBACK = 7, TRN_STAGE_FINISHED = 8 } ETrnStage; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index ee4a49ffdc..82fe296166 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -496,10 +496,15 @@ static int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) { } static void mndTransSendRpcRsp(STrans *pTrans) { - if (pTrans->rpcHandle != NULL) { - mDebug("trans:%d, send rsp, ahandle:%p code:0x%x", pTrans->id, pTrans->rpcAHandle, pTrans->code & 0xFFFF); - SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = pTrans->code, .ahandle = pTrans->rpcAHandle}; - rpcSendResponse(&rspMsg); + if (pTrans->stage == TRN_STAGE_FINISHED || pTrans->stage == TRN_STAGE_UNDO_LOG || + pTrans->stage == TRN_STAGE_UNDO_ACTION || pTrans->stage == TRN_STAGE_ROLLBACK) { + if (pTrans->rpcHandle != NULL) { + mDebug("trans:%d, send rsp, code:0x%x stage:%d app:%p", pTrans->id, pTrans->code & 0xFFFF, pTrans->stage, + pTrans->rpcAHandle); + SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = pTrans->code, .ahandle = pTrans->rpcAHandle}; + rpcSendResponse(&rspMsg); + pTrans->rpcHandle = NULL; + } } } @@ -764,7 +769,6 @@ static bool mndTransPerformCommitLogStage(SMnode *pMnode, STrans *pTrans) { pTrans->failedTimes++; mError("trans:%d, stage keep on commitLog since %s", pTrans->id, terrstr()); continueExec = false; - ; } return continueExec; @@ -791,7 +795,7 @@ static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans) { int32_t code = mndTransExecuteUndoActions(pMnode, pTrans); if (code == 0) { - pTrans->stage = TRN_STAGE_REDO_LOG; + pTrans->stage = TRN_STAGE_UNDO_LOG; mDebug("trans:%d, stage from undoAction to undoLog", pTrans->id); continueExec = true; } else if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { @@ -814,7 +818,6 @@ static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) { pTrans->stage = TRN_STAGE_FINISHED; mDebug("trans:%d, stage from rollback to finished", pTrans->id); continueExec = true; - ; } else { pTrans->failedTimes++; mError("trans:%d, stage keep on rollback since %s", pTrans->id, terrstr()); @@ -880,9 +883,7 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) { } } - if (pTrans->stage == TRN_STAGE_FINISHED) { - mndTransSendRpcRsp(pTrans); - } + mndTransSendRpcRsp(pTrans); } static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) { -- GitLab