public BootstrapState() { }
public RemoteCluster finish(TimeMaster timeMaster, NodeState localState)
{
List<RemoteClusterNode> overlapping = new ArrayList<RemoteClusterNode>();
final KeyRange localRange = localState.totalRange();
for (RemoteClusterNode node : _nodes.values()) {
if (localRange.overlapsWith(node.getTotalRange())) {
overlapping.add(node);
}
}
if (overlapping.isEmpty()) {
return null;
}
// Also, need to sort in descending order of preference
Collections.sort(overlapping, new Comparator<RemoteClusterNode>() {
@Override
public int compare(RemoteClusterNode c1, RemoteClusterNode c2) {
KeyRange r1 = c1.getTotalRange();
// First, exact match is the usual way, preferred
if (r1.equals(localRange)) {
return -1;
}
KeyRange r2 = c2.getTotalRange();
if (r2.equals(localRange)) {
return 1;
}
// If not, let's actually base it on stable clockwise-distance between
// starting points, such that we'll try to find range that starts as soon
// as possible _after_ local range
int dist1 = localRange.clockwiseDistance(r1);
int dist2 = localRange.clockwiseDistance(r2);
if (dist1 != dist2) {
return dist1 - dist2;
}
// And if this still doesn't resolve, choose one with _smaller_ range; assumption
// is that most likely cluster is growing, and smaller range indicates newer
// information
int diff = r1.getLength() - r2.getLength();
if (diff != 0) { // sort from smaller to bigger
return diff;
}
// and otherwise use simple lexicographic (~= alphabetic) ordering of endpoint IP