cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [6/8] cassandra git commit: Use empty partition rather than null one
Date Tue, 13 Sep 2016 08:53:01 GMT
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 <sylvain@datastax.com>
Authored: Fri Sep 2 11:21:33 2016 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
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


Mime
View raw message