From 9a0d27c6fcab9a3501dc387522e66dbc62b8990a Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 14 Dec 2021 18:07:29 +0800 Subject: [PATCH] TD-10431 test for create user --- source/dnode/mgmt/impl/test/dnode/dnode.cpp | 68 ++++++++-------- source/dnode/mgmt/impl/test/sut/deploy.cpp | 2 +- source/dnode/mnode/impl/inc/mndDef.h | 3 +- source/dnode/mnode/impl/src/mndTrans.c | 88 +++++++++++++-------- source/dnode/mnode/impl/src/mndUser.c | 18 +---- source/dnode/mnode/sdb/src/sdbHash.c | 11 +-- 6 files changed, 97 insertions(+), 93 deletions(-) diff --git a/source/dnode/mgmt/impl/test/dnode/dnode.cpp b/source/dnode/mgmt/impl/test/dnode/dnode.cpp index fba3794f6a..580fe8e131 100644 --- a/source/dnode/mgmt/impl/test/dnode/dnode.cpp +++ b/source/dnode/mgmt/impl/test/dnode/dnode.cpp @@ -379,41 +379,41 @@ TEST_F(DndTestDnode, RestartDnode_01) { const char* fqdn = "localhost"; const char* firstEp = "localhost:9521"; pServer1 = startServer("/tmp/dndTestDnode1", fqdn, 9521, firstEp); - // pServer1 = startServer("/tmp/dndTestDnode3", fqdn, 9523, firstEp); - // pServer1 = startServer("/tmp/dndTestDnode4", fqdn, 9524, firstEp); - // pServer1 = startServer("/tmp/dndTestDnode5", fqdn, 9525, firstEp); + pServer3 = startServer("/tmp/dndTestDnode3", fqdn, 9523, firstEp); + pServer4 = startServer("/tmp/dndTestDnode4", fqdn, 9524, firstEp); + pServer5 = startServer("/tmp/dndTestDnode5", fqdn, 9525, firstEp); uInfo("all server is running"); - // taosMsleep(1300); - // SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7); - // SendThenCheckShowRetrieveMsg(4); - // CheckInt16(1); - // CheckInt16(3); - // CheckInt16(4); - // CheckInt16(5); - // CheckBinary("localhost:9521", TSDB_EP_LEN); - // CheckBinary("localhost:9523", TSDB_EP_LEN); - // CheckBinary("localhost:9524", TSDB_EP_LEN); - // CheckBinary("localhost:9525", TSDB_EP_LEN); - // CheckInt16(0); - // CheckInt16(0); - // CheckInt16(0); - // CheckInt16(0); - // CheckInt16(1); - // CheckInt16(1); - // CheckInt16(1); - // CheckInt16(1); - // CheckBinary("ready", 10); - // CheckBinary("ready", 10); - // CheckBinary("ready", 10); - // CheckBinary("ready", 10); - // CheckTimestamp(); - // CheckTimestamp(); - // CheckTimestamp(); - // CheckTimestamp(); - // CheckBinary("", 24); - // CheckBinary("", 24); - // CheckBinary("", 24); - // CheckBinary("", 24); + taosMsleep(1300); + SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7); + SendThenCheckShowRetrieveMsg(4); + CheckInt16(1); + CheckInt16(3); + CheckInt16(4); + CheckInt16(5); + CheckBinary("localhost:9521", TSDB_EP_LEN); + CheckBinary("localhost:9523", TSDB_EP_LEN); + CheckBinary("localhost:9524", TSDB_EP_LEN); + CheckBinary("localhost:9525", TSDB_EP_LEN); + CheckInt16(0); + CheckInt16(0); + CheckInt16(0); + CheckInt16(0); + CheckInt16(1); + CheckInt16(1); + CheckInt16(1); + CheckInt16(1); + CheckBinary("ready", 10); + CheckBinary("ready", 10); + CheckBinary("ready", 10); + CheckBinary("ready", 10); + CheckTimestamp(); + CheckTimestamp(); + CheckTimestamp(); + CheckTimestamp(); + CheckBinary("", 24); + CheckBinary("", 24); + CheckBinary("", 24); + CheckBinary("", 24); } diff --git a/source/dnode/mgmt/impl/test/sut/deploy.cpp b/source/dnode/mgmt/impl/test/sut/deploy.cpp index 61fc27a595..640f300699 100644 --- a/source/dnode/mgmt/impl/test/sut/deploy.cpp +++ b/source/dnode/mgmt/impl/test/sut/deploy.cpp @@ -18,7 +18,7 @@ void initLog(const char* path) { dDebugFlag = 143; vDebugFlag = 0; - mDebugFlag = 143; + mDebugFlag = 207; cDebugFlag = 0; jniDebugFlag = 0; tmrDebugFlag = 0; diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 5c672c74be..74b4b1faa3 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -73,7 +73,8 @@ typedef enum { TRN_STAGE_EXECUTE = 2, TRN_STAGE_COMMIT = 3, TRN_STAGE_ROLLBACK = 4, - TRN_STAGE_RETRY = 5 + TRN_STAGE_RETRY = 5, + TRN_STAGE_OVER = 6, } ETrnStage; typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 65957e44bc..9ab84d6557 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -58,7 +58,7 @@ int32_t mndInitTrans(SMnode *pMnode) { void mndCleanupTrans(SMnode *pMnode) {} static SSdbRaw *mndTransActionEncode(STrans *pTrans) { - int32_t rawDataLen = 16 * sizeof(int32_t); + int32_t rawDataLen = 16 * sizeof(int32_t) + TSDB_TRN_RESERVE_SIZE; int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs); int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs); int32_t commitLogNum = taosArrayGetSize(pTrans->commitLogs); @@ -88,7 +88,6 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { int32_t dataPos = 0; SDB_SET_INT32(pRaw, dataPos, pTrans->id) - SDB_SET_INT8(pRaw, dataPos, pTrans->stage) SDB_SET_INT8(pRaw, dataPos, pTrans->policy) SDB_SET_INT32(pRaw, dataPos, redoLogNum) SDB_SET_INT32(pRaw, dataPos, undoLogNum) @@ -166,7 +165,6 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { int32_t dataPos = 0; SDB_GET_INT32(pRaw, pRow, dataPos, &pTrans->id) - SDB_GET_INT8(pRaw, pRow, dataPos, (int8_t *)&pTrans->stage) SDB_GET_INT8(pRaw, pRow, dataPos, (int8_t *)&pTrans->policy) SDB_GET_INT32(pRaw, pRow, dataPos, &redoLogNum) SDB_GET_INT32(pRaw, pRow, dataPos, &undoLogNum) @@ -231,6 +229,7 @@ TRANS_DECODE_OVER: } static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) { + pTrans->stage = TRN_STAGE_PREPARE; mTrace("trans:%d, perform insert action, stage:%s", pTrans->id, mndTransStageStr(pTrans->stage)); return 0; } @@ -263,7 +262,7 @@ void mndReleaseTrans(SMnode *pMnode, STrans *pTrans) { sdbRelease(pSdb, pTrans); } -static int32_t trnGenerateTransId() { +static int32_t mndGenerateTransId() { static int32_t tmp = 0; return ++tmp; } @@ -304,7 +303,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) { return NULL; } - pTrans->id = trnGenerateTransId(); + pTrans->id = mndGenerateTransId(); pTrans->stage = TRN_STAGE_PREPARE; pTrans->policy = policy; pTrans->rpcHandle = rpcHandle; @@ -428,6 +427,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { } mDebug("trans:%d, prepare finished", pNewTrans->id); + pNewTrans->rpcHandle = pTrans->rpcHandle; mndTransExecute(pMnode, pNewTrans); mndReleaseTrans(pMnode, pNewTrans); return 0; @@ -443,19 +443,21 @@ int32_t mndTransCommit(SMnode *pMnode, STrans *pTrans) { } sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED); - mTrace("trans:%d, start sync", pTrans->id); - int32_t code = mndSyncPropose(pMnode, pRaw); - if (code != 0) { - mError("trans:%d, failed to sync since %s", pTrans->id, terrstr()); - sdbFreeRaw(pRaw); - return -1; - } + if (taosArrayGetSize(pTrans->commitLogs) != 0) { + mTrace("trans:%d, start sync", pTrans->id); + int32_t code = mndSyncPropose(pMnode, pRaw); + if (code != 0) { + mError("trans:%d, failed to sync since %s", pTrans->id, terrstr()); + sdbFreeRaw(pRaw); + return -1; + } - mTrace("trans:%d, sync finished", pTrans->id); - code = sdbWrite(pMnode->pSdb, pRaw); - if (code != 0) { - mError("trans:%d, failed to write sdb since %s", pTrans->id, terrstr()); - return -1; + mTrace("trans:%d, sync finished", pTrans->id); + code = sdbWrite(pMnode->pSdb, pRaw); + if (code != 0) { + mError("trans:%d, failed to write sdb since %s", pTrans->id, terrstr()); + return -1; + } } mDebug("trans:%d, commit finished", pTrans->id); @@ -521,45 +523,58 @@ static int32_t mndTransExecuteArray(SMnode *pMnode, SArray *pArray) { } static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans) { - int32_t code = mndTransExecuteArray(pMnode, pTrans->redoLogs); - if (code != 0) { - mError("trans:%d, failed to execute redo logs since %s", pTrans->id, terrstr()) - } else { - mTrace("trans:%d, execute redo logs finished", pTrans->id) + int32_t code = 0; + if (taosArrayGetSize(pTrans->redoLogs) != 0) { + code = mndTransExecuteArray(pMnode, pTrans->redoLogs); + if (code != 0) { + mError("trans:%d, failed to execute redo logs since %s", pTrans->id, terrstr()) + } else { + mTrace("trans:%d, execute redo logs finished", pTrans->id) + } } return code; } static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans) { - int32_t code = mndTransExecuteArray(pMnode, pTrans->undoLogs); - if (code != 0) { - mError("trans:%d, failed to execute undo logs since %s", pTrans->id, terrstr()) - } else { - mTrace("trans:%d, execute undo logs finished", pTrans->id) + int32_t code = 0; + if (taosArrayGetSize(pTrans->undoLogs) != 0) { + code = mndTransExecuteArray(pMnode, pTrans->undoLogs); + if (code != 0) { + mError("trans:%d, failed to execute undo logs since %s", pTrans->id, terrstr()) + } else { + mTrace("trans:%d, execute undo logs finished", pTrans->id) + } } return code; } static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans) { - int32_t code = mndTransExecuteArray(pMnode, pTrans->commitLogs); - if (code != 0) { - mError("trans:%d, failed to execute commit logs since %s", pTrans->id, terrstr()) - } else { - mTrace("trans:%d, execute commit logs finished", pTrans->id) + int32_t code = 0; + if (taosArrayGetSize(pTrans->commitLogs) != 0) { + code = mndTransExecuteArray(pMnode, pTrans->commitLogs); + if (code != 0) { + mError("trans:%d, failed to execute commit logs since %s", pTrans->id, terrstr()) + } else { + mTrace("trans:%d, execute commit logs finished", pTrans->id) + } } return code; } static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans) { - mTrace("trans:%d, execute redo actions finished", pTrans->id); + if (taosArrayGetSize(pTrans->redoActions) != 0) { + mTrace("trans:%d, execute redo actions finished", pTrans->id); + } return 0; } static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans) { - mTrace("trans:%d, execute undo actions finished", pTrans->id); + if (taosArrayGetSize(pTrans->undoActions) != 0) { + mTrace("trans:%d, execute undo actions finished", pTrans->id); + } return 0; } @@ -603,7 +618,7 @@ static int32_t mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans) { int32_t code = mndTransExecuteCommitLogs(pMnode, pTrans); if (code == 0) { - pTrans->stage = TRN_STAGE_COMMIT; + pTrans->stage = TRN_STAGE_OVER; mTrace("trans:%d, commit stage finished", pTrans->id); } else { if (pTrans->policy == TRN_POLICY_ROLLBACK) { @@ -671,6 +686,9 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) { case TRN_STAGE_RETRY: code = mndTransPerformRetryStage(pMnode, pTrans); break; + default: + mndTransSendRpcRsp(pTrans, 0); + return; } } diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index e6bf30f41b..c4599b8e49 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -217,23 +217,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, mndTransDrop(pTrans); return -1; } - sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING); - - SSdbRaw *pUndoRaw = mndUserActionEncode(&userObj); - if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) { - mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } - sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED); - - SSdbRaw *pCommitRaw = mndUserActionEncode(&userObj); - if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { - mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } - sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); + sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY); if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 8d8daf5ce5..c3874caffc 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -132,11 +132,6 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosHashRemove(hash, pOldRow->pObj, keySize); taosWUnLockLatch(pLock); - SdbDeleteFp deleteFp = pSdb->deleteFps[pOldRow->type]; - if (deleteFp != NULL) { - code = (*deleteFp)(pSdb, pOldRow->pObj); - } - sdbRelease(pSdb, pOldRow->pObj); sdbFreeRow(pRow); return code; @@ -161,6 +156,7 @@ int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) { case SDB_STATUS_CREATING: code = sdbInsertRow(pSdb, hash, pRaw, pRow, keySize); break; + case SDB_STATUS_UPDATING: case SDB_STATUS_READY: case SDB_STATUS_DROPPING: code = sdbUpdateRow(pSdb, hash, pRaw, pRow, keySize); @@ -228,6 +224,11 @@ void sdbRelease(SSdb *pSdb, void *pObj) { int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1); if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) { + SdbDeleteFp deleteFp = pSdb->deleteFps[pRow->type]; + if (deleteFp != NULL) { + (*deleteFp)(pSdb, pRow->pObj); + } + sdbFreeRow(pRow); }