From ffd3425969981868be092a2463bc637bb7f7a861 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 11 Nov 2021 11:24:00 +0800 Subject: [PATCH] minor changes --- source/dnode/mnode/transaction/src/trnInt.c | 72 ++++++++++++++++++++ source/dnode/mnode/transaction/src/trnMain.c | 71 ------------------- 2 files changed, 72 insertions(+), 71 deletions(-) diff --git a/source/dnode/mnode/transaction/src/trnInt.c b/source/dnode/mnode/transaction/src/trnInt.c index 4a69007de5..03c1a506b9 100644 --- a/source/dnode/mnode/transaction/src/trnInt.c +++ b/source/dnode/mnode/transaction/src/trnInt.c @@ -148,6 +148,78 @@ int32_t trnActionUpdate(STrans *pSrcTrans, STrans *pDstTrans) { return 0; } int32_t trnGenerateTransId() { return 1; } +STrans *trnCreate(ETrnPolicy policy) { + STrans *pTrans = calloc(1, sizeof(STrans)); + if (pTrans == NULL) { + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; + return NULL; + } + + pTrans->id = trnGenerateTransId(); + pTrans->stage = TRN_STAGE_PREPARE; + pTrans->policy = policy; + pTrans->redoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *)); + pTrans->undoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *)); + pTrans->commitLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *)); + pTrans->redoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *)); + pTrans->undoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *)); + + if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL || + pTrans->redoActions == NULL || pTrans->undoActions == NULL) { + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; + return NULL; + } + + return pTrans; +} + +static void trnDropArray(SArray *pArray) { + for (int32_t index = 0; index < pArray->size; ++index) { + SSdbRaw *pRaw = taosArrayGetP(pArray, index); + tfree(pRaw); + } + + taosArrayDestroy(pArray); +} + +void trnDrop(STrans *pTrans) { + trnDropArray(pTrans->redoLogs); + trnDropArray(pTrans->undoLogs); + trnDropArray(pTrans->commitLogs); + trnDropArray(pTrans->redoActions); + trnDropArray(pTrans->undoActions); + tfree(pTrans); +} + +static int32_t trnAppendArray(SArray *pArray, SSdbRaw *pRaw) { + if (pArray == NULL || pRaw == NULL) { + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; + return -1; + } + + void *ptr = taosArrayPush(pArray, &pRaw); + if (ptr == NULL) { + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; + return -1; + } + + return 0; +} + +int32_t trnAppendRedoLog(STrans *pTrans, SSdbRaw *pRaw) { return trnAppendArray(pTrans->redoLogs, pRaw); } + +int32_t trnAppendUndoLog(STrans *pTrans, SSdbRaw *pRaw) { return trnAppendArray(pTrans->undoLogs, pRaw); } + +int32_t trnAppendCommitLog(STrans *pTrans, SSdbRaw *pRaw) { return trnAppendArray(pTrans->commitLogs, pRaw); } + +int32_t trnAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) { + return trnAppendArray(pTrans->redoActions, pMsg); +} + +int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) { + return trnAppendArray(pTrans->undoActions, pMsg); +} + int32_t trnInit() { SSdbDesc desc = {.sdbType = SDB_TRANS, .keyType = SDB_KEY_INT32, diff --git a/source/dnode/mnode/transaction/src/trnMain.c b/source/dnode/mnode/transaction/src/trnMain.c index 3ff991a676..1f8da2689e 100644 --- a/source/dnode/mnode/transaction/src/trnMain.c +++ b/source/dnode/mnode/transaction/src/trnMain.c @@ -17,83 +17,12 @@ #include "trnInt.h" #include "trpc.h" -STrans *trnCreate(ETrnPolicy policy) { - STrans *pTrans = calloc(1, sizeof(STrans)); - if (pTrans == NULL) { - terrno = TSDB_CODE_MND_OUT_OF_MEMORY; - return NULL; - } - - pTrans->id = trnGenerateTransId(); - pTrans->stage = TRN_STAGE_PREPARE; - pTrans->policy = policy; - pTrans->redoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *)); - pTrans->undoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *)); - pTrans->commitLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *)); - pTrans->redoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *)); - pTrans->undoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *)); - - if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL || - pTrans->redoActions == NULL || pTrans->undoActions == NULL) { - terrno = TSDB_CODE_MND_OUT_OF_MEMORY; - return NULL; - } - - return pTrans; -} - -static void trnDropArray(SArray *pArray) { - for (int32_t index = 0; index < pArray->size; ++index) { - SSdbRaw *pRaw = taosArrayGetP(pArray, index); - tfree(pRaw); - } - - taosArrayDestroy(pArray); -} - -void trnDrop(STrans *pTrans) { - trnDropArray(pTrans->redoLogs); - trnDropArray(pTrans->undoLogs); - trnDropArray(pTrans->commitLogs); - trnDropArray(pTrans->redoActions); - trnDropArray(pTrans->undoActions); - tfree(pTrans); -} - void trnSetRpcHandle(STrans *pTrans, void *rpcHandle) { if (pTrans != NULL) { pTrans->rpcHandle = rpcHandle; } } -static int32_t trnAppendArray(SArray *pArray, SSdbRaw *pRaw) { - if (pArray == NULL || pRaw == NULL) { - terrno = TSDB_CODE_MND_OUT_OF_MEMORY; - return -1; - } - - void *ptr = taosArrayPush(pArray, &pRaw); - if (ptr == NULL) { - terrno = TSDB_CODE_MND_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -int32_t trnAppendRedoLog(STrans *pTrans, SSdbRaw *pRaw) { return trnAppendArray(pTrans->redoLogs, pRaw); } - -int32_t trnAppendUndoLog(STrans *pTrans, SSdbRaw *pRaw) { return trnAppendArray(pTrans->undoLogs, pRaw); } - -int32_t trnAppendCommitLog(STrans *pTrans, SSdbRaw *pRaw) { return trnAppendArray(pTrans->commitLogs, pRaw); } - -int32_t trnAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) { - return trnAppendArray(pTrans->redoActions, pMsg); -} - -int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) { - return trnAppendArray(pTrans->undoActions, pMsg); -} int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) { if (syncfp == NULL) return -1;