Uploaded image for project: 'Rust Driver'
  1. Rust Driver
  2. RUST-585

Refactor Topology to use channels instead of locks

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.3.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      The Topology type could be refactored to use channels instead of locks (similar to the connection pool refactor in RUST-556). This refactor would allow us to more effectively leverage the async capabilities of the driver and hopefully make the SDAM machinery easier to reason about.

      Proposed layout:

      • Creating Topology starts a worker task that runs in the background, and the initialized Topology struct then serves as a handle to this task. The Topology contains a mpsc::Sender and a watch::Receiver, and the task holds on to the other ends of those channels. The task will stop running once all the watch::Receiver s are dropped (i.e. all the Topology are dropped).
      • Monitors send updated server descriptions over the mpsc::Sender. The task receives these descriptions, makes updates to the topology state, and publishes the new TopologyState via the watch::Sender. Monitors will stop executing once the receiving end of their senders are dropped (i.e. the worker task has quit)
      • In server selection, the latest TopologyState is grabbed from the watch channel. If selection fails, a check is requested via the mpsc::Sender and the watch channel is waited on until a new TopologyState is published or server selection timeout is hit.

      In this scheme, the worker task always has exclusive access to the mutable portions of the topology, while everything else always has immediate read access to the latest published TopologyState. This allows us to remove all locks and greatly simplify our SDAM machinery.

            Assignee:
            patrick.freed@mongodb.com Patrick Freed
            Reporter:
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: