Skip to content

Commit

Permalink
Merge 'origin/main' into create_shard
Browse files Browse the repository at this point in the history
  • Loading branch information
zichanglai committed Sep 19, 2023
2 parents 13a0d45 + 291b070 commit c909e05
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/lib/memory/shard_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ ShardManager::Result< ShardInfo > MemoryHomeObject::_create_shard(pg_id pg_owner
ShardManager::Result< ShardInfo > MemoryHomeObject::_seal_shard(shard_id id) {
auto lg = std::scoped_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& shard_info = (*shard_it->second).info;
shard_info.state = ShardInfo::State::SEALED;
return shard_info;
return shard_info;
}

} // namespace homeobject
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().info.state) return e.value().info;
return _seal_shard(e.value().info.id);
});
}


Expand Down

0 comments on commit c909e05

Please sign in to comment.