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

Replace ReplicaSetMonitorManager::removeMonitor with a custom deleter for shared_ptr<ReplicaSetMonitor>

    • Cluster Scalability
    • Sharding 2020-08-24
    • 3

      ReplicaSetMonitorManager stores ReplicaSetMonitors by weak_ptr so that the ReplicaSetMonitor is destroyed when the last shared_ptr reference to it goes out of scope.

      However, ReplicaSetMonitorManager also has a removeMonitor function, which currently the holder of the last shared_ptr reference has to call to remove the entry for the ReplicaSetMonitor from the ReplicaSetMonitorManager's map.

      Instead, the shared_ptr to ReplicaSetMonitor could be created with a custom deleter that removes the entry from the map, like:

              std::shared_ptr<Foo> sh5(new Foo, [](auto p) {
                 std::cout << "Call delete from lambda...\n";
                 delete p;
              });
      

      See also https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr.

      There are a couple complications:

      1. We probably still want to remove the hosts from the connection pool, which ReplicaSetMonitor::remove currently does.
      2. There are two implementations of ReplicaSetMonitor, and the Streamable implementation has a factory method to create its monitors.

            Assignee:
            backlog-server-cluster-scalability [DO NOT USE] Backlog - Cluster Scalability
            Reporter:
            esha.maharishi@mongodb.com Esha Maharishi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: