Fail all replication operations with the exception that this node is no longer the replica with the sent index
9642
private void nodeNotOwnsBackup(InternalPartitionImpl partition) {
        int partitionId = getPartitionId();
        int replicaIndex = getReplicaIndex();
        NodeEngine nodeEngine = getNodeEngine();

        ILogger logger = getLogger();
        if (logger.isFinestEnabled()) {
            int currentReplicaIndex = partition.getReplicaIndex(PartitionReplica.from(nodeEngine.getLocalMember()));
            logger.finest(
                    "This node is not backup replica of partitionId=" + partitionId + ", replicaIndex=" + replicaIndex
                            + " anymore. current replicaIndex=" + currentReplicaIndex);
        }

        if (operations != null) {
            PartitionReplica replica = partition.getReplica(replicaIndex);
            Member targetMember = null;
            if (replica != null) {
                ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService();
                targetMember = clusterService.getMember(replica.address(), replica.uuid());
            }
            Throwable throwable = new WrongTargetException(nodeEngine.getLocalMember(), targetMember, partitionId,
                    replicaIndex, getClass().getName());
            for (Operation op : operations) {
                prepareOperation(op);
                onOperationFailure(op, throwable);
            }
        }
    }
593269
protected void retryReplicationIfError() {
        Log.d(TAG, "retryReplicationIfError() state=" + stateMachine.getState() +
                ", error=" + this.error +
                ", isContinuous()=" + isContinuous() +
                ", isTransientError()=" + Utils.isTransientError(this.error));

        // Make sure if state is IDLE, this method should be called when state becomes IDLE
        if (!stateMachine.getState().equals(ReplicationState.IDLE))
            return;

        if (this.error != null) {
            // IDLE_ERROR
            if (isContinuous()) {
                // 12/16/2014 - only retry if error is transient error 50x http error
                // It may need to retry for any kind of errors
                if (Utils.isTransientError(this.error)) {
                    onBeforeScheduleRetry();
                    cancelRetryFuture();
                    scheduleRetryFuture();
                }
            }
        }
    }
1260976
def _stop_all_nodes(self, wait=False):
        
        failed = 0
        for node in self.get_all_nodes():
            if not node.instance_id:
                log.warning(
                    "Node `%s` has no instance ID."
                    " Assuming it did not start correctly,"
                    " so removing it anyway from the cluster.", node.name)
                self.nodes[node.kind].remove(node)
                continue
            # try and stop node
            try:
                # wait and pause for and recheck.
                node.stop(wait)

                self.nodes[node.kind].remove(node)
                log.debug(
                    "Removed node `%s` from cluster `%s`", node.name, self.name)
            except InstanceNotFoundError as err:
                log.info(
                    "Node `%s` (instance ID `%s`) was not found;"
                    " assuming it has already been terminated.",
                    node.name, node.instance_id)
            except Exception as err:
                failed += 1
                log.error(
                    "Could not stop node `%s` (instance ID `%s`): %s %s",
                    node.name, node.instance_id, err, err.__class__)
        return failed
387096
def _with_retries(self, pool, fn):
        
        skip_nodes = []

        def _skip_bad_nodes(transport):
            return transport._node not in skip_nodes

        retry_count = self.retries - 1
        first_try = True
        current_try = 0
        while True:
            try:
                with pool.transaction(
                        _filter=_skip_bad_nodes,
                        yield_resource=True) as resource:
                    transport = resource.object
                    try:
                        return fn(transport)
                    except (IOError, HTTPException, ConnectionClosed) as e:
                        resource.errored = True
                        if _is_retryable(e):
                            transport._node.error_rate.incr(1)
                            skip_nodes.append(transport._node)
                            if first_try:
                                continue
                            else:
                                raise BadResource(e)
                        else:
                            raise
            except BadResource as e:
                if current_try < retry_count:
                    resource.errored = True
                    current_try += 1
                    continue
                else:
                    # Re-raise the inner exception
                    raise e.args[0]
            finally:
                first_try = False
174204
function executeWriteOperation(args, options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = options || {};

  // TODO: once we drop Node 4, use destructuring either here or in arguments.
  const self = args.self;
  const op = args.op;
  const ns = args.ns;
  const ops = args.ops;

  if (self.state === DESTROYED) {
    return callback(new MongoError(f('topology was destroyed')));
  }

  const willRetryWrite =
    !args.retrying &&
    !!options.retryWrites &&
    options.session &&
    isRetryableWritesSupported(self) &&
    !options.session.inTransaction();

  if (!self.s.replicaSetState.hasPrimary()) {
    if (self.s.disconnectHandler) {
      // Not connected but we have a disconnecthandler
      return self.s.disconnectHandler.add(op, ns, ops, options, callback);
    } else if (!willRetryWrite) {
      // No server returned we had an error
      return callback(new MongoError('no primary server found'));
    }
  }

  const handler = (err, result) => {
    if (!err) return callback(null, result);
    if (!isRetryableError(err)) {
      return callback(err);
    }

    if (willRetryWrite) {
      const newArgs = Object.assign({}, args, { retrying: true });
      return executeWriteOperation(newArgs, options, callback);
    }

    // Per SDAM, remove primary from replicaset
    if (self.s.replicaSetState.primary) {
      self.s.replicaSetState.remove(self.s.replicaSetState.primary, { force: true });
    }

    return callback(err);
  };

  if (callback.operationId) {
    handler.operationId = callback.operationId;
  }

  // increment and assign txnNumber
  if (willRetryWrite) {
    options.session.incrementTransactionNumber();
    options.willRetryWrite = willRetryWrite;
  }

  self.s.replicaSetState.primary[op](ns, ops, options, handler);
}
1199951
def fail_remaining(self):
        
        self._failed.update(self._graph.nodes)
        self._graph = Graph()
        self._running = set()
1046937
def replace(self, source, dest):
        """"""
        for i, broker in enumerate(self.replicas):
            if broker == source:
                self.replicas[i] = dest
                return
1246523
public void updateIndex(Set<String> addedNodes, Set<String> removedNodes, Set<String> parentAddedNodes,
      Set<String> parentRemovedNodes)
   {
      // pass lists to search manager 
      if (searchManager != null && (addedNodes.size() > 0 || removedNodes.size() > 0))
      {
         try
         {
            searchManager.updateIndex(removedNodes, addedNodes);
         }
         catch (RepositoryException e)
         {
            log.error("Error indexing changes " + e, e);
         }
         catch (IOException e)
         {
            log.error("Error indexing changes " + e, e);
            try
            {
               handler.logErrorChanges(removedNodes, addedNodes);
            }
            catch (IOException ioe)
            {
               log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
            }
         }
      }
      // pass lists to parent search manager 
      if (parentSearchManager != null && (parentAddedNodes.size() > 0 || parentRemovedNodes.size() > 0))
      {
         try
         {
            parentSearchManager.updateIndex(parentRemovedNodes, parentAddedNodes);
         }
         catch (RepositoryException e)
         {
            log.error("Error indexing changes " + e, e);
         }
         catch (IOException e)
         {
            log.error("Error indexing changes " + e, e);
            try
            {
               parentHandler.logErrorChanges(parentRemovedNodes, parentAddedNodes);
            }
            catch (IOException ioe)
            {
               log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
            }
         }
      }
   }
557718
def process_backup_instance_faulty_msg(self,
                                           backup_faulty: BackupInstanceFaulty,
                                           frm: str) -> None:
        '''
        
        '''
        logger.debug("{} receive BackupInstanceFaulty "
                     "from {}: {}".format(self.node, frm, backup_faulty))
        instances = getattr(backup_faulty, f.INSTANCES.nm)
        if getattr(backup_faulty, f.VIEW_NO.nm) != self.node.viewNo or \
                self.node.master_replica.instId in instances:
            return

        # Don't process BackupInstanceFaulty if strategy for this reason is not need quorum
        reason = Suspicions.get_by_code(getattr(backup_faulty, f.REASON.nm))
        if (
                reason == Suspicions.BACKUP_PRIMARY_DISCONNECTED and
                not self.is_quorum_strategy(self.node.config.REPLICAS_REMOVING_WITH_PRIMARY_DISCONNECTED)
        ) or (
                reason == Suspicions.BACKUP_PRIMARY_DEGRADED and
                not self.is_quorum_strategy(self.node.config.REPLICAS_REMOVING_WITH_DEGRADATION)
        ):
            return

        for inst_id in getattr(backup_faulty, f.INSTANCES.nm):
            if inst_id not in self.node.replicas.keys():
                continue
            self.backup_instances_faulty.setdefault(inst_id, dict()).setdefault(frm, 0)
            self.backup_instances_faulty[inst_id][frm] += 1
            all_nodes_condition = self.node.quorums.backup_instance_faulty.is_reached(
                len(self.backup_instances_faulty[inst_id].keys()))
            this_node_condition = (self.node.name in self.backup_instances_faulty[inst_id] and
                                   self.node.quorums.backup_instance_faulty.is_reached(
                                       self.backup_instances_faulty[inst_id][self.node.name]))
            if all_nodes_condition or this_node_condition:
                self.node.replicas.remove_replica(inst_id)
                self.backup_instances_faulty.pop(inst_id)
108632
void stopDecommission(DatanodeDescriptor node)
    throws IOException {
    if ((node.isDecommissionInProgress() &&
      ((Monitor) dnthread.getRunnable()).stopDecommission(node)) ||
      node.isDecommissioned()) {
      LOG.info("Stop Decommissioning node " + node.getName());
      synchronized (heartbeats) {
        updateStats(node, false);
        node.stopDecommission();
        updateStats(node, true);
      }

      // Make sure we process over replicated blocks.
      writeLock();
      try {
        Iterator<BlockInfo> it = node.getBlockIterator();
        while (it.hasNext()) {
          Block b = it.next();
          if (countLiveNodes(b) > getReplication(b)) {
            overReplicatedBlocks.add(b);
          }
        }
      } finally {
        writeUnlock();
      }
    }
  }
986106
@Nonnull
  @VisibleForTesting
  List<CompletableFuture<AppendEntriesResponse>> sendRequests(final RaftStateContext ctx) {

    List<CompletableFuture<AppendEntriesResponse>> responses =
        managers.values().stream()
            .map(ReplicaManager::requestUpdate)
            .collect(toList());

    responses.forEach(response ->
        response.thenAccept(result -> {
          updateCommitted();
          checkTermOnResponse(ctx, result);
        }));


    // Cope if we're the only node in the cluster.
    if (responses.isEmpty()) {
      updateCommitted();
    }

    return responses;
  }
580773
def resend_sent(self, route_family, peer):
        
        if peer not in self._peers.values():
            raise ValueError('Could not find given peer (%s)' % peer)

        if route_family not in SUPPORTED_GLOBAL_RF:
            raise ValueError(
                'Given route family (%s) is not supported.' % route_family
            )

        # Iterate over the global table for given afi, safi and enqueue
        # out-going routes.
        table = self._table_manager.get_global_table_by_route_family(
            route_family
        )

        for destination in table.values():
            # Check if this destination's sent - routes include this peer.
            # i.e. check if this destinations was advertised and enqueue
            # the path only if it was. If the current best-path has not been
            # advertised before, it might already have a OutgoingRoute queued
            # to be sent to the peer.
            sent_routes = destination.sent_routes
            if sent_routes is None or len(sent_routes) == 0:
                continue
            for sent_route in sent_routes:
                if sent_route.sent_peer == peer:
                    # update med - if previously med was set per neighbor or
                    # wasn't set at all now it could have changed and we may
                    # need to set new value there
                    p = sent_route.path
                    if p.med_set_by_target_neighbor or p.get_pattr(
                            BGP_ATTR_TYPE_MULTI_EXIT_DISC) is None:
                        sent_route.path = \
                            clone_path_and_update_med_for_target_neighbor(
                                sent_route.path, peer.med
                            )

                    ogr = OutgoingRoute(sent_route.path,
                                        for_route_refresh=True)
                    peer.enque_outgoing_msg(ogr)
419713
def _get_node(self, node_id):
        """"""
        self.non_terminated_nodes({})  # Side effect: updates cache

        if node_id in self.cached_nodes:
            return self.cached_nodes[node_id]

        # Node not in {pending, running} -- retry with a point query. This
        # usually means the node was recently preempted or terminated.
        matches = list(self.ec2.instances.filter(InstanceIds=[node_id]))
        assert len(matches) == 1, "Invalid instance id {}".format(node_id)
        return matches[0]
528367
private void failIndex(PhaseThreeOptions phasecfg, String errorMessage) {
        stageError(errorMessage);
        final StringBuilder bldr = new StringBuilder();
        bldr.append("Could not find resource index file.");
        bldr.append("Expansion of protein families, named complexes, ");
        bldr.append("gene scaffolding, and orthology will not occur.");
        stageError(bldr.toString());
        ResourceIndex.INSTANCE.loadIndex();
        phasecfg.setInjectProteinFamilies(false);
        phasecfg.setInjectNamedComplexes(false);
        phasecfg.setInjectGeneScaffolding(false);
        phasecfg.setInjectOrthology(false);
    }
923097
protected void handleAppendResponseOk(MemberState member, AppendRequest request, AppendResponse response) {
    // Reset the member failure count and update the member's availability status if necessary.
    succeedAttempt(member);

    // If replication succeeded then trigger commit futures.
    if (response.succeeded()) {
      updateMatchIndex(member, response);

      // If there are more entries to send then attempt to send another commit.
      if (request.logIndex() != response.logIndex() && hasMoreEntries(member)) {
        appendEntries(member);
      }
    }
    // If we've received a greater term, update the term and transition back to follower.
    else if (response.term() > context.getTerm()) {
      context.setTerm(response.term()).setLeader(0);
      context.transition(CopycatServer.State.FOLLOWER);
    }
    // If the response failed, the follower should have provided the correct last index in their log. This helps
    // us converge on the matchIndex faster than by simply decrementing nextIndex one index at a time.
    else {
      resetMatchIndex(member, response);
      resetNextIndex(member);

      // If there are more entries to send then attempt to send another commit.
      if (response.logIndex() != request.logIndex() && hasMoreEntries(member)) {
        appendEntries(member);
      }
    }
  }
793071
protected void updatePeerEurekaNodes(List<String> newPeerUrls) {
        if (newPeerUrls.isEmpty()) {
            logger.warn("The replica size seems to be empty. Check the route 53 DNS Registry");
            return;
        }

        Set<String> toShutdown = new HashSet<>(peerEurekaNodeUrls);
        toShutdown.removeAll(newPeerUrls);
        Set<String> toAdd = new HashSet<>(newPeerUrls);
        toAdd.removeAll(peerEurekaNodeUrls);

        if (toShutdown.isEmpty() && toAdd.isEmpty()) { // No change
            return;
        }

        // Remove peers no long available
        List<PeerEurekaNode> newNodeList = new ArrayList<>(peerEurekaNodes);

        if (!toShutdown.isEmpty()) {
            logger.info("Removing no longer available peer nodes {}", toShutdown);
            int i = 0;
            while (i < newNodeList.size()) {
                PeerEurekaNode eurekaNode = newNodeList.get(i);
                if (toShutdown.contains(eurekaNode.getServiceUrl())) {
                    newNodeList.remove(i);
                    eurekaNode.shutDown();
                } else {
                    i++;
                }
            }
        }

        // Add new peers
        if (!toAdd.isEmpty()) {
            logger.info("Adding new peer nodes {}", toAdd);
            for (String peerUrl : toAdd) {
                newNodeList.add(createPeerEurekaNode(peerUrl));
            }
        }

        this.peerEurekaNodes = newNodeList;
        this.peerEurekaNodeUrls = new HashSet<>(newPeerUrls);
    }
1341585
public InvocationBuilder setReplicaIndex(int replicaIndex) {
        if (replicaIndex < 0 || replicaIndex >= InternalPartition.MAX_REPLICA_COUNT) {
            throw new IllegalArgumentException("Replica index is out of range [0-"
                    + (InternalPartition.MAX_REPLICA_COUNT - 1) + "]");
        }
        this.replicaIndex = replicaIndex;
        return this;
    }