From 68e014977a7e0e58a90aee28151a1ebbd028312b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 6 Dec 2022 15:45:45 +0800 Subject: [PATCH 1/2] enh: speed up drop dnode and avoid snapshot transfer --- source/dnode/mnode/impl/src/mndVgroup.c | 77 +++++++++++++++++-------- 1 file changed, 52 insertions(+), 25 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index b4ea8ee125..ea8bb581e0 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -1126,34 +1126,61 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, } if (!force) { - mInfo("vgId:%d, will add 1 vnode", pVgroup->vgId); - if (mndAddVnodeToVgroup(pMnode, pTrans, &newVg, pArray) != 0) return -1; - for (int32_t i = 0; i < newVg.replica - 1; ++i) { - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1; - } - if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[newVg.replica - 1]) != 0) return -1; - if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; - - mInfo("vgId:%d, will remove 1 vnode", pVgroup->vgId); - newVg.replica--; - SVnodeGid del = newVg.vnodeGid[vnIndex]; - newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica]; - memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid)); - { - SSdbRaw *pRaw = mndVgroupActionEncode(&newVg); - if (pRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRaw) != 0) { - sdbFreeRaw(pRaw); - return -1; + if (newVg.replica == 1) { + mInfo("vgId:%d, will add 1 vnode, replca:1", pVgroup->vgId); + if (mndAddVnodeToVgroup(pMnode, pTrans, &newVg, pArray) != 0) return -1; + for (int32_t i = 0; i < newVg.replica - 1; ++i) { + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1; } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); - } + if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[newVg.replica - 1]) != 0) return -1; + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; - if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1; - for (int32_t i = 0; i < newVg.replica; ++i) { - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1; + mInfo("vgId:%d, will remove 1 vnode, replca:2", pVgroup->vgId); + newVg.replica--; + SVnodeGid del = newVg.vnodeGid[vnIndex]; + newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica]; + memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid)); + { + SSdbRaw *pRaw = mndVgroupActionEncode(&newVg); + if (pRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRaw) != 0) { + sdbFreeRaw(pRaw); + return -1; + } + (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + } + + if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1; + for (int32_t i = 0; i < newVg.replica; ++i) { + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1; + } + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; + } else { // new replica == 3 + mInfo("vgId:%d, will add 1 vnode, replca:3", pVgroup->vgId); + if (mndAddVnodeToVgroup(pMnode, pTrans, &newVg, pArray) != 0) return -1; + mInfo("vgId:%d, will remove 1 vnode, replca:4", pVgroup->vgId); + newVg.replica--; + SVnodeGid del = newVg.vnodeGid[vnIndex]; + newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica]; + memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid)); + { + SSdbRaw *pRaw = mndVgroupActionEncode(&newVg); + if (pRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRaw) != 0) { + sdbFreeRaw(pRaw); + return -1; + } + (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + } + + if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1; + for (int32_t i = 0; i < newVg.replica - 1; ++i) { + if (i == vnIndex) continue; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1; + } + if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[vnIndex]) != 0) return -1; + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; } - if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; } else { mInfo("vgId:%d, will add 1 vnode and force remove 1 vnode", pVgroup->vgId); if (mndAddVnodeToVgroup(pMnode, pTrans, &newVg, pArray) != 0) return -1; From 130ef694c71d8978d6ea62f78c418ab8a5cb7b75 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 6 Dec 2022 19:37:43 +0800 Subject: [PATCH 2/2] fix: one less alter vnode request was sent --- source/dnode/mnode/impl/src/mndDnode.c | 4 ++-- source/dnode/mnode/impl/src/mndVgroup.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index df25e44bee..0538d70101 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -383,9 +383,9 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { pGid->syncCanRead != pVload->syncCanRead) { mInfo( "vgId:%d, state changed by status msg, old state:%s restored:%d canRead:%d new state:%s restored:%d " - "canRead:%d", + "canRead:%d, dnode:%d", pVgroup->vgId, syncStr(pGid->syncState), pGid->syncRestore, pGid->syncCanRead, - syncStr(pVload->syncState), pVload->syncRestore, pVload->syncCanRead); + syncStr(pVload->syncState), pVload->syncRestore, pVload->syncCanRead, pDnode->id); pGid->syncState = pVload->syncState; pGid->syncRestore = pVload->syncRestore; pGid->syncCanRead = pVload->syncCanRead; diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index ea8bb581e0..a6e52caf1f 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -1174,7 +1174,7 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, } if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1; - for (int32_t i = 0; i < newVg.replica - 1; ++i) { + for (int32_t i = 0; i < newVg.replica; ++i) { if (i == vnIndex) continue; if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1; }