Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] curvefs: mds: createfs error #2791

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions curvefs/src/mds/fs_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,7 @@ FSStatusCode FsManager::GetFsInfo(const std::string& fsName, uint32_t fsId,
}

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 @@ -808,16 +806,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