diff --git a/src/lib/memory/shard_manager.cpp b/src/lib/memory/shard_manager.cpp index 9f389532..60f56242 100644 --- a/src/lib/memory/shard_manager.cpp +++ b/src/lib/memory/shard_manager.cpp @@ -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 diff --git a/src/lib/memory/tests/ShardManagerTest.cpp b/src/lib/memory/tests/ShardManagerTest.cpp index 9bfc9fe1..f2b1f8ef 100644 --- a/src/lib/memory/tests/ShardManagerTest.cpp +++ b/src/lib/memory/tests/ShardManagerTest.cpp @@ -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[]) { diff --git a/src/lib/shard_manager.cpp b/src/lib/shard_manager.cpp index d83593a6..79d3fb3f 100644 --- a/src/lib/shard_manager.cpp +++ b/src/lib/shard_manager.cpp @@ -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); + }); }