Skip to content

Commit

Permalink
Merge branch 'cassandra-3.0' into cassandra-3.11
Browse files Browse the repository at this point in the history
* cassandra-3.0:
  Reject default_time_to_live option when creating or altering MVs
  • Loading branch information
Sylvain Lebresne committed Dec 5, 2016
2 parents b63c03b + 4d5a53e commit a06b469
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
3.11
Merged from 3.0:
* Reject default_time_to_live option when creating or altering MVs (CASSANDRA-12868)

3.10
* Use correct bounds for all-data range when filtering (CASSANDRA-12666)
* Remove timing window in test case (CASSANDRA-12875)
Expand Down
9 changes: 9 additions & 0 deletions NEWS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ restore snapshots created with the previous major version using the
'sstableloader' tool. You can upgrade the file format of your snapshots
using the provided 'sstableupgrade' tool.

3.11
====

Upgrading
---------
- 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.10
====

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public Event.SchemaChange announceMigration(boolean isLocalOnly) throws RequestV
"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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,21 @@ public Event.SchemaChange announceMigration(boolean isLocalOnly) throws RequestV
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(),
Expand Down
42 changes: 42 additions & 0 deletions test/unit/org/apache/cassandra/cql3/ViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1192,4 +1192,46 @@ public void testReservedKeywordsInMV() throws Throwable
assertRowsNet(protocolVersion, executeNet(protocolVersion, "SELECT * FROM %s"), row(0, 1));
assertRowsNet(protocolVersion, executeNet(protocolVersion, "SELECT * FROM mv"), row(1, 0));
}

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");

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)
{
}
}
}

0 comments on commit a06b469

Please sign in to comment.