Github user ifesdjeen commented on a diff in the pull request:
https://github.com/apache/cassandra/pull/224#discussion_r197133241
--- Diff: src/java/org/apache/cassandra/service/StorageProxy.java ---
@@ -344,47 +343,43 @@ private static void recordCasContention(int
contentions)
casWriteMetrics.contention.update(contentions);
}
- private static Predicate<InetAddressAndPort> sameDCPredicateFor(final
String dc)
+ private static Predicate<Replica> sameDCPredicateFor(final String dc)
{
final IEndpointSnitch snitch =
DatabaseDescriptor.getEndpointSnitch();
- return new Predicate<InetAddressAndPort>()
- {
- public boolean apply(InetAddressAndPort host)
- {
- return dc.equals(snitch.getDatacenter(host));
- }
- };
+ return replica -> dc.equals(snitch.getDatacenter(replica));
}
private static PaxosParticipants getPaxosParticipants(TableMetadata
metadata, DecoratedKey key, ConsistencyLevel consistencyForPaxos) throws
UnavailableException
{
Token tk = key.getToken();
- List<InetAddressAndPort> naturalEndpoints =
StorageService.instance.getNaturalEndpoints(metadata.keyspace, tk);
- Collection<InetAddressAndPort> pendingEndpoints =
StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk,
metadata.keyspace);
+ ReplicaList naturalReplicas =
StorageService.instance.getNaturalReplicas(metadata.keyspace, tk);
+ ReplicaList pendingReplicas = new
ReplicaList(StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk,
metadata.keyspace));
if (consistencyForPaxos == ConsistencyLevel.LOCAL_SERIAL)
{
- // Restrict naturalEndpoints and pendingEndpoints to node in
the local DC only
+ // Restrict naturalReplicas and pendingReplicas to node in the
local DC only
String localDc =
DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddressAndPort());
- Predicate<InetAddressAndPort> isLocalDc =
sameDCPredicateFor(localDc);
- naturalEndpoints =
ImmutableList.copyOf(Iterables.filter(naturalEndpoints, isLocalDc));
- pendingEndpoints =
ImmutableList.copyOf(Iterables.filter(pendingEndpoints, isLocalDc));
+ Predicate<Replica> isLocalDc = sameDCPredicateFor(localDc);
+ naturalReplicas =
ReplicaList.immutableCopyOf(naturalReplicas.filter(isLocalDc));
+ pendingReplicas =
ReplicaList.immutableCopyOf(pendingReplicas.filter(isLocalDc));
}
- int participants = pendingEndpoints.size() +
naturalEndpoints.size();
+ int participants = pendingReplicas.size() + naturalReplicas.size();
int requiredParticipants = participants / 2 + 1; // See
CASSANDRA-8346, CASSANDRA-833
- List<InetAddressAndPort> liveEndpoints =
ImmutableList.copyOf(Iterables.filter(Iterables.concat(naturalEndpoints,
pendingEndpoints), IAsyncCallback.isAlive));
- if (liveEndpoints.size() < requiredParticipants)
- throw new UnavailableException(consistencyForPaxos,
requiredParticipants, liveEndpoints.size());
+
+ Replicas concatenated =
Replicas.concatNaturalAndPending(naturalReplicas, pendingReplicas);
+ ReplicaList liveReplicas =
ReplicaList.immutableCopyOf(Replicas.filter(concatenated,
IAsyncCallback.isReplicaAlive));
--- End diff --
Same here (with Immutable).
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]