From 1dc157afe7da3dce57f7657e445ba12f16073d49 Mon Sep 17 00:00:00 2001 From: Aleksey Yeschenko Date: Tue, 3 Jun 2014 18:51:20 +0300 Subject: [PATCH 1/2] Fix handling of empty counter replication mutations patch by Aleksey Yeschenko; reviewed by Richard Low for CASSANDRA-7144 --- CHANGES.txt | 1 + .../org/apache/cassandra/db/CounterMutation.java | 3 ++- .../org/apache/cassandra/service/StorageProxy.java | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index e45cc7268e..8014170a69 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 1.2.17 + * Fix handling of empty counter replication mutations (CASSANDRA-7144) * Use LOCAL_ONE for non-superuser auth queries (CASSANDRA-7328) * Set keepalive on MessagingService connections (CASSANDRA-7170) * Add Cloudstack snitch (CASSANDRA-7147) diff --git a/src/java/org/apache/cassandra/db/CounterMutation.java b/src/java/org/apache/cassandra/db/CounterMutation.java index 62ea3f7d82..76aaeb5c56 100644 --- a/src/java/org/apache/cassandra/db/CounterMutation.java +++ b/src/java/org/apache/cassandra/db/CounterMutation.java @@ -96,7 +96,8 @@ public class CounterMutation implements IMutation cf.retainAll(rowMutation.getColumnFamily(cf.metadata().cfId)); replicationMutation.add(cf); } - return replicationMutation; + + return replicationMutation.isEmpty() ? null : replicationMutation; } private void addReadCommandFromColumnFamily(String table, ByteBuffer key, ColumnFamily columnFamily, List commands) diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index 7ef3d72fe3..3c3c052ae1 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -781,8 +781,18 @@ public class StorageProxy implements StorageProxyMBean { public void runMayThrow() throws OverloadedException { - // send mutation to other replica - sendToHintedEndpoints(cm.makeReplicationMutation(), remotes, responseHandler, localDataCenter, consistency_level); + // send the mutation to other replicas, if not null (see CASSANDRA-7144 for details) + RowMutation replicationMutation = cm.makeReplicationMutation(); + if (replicationMutation != null) + { + sendToHintedEndpoints(cm.makeReplicationMutation(), remotes, responseHandler, localDataCenter, consistency_level); + } + else + { + // simulate the rest of the responses to avoid the timeout + for (int i = 0; i < remotes.size(); i++) + responseHandler.response(null); + } } }); } From 12a7a7ebfcdbcbde0fea244c3b9ab95cd7cf68e5 Mon Sep 17 00:00:00 2001 From: Aleksey Yeschenko Date: Tue, 3 Jun 2014 18:59:18 +0300 Subject: [PATCH 2/2] CASSANDRA-7144 follow-up --- src/java/org/apache/cassandra/service/StorageProxy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index 3c3c052ae1..d17dea950d 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -785,7 +785,7 @@ public class StorageProxy implements StorageProxyMBean RowMutation replicationMutation = cm.makeReplicationMutation(); if (replicationMutation != null) { - sendToHintedEndpoints(cm.makeReplicationMutation(), remotes, responseHandler, localDataCenter, consistency_level); + sendToHintedEndpoints(replicationMutation, remotes, responseHandler, localDataCenter, consistency_level); } else {