Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-23345

RAII semantics for ReplicaSetMonitor

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.11
    • Affects Version/s: None
    • Component/s: Sharding
    • Labels:
    • Fully Compatible
    • ALL
    • Sharding 14 (05/13/16), Sharding 15 (06/03/16), Sharding 16 (06/24/16), Sharding 18 (08/05/16)
    • 0

      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.

            Assignee:
            misha.tyulenev@mongodb.com Misha Tyulenev (Inactive)
            Reporter:
            misha.tyulenev@mongodb.com Misha Tyulenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: