From 1575649888ec2632e02e5199bd57fb7de274d561 Mon Sep 17 00:00:00 2001 From: Jordan West Date: Mon, 17 Aug 2020 15:06:37 -0700 Subject: [PATCH] Regression Test for Compact Storage Upgrades When Table Has Clustering and Value Column Patch by Jordan West; Reviewed by Caleb Rackliffe for CASSANDRA-16054 --- .../CompactStorage2to3UpgradeTest.java | 257 +++++++++++++++++- 1 file changed, 256 insertions(+), 1 deletion(-) diff --git a/test/distributed/org/apache/cassandra/distributed/upgrade/CompactStorage2to3UpgradeTest.java b/test/distributed/org/apache/cassandra/distributed/upgrade/CompactStorage2to3UpgradeTest.java index f138861f8c..c6235d3ede 100644 --- a/test/distributed/org/apache/cassandra/distributed/upgrade/CompactStorage2to3UpgradeTest.java +++ b/test/distributed/org/apache/cassandra/distributed/upgrade/CompactStorage2to3UpgradeTest.java @@ -18,11 +18,16 @@ package org.apache.cassandra.distributed.upgrade; +import java.util.HashMap; +import java.util.Map; + import org.junit.Test; +import org.apache.cassandra.distributed.UpgradeableCluster; import org.apache.cassandra.distributed.api.ConsistencyLevel; import org.apache.cassandra.distributed.api.ICoordinator; -import org.apache.cassandra.distributed.shared.DistributedTestBase; +import org.apache.cassandra.distributed.api.IMessageFilters; +import org.apache.cassandra.distributed.api.NodeToolResult; import org.apache.cassandra.distributed.shared.Versions; import static org.apache.cassandra.distributed.shared.AssertUtils.*; @@ -96,4 +101,254 @@ public class CompactStorage2to3UpgradeTest extends UpgradeTestBase assertRows(rows, expected); })).run(); } + + @Test + public void testDropCompactWithClusteringAndValueColumn() throws Throwable + { + final String table = "clustering_and_value"; + final int partitions = 10; + final int rowsPerPartition = 10; + + final ResultsRecorder recorder = new ResultsRecorder(); + new TestCase() + .nodes(2) + .upgrade(Versions.Major.v22, Versions.Major.v30) + .setup(cluster -> { + cluster.schemaChange(String.format( + "CREATE TABLE %s.%s (key int, c1 int, c2 int, c3 int, PRIMARY KEY (key, c1, c2)) WITH COMPACT STORAGE", + KEYSPACE, table)); + ICoordinator coordinator = cluster.coordinator(1); + + + for (int i = 1; i <= partitions; i++) + { + for (int j = 1; j <= rowsPerPartition; j++) + { + coordinator.execute(String.format("INSERT INTO %s.%s (key, c1, c2, c3) VALUES (%d, %d, 1, 1)", + KEYSPACE, table, i, j), ConsistencyLevel.ALL); + coordinator.execute(String.format("INSERT INTO %s.%s (key, c1, c2, c3) VALUES (%d, %d, 2, 1)", + KEYSPACE, table, i, j), ConsistencyLevel.ALL); + } + } + + runQueries(cluster.coordinator(1), recorder, new String[] { + String.format("SELECT * FROM %s.%s", KEYSPACE, table), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 = %d", + KEYSPACE, table, partitions - 3, rowsPerPartition - 2), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 = %d", + KEYSPACE, table, partitions - 1, rowsPerPartition - 5), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 = %d and c2 = %d", + KEYSPACE, table, partitions - 1, rowsPerPartition - 5, 1), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 = %d and c2 = %d", + KEYSPACE, table, partitions - 4, rowsPerPartition - 9, 1), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 = %d and c2 > %d", + KEYSPACE, table, partitions - 4, rowsPerPartition - 9, 1), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 = %d and c2 > %d", + KEYSPACE, table, partitions - 4, rowsPerPartition - 9, 2), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 > %d", + KEYSPACE, table, partitions - 8, rowsPerPartition - 3), + + }); + }).runAfterClusterUpgrade(cluster -> + { + for (int i = 1; i <= cluster.size(); i++) + { + NodeToolResult result = cluster.get(1).nodetoolResult("upgradesstables"); + assertEquals("upgrade sstables failed for node " + i, 0, result.getRc()); + } + + // make sure the results are the same after upgrade and upgrade sstables but before dropping compact storage + recorder.validateResults(cluster, 1); + recorder.validateResults(cluster, 2); + + // make sure the results are the same after dropping compact storage on only the first node + IMessageFilters.Filter filter = cluster.verbs().allVerbs().to(2).drop(); + cluster.schemaChange(String.format("ALTER TABLE %s.%s DROP COMPACT STORAGE", KEYSPACE, table), 1); + + recorder.validateResults(cluster, 1, ConsistencyLevel.ONE); + + filter.off(); + recorder.validateResults(cluster, 1); + recorder.validateResults(cluster, 2); + + // make sure the results continue to be the same after dropping compact storage on the second node + cluster.schemaChange(String.format("ALTER TABLE %s.%s DROP COMPACT STORAGE", KEYSPACE, table), 2); + recorder.validateResults(cluster, 1); + recorder.validateResults(cluster, 2); + }) + .run(); + } + + @Test + public void testDropCompactWithClusteringAndValueColumnWithDeletesAndWrites() throws Throwable + { + final String table = "clustering_and_value_with_deletes"; + final int partitions = 10; + final int rowsPerPartition = 10; + final int additionalParititons = 5; + + new TestCase() + .nodes(2) + .upgrade(Versions.Major.v22, Versions.Major.v30) + .setup(cluster -> { + cluster.schemaChange(String.format( + "CREATE TABLE %s.%s (key int, c1 int, c2 int, c3 int, PRIMARY KEY (key, c1, c2)) WITH COMPACT STORAGE", + KEYSPACE, table)); + ICoordinator coordinator = cluster.coordinator(1); + + for (int i = 1; i <= partitions; i++) + { + for (int j = 1; j <= rowsPerPartition; j++) + { + coordinator.execute(String.format("INSERT INTO %s.%s (key, c1, c2, c3) VALUES (%d, %d, 1, 1)", + KEYSPACE, table, i, j), ConsistencyLevel.ALL); + coordinator.execute(String.format("INSERT INTO %s.%s (key, c1, c2, c3) VALUES (%d, %d, 2, 2)", + KEYSPACE, table, i, j), ConsistencyLevel.ALL); + coordinator.execute(String.format("INSERT INTO %s.%s (key, c1, c2, c3) VALUES (%d, %d, 3, 3)", + KEYSPACE, table, i, j), ConsistencyLevel.ALL); + } + } + + }) + .runAfterClusterUpgrade(cluster -> { + for (int i = 1; i <= cluster.size(); i++) + { + NodeToolResult result = cluster.get(1).nodetoolResult("upgradesstables"); + assertEquals("upgrade sstables failed for node " + i, 0, result.getRc()); + } + + // drop compact storage on only one node before performing writes + IMessageFilters.Filter filter = cluster.verbs().allVerbs().to(2).drop(); + cluster.schemaChange(String.format("ALTER TABLE %s.%s DROP COMPACT STORAGE", KEYSPACE, table), 1); + filter.off(); + + // add new partitions and delete some of the old ones + ICoordinator coordinator = cluster.coordinator(1); + for (int i = 0; i < additionalParititons; i++) + { + for (int j = 1; j <= rowsPerPartition; j++) + { + coordinator.execute(String.format("INSERT INTO %s.%s (key, c1, c2, c3) VALUES (%d, %d, 1, 1)", + KEYSPACE, table, i, j), ConsistencyLevel.ALL); + } + } + + coordinator.execute(String.format("DELETE FROM %s.%s WHERE key = %d and c1 = %d", + KEYSPACE, table, 0, 3), ConsistencyLevel.ALL); + + coordinator.execute(String.format("DELETE FROM %s.%s WHERE key = %d", + KEYSPACE, table, 1), ConsistencyLevel.ALL); + + coordinator.execute(String.format("DELETE FROM %s.%s WHERE key = %d and c1 = %d and c2 = %d", + KEYSPACE, table, 7, 2, 2), ConsistencyLevel.ALL); + + coordinator.execute(String.format("DELETE FROM %s.%s WHERE key = %d and c1 = %d and c2 = %d", + KEYSPACE, table, 7, 6, 1), ConsistencyLevel.ALL); + + coordinator.execute(String.format("DELETE FROM %s.%s WHERE key = %d and c1 = %d and c2 = %d", + KEYSPACE, table, 4, 1, 1), ConsistencyLevel.ALL); + + coordinator.execute(String.format("DELETE c3 FROM %s.%s WHERE key = %d and c1 = %d and c2 = %d", + KEYSPACE, table, 8, 1, 3), ConsistencyLevel.ALL); + + coordinator.execute(String.format("DELETE FROM %s.%s WHERE key = %d and c1 = %d and c2 > 1", + KEYSPACE, table, 6, 2, 4), ConsistencyLevel.ALL); + + ResultsRecorder recorder = new ResultsRecorder(); + runQueries(coordinator, recorder, new String[] { + String.format("SELECT * FROM %s.%s", KEYSPACE, table), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 = %d", + KEYSPACE, table, partitions - 3, rowsPerPartition - 2), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 = %d", + KEYSPACE, table, partitions - 1, rowsPerPartition - 5), + + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 > %d", + KEYSPACE, table, partitions - 8, rowsPerPartition - 3), + + String.format("SELECT * FROM %s.%s WHERE key = %d", + KEYSPACE, table, 7), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 = %d", + KEYSPACE, table, 7, 2), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 = %d", + KEYSPACE, table, 8, 1), + + String.format("SELECT c1, c2 FROM %s.%s WHERE key = %d and c1 = %d", + KEYSPACE, table, 8, 1), + + String.format("SELECT c1, c2 FROM %s.%s WHERE key = %d and c1 = %d", + KEYSPACE, table, 8, 1), + + String.format("SELECT c1, c2 FROM %s.%s WHERE key = %d and c1 = %d", + KEYSPACE, table, 4, 1), + + String.format("SELECT c1, c2 FROM %s.%s WHERE key = %d", + KEYSPACE, table, 6), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 > %d", + KEYSPACE, table, 0, 1), + + String.format("SELECT * FROM %s.%s WHERE key = %d", + KEYSPACE, table, partitions - (additionalParititons - 2)), + + String.format("SELECT * FROM %s.%s WHERE key = %d and c1 > %d", + KEYSPACE, table, partitions - (additionalParititons - 3), 4) + + }); + + // drop compact storage on remaining node and check result + cluster.schemaChange(String.format("ALTER TABLE %s.%s DROP COMPACT STORAGE", KEYSPACE, table), 2); + recorder.validateResults(cluster, 1); + recorder.validateResults(cluster, 2); + }).run(); + } + + + private void runQueries(ICoordinator coordinator, ResultsRecorder helper, String[] queries) + { + for (String query : queries) + helper.addResult(query, coordinator.execute(query, ConsistencyLevel.ALL)); + } + + public static class ResultsRecorder + { + final private Map preUpgradeResults = new HashMap<>(); + + public void addResult(String query, Object[][] results) + { + preUpgradeResults.put(query, results); + } + + public Map queriesAndResults() + { + return preUpgradeResults; + } + + public void validateResults(UpgradeableCluster cluster, int node) + { + validateResults(cluster, node, ConsistencyLevel.ALL); + } + + public void validateResults(UpgradeableCluster cluster, int node, ConsistencyLevel cl) + { + for (Map.Entry entry : queriesAndResults().entrySet()) + { + Object[][] postUpgradeResult = cluster.coordinator(node).execute(entry.getKey(), cl); + assertRows(postUpgradeResult, entry.getValue()); + } + + } + } + } \ No newline at end of file