From 001cab2da70797fdeb04a6b69c12a7018be79c3c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 26 Jan 2022 07:32:07 +0000 Subject: [PATCH] check dnodeId while create vnode --- source/dnode/mgmt/impl/src/dndVnodes.c | 7 ++++ source/dnode/mgmt/impl/test/vnode/vnode.cpp | 38 +++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/source/dnode/mgmt/impl/src/dndVnodes.c b/source/dnode/mgmt/impl/src/dndVnodes.c index c27f3a151e..c4d14ef697 100644 --- a/source/dnode/mgmt/impl/src/dndVnodes.c +++ b/source/dnode/mgmt/impl/src/dndVnodes.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "dndVnodes.h" #include "dndTransport.h" +#include "dndMgmt.h" typedef struct { int32_t vgId; @@ -577,6 +578,12 @@ int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *pReq) { SWrapperCfg wrapperCfg = {0}; dndGenerateWrapperCfg(pDnode, pCreate, &wrapperCfg); + if (pCreate->dnodeId != dndGetDnodeId(pDnode)) { + terrno = TSDB_CODE_DND_VNODE_INVALID_OPTION; + dDebug("vgId:%d, failed to create vnode since %s", pCreate->vgId, terrstr()); + return -1; + } + SVnodeObj *pVnode = dndAcquireVnode(pDnode, pCreate->vgId); if (pVnode != NULL) { dDebug("vgId:%d, already exist", pCreate->vgId); diff --git a/source/dnode/mgmt/impl/test/vnode/vnode.cpp b/source/dnode/mgmt/impl/test/vnode/vnode.cpp index 1799bf66b0..17092ed737 100644 --- a/source/dnode/mgmt/impl/test/vnode/vnode.cpp +++ b/source/dnode/mgmt/impl/test/vnode/vnode.cpp @@ -68,6 +68,44 @@ TEST_F(DndTestVnode, 01_Create_Vnode) { ASSERT_EQ(pRsp->code, TSDB_CODE_DND_VNODE_ALREADY_DEPLOYED); } } + + { + int32_t contLen = sizeof(SCreateVnodeReq); + + SCreateVnodeReq* pReq = (SCreateVnodeReq*)rpcMallocCont(contLen); + pReq->vgId = htonl(2); + pReq->dnodeId = htonl(3); + strcpy(pReq->db, "1.d1"); + pReq->dbUid = htobe64(9527); + pReq->vgVersion = htonl(1); + pReq->cacheBlockSize = htonl(16); + pReq->totalBlocks = htonl(10); + pReq->daysPerFile = htonl(10); + pReq->daysToKeep0 = htonl(3650); + pReq->daysToKeep1 = htonl(3650); + pReq->daysToKeep2 = htonl(3650); + pReq->minRows = htonl(100); + pReq->minRows = htonl(4096); + pReq->commitTime = htonl(3600); + pReq->fsyncPeriod = htonl(3000); + pReq->walLevel = 1; + pReq->precision = 0; + pReq->compression = 2; + pReq->replica = 1; + pReq->quorum = 1; + pReq->update = 0; + pReq->cacheLastRow = 0; + pReq->selfIndex = 0; + for (int r = 0; r < pReq->replica; ++r) { + SReplica* pReplica = &pReq->replicas[r]; + pReplica->id = htonl(1); + pReplica->port = htons(9527); + } + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_VNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_VNODE_INVALID_OPTION); + } } TEST_F(DndTestVnode, 02_ALTER_Vnode) { -- GitLab