From 56ce7b1baa0511553f18242423895d89eff2a353 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 10 Jun 2022 16:45:31 +0800 Subject: [PATCH] enh: adjust show transcations output --- source/common/src/systable.c | 2 +- source/dnode/mnode/impl/inc/mndDef.h | 6 +- source/dnode/mnode/impl/src/mndTrans.c | 90 ++++++++++++------- ...istribute_vgroup_replica3_move_1_vnode.sim | 32 +++++-- 4 files changed, 87 insertions(+), 43 deletions(-) diff --git a/source/common/src/systable.c b/source/common/src/systable.c index 2b59354d60..cb38a3cf70 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -221,7 +221,7 @@ static const SSysDbTableSchema transSchema[] = { {.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "failed_times", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "last_error", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "last_action_info", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; static const SSysDbTableSchema configSchema[] = { diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 382f8dd55f..ad0a384507 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -120,10 +120,10 @@ typedef struct { SArray* commitActions; int64_t createdTime; int64_t lastExecTime; - int32_t lastErrorAction; + int32_t lastAction; int32_t lastErrorNo; - tmsg_t lastErrorMsgType; - SEpSet lastErrorEpset; + tmsg_t lastMsgType; + SEpSet lastEpset; char dbname[TSDB_DB_FNAME_LEN]; int32_t startFunc; int32_t stopFunc; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 1124baf286..a689c89037 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -894,10 +894,19 @@ static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransActi code = 0; mDebug("trans:%d, %s:%d write to sdb, type:%s status:%s", pTrans->id, mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status)); + + pTrans->lastAction = pAction->id; + pTrans->lastMsgType = pAction->msgType; + pTrans->lastEpset = pAction->epSet; + pTrans->lastErrorNo = 0; } else { pAction->errCode = (terrno != 0) ? terrno : code; mError("trans:%d, %s:%d failed to write sdb since %s, type:%s status:%s", pTrans->id, mndTransStr(pAction->stage), pAction->id, terrstr(), sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status)); + pTrans->lastAction = pAction->id; + pTrans->lastMsgType = pAction->msgType; + pTrans->lastEpset = pAction->epSet; + pTrans->lastErrorNo = pAction->errCode; } return code; @@ -933,27 +942,48 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio pAction->msgReceived = 0; pAction->errCode = 0; mDebug("trans:%d, %s:%d is sent, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, detail); + + pTrans->lastAction = pAction->id; + pTrans->lastMsgType = pAction->msgType; + pTrans->lastEpset = pAction->epSet; + if (pTrans->lastErrorNo == 0) { + pTrans->lastErrorNo = TSDB_CODE_ACTION_IN_PROGRESS; + } } else { pAction->msgSent = 0; pAction->msgReceived = 0; pAction->errCode = (terrno != 0) ? terrno : code; mError("trans:%d, %s:%d not send since %s, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, terrstr(), detail); + + pTrans->lastAction = pAction->id; + pTrans->lastMsgType = pAction->msgType; + pTrans->lastEpset = pAction->epSet; + pTrans->lastErrorNo = pAction->errCode; } return code; } +static int32_t mndTransExecNullMsg(SMnode *pMnode, STrans *pTrans, STransAction *pAction) { + pAction->rawWritten = 0; + pAction->errCode = 0; + mDebug("trans:%d, %s:%d null action executed", pTrans->id, mndTransStr(pAction->stage), pAction->id); + + pTrans->lastAction = pAction->id; + pTrans->lastMsgType = pAction->msgType; + pTrans->lastEpset = pAction->epSet; + pTrans->lastErrorNo == 0; + return 0; +} + static int32_t mndTransExecSingleAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction) { if (pAction->actionType == TRANS_ACTION_RAW) { return mndTransWriteSingleLog(pMnode, pTrans, pAction); } else if (pAction->actionType == TRANS_ACTION_MSG) { return mndTransSendSingleMsg(pMnode, pTrans, pAction); } else { - pAction->rawWritten = 0; - pAction->errCode = 0; - mDebug("trans:%d, %s:%d null action executed", pTrans->id, mndTransStr(pAction->stage), pAction->id); - return 0; + return mndTransExecNullMsg(pMnode, pTrans, pAction); } } @@ -994,19 +1024,19 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA if (numOfExecuted == numOfActions) { if (errCode == 0) { - pTrans->lastErrorAction = 0; + pTrans->lastAction = 0; pTrans->lastErrorNo = 0; - pTrans->lastErrorMsgType = 0; - memset(&pTrans->lastErrorEpset, 0, sizeof(pTrans->lastErrorEpset)); + pTrans->lastMsgType = 0; + memset(&pTrans->lastEpset, 0, sizeof(pTrans->lastEpset)); mDebug("trans:%d, all %d actions execute successfully", pTrans->id, numOfActions); return 0; } else { mError("trans:%d, all %d actions executed, code:0x%x", pTrans->id, numOfActions, errCode & 0XFFFF); if (pErrAction != NULL) { - pTrans->lastErrorMsgType = pErrAction->msgType; - pTrans->lastErrorAction = pErrAction->id; + pTrans->lastMsgType = pErrAction->msgType; + pTrans->lastAction = pErrAction->id; pTrans->lastErrorNo = pErrAction->errCode; - pTrans->lastErrorEpset = pErrAction->epSet; + pTrans->lastEpset = pErrAction->epSet; } mndTransResetActions(pMnode, pTrans, pArray); terrno = errCode; @@ -1073,15 +1103,15 @@ static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans) } if (code == 0) { - pTrans->lastErrorAction = 0; + pTrans->lastAction = 0; pTrans->lastErrorNo = 0; - pTrans->lastErrorMsgType = 0; - memset(&pTrans->lastErrorEpset, 0, sizeof(pTrans->lastErrorEpset)); + pTrans->lastMsgType = 0; + memset(&pTrans->lastEpset, 0, sizeof(pTrans->lastEpset)); } else { - pTrans->lastErrorMsgType = pAction->msgType; - pTrans->lastErrorAction = action; - pTrans->lastErrorNo = pAction->errCode; - pTrans->lastErrorEpset = pAction->epSet; + pTrans->lastMsgType = pAction->msgType; + pTrans->lastAction = action; + pTrans->lastErrorNo = code; + pTrans->lastEpset = pAction->epSet; } if (code == 0) { @@ -1432,23 +1462,21 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)&pTrans->lastExecTime, false); - char lastError[TSDB_TRANS_ERROR_LEN + VARSTR_HEADER_SIZE] = {0}; - char detail[TSDB_TRANS_ERROR_LEN] = {0}; - if (pTrans->lastErrorNo != 0) { - int32_t len = snprintf(detail, sizeof(detail), "action:%d errno:0x%x(%s) ", pTrans->lastErrorAction, - pTrans->lastErrorNo & 0xFFFF, tstrerror(pTrans->lastErrorNo)); - SEpSet epset = pTrans->lastErrorEpset; - if (epset.numOfEps > 0) { - len += snprintf(detail + len, sizeof(detail) - len, "msgType:%s numOfEps:%d inUse:%d ", - TMSG_INFO(pTrans->lastErrorMsgType), epset.numOfEps, epset.inUse); - for (int32_t i = 0; i < pTrans->lastErrorEpset.numOfEps; ++i) { - len += snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port); - } + char lastInfo[TSDB_TRANS_ERROR_LEN + VARSTR_HEADER_SIZE] = {0}; + char detail[TSDB_TRANS_ERROR_LEN] = {0}; + int32_t len = snprintf(detail, sizeof(detail), "action:%d code:0x%x(%s) ", pTrans->lastAction, + pTrans->lastErrorNo & 0xFFFF, tstrerror(pTrans->lastErrorNo)); + SEpSet epset = pTrans->lastEpset; + if (epset.numOfEps > 0) { + len += snprintf(detail + len, sizeof(detail) - len, "msgType:%s numOfEps:%d inUse:%d ", + TMSG_INFO(pTrans->lastMsgType), epset.numOfEps, epset.inUse); + for (int32_t i = 0; i < pTrans->lastEpset.numOfEps; ++i) { + len += snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port); } } - STR_WITH_MAXSIZE_TO_VARSTR(lastError, detail, pShow->pMeta->pSchemas[cols].bytes); + STR_WITH_MAXSIZE_TO_VARSTR(lastInfo, detail, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, numOfRows, (const char *)lastError, false); + colDataAppend(pColInfo, numOfRows, (const char *)lastInfo, false); numOfRows++; sdbRelease(pSdb, pTrans); diff --git a/tests/script/tsim/dnode/redistribute_vgroup_replica3_move_1_vnode.sim b/tests/script/tsim/dnode/redistribute_vgroup_replica3_move_1_vnode.sim index f44061ce6e..cb9f4173ac 100644 --- a/tests/script/tsim/dnode/redistribute_vgroup_replica3_move_1_vnode.sim +++ b/tests/script/tsim/dnode/redistribute_vgroup_replica3_move_1_vnode.sim @@ -104,8 +104,7 @@ if $data(5)[4] != ready then goto step2 endi -return -print =============== step3: move follower +print =============== step31: move follower $leaderExist = 0 $leaderVnode = 0 $follower1 = 0 @@ -120,23 +119,23 @@ step3: return -1 endi sql show d1.vgroups -print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 if $rows != 1 then return -1 endi -if $data(2)[3] == leader then +if $data(2)[4] == leader then $leaderExist = 1 $leaderVnode = 4 $follower1 = 2 $follower2 = 3 endi -if $data(2)[4] != ready then +if $data(2)[6] == leader then $leaderExist = 1 $leaderVnode = 3 $follower1 = 2 $follower2 = 4 endi -if $data(3)[4] != ready then +if $data(2)[8] == leader then $leaderExist = 1 $leaderVnode = 2 $follower1 = 3 @@ -146,8 +145,25 @@ if $leaderExist != 1 then goto step3 endi -print redistribute vgroup 2 dnode $follower1 dnode $follower2 dnode 5 -sql redistribute vgroup 2 dnode $follower1 dnode $follower2 dnode 5 +print leader $leaderVnode +print follower1 $follower1 +print follower2 $follower2 + +print =============== step32: move follower2 +print redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5 +sql redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5 +return +print =============== step33: move follower1 +print redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5 +sql redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5 + +print =============== step34: move follower2 +print redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2 +sql redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2 + +print =============== step35: move follower1 +print redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower1 +sql redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower1 print =============== step4: move leader -- GitLab