Do not fail to start a node with materialized views after they are turned off in config

patch by Stefan Miklosovic; reviewed by Maxwell Guo for CASSANDRA-20452
This commit is contained in:
Stefan Miklosovic 2025-03-18 13:23:29 +01:00
parent 009146959a
commit 9843b3d40e
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
3 changed files with 53 additions and 4 deletions

View File

@ -1,4 +1,5 @@
5.1
* Do not fail to start a node with materialized views after they are turned off in config (CASSANDRA-20452)
* Fix nodetool gcstats output, support human-readable units and more output formats (CASSANDRA-19022)
* Various gossip to TCM upgrade fixes (CASSANDRA-20483)
* Add nodetool command to abort failed nodetool cms initialize (CASSANDRA-20482)

View File

@ -105,6 +105,9 @@ public final class CreateViewStatement extends AlterSchemaStatement
@Override
public void validate(ClientState state)
{
if (!DatabaseDescriptor.getMaterializedViewsEnabled())
throw ire("Materialized views are disabled. Enable in cassandra.yaml to use.");
super.validate(state);
// save the query state to use it for guardrails validation in #apply
@ -114,13 +117,9 @@ public final class CreateViewStatement extends AlterSchemaStatement
@Override
public Keyspaces apply(ClusterMetadata metadata)
{
if (!DatabaseDescriptor.getMaterializedViewsEnabled())
throw ire("Materialized views are disabled. Enable in cassandra.yaml to use.");
/*
* Basic dependency validations
*/
Keyspaces schema = metadata.schema.getKeyspaces();
KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
if (null == keyspace)

View File

@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.distributed;
import org.junit.Test;
import org.apache.cassandra.distributed.test.TestBaseImpl;
import static org.apache.cassandra.distributed.api.ConsistencyLevel.ALL;
public class MaterializedViewTest extends TestBaseImpl
{
@Test
public void testDisablingMaterializedViewsDontFailNodeToStart() throws Throwable
{
try (Cluster cluster = init(Cluster.build(1)
.withConfig(c -> c.set("materialized_views_enabled", true))
.start()))
{
cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (id uuid, col1 text, col2 text, primary key (id));");
cluster.schemaChange("CREATE MATERIALIZED VIEW " + KEYSPACE + ".a_view AS SELECT id, col1, col2 " +
"FROM tbl WHERE col2 IS NOT NULL AND id IS NOT NULL PRIMARY KEY (col2, id) " +
"WITH CLUSTERING ORDER BY (id ASC);");
cluster.coordinator(1).execute(withKeyspace("select * from %s.a_view"), ALL);
cluster.get(1).shutdown().get();
cluster.get(1).config().set("materialized_views_enabled", false);
cluster.get(1).startup();
cluster.coordinator(1).execute(withKeyspace("select * from %s.a_view"), ALL);
}
}
}