public boolean isSufficientLiveNodes(Keyspace keyspace, Iterable<InetAddress> liveEndpoints) { switch (this) { case ANY: // local hint is acceptable, and local node is always live return true; case LOCAL_ONE: return countLocalEndpoints(liveEndpoints) >= 1; case LOCAL_QUORUM: return countLocalEndpoints(liveEndpoints) >= blockFor(keyspace); case EACH_QUORUM: if (keyspace.getReplicationStrategy() instanceof NetworkTopologyStrategy) { for (Map.Entry<String, Integer> entry : countPerDCEndpoints(keyspace, liveEndpoints).entrySet()) { if (entry.getValue() < localQuorumFor(keyspace, entry.getKey())) return false; } return true; } // Fallthough on purpose for SimpleStrategy default: return Iterables.size(liveEndpoints) >= blockFor(keyspace); } }
public static ConsistencyLevel readConsistencyLevel(ByteBuf cb) { return ConsistencyLevel.fromCode(cb.readUnsignedShort()); }
public void assureSufficientLiveNodes() throws UnavailableException { consistencyLevel.assureSufficientLiveNodes(keyspace, endpoints); }
@Override protected int totalBlockFor() { // during bootstrap, include pending endpoints (only local here) in the count // or we may fail the consistency level guarantees (see #833, #8058) return consistencyLevel.blockFor(keyspace) + consistencyLevel.countLocalEndpoints(pendingEndpoints); }
return filterForEachQuorum(keyspace, liveEndpoints, readRepair); return liveEndpoints.subList(0, Math.min(liveEndpoints.size(), blockFor(keyspace))); case GLOBAL: return liveEndpoints; for (InetAddress add : liveEndpoints) if (isLocal(add)) local.add(add); else int blockFor = blockFor(keyspace); if (local.size() < blockFor) local.addAll(other.subList(0, Math.min(blockFor - local.size(), other.size())));
? ReadRepairDecision.NONE : command.metadata().newReadRepairDecision(); List<InetAddress> targetReplicas = consistencyLevel.filterForQuery(keyspace, allReplicas, repairDecision); consistencyLevel.assureSufficientLiveNodes(keyspace, targetReplicas); || consistencyLevel.blockFor(keyspace) == allReplicas.size()) return new NeverSpeculatingReadExecutor(keyspace, command, consistencyLevel, targetReplicas, queryStartNanoTime);
public long serializedSize(CounterMutation cm, int version) { return Mutation.serializer.serializedSize(cm.mutation, version) + TypeSizes.sizeof(cm.consistency.name()); } }
if (!consistency.isSufficientLiveNodes(keyspace, merged)) break; List<InetAddress> filteredMerged = consistency.filterForQuery(keyspace, merged);
return liveEndpoints.subList(0, Math.min(liveEndpoints.size(), blockFor(keyspace))); case GLOBAL: return liveEndpoints; for (InetAddress add : liveEndpoints) if (isLocal(add)) local.add(add); else int blockFor = blockFor(keyspace); if (local.size() < blockFor) local.addAll(other.subList(0, Math.min(blockFor - local.size(), other.size())));
/** * @return the minimum number of endpoints that must reply. */ protected int totalBlockFor() { // During bootstrap, we have to include the pending endpoints or we may fail the consistency level // guarantees (see #833) return consistencyLevel.blockFor(keyspace) + pendingEndpoints.size(); }
: nextEndpoints; List<InetAddress> filteredEndpoints = nextFilteredEndpoints == null ? consistency_level.filterForQuery(keyspace, liveEndpoints) : nextFilteredEndpoints; ++i; nextFilteredEndpoints = consistency_level.filterForQuery(keyspace, nextEndpoints); if (!consistency_level.isSufficientLiveNodes(keyspace, merged)) break; List<InetAddress> filteredMerged = consistency_level.filterForQuery(keyspace, merged); List<InetAddress> minimalEndpoints = filteredEndpoints.subList(0, Math.min(filteredEndpoints.size(), consistency_level.blockFor(keyspace))); ReadCallback<RangeSliceReply, Iterable<Row>> handler = new ReadCallback<>(resolver, consistency_level, nodeCmd, minimalEndpoints); handler.assureSufficientLiveNodes(); int blockFor = consistency_level.blockFor(keyspace); int responseCount = resolver.responses.size(); String gotData = responseCount > 0 int blockFor = consistency_level.blockFor(keyspace); if (Tracing.isTracing()) Tracing.trace("Timed out while read-repairing after receiving all {} data and digest responses", blockFor);
throw new UnavailableException(cl, cl.blockFor(keyspace), 0); if (cl.isDatacenterLocal()) throw new UnavailableException(cl, cl.blockFor(keyspace), 0);
public DatacenterWriteResponseHandler(Collection<InetAddress> naturalEndpoints, Collection<InetAddress> pendingEndpoints, ConsistencyLevel consistencyLevel, Keyspace keyspace, Runnable callback, WriteType writeType, long queryStartNanoTime) { super(naturalEndpoints, pendingEndpoints, consistencyLevel, keyspace, callback, writeType, queryStartNanoTime); assert consistencyLevel.isDatacenterLocal(); }
public int countLocalEndpoints(Iterable<InetAddress> liveEndpoints) { int count = 0; for (InetAddress endpoint : liveEndpoints) if (isLocal(endpoint)) count++; return count; }
protected RangeForQuery computeNext() { if (!ranges.hasNext()) { return endOfData(); } AbstractBounds<PartitionPosition> range = ranges.next(); List<InetAddress> liveEndpoints = StorageProxy.getLiveSortedEndpoints(keyspace, range.right); return new RangeForQuery(range, liveEndpoints, consistency.filterForQuery(keyspace, liveEndpoints)); } }
return filterForEachQuorum(keyspace, liveEndpoints, readRepair); return liveEndpoints.subList(0, Math.min(liveEndpoints.size(), blockFor(keyspace))); case GLOBAL: return liveEndpoints; for (InetAddress add : liveEndpoints) if (isLocal(add)) local.add(add); else int blockFor = blockFor(keyspace); if (local.size() < blockFor) local.addAll(other.subList(0, Math.min(blockFor - local.size(), other.size())));
? ReadRepairDecision.NONE : command.metadata().newReadRepairDecision(); List<InetAddress> targetReplicas = consistencyLevel.filterForQuery(keyspace, allReplicas, repairDecision); consistencyLevel.assureSufficientLiveNodes(keyspace, targetReplicas); || consistencyLevel.blockFor(keyspace) == allReplicas.size()) return new NeverSpeculatingReadExecutor(keyspace, command, consistencyLevel, targetReplicas, queryStartNanoTime);
public long serializedSize(CounterMutation cm, int version) { return Mutation.serializer.serializedSize(cm.mutation, version) + TypeSizes.sizeof(cm.consistency.name()); } }
if (!consistency.isSufficientLiveNodes(keyspace, merged)) break; List<InetAddress> filteredMerged = consistency.filterForQuery(keyspace, merged);
/** * @return the minimum number of endpoints that must reply. */ protected int totalBlockFor() { // During bootstrap, we have to include the pending endpoints or we may fail the consistency level // guarantees (see #833) return consistencyLevel.blockFor(keyspace) + pendingEndpoints.size(); }