Last active
August 29, 2015 14:23
-
-
Save dagolden/af74fd30576b7b8f601c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getServer(criteria): | |
startTime = loopEndTime = gettime() | |
maxTime = startTime + serverSelectionTimeoutMS/1000 | |
if topology.lastUpdateTime - startTime > heartbeatFrequencyMS/1000: | |
topology.stale = true | |
while true: | |
if topology.stale: | |
scanReadyTime = topology.lastUpdateTime + minHeartbeatFrequencyMS/1000 | |
if ((not serverSelectionTryOnce) && (scanReadyTime > maxTime)): | |
throw server selection error with details | |
sleepTime = scanReadyTime - loopEndTime | |
if sleepTime > 0: | |
sleep sleepTime | |
# rescan must update topology.lastUpdateTime | |
rescan all servers | |
if not topology.compatible: | |
topology.stale = true | |
throw invalid wire protocol range error with details | |
servers = all servers in topology matching criteria | |
if servers is not empty: | |
in_window = servers within the latency window | |
return random entry from in_window | |
else: | |
topology.stale = true | |
loopEndTime = gettime(); | |
if serverSelectionTryOnce: | |
if topology.lastUpdateTime > startTime: | |
throw server selection error with details | |
else if loopEndTime > maxTime: | |
throw server selection error with details | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment