Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CC7F6200B81 for ; Tue, 13 Sep 2016 10:52:59 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CB24F160AD3; Tue, 13 Sep 2016 08:52:59 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 14EF1160AD9 for ; Tue, 13 Sep 2016 10:52:58 +0200 (CEST) Received: (qmail 24248 invoked by uid 500); 13 Sep 2016 08:52:57 -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 24113 invoked by uid 99); 13 Sep 2016 08:52:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Sep 2016 08:52:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1CA13E08BA; Tue, 13 Sep 2016 08:52:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: slebresne@apache.org To: commits@cassandra.apache.org Date: Tue, 13 Sep 2016 08:53:01 -0000 Message-Id: In-Reply-To: <7916db71bc134d34a99bb37928b584e7@git.apache.org> References: <7916db71bc134d34a99bb37928b584e7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [6/8] cassandra git commit: Use empty partition rather than null one archived-at: Tue, 13 Sep 2016 08:53:00 -0000 Use empty partition rather than null one Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f58c3510 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f58c3510 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f58c3510 Branch: refs/heads/12060-3.0-v2 Commit: f58c351077bd1e20e2714a3a7c74d72e746efce4 Parents: 578450b Author: Sylvain Lebresne Authored: Fri Sep 2 11:21:33 2016 +0200 Committer: Sylvain Lebresne Committed: Mon Sep 12 11:50:22 2016 +0200 ---------------------------------------------------------------------- .../cql3/statements/CQL3CasRequest.java | 19 +++++++++++++++---- .../cql3/statements/ModificationStatement.java | 5 +---- .../apache/cassandra/service/StorageProxy.java | 2 +- .../apache/cassandra/thrift/CassandraServer.java | 4 ++-- 4 files changed, 19 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/f58c3510/src/java/org/apache/cassandra/cql3/statements/CQL3CasRequest.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/statements/CQL3CasRequest.java b/src/java/org/apache/cassandra/cql3/statements/CQL3CasRequest.java index 6ce05f3..3af3c35 100644 --- a/src/java/org/apache/cassandra/cql3/statements/CQL3CasRequest.java +++ b/src/java/org/apache/cassandra/cql3/statements/CQL3CasRequest.java @@ -27,6 +27,7 @@ import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.cql3.*; import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.*; +import org.apache.cassandra.db.rows.Row; import org.apache.cassandra.db.partitions.FilteredPartition; import org.apache.cassandra.db.partitions.Partition; import org.apache.cassandra.db.partitions.PartitionUpdate; @@ -176,6 +177,15 @@ public class CQL3CasRequest implements CASRequest return SinglePartitionReadCommand.create(cfm, nowInSec, key, ColumnFilter.selection(columnsToRead()), filter); } + /** + * Checks whether the conditions represented by this object applies provided the current state of the partition on + * which those conditions are. + * + * @param current the partition with current data corresponding to these conditions. More precisely, this must be + * the result of executing the command returned by {@link #readCommand}. This can be empty but it should not be + * {@code null}. + * @return whether the conditions represented by this object applies or not. + */ public boolean appliesTo(FilteredPartition current) throws InvalidRequestException { if (staticConditions != null && !staticConditions.appliesTo(current)) @@ -261,7 +271,7 @@ public class CQL3CasRequest implements CASRequest public boolean appliesTo(FilteredPartition current) { - return current == null || current.getRow(clustering) == null; + return current.getRow(clustering) == null; } } @@ -274,7 +284,7 @@ public class CQL3CasRequest implements CASRequest public boolean appliesTo(FilteredPartition current) { - return current != null && current.getRow(clustering) != null; + return current.getRow(clustering) != null; } } @@ -298,12 +308,13 @@ public class CQL3CasRequest implements CASRequest public boolean appliesTo(FilteredPartition current) throws InvalidRequestException { - if (current == null) + if (current.isEmpty()) return conditions.isEmpty(); + Row row = current.getRow(clustering); for (ColumnCondition.Bound condition : conditions.values()) { - if (!condition.appliesTo(current.getRow(clustering))) + if (!condition.appliesTo(row)) return false; } return true; http://git-wip-us.apache.org/repos/asf/cassandra/blob/f58c3510/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java index 7094853..01c2ad1 100644 --- a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java @@ -587,11 +587,8 @@ public abstract class ModificationStatement implements CQLStatement current = FilteredPartition.create(PartitionIterators.getOnlyElement(iter, readCommand)); } - // If partition is effectively empty (no rows, no statics, not live), we pass null to indicate it does not exist - if (!request.appliesTo(current.isEmpty() ? null : current)) - { + if (!request.appliesTo(current)) return current.rowIterator(); - } PartitionUpdate updates = request.makeUpdates(current); updates = TriggerExecutor.instance.execute(updates); http://git-wip-us.apache.org/repos/asf/cassandra/blob/f58c3510/src/java/org/apache/cassandra/service/StorageProxy.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index 1550bb0..8a151f2 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -251,7 +251,7 @@ public class StorageProxy implements StorageProxyMBean current = FilteredPartition.create(rowIter); } - if (!request.appliesTo(current.isEmpty() ? null : current)) + if (!request.appliesTo(current)) { Tracing.trace("CAS precondition does not match current values {}", current); casWriteMetrics.conditionNotMet.inc(); http://git-wip-us.apache.org/repos/asf/cassandra/blob/f58c3510/src/java/org/apache/cassandra/thrift/CassandraServer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/thrift/CassandraServer.java b/src/java/org/apache/cassandra/thrift/CassandraServer.java index 201dc43..0dec94e 100644 --- a/src/java/org/apache/cassandra/thrift/CassandraServer.java +++ b/src/java/org/apache/cassandra/thrift/CassandraServer.java @@ -2554,8 +2554,8 @@ public class CassandraServer implements Cassandra.Iface public boolean appliesTo(FilteredPartition current) { if (expected.isEmpty()) - return current == null; - else if (current == null) + return current.isEmpty(); + else if (current.isEmpty()) return false; // Push the expected results through ThriftResultsMerger to translate any static