コード例 #1
0
 Node getMasterNode() {
   _checkClosed();
   for (int i = 0; i < _all.size(); i++) {
     Node n = _all.get(i);
     if (n.master()) return n;
   }
   return null;
 }
コード例 #2
0
  /** @return a good secondary or null if can't find one */
  ServerAddress getASecondary() {
    _checkClosed();
    Node best = null;
    double badBeforeBest = 0;

    int start = _random.nextInt(_all.size());

    double mybad = 0;

    for (int i = 0; i < _all.size(); i++) {
      Node n = _all.get((start + i) % _all.size());

      if (!n.secondary()) {
        mybad++;
        continue;
      }

      if (best == null) {
        best = n;
        badBeforeBest = mybad;
        mybad = 0;
        continue;
      }

      long diff = best._pingTime - n._pingTime;
      if (diff > slaveAcceptableLatencyMS
          ||
          // this is a complex way to make sure we get a random distribution of slaves
          ((badBeforeBest - mybad) / (_all.size() - 1)) > _random.nextDouble()) {
        best = n;
        badBeforeBest = mybad;
        mybad = 0;
      }
    }

    if (best == null) return null;
    return best._addr;
  }
コード例 #3
0
 Node getMasterNode() {
   _checkClosed();
   return _replicaSetHolder.get().getMaster();
 }