Source:
public ReplicaList calculateNaturalReplicas(Token token, TokenMetadata metadata) { ReplicaList replicas = new ReplicaList(rf.replicas); ArrayList<Token> tokens = metadata.sortedTokens(); if (tokens.isEmpty()) return replicas; Iterator<Token> iter = TokenMetadata.ringIterator(tokens, token, false); Token primaryToken = iter.next(); Token previousToken = metadata.getPredecessor(primaryToken); assert rf.trans == 0: "support transient replicas"; replicas.add(Replica.full(metadata.getEndpoint(primaryToken), previousToken, primaryToken)); boolean bDataCenter = false; boolean bOtherRack = false; while (replicas.size() < rf.replicas && iter.hasNext()) { Token t = iter.next(); if (!snitch.getDatacenter(metadata.getEndpoint(primaryToken)).equals(snitch.getDatacenter(metadata.getEndpoint(t)))) { if (!bDataCenter) { replicas.add(Replica.full(metadata.getEndpoint(t), previousToken, primaryToken)); bDataCenter = true; } continue; } if (!snitch.getRack(metadata.getEndpoint(primaryToken)).equals(snitch.getRack(metadata.getEndpoint(t))) && snitch.getDatacenter(metadata.getEndpoint(primaryToken)).equals(snitch.getDatacenter(metadata.getEndpoint(t)))) { if (!bOtherRack) { replicas.add(Replica.full(metadata.getEndpoint(t), previousToken, primaryToken)); bOtherRack = true; } } } if (replicas.size() < rf.replicas) { iter = TokenMetadata.ringIterator(tokens, token, false); while (replicas.size() < rf.replicas && iter.hasNext()) { Token t = iter.next(); Replica replica = Replica.full(metadata.getEndpoint(t), previousToken, primaryToken); if (!replicas.containsEndpoint(replica.getEndpoint())) replicas.add(replica); } } return replicas; }

Target:
public ReplicaList calculateNaturalReplicas(Token token, TokenMetadata metadata) { ReplicaList replicas = new ReplicaList(rf.replicas); ArrayList<Token> tokens = metadata.sortedTokens(); if (tokens.isEmpty()) return replicas; Iterator<Token> iter = TokenMetadata.ringIterator(tokens, token, false); Token primaryToken = iter.next(); Token previousToken = metadata.getPredecessor(primaryToken); assert rf.trans == 0: "support transient replicas"; replicas.add(new Replica(metadata.getEndpoint(primaryToken), previousToken, primaryToken, true)); boolean bDataCenter = false; boolean bOtherRack = false; while (replicas.size() < rf.replicas && iter.hasNext()) { Token t = iter.next(); if (!snitch.getDatacenter(metadata.getEndpoint(primaryToken)).equals(snitch.getDatacenter(metadata.getEndpoint(t)))) { if (!bDataCenter) { replicas.add(new Replica(metadata.getEndpoint(t), previousToken, primaryToken, true)); bDataCenter = true; } continue; } if (!snitch.getRack(metadata.getEndpoint(primaryToken)).equals(snitch.getRack(metadata.getEndpoint(t))) && snitch.getDatacenter(metadata.getEndpoint(primaryToken)).equals(snitch.getDatacenter(metadata.getEndpoint(t)))) { if (!bOtherRack) { replicas.add(new Replica(metadata.getEndpoint(t), previousToken, primaryToken, true)); bOtherRack = true; } } } if (replicas.size() < rf.replicas) { iter = TokenMetadata.ringIterator(tokens, token, false); while (replicas.size() < rf.replicas && iter.hasNext()) { Token t = iter.next(); Replica replica = new Replica(metadata.getEndpoint(t), previousToken, primaryToken, true); if (!replicas.containsEndpoint(replica.getEndpoint())) replicas.add(replica); } } return replicas; }