From cba62bebbae802bf2faafe2ccaaaf9be3cc6bd36 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 15 Jun 2022 09:35:44 +0800 Subject: [PATCH] feat: make create db retry --- source/dnode/mnode/impl/src/mndDb.c | 2 +- source/dnode/mnode/impl/src/mndTrans.c | 12 +-- tests/script/jenkins/basic.txt | 2 +- tests/script/tsim/trans/create_db.sim | 123 ++++++++++++++++--------- 4 files changed, 88 insertions(+), 51 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 43263af573..004066e016 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -472,7 +472,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, } int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB, pReq); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq); if (pTrans == NULL) goto _OVER; mDebug("trans:%d, used to create db:%s", pTrans->id, pCreate->db); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 1ec4799419..1631c9825b 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -1347,13 +1347,11 @@ int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) { for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) { STransAction *pAction = taosArrayGet(pArray, i); - if (pAction->errCode != 0) { - mInfo("trans:%d, %s:%d set processed for kill msg received, errCode from %s to success", pTrans->id, - mndTransStr(pAction->stage), i, tstrerror(pAction->errCode)); - pAction->msgSent = 1; - pAction->msgReceived = 1; - pAction->errCode = 0; - } + mInfo("trans:%d, %s:%d set processed for kill msg received, errCode from %s to success", pTrans->id, + mndTransStr(pAction->stage), i, tstrerror(pAction->errCode)); + pAction->msgSent = 1; + pAction->msgReceived = 1; + pAction->errCode = 0; } mndTransExecute(pMnode, pTrans); diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 85bb957dc1..206b0656f9 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -58,7 +58,7 @@ # ---- mnode ./test.sh -f tsim/mnode/basic1.sim ./test.sh -f tsim/mnode/basic2.sim -#./test.sh -f tsim/mnode/basic3.sim +./test.sh -f tsim/mnode/basic3.sim ./test.sh -f tsim/mnode/basic4.sim ./test.sh -f tsim/mnode/basic5.sim diff --git a/tests/script/tsim/trans/create_db.sim b/tests/script/tsim/trans/create_db.sim index e13014f9c0..f730f2fb67 100644 --- a/tests/script/tsim/trans/create_db.sim +++ b/tests/script/tsim/trans/create_db.sim @@ -7,44 +7,28 @@ system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode2 -s start sql connect -print =============== show dnodes -sql show dnodes; -if $rows != 1 then - return -1 -endi - -if $data00 != 1 then - return -1 -endi - -sql show mnodes; -if $rows != 1 then - return -1 -endi - -if $data00 != 1 then - return -1 -endi - -if $data02 != leader then - return -1 -endi - print =============== create dnodes sql create dnode $hostname port 7200 -sleep 2000 -sql show dnodes; -if $rows != 2 then - return -1 -endi - -if $data00 != 1 then +$x = 0 +step1: + $x = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 2 then return -1 endi - -if $data10 != 2 then - return -1 +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 endi print =============== kill dnode2 @@ -68,7 +52,7 @@ if $data[0][0] != 7 then return -1 endi -if $data[0][2] != undoAction then +if $data[0][2] != redoAction then return -1 endi @@ -80,14 +64,34 @@ sql_error create database d1 vgroups 2; print =============== start dnode2 system sh/exec.sh -n dnode2 -s start -sleep 3000 + +$x = 0 +step2: + $x = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 2 then + return -1 +endi +if $data(1)[4] != ready then + goto step2 +endi +if $data(2)[4] != ready then + goto step2 +endi sql show transactions if $rows != 0 then return -1 endi -sql create database d1 vgroups 2; +sql_error create database d1 vgroups 2; print =============== kill dnode2 system sh/exec.sh -n dnode2 -s stop -x SIGINT @@ -106,22 +110,31 @@ if $rows != 1 then return -1 endi -if $data[0][0] != 9 then +if $data[0][0] != 8 then return -1 endi -if $data[0][2] != undoAction then +if $data[0][2] != redoAction then return -1 endi if $data[0][3] != d2 then return -1 endi -return + +sql show databases ; +if $rows != 4 then + return -1 +endi +print d2 ==> $data(d2)[19] +if $data(d2)[19] != creating then + return -1 +endi + sql_error create database d2 vgroups 2; print =============== kill transaction -sql kill transaction 9; +sql kill transaction 8; sleep 2000 sql show transactions @@ -131,7 +144,34 @@ endi print =============== start dnode2 system sh/exec.sh -n dnode2 -s start -sleep 3000 + +$x = 0 +step3: + $x = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 2 then + return -1 +endi +if $data(1)[4] != ready then + goto step3 +endi +if $data(2)[4] != ready then + goto step3 +endi + +sql show transactions +if $rows != 0 then + return -1 +endi + +sql drop database d2; sql show transactions if $rows != 0 then @@ -145,6 +185,5 @@ sql_error kill transaction 3; sql_error kill transaction 4; sql_error kill transaction 5; -return system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT \ No newline at end of file