Skip to content

Commit

Permalink
[fix] curvefs: mds: createfs error
Browse files Browse the repository at this point in the history
Signed-off-by: swj <1186093704@qq.com>
  • Loading branch information
201341 authored and wuhongsong committed Nov 16, 2023
1 parent b134e88 commit a22e6d1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
34 changes: 25 additions & 9 deletions curvefs/src/mds/fs_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions curvefs/test/mds/fs_manager_test2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const std::string&>(_)))
.WillOnce(Return(true));

EXPECT_CALL(*storage_, Get(Matcher<const std::string&>(_), _))
.WillOnce(
DoAll(SetArgPointee<1>(wrapper), Return(FSStatusCode::OK)));

EXPECT_EQ(FSStatusCode::FS_EXIST, fsManager_->CreateFs(&req, nullptr));
}
}

TEST_F(FsManagerTest2, CreateFoundUnCompleteOperation) {
Expand Down

0 comments on commit a22e6d1

Please sign in to comment.