Skip to content

Commit

Permalink
curvefs: add ut for mdsaddrs override function
Browse files Browse the repository at this point in the history
Signed-off-by: h0hmj <h0hmjcn@gmail.com>
  • Loading branch information
h0hmj committed Dec 8, 2023
1 parent 6bc86aa commit c653b74
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
5 changes: 5 additions & 0 deletions curvefs/src/mds/fs_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,11 @@ bool FsManager::FillVolumeInfo(common::Volume* volume) {
return true;
}

std::string FsManager::GetClientMdsAddrsOverride() {
ReadLockGuard lock(clientMdsAddrsOverrideMutex_);
return clientMdsAddrsOverride_;
}

void FsManager::SetClientMdsAddrsOverride(const std::string& addrs) {
// always add active mds to override to improve availability
auto addrsWithActiveMds = addrs + "," + option_.mdsListenAddr;
Expand Down
1 change: 1 addition & 0 deletions curvefs/src/mds/fs_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class FsManager {
bool GetClientAliveTime(const std::string& mountpoint,
std::pair<std::string, uint64_t>* out);

std::string GetClientMdsAddrsOverride();
void SetClientMdsAddrsOverride(const std::string& addrs);

private:
Expand Down
10 changes: 10 additions & 0 deletions curvefs/test/client/rpcclient/mds_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,16 @@ TEST_F(MdsClientImplTest, test_AllocOrGetMemcacheCluster) {
mdsclient_.AllocOrGetMemcacheCluster(1, &cluster2));
}

TEST_F(MdsClientImplTest, test_GetMdsAddrs) {
ASSERT_EQ(mdsclient_.GetMdsAddrs(), addr_);
}

TEST_F(MdsClientImplTest, test_SetMdsAddrs) {
auto addr_new = addr_ + ",127.0.0.1:5600";
mdsclient_.SetMdsAddrs(addr_new);
ASSERT_EQ(mdsclient_.GetMdsAddrs(), addr_new);
}

} // namespace rpcclient
} // namespace client
} // namespace curvefs
85 changes: 85 additions & 0 deletions curvefs/test/mds/fs_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class FSManagerTest : public ::testing::Test {
FsManagerOption fsManagerOption;
fsManagerOption.backEndThreadRunInterSec = 1;
fsManagerOption.clientTimeoutSec = 1;
fsManagerOption.mdsListenAddr = addr_;
s3Adapter_ = std::make_shared<MockS3Adapter>();
fsManager_ = std::make_shared<FsManager>(fsStorage_, spaceManager_,
metaserverClient_,
Expand Down Expand Up @@ -1032,5 +1033,89 @@ TEST_F(FSManagerTest, test_success_get_latest_txid_with_fsid) {
ASSERT_EQ(response.txids_size(), 1);
}

TEST_F(FSManagerTest, test_GetClientMdsAddrsOverride) {
ASSERT_EQ(fsManager_->GetClientMdsAddrsOverride(), std::string());
}

TEST_F(FSManagerTest, test_SetClientMdsAddrsOverride) {
std::string addr("127.0.0.1:9999,127.0.0.1:10000");
fsManager_->SetClientMdsAddrsOverride(addr);
ASSERT_EQ(fsManager_->GetClientMdsAddrsOverride(), addr + "," + addr_);
}

TEST_F(FSManagerTest, test_refresh_session_with_mdsoverride) {
CreateS3Fs();
// set override
std::string mds_new("127.0.0.1:9999");
fsManager_->SetClientMdsAddrsOverride(mds_new);

PartitionTxId tmp;
tmp.set_partitionid(1);
tmp.set_txid(1);
std::string fsName = kFsName2;
Mountpoint mountpoint;
mountpoint.set_hostname("127.0.0.1");
mountpoint.set_port(9000);
mountpoint.set_path("/mnt");

RefreshSessionResponse response;
RefreshSessionRequest request;
request.set_fsname(fsName);
*request.mutable_mountpoint() = mountpoint;
request.set_mdsaddrs(addr_);
fsManager_->RefreshSession(&request, &response);
ASSERT_EQ(response.mdsaddrsoverride(), mds_new + "," + addr_);
fsManager_->SetClientMdsAddrsOverride(std::string());
}

TEST_F(FSManagerTest, test_refresh_session_with_same_mdsoverride) {
CreateS3Fs();
// set override
std::string mds_new("127.0.0.1:9999");
fsManager_->SetClientMdsAddrsOverride(mds_new);
PartitionTxId tmp;
tmp.set_partitionid(1);
tmp.set_txid(1);
std::string fsName = kFsName2;
Mountpoint mountpoint;
mountpoint.set_hostname("127.0.0.1");
mountpoint.set_port(9000);
mountpoint.set_path("/mnt");

RefreshSessionResponse response;
RefreshSessionRequest request;
request.set_fsname(fsName);
*request.mutable_mountpoint() = mountpoint;
request.set_mdsaddrs(mds_new + "," + addr_);
fsManager_->RefreshSession(&request, &response);
ASSERT_FALSE(response.has_mdsaddrsoverride());
fsManager_->SetClientMdsAddrsOverride(std::string());
}

TEST_F(FSManagerTest, test_refresh_session_with_old_client) {
CreateS3Fs();
// set override
auto mds_new = "127.0.0.1:9999";
fsManager_->SetClientMdsAddrsOverride(mds_new);

PartitionTxId tmp;
tmp.set_partitionid(1);
tmp.set_txid(1);
std::string fsName = kFsName2;
Mountpoint mountpoint;
mountpoint.set_hostname("127.0.0.1");
mountpoint.set_port(9000);
mountpoint.set_path("/mnt");

RefreshSessionResponse response;
RefreshSessionRequest request;
request.set_fsname(fsName);
*request.mutable_mountpoint() = mountpoint;
// old client do not have mdsaddr in request
fsManager_->RefreshSession(&request, &response);
ASSERT_FALSE(response.has_mdsaddrsoverride());
fsManager_->SetClientMdsAddrsOverride(std::string());
}

} // namespace mds
} // namespace curvefs

0 comments on commit c653b74

Please sign in to comment.