From 9ead608f2cb3496212d07f80440c964aa30861f0 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 12 Jul 2020 10:10:25 +0000 Subject: [PATCH] If the table is deleted by another thread during creation, stop creating and send drop msg to vnode --- src/mnode/inc/mnodeSdb.h | 1 + src/mnode/src/mnodeSdb.c | 8 ++++++++ src/mnode/src/mnodeTable.c | 17 ++++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/mnode/inc/mnodeSdb.h b/src/mnode/inc/mnodeSdb.h index eec6d45e23..0c47f684f8 100644 --- a/src/mnode/inc/mnodeSdb.h +++ b/src/mnode/inc/mnodeSdb.h @@ -94,6 +94,7 @@ void sdbDecRef(void *thandle, void *pRow); int64_t sdbGetNumOfRows(void *handle); int32_t sdbGetId(void *handle); uint64_t sdbGetVersion(); +bool sdbCheckRowDeleted(void *thandle, void *pRow); #ifdef __cplusplus } diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index d3192a2460..c8e4ae956c 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -661,6 +661,14 @@ int32_t sdbInsertRow(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } +bool sdbCheckRowDeleted(void *pTableInput, void *pRow) { + SSdbTable *pTable = pTableInput; + if (pTable == NULL) return false; + + int8_t *updateEnd = pRow + pTable->refCountPos - 1; + return (*updateEnd == 1); +} + int32_t sdbDeleteRow(SSdbOper *pOper) { SSdbTable *pTable = (SSdbTable *)pOper->table; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index f4251e4f83..8dac135885 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -72,7 +72,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg); static int32_t mnodeProcessDropTableMsg(SMnodeMsg *mnodeMsg); static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg); static void mnodeProcessDropSuperTableRsp(SRpcMsg *rpcMsg); -static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg); +static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn); static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg); static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *mnodeMsg); @@ -754,7 +754,7 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) { SChildTableObj *pCTable = (SChildTableObj *)pMsg->pTable; mInfo("app:%p:%p, table:%s, start to drop ctable, vgId:%d sid:%d uid:%" PRIu64, pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId, pCTable->vgId, pCTable->sid, pCTable->uid); - return mnodeProcessDropChildTableMsg(pMsg); + return mnodeProcessDropChildTableMsg(pMsg, true); } } @@ -1758,7 +1758,7 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) { } } -static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { +static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) { SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable; if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId); if (pMsg->pVgroup == NULL) { @@ -1793,6 +1793,8 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { .msgType = TSDB_MSG_TYPE_MD_DROP_TABLE }; + if (!needReturn) rpcMsg.ahandle = NULL; + dnodeSendMsgToDnode(&ipSet, &rpcMsg); return TSDB_CODE_MND_ACTION_IN_PROGRESS; @@ -2246,6 +2248,15 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { SChildTableObj *pTable = (SChildTableObj *)mnodeMsg->pTable; assert(pTable); + // If the table is deleted by another thread during creation, stop creating and send drop msg to vnode + if (sdbCheckRowDeleted(tsChildTableSdb, pTable)) { + mDebug("app:%p:%p, table:%s, create table rsp received, but a deleting opertion incoming, vgId:%d sid:%d uid:%" PRIu64, + mnodeMsg->rpcMsg.ahandle, mnodeMsg, pTable->info.tableId, pTable->vgId, pTable->sid, pTable->uid); + mnodeProcessDropChildTableMsg(mnodeMsg, false); + dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_SUCCESS); + return; + } + if (rpcMsg->code == TSDB_CODE_SUCCESS || rpcMsg->code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) { SCMCreateTableMsg *pCreate = mnodeMsg->rpcMsg.pCont; if (pCreate->getMeta) { -- GitLab