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

Cleanup refcounting and lifetime of ReplicaSetMonitor

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      This is an umbrella task to keep track of all smaller tasks to accomplish the refactoring.

      UPDATE: hopefully we don't need TTL. I will rename or delete this ticket when it's more clear. For now it holds the list of other tickets needed for refactoring, below.

       

      The problem: the lifetime if the ReplicaSetMonitor is managed by the shared_ptr. The ownership graph has circular dependencies (like _eventsPublisher and TopologyListenerPtr) that prevent the instance to be deleted. At the same time, breaking those circular dependencies by replacing a listener with weak_ptr is making the RSM to be deleted too fast.

      The solution: convert the ReplicaSetMonitor factory and ReplicaSetMonitorManager to cache with TTL:

      1. Do not have a strict refcounting delete policy, have a lazy delete with TTL (about 1 hour or so)
      2. Make the callers to not keep the reference for a while, even use a weak pointer when possible. TTL will prevent the immediate deletion
      3. Remove the get() method, so an entry in the cache is always recreated. With 1 hour TTL it is guaranteed that each record is recreated not more often than once per hour, so the cost is very low
      4. Thus we still have the remove() method that clears the entry from cache immediately, and the dangling references will delete the instance soon, however we cannot force it to terminate immediately. I think the remove() should set a flag in the instance that it should terminate asap

      In the tests, set TTL to be short, like 10 seconds. 

            Assignee:
            andrew.shuvalov@mongodb.com Andrew Shuvalov (Inactive)
            Reporter:
            andrew.shuvalov@mongodb.com Andrew Shuvalov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: