cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [1/5] git commit: Fix the consistencylevel during bootstrap fix
Date Tue, 19 Mar 2013 20:51:07 GMT
Fix the consistencylevel during bootstrap fix

patch by slebresne; reviewed by jbellis for CASSANDRA-5354


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4d29c709
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4d29c709
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4d29c709

Branch: refs/heads/trunk
Commit: 4d29c709a88b2c6d55011554e79205115277dc65
Parents: 28be383
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Mon Mar 18 14:45:07 2013 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Mon Mar 18 14:45:07 2013 +0100

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../service/AbstractWriteResponseHandler.java      |    9 ++++++-
 .../DatacenterSyncWriteResponseHandler.java        |   18 ++++++++------
 .../cassandra/service/WriteResponseHandler.java    |    4 +-
 4 files changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/4d29c709/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b3fbf9b..6ce5912 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,6 @@
 1.2.4
  * Fix mixing prepared statements between keyspaces (CASSANDRA-5352)
+ * Fix consistency level during bootstrap - strike 3 (CASSANDRA-5354)
 
 1.2.3
  * add check for sstable overlap within a level on startup (CASSANDRA-5327)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4d29c709/src/java/org/apache/cassandra/service/AbstractWriteResponseHandler.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/AbstractWriteResponseHandler.java b/src/java/org/apache/cassandra/service/AbstractWriteResponseHandler.java
index c792819..4df9e1f 100644
--- a/src/java/org/apache/cassandra/service/AbstractWriteResponseHandler.java
+++ b/src/java/org/apache/cassandra/service/AbstractWriteResponseHandler.java
@@ -88,7 +88,14 @@ public abstract class AbstractWriteResponseHandler implements IAsyncCallback
         }
 
         if (!success)
-            throw new WriteTimeoutException(writeType, consistencyLevel, ackCount(), consistencyLevel.blockFor(table)
+ pendingEndpoints.size());
+            throw new WriteTimeoutException(writeType, consistencyLevel, ackCount(), totalBlockFor());
+    }
+
+    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(table) + pendingEndpoints.size();
     }
 
     protected abstract int ackCount();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4d29c709/src/java/org/apache/cassandra/service/DatacenterSyncWriteResponseHandler.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/DatacenterSyncWriteResponseHandler.java
b/src/java/org/apache/cassandra/service/DatacenterSyncWriteResponseHandler.java
index 55e833d..ee1e5d6 100644
--- a/src/java/org/apache/cassandra/service/DatacenterSyncWriteResponseHandler.java
+++ b/src/java/org/apache/cassandra/service/DatacenterSyncWriteResponseHandler.java
@@ -45,6 +45,7 @@ public class DatacenterSyncWriteResponseHandler extends AbstractWriteResponseHan
 
     private final NetworkTopologyStrategy strategy;
     private final HashMap<String, AtomicInteger> responses = new HashMap<String,
AtomicInteger>();
+    private final AtomicInteger acks = new AtomicInteger(0);
 
     public DatacenterSyncWriteResponseHandler(Collection<InetAddress> naturalEndpoints,
                                               Collection<InetAddress> pendingEndpoints,
@@ -64,6 +65,13 @@ public class DatacenterSyncWriteResponseHandler extends AbstractWriteResponseHan
             int rf = strategy.getReplicationFactor(dc);
             responses.put(dc, new AtomicInteger((rf / 2) + 1));
         }
+
+        // During bootstrap, we have to include the pending endpoints or we may fail the
consistency level
+        // guarantees (see #833)
+        for (InetAddress pending : pendingEndpoints)
+        {
+            responses.get(snitch.getDatacenter(pending)).incrementAndGet();
+        }
     }
 
     public void response(MessageIn message)
@@ -73,6 +81,7 @@ public class DatacenterSyncWriteResponseHandler extends AbstractWriteResponseHan
                             : snitch.getDatacenter(message.from);
 
         responses.get(dataCenter).getAndDecrement();
+        acks.incrementAndGet();
 
         for (AtomicInteger i : responses.values())
         {
@@ -86,14 +95,7 @@ public class DatacenterSyncWriteResponseHandler extends AbstractWriteResponseHan
 
     protected int ackCount()
     {
-        int n = 0;
-        for (Map.Entry<String, AtomicInteger> entry : responses.entrySet())
-        {
-            String dc = entry.getKey();
-            AtomicInteger i = entry.getValue();
-            n += (strategy.getReplicationFactor(dc) / 2) + 1 - i.get();
-        }
-        return n;
+        return acks.get();
     }
 
     public boolean isLatencyForSnitch()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4d29c709/src/java/org/apache/cassandra/service/WriteResponseHandler.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/WriteResponseHandler.java b/src/java/org/apache/cassandra/service/WriteResponseHandler.java
index 1c229d5..6c1440b 100644
--- a/src/java/org/apache/cassandra/service/WriteResponseHandler.java
+++ b/src/java/org/apache/cassandra/service/WriteResponseHandler.java
@@ -51,7 +51,7 @@ public class WriteResponseHandler extends AbstractWriteResponseHandler
                                 WriteType writeType)
     {
         super(table, writeEndpoints, pendingEndpoints, consistencyLevel, callback, writeType);
-        responses = new AtomicInteger(consistencyLevel.blockFor(table));
+        responses = new AtomicInteger(totalBlockFor());
     }
 
     public WriteResponseHandler(InetAddress endpoint, WriteType writeType, Runnable callback)
@@ -72,7 +72,7 @@ public class WriteResponseHandler extends AbstractWriteResponseHandler
 
     protected int ackCount()
     {
-        return consistencyLevel.blockFor(table) - responses.get();
+        return totalBlockFor() - responses.get();
     }
 
     public boolean isLatencyForSnitch()


Mime
View raw message