From a22e6d1368ae69d6d7c843da36a095e9022becb0 Mon Sep 17 00:00:00 2001 From: swj <1186093704@qq.com> Date: Tue, 10 Oct 2023 11:46:03 +0800 Subject: [PATCH] [fix] curvefs: mds: createfs error Signed-off-by: swj <1186093704@qq.com> --- curvefs/src/mds/fs_manager.cpp | 34 ++++++++++++++++++++------- curvefs/test/mds/fs_manager_test2.cpp | 25 ++++++++++++++++++++ 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/curvefs/src/mds/fs_manager.cpp b/curvefs/src/mds/fs_manager.cpp index 6ab8090946..34a960287c 100644 --- a/curvefs/src/mds/fs_manager.cpp +++ b/curvefs/src/mds/fs_manager.cpp @@ -841,9 +841,7 @@ FSStatusCode FsManager::UpdateFsInfo( } int FsManager::IsExactlySameOrCreateUnComplete(const std::string& fsName, - FSType fsType, - uint64_t blocksize, - const FsDetail& detail) { + FSType fsType, uint64_t blocksize, const FsDetail& detail) { FsInfoWrapper existFs; auto volumeInfoComparator = [](common::Volume lhs, common::Volume rhs) { @@ -858,16 +856,34 @@ int FsManager::IsExactlySameOrCreateUnComplete(const std::string& fsName, return google::protobuf::util::MessageDifferencer::Equals(lhs, rhs); }; - auto checkFsInfo = [fsType, volumeInfoComparator](const FsDetail& lhs, - const FsDetail& rhs) { + auto s3InfoComparator = [](common::S3Info newFs, common::S3Info existFs) { + // If the s3info detail stored in mds doesn't have prefix, the new + // client which has prefix value bigger than 0 can't mount filesystem. + if (newFs.has_objectprefix() && !existFs.has_objectprefix() && + newFs.objectprefix() != 0) { + return false; + } + // If the s3info detail stored in mds has prefix value bigger than 0, + // the old client which doesn't have prefix can't mount filesystem. + if (existFs.has_objectprefix() && !newFs.has_objectprefix() && + existFs.objectprefix() != 0) { + return false; + } + + return google::protobuf::util::MessageDifferencer::Equals( + newFs, existFs); + }; + + auto checkFsInfo = [fsType, volumeInfoComparator, s3InfoComparator]( + const FsDetail& newFs, const FsDetail& existFs) { switch (fsType) { case curvefs::common::FSType::TYPE_S3: - return MessageDifferencer::Equals(lhs.s3info(), rhs.s3info()); + return s3InfoComparator(newFs.s3info(), existFs.s3info()); case curvefs::common::FSType::TYPE_VOLUME: - return volumeInfoComparator(lhs.volume(), rhs.volume()); + return volumeInfoComparator(newFs.volume(), existFs.volume()); case curvefs::common::FSType::TYPE_HYBRID: - return MessageDifferencer::Equals(lhs.s3info(), rhs.s3info()) && - volumeInfoComparator(lhs.volume(), rhs.volume()); + return s3InfoComparator(newFs.s3info(), existFs.s3info()) && + volumeInfoComparator(newFs.volume(), existFs.volume()); } return false; diff --git a/curvefs/test/mds/fs_manager_test2.cpp b/curvefs/test/mds/fs_manager_test2.cpp index c0c2bc6685..08c6c40d10 100644 --- a/curvefs/test/mds/fs_manager_test2.cpp +++ b/curvefs/test/mds/fs_manager_test2.cpp @@ -241,6 +241,31 @@ TEST_F(FsManagerTest2, CreateFoundConflictFsNameAndNotIdenticalToPreviousOne) { EXPECT_EQ(FSStatusCode::FS_EXIST, fsManager_->CreateFs(&req, nullptr)); } + + // prefix is different + { + FsInfo fsinfo; + fsinfo.set_status(FsStatus::NEW); + fsinfo.set_fsname(fsname); + fsinfo.set_blocksize(4 * 1024); + fsinfo.set_fstype(FSType::TYPE_S3); + + auto s3Info2 = *s3Info; + s3Info2.set_objectprefix(1); + fsinfo.mutable_detail()->set_allocated_s3info( + new curvefs::common::S3Info(s3Info2)); + + FsInfoWrapper wrapper(fsinfo); + + EXPECT_CALL(*storage_, Exist(Matcher(_))) + .WillOnce(Return(true)); + + EXPECT_CALL(*storage_, Get(Matcher(_), _)) + .WillOnce( + DoAll(SetArgPointee<1>(wrapper), Return(FSStatusCode::OK))); + + EXPECT_EQ(FSStatusCode::FS_EXIST, fsManager_->CreateFs(&req, nullptr)); + } } TEST_F(FsManagerTest2, CreateFoundUnCompleteOperation) {