code: def prefer_replica(nodes: List[DiscoveredNode]) -> Optional[DiscoveredNode]:
      
      masters = [node for node in nodes if node.state == NodeState.Master]
      replicas = [node for node in nodes if node.state != NodeState.Master]
  
      if replicas:
          return random.choice(replicas)
      else:
          # if you have more than one master then you're on your own, bud.
  
          return masters[0]
docs: Select a random replica if any are available or fall back to the master.