Skip to content

Commit

Permalink
Merge pull request #133 from raakella1/memory_apis
Browse files Browse the repository at this point in the history
implement mem pg manager apis for SM unit tests
  • Loading branch information
raakella1 authored Jan 18, 2024
2 parents b1ea8f9 + ec4e9af commit 53a412c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/lib/memory_backend/mem_pg_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,42 @@ PGManager::NullAsyncResult MemoryHomeObject::_replace_member(pg_id_t id, peer_id
return folly::makeSemiFuture< PGManager::NullResult >(folly::makeUnexpected(PGError::UNSUPPORTED_OP));
}

bool MemoryHomeObject::_get_stats(pg_id_t id, PGStats& stats) const { RELEASE_ASSERT(false, "Not implemented!"); }
bool MemoryHomeObject::_get_stats(pg_id_t id, PGStats& stats) const {
auto lg = std::shared_lock(_pg_lock);
auto it = _pg_map.find(id);
if (_pg_map.end() == it) { return false; }
auto pg = it->second.get();
stats.id = pg->pg_info_.id;
stats.replica_set_uuid = pg->pg_info_.replica_set_uuid;
stats.num_members = pg->pg_info_.members.size();
stats.total_shards = pg->shards_.size();
stats.open_shards =
std::count_if(pg->shards_.begin(), pg->shards_.end(), [](auto const& s) { return s->is_open(); });
for (auto const& m : pg->pg_info_.members) {
stats.members.emplace_back(std::make_tuple(m.id, m.name, 0 /* last commit lsn */));
}

void MemoryHomeObject::_get_pg_ids(std::vector< pg_id_t >& pg_ids) const { RELEASE_ASSERT(false, "Not implemented!"); }
return true;
}

void MemoryHomeObject::_get_pg_ids(std::vector< pg_id_t >& pg_ids) const {
auto lg = std::shared_lock(_pg_lock);
for (auto& [id, _] : _pg_map) {
pg_ids.push_back(id);
}
}

HomeObjectStats MemoryHomeObject::_get_stats() const { RELEASE_ASSERT(false, "Not implemented!"); }
HomeObjectStats MemoryHomeObject::_get_stats() const {
HomeObjectStats stats;
uint32_t num_open_shards = 0ul;
std::scoped_lock shared_lock(_pg_lock);
for (auto const& [_, pg] : _pg_map) {
auto mem_pg = pg.get();
num_open_shards +=
std::count_if(mem_pg->shards_.begin(), mem_pg->shards_.end(), [](auto const& s) { return s->is_open(); });
}

stats.num_open_shards = num_open_shards;
return stats;
}
} // namespace homeobject
8 changes: 8 additions & 0 deletions src/lib/tests/fixture_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ void TestFixture::SetUp() {
EXPECT_STREQ(blob.user_key.c_str(), "test_blob");
EXPECT_EQ(blob.object_off, 4 * Mi);
});

// cover the memory version of get_stats
// homestore version has a dedicated test for this.
homeobject::PGStats stats;
std::vector< homeobject::pg_id_t > pg_ids;
homeobj_->pg_manager()->get_stats(_pg_id, stats);
homeobj_->get_stats();
homeobj_->pg_manager()->get_pg_ids(pg_ids);
}

void TestFixture::TearDown() { std::dynamic_pointer_cast< FixtureApp >(app)->clean(); }
Expand Down

0 comments on commit 53a412c

Please sign in to comment.