From 0a221aa230154846e00f8ce930aefebc60a401cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=B2=91=E7=82=AF?= <834727721@qq.com> Date: Wed, 26 Mar 2025 17:15:29 +0800 Subject: [PATCH] handle cases where relation has been removed during compressed table accessing --- src/gausskernel/storage/smgr/cfs/cfs_md.cpp | 14 ++++++++++++++ src/gausskernel/storage/smgr/md.cpp | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/gausskernel/storage/smgr/cfs/cfs_md.cpp b/src/gausskernel/storage/smgr/cfs/cfs_md.cpp index 6fd99a521d..78998e1af3 100644 --- a/src/gausskernel/storage/smgr/cfs/cfs_md.cpp +++ b/src/gausskernel/storage/smgr/cfs/cfs_md.cpp @@ -1070,6 +1070,10 @@ void CfsHeaderPageCheckAndRepair(SMgrRelation reln, BlockNumber logicBlockNumber { errno_t rc = 0; int fd = CfsGetFd(reln, MAIN_FORKNUM, logicBlockNumber, true, EXTENT_OPEN_FILE); + /* The relation has been removed, nothing to do here. */ + if (fd < 0) { + return; + } ExtentLocation location = g_location_convert[COMMON_STORAGE](reln, reln->smgr_rnode.node, fd, CFS_EXTENT_SIZE, MAIN_FORKNUM, logicBlockNumber); @@ -1430,6 +1434,10 @@ void MdRecoveryPcaPage(SMgrRelation reln, ForkNumber forknum, BlockNumber blockn CfsExtentAddress *extAddr = NULL; int fd = CfsGetFd(reln, forknum, blocknum, skipFsync, WRITE_BACK_OPEN_FILE); + /* The relation has been removed, nothing to do here. */ + if (fd < 0) { + return; + } /* buffer init is ahead of dw, buffer can be used for reading pca */ ExtentLocation location = StorageConvert(reln, reln->smgr_rnode.node, fd, CFS_EXTENT_SIZE, forknum, blocknum); @@ -1475,6 +1483,12 @@ void MdAssistFileProcess(SMgrRelation relation, const char *assistInfo, int assi int fd = CfsGetFd(relation, extInfo->forknum, extInfo->extentNumber * CFS_LOGIC_BLOCKS_PER_EXTENT, false, WRITE_BACK_OPEN_FILE); + + /* The relation has been removed, nothing to do here. */ + if (fd < 0) { + return; + } + ExtentLocation location = StorageConvert(relation, relation->smgr_rnode.node, fd, CFS_EXTENT_SIZE, extInfo->forknum, extInfo->extentNumber * CFS_LOGIC_BLOCKS_PER_EXTENT); diff --git a/src/gausskernel/storage/smgr/md.cpp b/src/gausskernel/storage/smgr/md.cpp index e9201f3ce2..9f177526b5 100644 --- a/src/gausskernel/storage/smgr/md.cpp +++ b/src/gausskernel/storage/smgr/md.cpp @@ -891,6 +891,10 @@ void mdwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, while (nblocks > 0) { if (IS_COMPRESSED_MAINFORK(reln, forknum)) { int fd = CfsGetFd(reln, MAIN_FORKNUM, blocknum, true, WRITE_BACK_OPEN_FILE); + /* The relation has been removed, nothing to do here. */ + if (fd < 0) { + return; + } auto nflushed = CfsWriteBack(reln, relNode, fd, CFS_LOGIC_BLOCKS_PER_EXTENT, forknum, blocknum, nblocks, COMMON_STORAGE); if (nflushed == InvalidBlockNumber) { @@ -1468,6 +1472,10 @@ void mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const bool compressed = IS_COMPRESSED_MAINFORK(reln, forknum); if (compressed) { int fd = CfsGetFd(reln, forknum, blocknum, skipFsync, EXTENT_OPEN_FILE); + /* The relation has been removed, nothing to do here. */ + if (fd < 0) { + return; + } nbytes = (int)CfsWritePage(reln, reln->smgr_rnode.node, fd, CFS_LOGIC_BLOCKS_PER_EXTENT, forknum, blocknum, buffer, false, COMMON_STORAGE); } else { -- Gitee