Merge branch 'cassandra-4.0' into cassandra-4.1

This commit is contained in:
Andrés de la Peña 2023-01-23 11:42:24 +00:00
commit 6c96e2fd41
7 changed files with 295 additions and 1 deletions

View File

@ -3,6 +3,7 @@
* Streaming progress virtual table lock contention can trigger TCP_USER_TIMEOUT and fail streaming (CASSANDRA-18110)
* Fix perpetual load of denylist on read in cases where denylist can never be loaded (CASSANDRA-18116)
Merged from 4.0:
* Fix legacy clustering serialization for paging with compact storage (CASSANDRA-17507)
* Add support for python 3.11 (CASSANDRA-18088)
* Fix formatting of duration in cqlsh (CASSANDRA-18141)
* Fix sstable loading of keyspaces named snapshots or backups (CASSANDRA-14013)

View File

@ -53,7 +53,7 @@ using the provided 'sstableupgrade' tool.
4.1.1
===
=====
G1GC Recommended
----------------
@ -62,6 +62,13 @@ G1GC Recommended
to G1 for performance and for simpler GC tuning. CMS is already deprecated in JDK9, and the next major
release of Cassandra makes G1 the default configuration.
Upgrading
---------
- All previous versions of 4.x contained a mistake on the implementation of the old CQL native protocol v3. That
mistake produced issues when paging over tables with compact storage and a single clustering column during rolling
upgrades involving 3.x and 4.x nodes. The fix for that issue makes it can now appear during rolling upgrades from
4.1.0 or 4.0.0-4.0.7. If that is your case, please use protocol v4 or higher in your driver. See CASSANDRA-17507
for further details.
4.1
===

View File

@ -421,6 +421,10 @@ public class PagingState
// Old (pre-3.0) encoding of cells. We need that for the protocol v3 as that is how things where encoded
private static ByteBuffer encodeCellName(TableMetadata metadata, Clustering<?> clustering, ByteBuffer columnName, ByteBuffer collectionElement)
{
// v30 and v3X don't use composites for single-element clusterings in compact tables
if (metadata.isCompactTable() && metadata.comparator.size() == 1)
return clustering.bufferAt(0);
boolean isStatic = clustering == Clustering.STATIC_CLUSTERING;
// We use comparator.size() rather than clustering.size() because of static clusterings
@ -457,6 +461,10 @@ public class PagingState
if (csize == 0)
return Clustering.EMPTY;
// v30 and v3X don't use composites for single-element clusterings in compact tables
if (metadata.isCompactTable() && metadata.comparator.size() == 1)
return Clustering.make(value);
if (CompositeType.isStaticName(value, ByteBufferAccessor.instance))
return Clustering.STATIC_CLUSTERING;

View File

@ -0,0 +1,179 @@
/*
* 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.upgrade;
import java.nio.ByteBuffer;
import java.util.List;
import org.junit.Test;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ColumnDefinitions;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ProtocolVersion;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SimpleStatement;
import com.datastax.driver.core.Statement;
import com.vdurmont.semver4j.Semver;
import org.apache.cassandra.distributed.api.ConsistencyLevel;
import static org.apache.cassandra.distributed.api.Feature.GOSSIP;
import static org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL;
import static org.apache.cassandra.distributed.api.Feature.NETWORK;
import static org.junit.Assert.assertEquals;
/**
* Tests paging over a table with {@code COMPACT STORAGE} in a mixed version cluster using different protocol versions.
*/
public abstract class CompactStoragePagingWithProtocolTester extends UpgradeTestBase
{
/**
* The initial version from which we are upgrading.
*/
protected abstract Semver initialVersion();
@Test
public void testPagingWithCompactStorageSingleClustering() throws Throwable
{
Object[] row1 = new Object[]{ "0", "01", "v" };
Object[] row2 = new Object[]{ "0", "02", "v" };
Object[] row3 = new Object[]{ "1", "01", "v" };
Object[] row4 = new Object[]{ "1", "02", "v" };
new TestCase()
.nodes(2)
.nodesToUpgrade(1)
.singleUpgrade(initialVersion())
.withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL))
.setup(c -> {
c.schemaChange(withKeyspace("CREATE TABLE %s.t (pk text, ck text, v text, " +
"PRIMARY KEY (pk, ck)) WITH COMPACT STORAGE"));
String insert = withKeyspace("INSERT INTO %s.t (pk, ck, v) VALUES (?, ?, ?)");
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row1);
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row2);
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row3);
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row4);
})
.runAfterNodeUpgrade((cluster, node) -> assertRowsWithAllProtocolVersions(row1, row2, row3, row4))
.run();
}
@Test
public void testPagingWithCompactStorageMultipleClusterings() throws Throwable
{
Object[] row1 = new Object[]{ "0", "01", "10", "v" };
Object[] row2 = new Object[]{ "0", "01", "20", "v" };
Object[] row3 = new Object[]{ "0", "02", "10", "v" };
Object[] row4 = new Object[]{ "0", "02", "20", "v" };
Object[] row5 = new Object[]{ "1", "01", "10", "v" };
new TestCase()
.nodes(2)
.nodesToUpgrade(1)
.singleUpgrade(initialVersion())
.withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL))
.setup(c -> {
c.schemaChange(withKeyspace("CREATE TABLE %s.t (pk text, ck1 text, ck2 text, v text, " +
"PRIMARY KEY (pk, ck1, ck2)) WITH COMPACT STORAGE"));
String insert = withKeyspace("INSERT INTO %s.t (pk, ck1, ck2, v) VALUES (?, ?, ?, ?)");
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row1);
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row2);
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row3);
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row4);
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row5);
})
.runAfterNodeUpgrade((cluster, node) -> assertRowsWithAllProtocolVersions(row1, row2, row3, row4, row5))
.run();
}
@Test
public void testPagingWithCompactStorageWithoutClustering() throws Throwable
{
Object[] row1 = new Object[]{ "1", "v1", "v2" };
Object[] row2 = new Object[]{ "2", "v1", "v2" };
Object[] row3 = new Object[]{ "3", "v1", "v2" };
new TestCase()
.nodes(2)
.nodesToUpgrade(1)
.singleUpgrade(initialVersion())
.withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL))
.setup(c -> {
c.schemaChange(withKeyspace("CREATE TABLE %s.t (pk text PRIMARY KEY, v1 text, v2 text) WITH COMPACT STORAGE"));
String insert = withKeyspace("INSERT INTO %s.t (pk, v1, v2) VALUES (?, ?, ?)");
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row1);
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row2);
c.coordinator(1).execute(insert, ConsistencyLevel.ALL, row3);
})
.runAfterNodeUpgrade((cluster, node) -> assertRowsWithAllProtocolVersions(row3, row2, row1))
.run();
}
private void assertRowsWithAllProtocolVersions(Object[]... rows)
{
String query = withKeyspace("SELECT * FROM %s.t");
assertRows(query, ProtocolVersion.V3, rows);
assertRows(query, ProtocolVersion.V4, rows);
if (initialVersion().isGreaterThanOrEqualTo(v3X))
assertRows(query, ProtocolVersion.V5, rows);
}
private static void assertRows(String query, ProtocolVersion protocolVersion, Object[]... expectedRows)
{
Cluster.Builder builder = com.datastax.driver.core.Cluster.builder()
.addContactPoint("127.0.0.1")
.withProtocolVersion(protocolVersion);
try (com.datastax.driver.core.Cluster cluster = builder.build();
Session session = cluster.connect())
{
Statement stmt = new SimpleStatement(query);
stmt.setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel.ALL);
stmt.setFetchSize(1);
ResultSet result = session.execute(stmt);
List<Row> actualRows = result.all();
assertEquals(expectedRows.length, actualRows.size());
ColumnDefinitions columnDefs = result.getColumnDefinitions();
com.datastax.driver.core.ProtocolVersion driverProtocolVersion =
com.datastax.driver.core.ProtocolVersion.fromInt(protocolVersion.toInt());
for (int rowIndex = 0; rowIndex < expectedRows.length; rowIndex++)
{
Object[] expectedRow = expectedRows[rowIndex];
Row actualRow = actualRows.get(rowIndex);
assertEquals(expectedRow.length, actualRow.getColumnDefinitions().size());
for (int columnIndex = 0; columnIndex < columnDefs.size(); columnIndex++)
{
DataType type = columnDefs.getType(columnIndex);
ByteBuffer expectedByteValue = cluster.getConfiguration()
.getCodecRegistry()
.codecFor(type)
.serialize(expectedRow[columnIndex], driverProtocolVersion);
ByteBuffer actualValue = actualRow.getBytesUnsafe(columnDefs.getName(columnIndex));
assertEquals(expectedByteValue, actualValue);
}
}
}
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.upgrade;
import com.vdurmont.semver4j.Semver;
/**
* {@link CompactStoragePagingWithProtocolTester} for v30 -> CURRENT upgrade path.
*/
public class CompactStoragePagingWithProtocolV30Test extends CompactStoragePagingWithProtocolTester
{
@Override
protected Semver initialVersion()
{
return v30;
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.upgrade;
import com.vdurmont.semver4j.Semver;
/**
* {@link CompactStoragePagingWithProtocolTester} for v3X -> CURRENT upgrade path.
*/
public class CompactStoragePagingWithProtocolV3XTest extends CompactStoragePagingWithProtocolTester
{
@Override
protected Semver initialVersion()
{
return v3X;
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.upgrade;
import com.vdurmont.semver4j.Semver;
/**
* {@link CompactStoragePagingWithProtocolTester} for v40 -> CURRENT upgrade path.
*/
public class CompactStoragePagingWithProtocolV40Test extends CompactStoragePagingWithProtocolTester
{
@Override
protected Semver initialVersion()
{
return v40;
}
}