Delegate the cleanup of resources used by ReplicaSetMonitor the do its d-tor. Currently its done in ReplicaSetMonitor::remove() .
a) Change ReplicaSetMonitorManager _monitors type to StringMap<std::weak_ptr<RepliceSetMonitor>>
so the map does not own monitors and hence every object will call a d-tor as soon as its refcount is 0
b) ReplicaSetMonitor::~ReplicaSetMonitor will now be called when it goes out of scope and hence it should erase itself from the _monitors map.
c) ReplicaSetMonitorManager::getMonitor should
lock() a weak_ptr to existing monitor to convert it to shared_ptr() before returning it. It should invariant that lock() works i.e. the map can not have a dangling weak_ptr.
d) disallow calling ReplicaSetMonitor::remove() - make its private or delete if not needed
e) Optionally in the case there is need to get a shared_ptr from ReplicaSetMonitor object: derive ReplicaSetMonitor from enable_shared_from_this and use shared_from_this() call to get shared_ptr.
- related to
-
SERVER-23192 mongos and shards will become unusable if contact is lost with all CSRS config server nodes for more than 30 consecutive failed attempts to contact
- Closed