Skip to content

Instantly share code, notes, and snippets.

@dagolden
Created June 19, 2015 21:17
Show Gist options
  • Save dagolden/a8c95e0d4d9d89f26716 to your computer and use it in GitHub Desktop.
Save dagolden/a8c95e0d4d9d89f26716 to your computer and use it in GitHub Desktop.
Multi-threaded
1. Record the server selection start time
2. If the topology wire version is invalid, raise an error
3. Find suitable servers by topology type and operation type
4. If there are any suitable servers, choose one at random from those
within the latency window and return it; otherwise, continue to step #5
5. Request an immediate topology check, then block the server selection
thread until the topology changes or until the the server selection timeout
has elapsed.
6. If more than ``serverSelectionTimeoutMS`` milliseconds have elapsed since
the selection start time, raise a `server selection error`_
7. Goto Step #2
Single-threaded
1. Record the server selection start time
2. If the topology has not been scanned in ``heartBeatFrequencyMS``
milliseconds or if the topology is marked stale, do a (blocking)
immediate topology check
3. If the topology wire version is invalid, mark the topology stale and
raise an error
4. Find suitable servers by topology type and operation type
5. If there are any suitable servers, choose one at random from those
within the latency window and return it; otherwise, continue to step #6
6. Mark the topology stale
7. If ``serverSelectionTimeoutMS`` is -1, or more than
``serverSelectionTimeoutMS`` milliseconds have elapsed since the selection
start time, raise a `server selection error`_
8. Sleep ``minHeartbeatFrequencyMS`` milliseconds
9. Goto Step #2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment