cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [04/10] cassandra git commit: Reject default_time_to_live option when creating or altering MVs
Date Mon, 05 Dec 2016 11:13:50 GMT
Reject default_time_to_live option when creating or altering MVs

patch by Sundar Srinivasan; reviewed by Sylvain Lebresne for CASSANDRA-12868


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

Branch: refs/heads/trunk
Commit: 4d5a53e9b7008c1159164f1fb2107511df015332
Parents: 255505e
Author: Sundar Srinivasan <krishna.sun@gmail.com>
Authored: Mon Nov 21 16:29:43 2016 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Mon Dec 5 12:04:48 2016 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 NEWS.txt                                        |  3 ++
 .../cql3/statements/AlterViewStatement.java     |  8 ++++
 .../cql3/statements/CreateViewStatement.java    | 11 ++++-
 .../org/apache/cassandra/cql3/ViewTest.java     | 46 ++++++++++++++++++++
 5 files changed, 68 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/4d5a53e9/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index fff1d54..8cdca57 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.11
+ * Reject default_time_to_live option when creating or altering MVs (CASSANDRA-12868)
  * Nodetool should use a more sane max heap size (CASSANDRA-12739)
  * LocalToken ensures token values are cloned on heap (CASSANDRA-12651)
  * AnticompactionRequestSerializer serializedSize is incorrect (CASSANDRA-12934)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4d5a53e9/NEWS.txt
----------------------------------------------------------------------
diff --git a/NEWS.txt b/NEWS.txt
index d5f4f06..32b5084 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -20,6 +20,9 @@ Upgrading
 ---------
    - Nothing specific to this release, but please see previous versions upgrading section,
      especially if you are upgrading from 2.2.
+   - Specifying the default_time_to_live option when creating or altering a
+     materialized view was erroneously accepted (and ignored). It is now
+     properly rejected.
 
 3.0.10
 =====

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4d5a53e9/src/java/org/apache/cassandra/cql3/statements/AlterViewStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/AlterViewStatement.java b/src/java/org/apache/cassandra/cql3/statements/AlterViewStatement.java
index 5b1699b..ba077c7 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterViewStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterViewStatement.java
@@ -75,6 +75,14 @@ public class AlterViewStatement extends SchemaAlteringStatement
                                               "value is used to TTL undelivered updates.
Setting gc_grace_seconds too " +
                                               "low might cause undelivered updates to expire
before being replayed.");
         }
+
+        if (params.defaultTimeToLive > 0)
+        {
+            throw new InvalidRequestException("Cannot set or alter default_time_to_live for
a materialized view. " +
+                                              "Data in a materialized view always expire
at the same time than " +
+                                              "the corresponding data in the parent table.");
+        }
+
         viewCopy.metadata.params(params);
 
         MigrationManager.announceViewUpdate(viewCopy, isLocalOnly);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4d5a53e9/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java
index 13e528c..30e55a0 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java
@@ -275,12 +275,21 @@ public class CreateViewStatement extends SchemaAlteringStatement
         if (targetClusteringColumns.isEmpty())
             throw new InvalidRequestException("No columns are defined for Materialized View
other than primary key");
 
+        TableParams params = properties.properties.asNewTableParams();
+
+        if (params.defaultTimeToLive > 0)
+        {
+            throw new InvalidRequestException("Cannot set default_time_to_live for a materialized
view. " +
+                                              "Data in a materialized view always expire
at the same time than " +
+                                              "the corresponding data in the parent table.");
+        }
+
         CFMetaData.Builder cfmBuilder = CFMetaData.Builder.createView(keyspace(), columnFamily());
         add(cfm, targetPartitionKeys, cfmBuilder::addPartitionKey);
         add(cfm, targetClusteringColumns, cfmBuilder::addClusteringColumn);
         add(cfm, includedColumns, cfmBuilder::addRegularColumn);
         cfmBuilder.withId(properties.properties.getId());
-        TableParams params = properties.properties.asNewTableParams();
+
         CFMetaData viewCfm = cfmBuilder.build().params(params);
         ViewDefinition definition = new ViewDefinition(keyspace(),
                                                        columnFamily(),

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4d5a53e9/test/unit/org/apache/cassandra/cql3/ViewTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/ViewTest.java b/test/unit/org/apache/cassandra/cql3/ViewTest.java
index a6de756..2070bef 100644
--- a/test/unit/org/apache/cassandra/cql3/ViewTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ViewTest.java
@@ -335,6 +335,52 @@ public class ViewTest extends CQLTester
     }
 
     @Test
+    public void testCreateMvWithTTL() throws Throwable
+    {
+        createTable("CREATE TABLE %s (" +
+                "k int PRIMARY KEY, " +
+                "c int, " +
+                "val int) WITH default_time_to_live = 60");
+
+        execute("USE " + keyspace());
+        executeNet(protocolVersion, "USE " + keyspace());
+
+        // Must NOT include "default_time_to_live" for Materialized View creation
+        try
+        {
+            createView("mv_ttl1", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE
k IS NOT NULL AND c IS NOT NULL PRIMARY KEY (k,c) WITH default_time_to_live = 30");
+            Assert.fail("Should fail if TTL is provided for materialized view");
+        }
+        catch (Exception e)
+        {
+        }
+    }
+
+    @Test
+    public void testAlterMvWithTTL() throws Throwable
+    {
+        createTable("CREATE TABLE %s (" +
+                    "k int PRIMARY KEY, " +
+                    "c int, " +
+                    "val int) WITH default_time_to_live = 60");
+
+        execute("USE " + keyspace());
+        executeNet(protocolVersion, "USE " + keyspace());
+
+        createView("mv_ttl2", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE k IS
NOT NULL AND c IS NOT NULL PRIMARY KEY (k,c)");
+
+        // Must NOT include "default_time_to_live" on alter Materialized View
+        try
+        {
+            executeNet(protocolVersion, "ALTER MATERIALIZED VIEW %s WITH default_time_to_live
= 30");
+            Assert.fail("Should fail if TTL is provided while altering materialized view");
+        }
+        catch (Exception e)
+        {
+        }
+    }
+
+    @Test
     public void complexTimestampUpdateTestWithFlush() throws Throwable
     {
         complexTimestampUpdateTest(true);


Mime
View raw message