Return-Path: Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: (qmail 10965 invoked from network); 28 Dec 2010 21:24:12 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 28 Dec 2010 21:24:12 -0000 Received: (qmail 39941 invoked by uid 500); 28 Dec 2010 21:24:12 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 39920 invoked by uid 500); 28 Dec 2010 21:24:12 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 39912 invoked by uid 99); 28 Dec 2010 21:24:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Dec 2010 21:24:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Dec 2010 21:24:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4EB6D23889CB; Tue, 28 Dec 2010 21:23:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1053443 - /cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/ReadResponseResolver.java Date: Tue, 28 Dec 2010 21:23:51 -0000 To: commits@cassandra.apache.org From: jbellis@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101228212351.4EB6D23889CB@eris.apache.org> Author: jbellis Date: Tue Dec 28 21:23:50 2010 New Revision: 1053443 URL: http://svn.apache.org/viewvc?rev=1053443&view=rev Log: simplify and update comments for RRR.resolve patch by jbellis Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/ReadResponseResolver.java Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/ReadResponseResolver.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/ReadResponseResolver.java?rev=1053443&r1=1053442&r2=1053443&view=diff ============================================================================== --- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/ReadResponseResolver.java (original) +++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/ReadResponseResolver.java Tue Dec 28 21:23:50 2010 @@ -54,13 +54,17 @@ public class ReadResponseResolver implem } /* - * This method for resolving read data should look at the timestamps of each - * of the columns that are read and should pick up columns with the latest - * timestamp. For those columns where the timestamp is not the latest a - * repair request should be scheduled. - * - */ - public Row resolve() throws DigestMismatchException, IOException + * This method handles two different scenarios: + * + * 1) we're handling the initial read, of data from the closest replica + digests + * from the rest. In this case we check the digests against each other, + * throw an exception if there is a mismatch, otherwise return the data row. + * + * 2) there was a mismatch on the initial read, so we redid the digest requests + * as full data reads. In this case we need to compute the most recent version + * of each column, and send diffs to out-of-date replicas. + */ + public Row resolve() throws DigestMismatchException, IOException { if (logger_.isDebugEnabled()) logger_.debug("resolving " + results.size() + " responses"); @@ -70,50 +74,27 @@ public class ReadResponseResolver implem List endpoints = new ArrayList(); ByteBuffer digest = null; - /* - * Populate the list of rows from each of the messages - * Check to see if there is a digest query. If a digest - * query exists then we need to compare the digest with - * the digest of the data that is received. - */ + // validate digests against each other; throw immediately on mismatch. + // also, collects data results into versions/endpoints lists. for (Map.Entry entry : results.entrySet()) { ReadResponse result = entry.getValue(); Message message = entry.getKey(); - if (result.isDigestQuery()) - { - if (digest == null) - { - digest = result.digest(); - } - else - { - ByteBuffer digest2 = result.digest(); - if (!digest.equals(digest2)) - throw new DigestMismatchException(key, digest, digest2); - } - } - else + ByteBuffer resultDigest = result.isDigestQuery() ? result.digest() : ColumnFamily.digest(result.row().cf); + if (digest == null) + digest = resultDigest; + else if (!digest.equals(resultDigest)) + throw new DigestMismatchException(key, digest, resultDigest); + + if (!result.isDigestQuery()) { versions.add(result.row().cf); endpoints.add(message.getFrom()); } } - // 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 (digest != null) - { - - for (ColumnFamily cf : versions) - { - ByteBuffer digest2 = ColumnFamily.digest(cf); - if (!digest.equals(digest2)) - throw new DigestMismatchException(key, digest, digest2); - } - if (logger_.isDebugEnabled()) - logger_.debug("digests verified"); - } + if (logger_.isDebugEnabled()) + logger_.debug("digests verified"); ColumnFamily resolved; if (versions.size() > 1)