From 03d68a037693120001a69d6653d38c8da5e1464f Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Wed, 21 Feb 2024 13:37:15 +0800 Subject: [PATCH 01/10] enh: change redo logs of trans create-stb as prepare logs --- source/dnode/mnode/impl/src/mndStb.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index aad1dc881b..a1aed7b735 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -617,10 +617,10 @@ int32_t mndCheckCreateStbReq(SMCreateStbReq *pCreate) { return 0; } -static int32_t mndSetCreateStbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { +static int32_t mndSetCreateStbPrepareLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { SSdbRaw *pRedoRaw = mndStbActionEncode(pStb); if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { + if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) { sdbFreeRaw(pRedoRaw); return -1; } @@ -629,18 +629,6 @@ static int32_t mndSetCreateStbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *p return 0; } -static int32_t mndSetCreateStbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { - SSdbRaw *pUndoRaw = mndStbActionEncode(pStb); - if (pUndoRaw == NULL) return -1; - if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) { - sdbFreeRaw(pUndoRaw); - return -1; - } - if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1; - - return 0; -} - static int32_t mndSetCreateStbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { SSdbRaw *pCommitRaw = mndStbActionEncode(pStb); if (pCommitRaw == NULL) return -1; @@ -913,8 +901,7 @@ _OVER: int32_t mndAddStbToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { mndTransSetDbName(pTrans, pDb->name, pStb->name); if (mndTransCheckConflict(pMnode, pTrans) != 0) return -1; - if (mndSetCreateStbRedoLogs(pMnode, pTrans, pDb, pStb) != 0) return -1; - if (mndSetCreateStbUndoLogs(pMnode, pTrans, pDb, pStb) != 0) return -1; + if (mndSetCreateStbPrepareLogs(pMnode, pTrans, pDb, pStb) != 0) return -1; if (mndSetCreateStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) return -1; if (mndSetCreateStbRedoActions(pMnode, pTrans, pDb, pStb) != 0) return -1; if (mndSetCreateStbUndoActions(pMnode, pTrans, pDb, pStb) != 0) return -1; From 3a81c9777ca3297a6e7ca682a84707154add14b3 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Wed, 21 Feb 2024 20:00:04 +0800 Subject: [PATCH 02/10] enh: change redo logs of trans alter-stb and drop-stb as prepare logs --- source/dnode/mnode/impl/src/mndStb.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index a1aed7b735..b6e49b4d8b 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -1733,10 +1733,10 @@ static int32_t mndAlterStbColumnBytes(SMnode *pMnode, const SStbObj *pOld, SStbO return 0; } -static int32_t mndSetAlterStbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { +static int32_t mndSetAlterStbPrepareLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { SSdbRaw *pRedoRaw = mndStbActionEncode(pStb); if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { + if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) { sdbFreeRaw(pRedoRaw); return -1; } @@ -2142,7 +2142,7 @@ static int32_t mndAlterStbImp(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbOb mndTransSetRpcRsp(pTrans, pCont, contLen); } - if (mndSetAlterStbRedoLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; + if (mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; if (mndSetAlterStbRedoActions(pMnode, pTrans, pDb, pStb, alterOriData, alterOriDataLen) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; @@ -2179,11 +2179,11 @@ static int32_t mndAlterStbAndUpdateTagIdxImp(SMnode *pMnode, SRpcMsg *pReq, SDbO if (mndGetIdxsByTagName(pMnode, pStb, pField0->name, &idxObj) == 0) { exist = true; } - if (mndSetAlterStbRedoLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; + if (mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; if (exist == true) { - if (mndSetDropIdxRedoLogs(pMnode, pTrans, &idxObj) != 0) goto _OVER; + if (mndSetDropIdxPrepareLogs(pMnode, pTrans, &idxObj) != 0) goto _OVER; if (mndSetDropIdxCommitLogs(pMnode, pTrans, &idxObj) != 0) goto _OVER; } @@ -2202,13 +2202,13 @@ static int32_t mndAlterStbAndUpdateTagIdxImp(SMnode *pMnode, SRpcMsg *pReq, SDbO exist = true; } - if (mndSetAlterStbRedoLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; + if (mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; if (exist == true) { memcpy(idxObj.colName, nTagName, strlen(nTagName)); idxObj.colName[strlen(nTagName)] = 0; - if (mndSetAlterIdxRedoLogs(pMnode, pTrans, &idxObj) != 0) goto _OVER; + if (mndSetAlterIdxPrepareLogs(pMnode, pTrans, &idxObj) != 0) goto _OVER; if (mndSetAlterIdxCommitLogs(pMnode, pTrans, &idxObj) != 0) goto _OVER; } @@ -2341,10 +2341,10 @@ _OVER: return code; } -static int32_t mndSetDropStbRedoLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) { +static int32_t mndSetDropStbPrepareLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) { SSdbRaw *pRedoRaw = mndStbActionEncode(pStb); if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { + if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) { sdbFreeRaw(pRedoRaw); return -1; } @@ -2414,7 +2414,7 @@ static int32_t mndDropStb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *p mndTransSetDbName(pTrans, pDb->name, pStb->name); if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER; - if (mndSetDropStbRedoLogs(pMnode, pTrans, pStb) != 0) goto _OVER; + if (mndSetDropStbPrepareLogs(pMnode, pTrans, pStb) != 0) goto _OVER; if (mndSetDropStbCommitLogs(pMnode, pTrans, pStb) != 0) goto _OVER; if (mndSetDropStbRedoActions(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; if (mndDropIdxsByStb(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; @@ -3534,7 +3534,7 @@ static int32_t mndCheckIndexReq(SCreateTagIndexReq *pReq) { mndTransSetDbName(pTrans, pDb->name, pStb->name); if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER; - if (mndSetAlterStbRedoLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; + if (mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; if (mndSetAlterStbRedoActions2(pMnode, pTrans, pDb, pStb, sql, len) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; From 8f3b6a717df0eb8a4ae4b464ff2c00ac3f9ebbfe Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Wed, 21 Feb 2024 20:03:21 +0800 Subject: [PATCH 03/10] enh: change redo logs of trans alter-db and drop-db as prepare logs --- source/dnode/mnode/impl/src/mndDb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 077c0a9c2a..2ea1cdfe2a 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -884,10 +884,10 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) { return terrno; } -static int32_t mndSetAlterDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOld, SDbObj *pNew) { +static int32_t mndSetAlterDbPrepareLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOld, SDbObj *pNew) { SSdbRaw *pRedoRaw = mndDbActionEncode(pOld); if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { + if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) { sdbFreeRaw(pRedoRaw); return -1; } @@ -943,7 +943,7 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p mndTransSetDbName(pTrans, pOld->name, NULL); if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER; - if (mndSetAlterDbRedoLogs(pMnode, pTrans, pOld, pNew) != 0) goto _OVER; + if (mndSetAlterDbPrepareLogs(pMnode, pTrans, pOld, pNew) != 0) goto _OVER; if (mndSetAlterDbCommitLogs(pMnode, pTrans, pOld, pNew) != 0) goto _OVER; if (mndSetAlterDbRedoActions(pMnode, pTrans, pOld, pNew) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; @@ -1120,10 +1120,10 @@ _OVER: return code; } -static int32_t mndSetDropDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { +static int32_t mndSetDropDbPrepareLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { SSdbRaw *pRedoRaw = mndDbActionEncode(pDb); if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) return -1; if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1; return 0; @@ -1257,7 +1257,7 @@ static int32_t mndDropDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb) { goto _OVER; } - if (mndSetDropDbRedoLogs(pMnode, pTrans, pDb) != 0) goto _OVER; + if (mndSetDropDbPrepareLogs(pMnode, pTrans, pDb) != 0) goto _OVER; if (mndSetDropDbCommitLogs(pMnode, pTrans, pDb) != 0) goto _OVER; /*if (mndDropOffsetByDB(pMnode, pTrans, pDb) != 0) goto _OVER;*/ /*if (mndDropSubByDB(pMnode, pTrans, pDb) != 0) goto _OVER;*/ From 94f7e0c811af2a7ce4ab4e8ed9ebc853230b7341 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Wed, 21 Feb 2024 20:07:45 +0800 Subject: [PATCH 04/10] enh: change redo logs of trans create-stb-index and drop-index as prepare logs --- source/dnode/mnode/impl/inc/mndIndex.h | 8 ++++---- source/dnode/mnode/impl/src/mndIndex.c | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndIndex.h b/source/dnode/mnode/impl/inc/mndIndex.h index 2d5479bc9b..3b9b68a1b5 100644 --- a/source/dnode/mnode/impl/inc/mndIndex.h +++ b/source/dnode/mnode/impl/inc/mndIndex.h @@ -19,16 +19,16 @@ int32_t mndGetTableIdx(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool int32_t mndRetrieveTagIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); int32_t mndProcessDropTagIdxReq(SRpcMsg *pReq); -int32_t mndSetCreateIdxRedoLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx); +int32_t mndSetCreateIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx); int32_t mndSetCreateIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx); -int32_t mndSetDropIdxRedoLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx); +int32_t mndSetDropIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx); int32_t mndSetDropIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx); -int32_t mndSetAlterIdxRedoLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx); +int32_t mndSetAlterIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx); int32_t mndSetAlterIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx); #ifdef __cplusplus } #endif -#endif /*_TD_MND_IDX_H_*/ \ No newline at end of file +#endif /*_TD_MND_IDX_H_*/ diff --git a/source/dnode/mnode/impl/src/mndIndex.c b/source/dnode/mnode/impl/src/mndIndex.c index 041cc664e5..622ed0080f 100644 --- a/source/dnode/mnode/impl/src/mndIndex.c +++ b/source/dnode/mnode/impl/src/mndIndex.c @@ -331,10 +331,10 @@ SDbObj *mndAcquireDbByIdx(SMnode *pMnode, const char *idxName) { return mndAcquireDb(pMnode, db); } -int32_t mndSetCreateIdxRedoLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) { +int32_t mndSetCreateIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) { SSdbRaw *pRedoRaw = mndIdxActionEncode(pIdx); if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) return -1; if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1; return 0; @@ -349,10 +349,10 @@ int32_t mndSetCreateIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) return 0; } -int32_t mndSetAlterIdxRedoLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) { +int32_t mndSetAlterIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) { SSdbRaw *pRedoRaw = mndIdxActionEncode(pIdx); if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { + if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) { sdbFreeRaw(pRedoRaw); return -1; } @@ -482,10 +482,10 @@ _OVER: return code; } -int32_t mndSetDropIdxRedoLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) { +int32_t mndSetDropIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) { SSdbRaw *pRedoRaw = mndIdxActionEncode(pIdx); if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) return -1; if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1; return 0; @@ -652,7 +652,7 @@ int32_t mndAddIndexImpl(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pSt mndTransSetSerial(pTrans); - if (mndSetCreateIdxRedoLogs(pMnode, pTrans, pIdx) != 0) goto _OVER; + if (mndSetCreateIdxPrepareLogs(pMnode, pTrans, pIdx) != 0) goto _OVER; if (mndSetCreateIdxCommitLogs(pMnode, pTrans, pIdx) != 0) goto _OVER; if (mndSetUpdateIdxStbCommitLogs(pMnode, pTrans, pStb, &newStb, pIdx->colName, 1) != 0) goto _OVER; @@ -771,7 +771,7 @@ static int32_t mndDropIdx(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SIdxObj *p if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER; mndTransSetSerial(pTrans); - if (mndSetDropIdxRedoLogs(pMnode, pTrans, pIdx) != 0) goto _OVER; + if (mndSetDropIdxPrepareLogs(pMnode, pTrans, pIdx) != 0) goto _OVER; if (mndSetDropIdxCommitLogs(pMnode, pTrans, pIdx) != 0) goto _OVER; if (mndSetUpdateIdxStbCommitLogs(pMnode, pTrans, pStb, &newObj, pIdx->colName, 0) != 0) goto _OVER; From fbd2a0035c2a6122dc30f8332905b2ec0f9d8b3b Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Wed, 21 Feb 2024 20:09:01 +0800 Subject: [PATCH 05/10] enh: change type of trans create-snode and drop-snode as serial --- source/dnode/mnode/impl/src/mndSnode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 1275ba7962..4243ccb77c 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -257,6 +257,7 @@ static int32_t mndCreateSnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-snode"); if (pTrans == NULL) goto _OVER; + mndTransSetSerial(pTrans); mInfo("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId); @@ -383,6 +384,7 @@ static int32_t mndDropSnode(SMnode *pMnode, SRpcMsg *pReq, SSnodeObj *pObj) { STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq, "drop-snode"); if (pTrans == NULL) goto _OVER; + mndTransSetSerial(pTrans); mInfo("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER; From a371afa58e054d02fe62975ea7ff3984a33ee66f Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Wed, 21 Feb 2024 20:12:29 +0800 Subject: [PATCH 06/10] enh: change type of trans create-qnode and drop-qnode as serial --- source/dnode/mnode/impl/src/mndQnode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index a7d8c81d3f..2f4ad69e2a 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -257,6 +257,7 @@ static int32_t mndCreateQnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-qnode"); if (pTrans == NULL) goto _OVER; + mndTransSetSerial(pTrans); mInfo("trans:%d, used to create qnode:%d", pTrans->id, pCreate->dnodeId); if (mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj) != 0) goto _OVER; @@ -380,6 +381,7 @@ static int32_t mndDropQnode(SMnode *pMnode, SRpcMsg *pReq, SQnodeObj *pObj) { STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq, "drop-qnode"); if (pTrans == NULL) goto _OVER; + mndTransSetSerial(pTrans); mInfo("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id); if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER; From dfef26866a4ac267457d5207b9dc16ffc6198430 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Thu, 22 Feb 2024 10:34:00 +0800 Subject: [PATCH 07/10] enh: decode sdb raw object in SdbValidateFp instead --- source/dnode/mnode/impl/src/mndDb.c | 20 +++++++++++++----- source/dnode/mnode/impl/src/mndSync.c | 17 ++-------------- source/dnode/mnode/impl/src/mndVgroup.c | 27 +++++++++++++++++-------- source/dnode/mnode/sdb/inc/sdb.h | 2 +- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 2ea1cdfe2a..9f644fb290 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -41,7 +41,7 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw); static int32_t mndDbActionInsert(SSdb *pSdb, SDbObj *pDb); static int32_t mndDbActionDelete(SSdb *pSdb, SDbObj *pDb); static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew); -static int32_t mndNewDbActionValidate(SMnode *pMnode, STrans *pTrans, void *pObj); +static int32_t mndNewDbActionValidate(SMnode *pMnode, STrans *pTrans, SSdbRaw *pRaw); static int32_t mndProcessCreateDbReq(SRpcMsg *pReq); static int32_t mndProcessAlterDbReq(SRpcMsg *pReq); @@ -256,17 +256,27 @@ _OVER: return pRow; } -static int32_t mndNewDbActionValidate(SMnode *pMnode, STrans *pTrans, void *pObj) { - SDbObj *pNewDb = pObj; +static int32_t mndNewDbActionValidate(SMnode *pMnode, STrans *pTrans, SSdbRaw *pRaw) { + SSdb *pSdb = pMnode->pSdb; + SSdbRow *pRow = NULL; + int code = -1; + + pRow = mndDbActionDecode(pRaw); + if (pRow == NULL) goto _OVER; + SDbObj *pNewDb = sdbGetRowObj(pRow); + if (pNewDb == NULL) goto _OVER; SDbObj *pOldDb = sdbAcquire(pMnode->pSdb, SDB_DB, pNewDb->name); if (pOldDb != NULL) { mError("trans:%d, db name already in use. name: %s", pTrans->id, pNewDb->name); sdbRelease(pMnode->pSdb, pOldDb); - return -1; + goto _OVER; } - return 0; + code = 0; +_OVER: + taosMemoryFree(pRow); + return code; } static int32_t mndDbActionInsert(SSdb *pSdb, SDbObj *pDb) { diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 0fc8dad420..a1490a3813 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -77,29 +77,16 @@ static int32_t mndSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) { static int32_t mndTransValidatePrepareAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction) { SSdbRaw *pRaw = pAction->pRaw; SSdb *pSdb = pMnode->pSdb; - SSdbRow *pRow = NULL; - void *pObj = NULL; - int code = -1; + int code = 0; if (pRaw->status != SDB_STATUS_CREATING) goto _OUT; - pRow = (pSdb->decodeFps[pRaw->type])(pRaw); - if (pRow == NULL) goto _OUT; - pObj = sdbGetRowObj(pRow); - if (pObj == NULL) goto _OUT; - SdbValidateFp validateFp = pSdb->validateFps[pRaw->type]; - code = 0; if (validateFp) { - code = validateFp(pMnode, pTrans, pObj); + code = validateFp(pMnode, pTrans, pRaw); } _OUT: - if (pRow) { - SdbDeleteFp deleteFp = pSdb->deleteFps[pRaw->type]; - if (deleteFp) (*deleteFp)(pSdb, pRow->pObj, false); - taosMemoryFreeClear(pRow); - } return code; } diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index a5df9ad820..6bd29f7910 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -31,10 +31,10 @@ #define VGROUP_VER_NUMBER 1 #define VGROUP_RESERVE_SIZE 64 -static int32_t mndVgroupActionInsert(SSdb *pSdb, SVgObj *pVgroup); -static int32_t mndVgroupActionDelete(SSdb *pSdb, SVgObj *pVgroup); -static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOld, SVgObj *pNew); -static int32_t mndNewVgActionValidate(SMnode *pMnode, STrans *pTrans, void *pObj); +static int32_t mndVgroupActionInsert(SSdb *pSdb, SVgObj *pVgroup); +static int32_t mndVgroupActionDelete(SSdb *pSdb, SVgObj *pVgroup); +static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOld, SVgObj *pNew); +static int32_t mndNewVgActionValidate(SMnode *pMnode, STrans *pTrans, SSdbRaw *pRaw); static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextVgroup(SMnode *pMnode, void *pIter); @@ -181,15 +181,26 @@ _OVER: return pRow; } -static int32_t mndNewVgActionValidate(SMnode *pMnode, STrans *pTrans, void *pObj) { - SVgObj *pVgroup = pObj; +static int32_t mndNewVgActionValidate(SMnode *pMnode, STrans *pTrans, SSdbRaw *pRaw) { + SSdb *pSdb = pMnode->pSdb; + SSdbRow *pRow = NULL; + int code = -1; + + pRow = mndVgroupActionDecode(pRaw); + if (pRow == NULL) goto _OVER; + SVgObj *pVgroup = sdbGetRowObj(pRow); + if (pVgroup == NULL) goto _OVER; int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP); if (maxVgId > pVgroup->vgId) { mError("trans:%d, vgroup id %d already in use. maxVgId:%d", pTrans->id, pVgroup->vgId, maxVgId); - return -1; + goto _OVER; } - return 0; + + code = 0; +_OVER: + taosMemoryFree(pRow); + return code; } static int32_t mndVgroupActionInsert(SSdb *pSdb, SVgObj *pVgroup) { diff --git a/source/dnode/mnode/sdb/inc/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h index 9d1125dad2..e2d4a1f6fc 100644 --- a/source/dnode/mnode/sdb/inc/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -106,7 +106,7 @@ typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj); typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj); typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj, bool callFunc); typedef int32_t (*SdbDeployFp)(SMnode *pMnode); -typedef int32_t (*SdbValidateFp)(SMnode *pMnode, void *pTrans, void *pObj); +typedef int32_t (*SdbValidateFp)(SMnode *pMnode, void *pTrans, SSdbRaw *pRaw); typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw); typedef SSdbRaw *(*SdbEncodeFp)(void *pObj); typedef bool (*sdbTraverseFp)(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3); From 1b2bccd1d9866c78ec9c80002e530ef515bfed76 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Thu, 22 Feb 2024 15:49:30 +0800 Subject: [PATCH 08/10] enh: not use prepare log in trans create-stb anymore --- source/dnode/mnode/impl/src/mndStb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index b6e49b4d8b..7ee1b36916 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -901,7 +901,6 @@ _OVER: int32_t mndAddStbToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { mndTransSetDbName(pTrans, pDb->name, pStb->name); if (mndTransCheckConflict(pMnode, pTrans) != 0) return -1; - if (mndSetCreateStbPrepareLogs(pMnode, pTrans, pDb, pStb) != 0) return -1; if (mndSetCreateStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) return -1; if (mndSetCreateStbRedoActions(pMnode, pTrans, pDb, pStb) != 0) return -1; if (mndSetCreateStbUndoActions(pMnode, pTrans, pDb, pStb) != 0) return -1; From ec093cb47732f3fc63e439014d44d68c43960e60 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Fri, 23 Feb 2024 11:25:42 +0800 Subject: [PATCH 09/10] enh: ensure decoded obj cleared in new obj action validate --- source/dnode/mnode/impl/src/mndDb.c | 6 ++++-- source/dnode/mnode/impl/src/mndVgroup.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 9f644fb290..37c2d19bd4 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -259,11 +259,12 @@ _OVER: static int32_t mndNewDbActionValidate(SMnode *pMnode, STrans *pTrans, SSdbRaw *pRaw) { SSdb *pSdb = pMnode->pSdb; SSdbRow *pRow = NULL; + SDbObj *pNewDb = NULL; int code = -1; pRow = mndDbActionDecode(pRaw); if (pRow == NULL) goto _OVER; - SDbObj *pNewDb = sdbGetRowObj(pRow); + pNewDb = sdbGetRowObj(pRow); if (pNewDb == NULL) goto _OVER; SDbObj *pOldDb = sdbAcquire(pMnode->pSdb, SDB_DB, pNewDb->name); @@ -275,7 +276,8 @@ static int32_t mndNewDbActionValidate(SMnode *pMnode, STrans *pTrans, SSdbRaw *p code = 0; _OVER: - taosMemoryFree(pRow); + if (pNewDb) mndDbActionDelete(pSdb, pNewDb); + taosMemoryFreeClear(pRow); return code; } diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 6bd29f7910..b0290191bc 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -184,11 +184,12 @@ _OVER: static int32_t mndNewVgActionValidate(SMnode *pMnode, STrans *pTrans, SSdbRaw *pRaw) { SSdb *pSdb = pMnode->pSdb; SSdbRow *pRow = NULL; + SVgObj *pVgroup = NULL; int code = -1; pRow = mndVgroupActionDecode(pRaw); if (pRow == NULL) goto _OVER; - SVgObj *pVgroup = sdbGetRowObj(pRow); + pVgroup = sdbGetRowObj(pRow); if (pVgroup == NULL) goto _OVER; int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP); @@ -199,7 +200,8 @@ static int32_t mndNewVgActionValidate(SMnode *pMnode, STrans *pTrans, SSdbRaw *p code = 0; _OVER: - taosMemoryFree(pRow); + if (pVgroup) mndVgroupActionDelete(pSdb, pVgroup); + taosMemoryFreeClear(pRow); return code; } From f2c1b7da05eaca83d30b3ed5f5a8d490be78d097 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Fri, 23 Feb 2024 13:16:59 +0800 Subject: [PATCH 10/10] enh: keep in redo stage on context switch for rollback trans --- source/dnode/mnode/impl/src/mndTrans.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 1adc4ed4bf..5c76baff08 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -1419,7 +1419,7 @@ static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans, bool pTrans->stage = TRN_STAGE_COMMIT; mInfo("trans:%d, stage from redoAction to commit", pTrans->id); continueExec = true; - } else if (code == TSDB_CODE_ACTION_IN_PROGRESS) { + } else if (code == TSDB_CODE_ACTION_IN_PROGRESS || code == TSDB_CODE_MND_TRANS_CTX_SWITCH) { mInfo("trans:%d, stage keep on redoAction since %s", pTrans->id, tstrerror(code)); continueExec = false; } else {