cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [2/6] cassandra git commit: Fix missing original update in TriggerExecutor
Date Fri, 22 Sep 2017 14:44:24 GMT
Fix missing original update in TriggerExecutor

Patch by Jason Stack; Reviewed by Paulo Motta for CASSANDRA-13894


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

Branch: refs/heads/cassandra-3.11
Commit: 51e6f2446e71c8bd2ce89480b7d30d5b9ed1546e
Parents: 2b897d2
Author: Zhao Yang <zhaoyangsingapore@gmail.com>
Authored: Fri Sep 22 17:04:05 2017 +0800
Committer: Paulo Motta <paulo@apache.org>
Committed: Fri Sep 22 09:39:29 2017 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/triggers/TriggerExecutor.java     |  7 ++++-
 .../cassandra/triggers/TriggerExecutorTest.java | 23 ++++++++++++---
 .../apache/cassandra/triggers/TriggersTest.java | 30 ++++++++++++--------
 4 files changed, 44 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/51e6f244/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 91f5a51..68da81a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.15
+ * Fix missing original update in TriggerExecutor (CASSANDRA-13894)
  * Remove non-rpc-ready nodes from counter leader candidates (CASSANDRA-13043)
  * Improve short read protection performance (CASSANDRA-13794)
  * Fix sstable reader to support range-tombstone-marker for multi-slices (CASSANDRA-13787)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/51e6f244/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
index 40d4094..3996127 100644
--- a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
+++ b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
@@ -85,7 +85,12 @@ public class TriggerExecutor
         if (intermediate == null || intermediate.isEmpty())
             return updates;
 
-        return PartitionUpdate.merge(validateForSinglePartition(updates.metadata().cfId,
updates.partitionKey(), intermediate));
+        List<PartitionUpdate> augmented = validateForSinglePartition(updates.metadata().cfId,
+                                                                     updates.partitionKey(),
+                                                                     intermediate);
+        // concatenate augmented and origin
+        augmented.add(updates);
+        return PartitionUpdate.merge(augmented);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/51e6f244/test/unit/org/apache/cassandra/triggers/TriggerExecutorTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/triggers/TriggerExecutorTest.java b/test/unit/org/apache/cassandra/triggers/TriggerExecutorTest.java
index 44391c8..d3c6961 100644
--- a/test/unit/org/apache/cassandra/triggers/TriggerExecutorTest.java
+++ b/test/unit/org/apache/cassandra/triggers/TriggerExecutorTest.java
@@ -44,14 +44,29 @@ public class TriggerExecutorTest
     public void sameKeySameCfColumnFamilies() throws ConfigurationException, InvalidRequestException
     {
         CFMetaData metadata = makeCfMetaData("ks1", "cf1", TriggerMetadata.create("test",
SameKeySameCfTrigger.class.getName()));
+        // origin column 'c1' = "v1", augment extra column 'c2' = "trigger"
         PartitionUpdate mutated = TriggerExecutor.instance.execute(makeCf(metadata, "k1",
"v1", null));
 
-        RowIterator rowIterator = UnfilteredRowIterators.filter(mutated.unfilteredIterator(),
FBUtilities.nowInSeconds());
+        List<Row> rows = new ArrayList<>();
+        try (RowIterator iterator = UnfilteredRowIterators.filter(mutated.unfilteredIterator(),
+                                                                  FBUtilities.nowInSeconds()))
+        {
+            iterator.forEachRemaining(rows::add);
+        }
+
+        // only 1 row
+        assertEquals(1, rows.size());
+
+        List<Cell> cells = new ArrayList<>();
+        rows.get(0).cells().forEach(cells::add);
 
-        Iterator<Cell> cells = rowIterator.next().cells().iterator();
-        assertEquals(bytes("trigger"), cells.next().value());
+        // 2 columns
+        assertEquals(2, cells.size());
 
-        assertTrue(!rowIterator.hasNext());
+        // check column 'c1'
+        assertEquals(bytes("v1"), cells.get(0).value());
+        // check column 'c2'
+        assertEquals(bytes("trigger"), cells.get(1).value());
     }
 
     @Test(expected = InvalidRequestException.class)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/51e6f244/test/unit/org/apache/cassandra/triggers/TriggersTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/triggers/TriggersTest.java b/test/unit/org/apache/cassandra/triggers/TriggersTest.java
index 13ecbe9..67619dc 100644
--- a/test/unit/org/apache/cassandra/triggers/TriggersTest.java
+++ b/test/unit/org/apache/cassandra/triggers/TriggersTest.java
@@ -108,7 +108,7 @@ public class TriggersTest
     {
         String cql = String.format("INSERT INTO %s.%s (k, v1) VALUES (0, 0)", ksName, cfName);
         QueryProcessor.process(cql, ConsistencyLevel.ONE);
-        assertUpdateIsAugmented(0);
+        assertUpdateIsAugmented(0, "v1", 0);
     }
 
     @Test
@@ -119,7 +119,7 @@ public class TriggersTest
                                    "APPLY BATCH",
                                    ksName, cfName);
         QueryProcessor.process(cql, ConsistencyLevel.ONE);
-        assertUpdateIsAugmented(1);
+        assertUpdateIsAugmented(1, "v1", 1);
     }
 
     @Test
@@ -135,7 +135,7 @@ public class TriggersTest
                       getColumnForInsert("v1", 2),
                       org.apache.cassandra.thrift.ConsistencyLevel.ONE);
 
-        assertUpdateIsAugmented(2);
+        assertUpdateIsAugmented(2, "v1", 2);
     }
 
     @Test
@@ -156,7 +156,7 @@ public class TriggersTest
                                                               Collections.singletonList(mutation))),
             org.apache.cassandra.thrift.ConsistencyLevel.ONE);
 
-        assertUpdateIsAugmented(3);
+        assertUpdateIsAugmented(3, "v1", 3);
     }
 
     @Test
@@ -164,7 +164,7 @@ public class TriggersTest
     {
         String cql = String.format("INSERT INTO %s.%s (k, v1) VALUES (4, 4) IF NOT EXISTS",
ksName, cfName);
         QueryProcessor.process(cql, ConsistencyLevel.ONE);
-        assertUpdateIsAugmented(4);
+        assertUpdateIsAugmented(4, "v1", 4);
     }
 
     @Test
@@ -176,7 +176,7 @@ public class TriggersTest
                                    "APPLY BATCH",
                                     ksName, cfName);
         QueryProcessor.process(cql, ConsistencyLevel.ONE);
-        assertUpdateIsAugmented(5);
+        assertUpdateIsAugmented(5, "v1", 5);
     }
 
     @Test
@@ -194,7 +194,7 @@ public class TriggersTest
                    org.apache.cassandra.thrift.ConsistencyLevel.LOCAL_SERIAL,
                    org.apache.cassandra.thrift.ConsistencyLevel.ONE);
 
-        assertUpdateIsAugmented(6);
+        assertUpdateIsAugmented(6, "v1", 6);
     }
 
     // Unfortunately, an IRE thrown from StorageProxy.cas
@@ -295,12 +295,18 @@ public class TriggersTest
         QueryProcessor.process(cql, ConsistencyLevel.ONE);
     }
 
-    private void assertUpdateIsAugmented(int key)
+    private void assertUpdateIsAugmented(int key, String originColumnName, Object originColumnValue)
     {
-        UntypedResultSet rs = QueryProcessor.executeInternal(
-                String.format("SELECT * FROM %s.%s WHERE k=%s", ksName, cfName, key));
-        assertTrue(String.format("Expected value (%s) for augmented cell v2 was not found",
key), rs.one().has("v2"));
-        assertEquals(999, rs.one().getInt("v2"));
+        UntypedResultSet rs = QueryProcessor.process(String.format("SELECT * FROM %s.%s WHERE
k=%s", ksName, cfName, key), ConsistencyLevel.ONE);
+        assertRowValue(rs.one(), key, "v2", 999); // from trigger
+        assertRowValue(rs.one(), key, originColumnName, originColumnValue); // from original
update
+    }
+    
+    private void assertRowValue(UntypedResultSet.Row row, int key, String columnName, Object
columnValue)
+    {
+        assertTrue(String.format("Expected value (%s) for augmented cell %s was not found",
key, columnName),
+                   row.has(columnName));
+        assertEquals(columnValue, row.getInt(columnName));
     }
 
     private void assertUpdateNotExecuted(String cf, int key)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message