From 2f4148e8d40a4396feb134eddcaf5d8466d8a597 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 15 Feb 2022 17:40:38 +0800 Subject: [PATCH] Need to delete stb when deleting database --- source/dnode/mnode/impl/inc/mndStb.h | 1 + source/dnode/mnode/impl/src/mndDb.c | 19 +++++++++++++++++++ source/dnode/mnode/impl/src/mndStb.c | 3 +-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndStb.h b/source/dnode/mnode/impl/inc/mndStb.h index 4ff696381e..82d93a4b9b 100644 --- a/source/dnode/mnode/impl/inc/mndStb.h +++ b/source/dnode/mnode/impl/inc/mndStb.h @@ -26,6 +26,7 @@ int32_t mndInitStb(SMnode *pMnode); void mndCleanupStb(SMnode *pMnode); SStbObj *mndAcquireStb(SMnode *pMnode, char *stbName); void mndReleaseStb(SMnode *pMnode, SStbObj *pStb); +SSdbRaw *mndStbActionEncode(SStbObj *pStb); int32_t mndValidateStbInfo(SMnode *pMnode, SSTableMetaVersion *pStbs, int32_t numOfStbs, void **ppRsp, int32_t *pRspLen); diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index a6d7e92da6..0cceb1084b 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -18,6 +18,7 @@ #include "mndAuth.h" #include "mndDnode.h" #include "mndShow.h" +#include "mndStb.h" #include "mndTrans.h" #include "mndUser.h" #include "mndVgroup.h" @@ -722,6 +723,24 @@ static int32_t mndSetDropDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD sdbRelease(pSdb, pVgroup); } + while (1) { + SStbObj *pStb = NULL; + pIter = sdbFetch(pSdb, SDB_STB, pIter, (void **)&pStb); + if (pIter == NULL) break; + + if (pStb->dbUid == pDb->uid) { + SSdbRaw *pStbRaw = mndStbActionEncode(pStb); + if (pStbRaw == NULL || mndTransAppendCommitlog(pTrans, pStbRaw) != 0) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pStbRaw); + return -1; + } + sdbSetRawStatus(pStbRaw, SDB_STATUS_DROPPED); + } + + sdbRelease(pSdb, pStb); + } + return 0; } diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 69a8479d47..31e2d35c01 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -28,7 +28,6 @@ #define TSDB_STB_VER_NUMBER 1 #define TSDB_STB_RESERVE_SIZE 64 -static SSdbRaw *mndStbActionEncode(SStbObj *pStb); static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw); static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb); static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb); @@ -70,7 +69,7 @@ int32_t mndInitStb(SMnode *pMnode) { void mndCleanupStb(SMnode *pMnode) {} -static SSdbRaw *mndStbActionEncode(SStbObj *pStb) { +SSdbRaw *mndStbActionEncode(SStbObj *pStb) { terrno = TSDB_CODE_OUT_OF_MEMORY; int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema) + TSDB_STB_RESERVE_SIZE; -- GitLab