Add flag to disable materialized views, and warnings on creation

Patch by Blake Eggleston; Reviewed by Aleksey Yeschenko for CASSANDRA-13959
This commit is contained in:
Blake Eggleston 2017-10-09 16:40:04 -07:00
parent 8fad4cd59e
commit b8697441d7
6 changed files with 37 additions and 1 deletions

View File

@ -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)

View File

@ -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
=====

View File

@ -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

View File

@ -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!

View File

@ -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;

View File

@ -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<RawSelector> 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());
}