From 3380fa7baf76998b7c2fdbcb85b23fa3f0099f7c Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Sun, 1 Sep 2013 14:34:11 -0500 Subject: [PATCH] Allow local batchlog writes for CL.ANY patch by jbellis; reviewed by Aleksey for CASSANDRA-5967 --- CHANGES.txt | 1 + src/java/org/apache/cassandra/service/StorageProxy.java | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1943217cf3..89f66a8ffd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 1.2.10 + * Allow local batchlog writes for CL.ANY (CASSANDRA-5967) * Optimize name query performance in wide rows (CASSANDRA-5966) * Upgrade metrics-core to version 2.2.0 (CASSANDRA-5947) * Add snitch, schema version, cluster, partitioner to JMX (CASSANDRA-5881) diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index ec27891f63..94db26d23c 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -261,7 +261,7 @@ public class StorageProxy implements StorageProxyMBean } // write to the batchlog - Collection batchlogEndpoints = getBatchlogEndpoints(localDataCenter); + Collection batchlogEndpoints = getBatchlogEndpoints(localDataCenter, consistency_level); UUID batchUUID = UUID.randomUUID(); syncWriteToBatchlog(mutations, batchlogEndpoints, batchUUID); @@ -418,7 +418,7 @@ public class StorageProxy implements StorageProxyMBean * - choose min(2, number of qualifying candiates above) * - allow the local node to be the only replica only if it's a single-node cluster */ - private static Collection getBatchlogEndpoints(String localDataCenter) throws UnavailableException + private static Collection getBatchlogEndpoints(String localDataCenter, ConsistencyLevel consistencyLevel) throws UnavailableException { // will include every known node in the DC, including localhost. TokenMetadata.Topology topology = StorageService.instance.getTokenMetadata().cloneOnlyTokenMap().getTopology(); @@ -440,7 +440,12 @@ public class StorageProxy implements StorageProxyMBean } if (candidates.isEmpty()) + { + if (consistencyLevel == ConsistencyLevel.ANY) + return Collections.singleton(FBUtilities.getBroadcastAddress()); + throw new UnavailableException(ConsistencyLevel.ONE, 1, 0); + } if (candidates.size() > 2) {