cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1049628 - in /cassandra/branches/cassandra-0.6: CHANGES.txt src/java/org/apache/cassandra/service/DigestMismatchException.java src/java/org/apache/cassandra/service/ReadResponseResolver.java
Date Wed, 15 Dec 2010 16:09:31 GMT
Author: jbellis
Date: Wed Dec 15 16:09:31 2010
New Revision: 1049628

URL: http://svn.apache.org/viewvc?rev=1049628&view=rev
Log:
ReadResponseResolver check digests against each other
patch by Randall Leeds and jbellis; reviewed by slebrense for CASSANDRA-1830

Modified:
    cassandra/branches/cassandra-0.6/CHANGES.txt
    cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/DigestMismatchException.java
    cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/ReadResponseResolver.java

Modified: cassandra/branches/cassandra-0.6/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/CHANGES.txt?rev=1049628&r1=1049627&r2=1049628&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.6/CHANGES.txt Wed Dec 15 16:09:31 2010
@@ -18,6 +18,7 @@
    (CASSANDRA-1811)
  * correct ordering of drain operations so CL.recover is no longer necessary
    (CASSANDRA-1408)
+ * ReadResponseResolver check digests against each other (CASSANDRA-1830)
 
 
 0.6.8

Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/DigestMismatchException.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/DigestMismatchException.java?rev=1049628&r1=1049627&r2=1049628&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/DigestMismatchException.java
(original)
+++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/DigestMismatchException.java
Wed Dec 15 16:09:31 2010
@@ -18,10 +18,15 @@
 
 package org.apache.cassandra.service;
 
+import org.apache.cassandra.utils.FBUtilities;
+
 public class DigestMismatchException extends Exception
 {
-	public DigestMismatchException(String message)
-	{
-		super(message);
-	}
+    public DigestMismatchException(String key, byte[] digest1, byte[] digest2)
+    {
+        super(String.format("Mismatch for key %s (%s vs %s)",
+                            key,
+                            FBUtilities.bytesToHex(digest1),
+                            FBUtilities.bytesToHex(digest2)));
+    }
 }

Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/ReadResponseResolver.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/ReadResponseResolver.java?rev=1049628&r1=1049627&r2=1049628&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/ReadResponseResolver.java
(original)
+++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/ReadResponseResolver.java
Wed Dec 15 16:09:31 2010
@@ -74,9 +74,8 @@ public class ReadResponseResolver implem
 		List<ColumnFamily> versions = new ArrayList<ColumnFamily>(responses.size());
 		List<InetAddress> endPoints = new ArrayList<InetAddress>(responses.size());
 		String key = null;
-		byte[] digest = new byte[0];
-		boolean isDigestQuery = false;
-        
+		byte[] digest = null;
+
         /*
 		 * Populate the list of rows from each of the messages
 		 * Check to see if there is a digest query. If a digest 
@@ -90,8 +89,16 @@ public class ReadResponseResolver implem
                 continue; // arrived after quorum already achieved
             if (result.isDigestQuery())
             {
-                digest = result.digest();
-                isDigestQuery = true;
+                if (digest == null)
+                {
+                    digest = result.digest();
+                }
+                else
+                {
+                    byte[] digest2 = result.digest();
+                    if (!Arrays.equals(digest, digest2))
+                        throw new DigestMismatchException(key, digest, digest2);
+                }
             }
             else
             {
@@ -103,16 +110,13 @@ public class ReadResponseResolver implem
 
 		// If there was a digest query compare it with all the data digests
 		// If there is a mismatch then throw an exception so that read repair can happen.
-        if (isDigestQuery)
+        if (digest != null)
         {
             for (ColumnFamily cf : versions)
             {
-                if (!Arrays.equals(ColumnFamily.digest(cf), digest))
-                {
-                    /* Wrap the key as the context in this exception */
-                    String s = String.format("Mismatch for key %s (%s vs %s)", key, FBUtilities.bytesToHex(ColumnFamily.digest(cf)),
FBUtilities.bytesToHex(digest));
-                    throw new DigestMismatchException(s);
-                }
+                byte[] digest2 = ColumnFamily.digest(cf);
+                if (!Arrays.equals(digest, digest2))
+                    throw new DigestMismatchException(key, digest, digest2);
             }
             if (logger_.isDebugEnabled())
                 logger_.debug("digests verified");



Mime
View raw message