-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Internal Code
-
None
-
Service Arch
-
Fully Compatible
-
Service Arch 2024-04-01
As highlighted in the following code snippet, ShardingState is using a mutex to synchronize accesses to its Future, which is unnecessary as Future is a thread-safe primitive:
boost::optional<ClusterRole> ShardingState::pollClusterRole() const { stdx::unique_lock<Latch> ul(_mutex); if (!_future.isReady()) return boost::none; const auto& role = uassertStatusOK(_future.getNoThrow()); return role.role; }
So, the above can be simplified and rewritten as follows:
boost::optional<ClusterRole> ShardingState::pollClusterRole() const { if (!_future.isReady()) return boost::none; return _future.get().role; }
As part of this ticket, we should ShardingState::_mutex and better utilize Future APIs.