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

Short circuit sealing a sealed shard. Test as well. #60

Merged
merged 2 commits into from
Sep 19, 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
3 changes: 2 additions & 1 deletion src/lib/memory/shard_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ ShardManager::Result< ShardInfo > MemoryHomeObject::_create_shard(pg_id pg_owner
ShardManager::Result< ShardInfo > MemoryHomeObject::_seal_shard(shard_id id) {
auto lg = std::scoped_lock(_pg_lock, _shard_lock);
auto shard_it = _shard_map.find(id);
if (_shard_map.end() == shard_it) return folly::makeUnexpected(ShardError::UNKNOWN_SHARD);
RELEASE_ASSERT(_shard_map.end() != shard_it, "Missing ShardIterator!");

auto const_it = shard_it->second;
auto pg_it = _pg_map.find(const_it->placement_group);
RELEASE_ASSERT(_pg_map.end() != pg_it, "Missing ShardInfo!");

// Copy the Info and replace it
auto new_info = *const_it;
new_info.state = ShardInfo::State::SEALED;
pg_it->second.second.erase(const_it);
Expand Down
16 changes: 9 additions & 7 deletions src/lib/memory/tests/ShardManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ TEST_F(ShardManagerFixtureWShard, SealShardNoShard) {
}

TEST_F(ShardManagerFixtureWShard, SealShard) {
auto e = m_memory_homeobj->shard_manager()->seal_shard(_shard.id).get();
ASSERT_TRUE(!!e);
e.then([this](auto const& info) {
EXPECT_TRUE(info.id == _shard.id);
EXPECT_TRUE(info.placement_group == _shard.placement_group);
EXPECT_EQ(info.state, ShardInfo::State::SEALED);
});
for (auto i = 0; 2 > i; ++i) {
auto e = m_memory_homeobj->shard_manager()->seal_shard(_shard.id).get();
ASSERT_TRUE(!!e);
e.then([this](auto const& info) {
EXPECT_TRUE(info.id == _shard.id);
EXPECT_TRUE(info.placement_group == _shard.placement_group);
EXPECT_EQ(info.state, ShardInfo::State::SEALED);
});
}
}

int main(int argc, char* argv[]) {
Expand Down
7 changes: 5 additions & 2 deletions src/lib/shard_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ ShardManager::AsyncResult< InfoList > HomeObjectImpl::list_shards(pg_id pg) cons
}

ShardManager::AsyncResult< ShardInfo > HomeObjectImpl::seal_shard(shard_id id) {
return _defer().thenValue(
[this, id](auto) mutable -> ShardManager::Result< ShardInfo > { return _seal_shard(id); });
return _get_shard(id).thenValue([this](auto const e) mutable -> ShardManager::Result< ShardInfo > {
if (!e) return folly::makeUnexpected(ShardError::UNKNOWN_SHARD);
if (ShardInfo::State::SEALED == e.value().state) return e.value();
return _seal_shard(e.value().id);
});
}

ShardManager::AsyncResult< ShardInfo > HomeObjectImpl::get_shard(shard_id id) const { return _get_shard(id); }
Expand Down