Skip to content

Commit

Permalink
Fixed - Can't find slave error in cluster mode if failed slave hasn't…
Browse files Browse the repository at this point in the history
… been added before. #593
  • Loading branch information
Nikita committed Aug 31, 2016
1 parent 564258d commit 60b1c8f
Showing 1 changed file with 7 additions and 8 deletions.
Expand Up @@ -296,9 +296,6 @@ public void run() {
if (nodesIterator == null) {
List<URI> nodes = new ArrayList<URI>();
List<URI> slaves = new ArrayList<URI>();
if (lastPartitions.isEmpty()) {
System.out.println("lastPartitions.isEmpty()");
}

for (ClusterPartition partition : getLastPartitions()) {
if (!partition.isMasterFail()) {
Expand Down Expand Up @@ -391,17 +388,18 @@ private void checkSlaveNodesChange(Collection<ClusterPartition> newPartitions) {

MasterSlaveEntry entry = getEntry(currentPart.getMasterAddr());
// should be invoked first in order to remove stale failedSlaveAddresses
addRemoveSlaves(entry, currentPart, newPart);
// Does some slaves change failed state to alive?
upDownSlaves(entry, currentPart, newPart);
Set<URI> addedSlaves = addRemoveSlaves(entry, currentPart, newPart);
// Do some slaves have changed state from failed to alive?
upDownSlaves(entry, currentPart, newPart, addedSlaves);

break;
}
}
}

private void upDownSlaves(final MasterSlaveEntry entry, final ClusterPartition currentPart, final ClusterPartition newPart) {
private void upDownSlaves(final MasterSlaveEntry entry, final ClusterPartition currentPart, final ClusterPartition newPart, Set<URI> addedSlaves) {
Set<URI> aliveSlaves = new HashSet<URI>(currentPart.getFailedSlaveAddresses());
aliveSlaves.removeAll(addedSlaves);
aliveSlaves.removeAll(newPart.getFailedSlaveAddresses());
for (URI uri : aliveSlaves) {
currentPart.removeFailedSlaveAddress(uri);
Expand All @@ -420,7 +418,7 @@ private void upDownSlaves(final MasterSlaveEntry entry, final ClusterPartition c
}
}

private void addRemoveSlaves(final MasterSlaveEntry entry, final ClusterPartition currentPart, final ClusterPartition newPart) {
private Set<URI> addRemoveSlaves(final MasterSlaveEntry entry, final ClusterPartition currentPart, final ClusterPartition newPart) {
Set<URI> removedSlaves = new HashSet<URI>(currentPart.getSlaveAddresses());
removedSlaves.removeAll(newPart.getSlaveAddresses());

Expand Down Expand Up @@ -450,6 +448,7 @@ public void operationComplete(Future<Void> future) throws Exception {
}
});
}
return addedSlaves;
}

private Collection<Integer> slots(Collection<ClusterPartition> partitions) {
Expand Down

0 comments on commit 60b1c8f

Please sign in to comment.