diff --git a/CHANGES.txt b/CHANGES.txt index 75f2c29d2a..935931cbe7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,10 +1,10 @@ 3.0.16 + * Add flag to disable materialized views, and warnings on creation (CASSANDRA-13959) * Don't let user drop or generally break tables in system_distributed (CASSANDRA-13813) * Provide a JMX call to sync schema with local storage (CASSANDRA-13954) * Mishandling of cells for removed/dropped columns when reading legacy files (CASSANDRA-13939) * Deserialise sstable metadata in nodetool verify (CASSANDRA-13922) - 3.0.15 * Improve TRUNCATE performance (CASSANDRA-13909) * Implement short read protection on partition boundaries (CASSANDRA-13595) diff --git a/NEWS.txt b/NEWS.txt index 944857b392..60cf77cc78 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -21,6 +21,14 @@ Upgrading - Nothing specific to this release, but please see previous upgrading sections, especially if you are upgrading from 2.2. +Materialized Views +------------------- + - Following a discussion regarding concerns about the design and safety of Materialized Views, the C* development + community no longer recommends them for production use, and considers them experimental. Warnings messages will + now be logged when they are created. (See https://www.mail-archive.com/dev@cassandra.apache.org/msg11511.html) + - An 'enable_materialized_views' flag has been added to cassandra.yaml to allow operators to prevent creation of + views + 3.0.15 ===== diff --git a/conf/cassandra.yaml b/conf/cassandra.yaml index d77d27a2f5..b783090ccf 100644 --- a/conf/cassandra.yaml +++ b/conf/cassandra.yaml @@ -952,6 +952,10 @@ enable_user_defined_functions: false # This option has no effect, if enable_user_defined_functions is false. enable_scripted_user_defined_functions: false +# Enables materialized view creation on this node. +# Materialized views are considered experimental and are not recommended for production use. +enable_materialized_views: true + # The default Windows kernel timer and scheduling resolution is 15.6ms for power conservation. # Lowering this value on Windows can provide much tighter latency and better throughput, however # some virtualized environments may see a negative performance impact from changing this setting diff --git a/src/java/org/apache/cassandra/config/Config.java b/src/java/org/apache/cassandra/config/Config.java index 6a99cd3cbd..64d41bb5f0 100644 --- a/src/java/org/apache/cassandra/config/Config.java +++ b/src/java/org/apache/cassandra/config/Config.java @@ -308,6 +308,9 @@ public class Config public boolean enable_user_defined_functions = false; public boolean enable_scripted_user_defined_functions = false; + + public boolean enable_materialized_views = true; + /** * Optionally disable asynchronous UDF execution. * Disabling asynchronous UDF execution also implicitly disables the security-manager! diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java index 029db89cd9..efc71efa2a 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -2043,6 +2043,11 @@ public class DatabaseDescriptor conf.user_defined_function_warn_timeout = userDefinedFunctionWarnTimeout; } + public static boolean enableMaterializedViews() + { + return conf.enable_materialized_views; + } + public static long getUserDefinedFunctionFailTimeout() { return conf.user_defined_function_fail_timeout; diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java index 47304b6d0d..778a3f4c04 100644 --- a/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java @@ -23,9 +23,13 @@ import java.util.stream.Collectors; import com.google.common.collect.Iterables; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.cassandra.auth.Permission; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.ColumnDefinition; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.config.Schema; import org.apache.cassandra.config.ViewDefinition; import org.apache.cassandra.cql3.*; @@ -49,6 +53,8 @@ import org.apache.cassandra.transport.Event; public class CreateViewStatement extends SchemaAlteringStatement { + private static final Logger logger = LoggerFactory.getLogger(CreateViewStatement.class); + private final CFName baseName; private final List selectClause; private final WhereClause whereClause; @@ -114,6 +120,11 @@ public class CreateViewStatement extends SchemaAlteringStatement public Event.SchemaChange announceMigration(QueryState queryState, boolean isLocalOnly) throws RequestValidationException { + if (!DatabaseDescriptor.enableMaterializedViews()) + { + throw new InvalidRequestException("Materialized views are disabled. Enable in cassandra.yaml to use."); + } + // We need to make sure that: // - primary key includes all columns in base table's primary key // - make sure that the select statement does not have anything other than columns @@ -303,8 +314,13 @@ public class CreateViewStatement extends SchemaAlteringStatement whereClauseText, viewCfm); + logger.warn("Creating materialized view {} for {}.{}. " + + "Materialized views are experimental and are not recommended for production use.", + definition.viewName, cfm.ksName, cfm.cfName); + try { + ClientWarn.instance.warn("Materialized views are experimental and are not recommended for production use."); MigrationManager.announceNewView(definition, isLocalOnly); return new Event.SchemaChange(Event.SchemaChange.Change.CREATED, Event.SchemaChange.Target.TABLE, keyspace(), columnFamily()); }