Bti shouldn't be available in compatibility mode

Patch by Berenguer Blasi; reviewed by Andrés de la Peña for CASSANDRA-18569
This commit is contained in:
Bereng 2023-06-06 12:37:56 +02:00
parent e4f31b73c2
commit 70389abcf7
3 changed files with 72 additions and 2 deletions

View File

@ -1424,6 +1424,8 @@ public class DatabaseDescriptor
if (selectedFormat == null)
throw new ConfigurationException(String.format("Selected sstable format '%s' is not available.", selectedFormatName));
getStorageCompatibilityMode().validateSstableFormat(selectedFormat);
return selectedFormat;
}

View File

@ -19,6 +19,9 @@
package org.apache.cassandra.utils;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.sstable.format.SSTableFormat;
import org.apache.cassandra.io.sstable.format.bti.BtiFormat;
/**
* The mode of compatibility with older Cassandra versions.
@ -33,7 +36,7 @@ public enum StorageCompatibilityMode
CASSANDRA_4(4),
/**
* Use the storage formats of the current version, but dissabling features that are not compatible with any
* Use the storage formats of the current version, but disabling features that are not compatible with any
* not-upgraded nodes in the cluster. Use this during rolling upgrades to a new major Cassandra version. Once all
* nodes have been upgraded, you can set the compatibility to {@link #NONE}.
*/
@ -42,7 +45,7 @@ public enum StorageCompatibilityMode
/**
* Don't try to be compatible with older versions. Data will be written with the most recent format, which might
* prevent a rollback to previous Cassandra versions. Features that are not compatible with older nodes will be
* enabled, asuming that all nodes in the cluster are in the same major version as this node.
* enabled, assuming that all nodes in the cluster are in the same major version as this node.
*/
NONE(Integer.MAX_VALUE);
@ -67,4 +70,12 @@ public enum StorageCompatibilityMode
{
return this.major < major;
}
public void validateSstableFormat(SSTableFormat<?, ?> selectedFormat)
{
if (selectedFormat.name().equals(BtiFormat.NAME) && this == StorageCompatibilityMode.CASSANDRA_4)
throw new ConfigurationException(String.format("Selected sstable format '%s' is not available when in storage compatibility mode '%s'.",
selectedFormat.name(),
this));
}
}

View File

@ -0,0 +1,57 @@
/*
* 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.utils;
import org.junit.Test;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.sstable.format.SSTableFormat;
import org.apache.cassandra.io.sstable.format.big.BigFormat;
import org.apache.cassandra.io.sstable.format.bti.BtiFormat;
import org.assertj.core.api.Assertions;
public class StorageCompatibilityModeTest
{
@Test
public void testBtiFormatAndStorageCompatibilityMode()
{
SSTableFormat<?, ?> big = new BigFormat(null);
SSTableFormat<?, ?> trie = new BtiFormat(null);
for (StorageCompatibilityMode mode : StorageCompatibilityMode.values())
{
switch (mode)
{
case UPGRADING:
case NONE:
mode.validateSstableFormat(big);
mode.validateSstableFormat(trie);
break;
case CASSANDRA_4:
mode.validateSstableFormat(big);
Assertions.assertThatThrownBy(() -> mode.validateSstableFormat(trie))
.isInstanceOf(ConfigurationException.class)
.hasMessageContaining("is not available when in storage compatibility mode");
break;
default:
throw new AssertionError("Undefined behaviour for mode " + mode);
}
}
}
}