Merge branch 'cassandra-4.1' into cassandra-5.0

This commit is contained in:
Stefan Miklosovic 2024-07-10 10:45:06 +02:00
commit 52a513f724
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
3 changed files with 88 additions and 1 deletions

View File

@ -55,6 +55,7 @@ Merged from 4.1:
* Memoize Cassandra verion and add a backoff interval for failed schema pulls (CASSANDRA-18902)
* Fix StackOverflowError on ALTER after many previous schema changes (CASSANDRA-19166)
Merged from 4.0:
* Fix schema.cql created by a snapshot after dropping more than one column (CASSANDRA-19747)
* UnsupportedOperationException when reducing scope for LCS compactions (CASSANDRA-19704)
* Make LWT conditions behavior on frozen and non-frozen columns consistent for null column values (CASSANDRA-19637)
* Add timeout specifically for bootstrapping nodes (CASSANDRA-15439)

View File

@ -1378,7 +1378,7 @@ public class TableMetadata implements SchemaElement
DroppedColumn dropped = iterDropped.next();
dropped.column.appendCqlTo(builder);
if (!hasSingleColumnPrimaryKey || iter.hasNext())
if (!hasSingleColumnPrimaryKey || iterDropped.hasNext())
builder.append(',');
builder.newLine();

View File

@ -459,6 +459,92 @@ public class SchemaCQLHelperTest extends CQLTester
Assert.assertEquals(isIndexLegacy ? 2 : 1, files.size());
}
@Test
public void testSnapshotWithDroppedColumnsWithoutReAdding() throws Throwable
{
String tableName = createTable("CREATE TABLE IF NOT EXISTS %s (" +
"pk1 varint," +
"pk2 ascii," +
"ck1 varint," +
"ck2 varint," +
"reg1 int," +
"reg2 int," +
"reg3 int," +
"PRIMARY KEY ((pk1, pk2), ck1, ck2)) WITH " +
"CLUSTERING ORDER BY (ck1 ASC, ck2 DESC);");
alterTable("ALTER TABLE %s DROP reg2 USING TIMESTAMP 10000;");
alterTable("ALTER TABLE %s DROP reg3 USING TIMESTAMP 10000;");
for (int i = 0; i < 10; i++)
execute("INSERT INTO %s (pk1, pk2, ck1, ck2, reg1) VALUES (?, ?, ?, ?, ?)", i, i + 1, i + 2, i + 3, null);
ColumnFamilyStore cfs = Keyspace.open(keyspace()).getColumnFamilyStore(tableName);
cfs.snapshot(SNAPSHOT);
String schema = Files.toString(cfs.getDirectories().getSnapshotSchemaFile(SNAPSHOT).toJavaIOFile(), Charset.defaultCharset());
schema = schema.substring(schema.indexOf("CREATE TABLE")); // trim to ensure order
String expected = "CREATE TABLE IF NOT EXISTS " + keyspace() + "." + tableName + " (\n" +
" pk1 varint,\n" +
" pk2 ascii,\n" +
" ck1 varint,\n" +
" ck2 varint,\n" +
" reg1 int,\n" +
" reg3 int,\n" +
" reg2 int,\n" +
" PRIMARY KEY ((pk1, pk2), ck1, ck2)\n" +
") WITH ID = " + cfs.metadata.id + "\n" +
" AND CLUSTERING ORDER BY (ck1 ASC, ck2 DESC)";
assertThat(schema,
allOf(startsWith(expected),
containsString("ALTER TABLE " + keyspace() + "." + tableName + " DROP reg2 USING TIMESTAMP 10000;"),
containsString("ALTER TABLE " + keyspace() + "." + tableName + " DROP reg3 USING TIMESTAMP 10000;")));
JsonNode manifest = JsonUtils.JSON_OBJECT_MAPPER.readTree(cfs.getDirectories().getSnapshotManifestFile(SNAPSHOT).toJavaIOFile());
JsonNode files = manifest.get("files");
Assert.assertTrue(files.isArray());
Assert.assertEquals(1, files.size());
}
@Test
public void testSnapshotWithDroppedColumnsWithoutReAddingOnSingleKeyTable() throws Throwable
{
String tableName = createTable("CREATE TABLE IF NOT EXISTS %s (" +
"pk1 varint PRIMARY KEY," +
"reg1 int," +
"reg2 int," +
"reg3 int);");
alterTable("ALTER TABLE %s DROP reg2 USING TIMESTAMP 10000;");
alterTable("ALTER TABLE %s DROP reg3 USING TIMESTAMP 10000;");
for (int i = 0; i < 10; i++)
execute("INSERT INTO %s (pk1, reg1) VALUES (?, ?)", i, i + 1);
ColumnFamilyStore cfs = Keyspace.open(keyspace()).getColumnFamilyStore(tableName);
cfs.snapshot(SNAPSHOT);
String schema = Files.toString(cfs.getDirectories().getSnapshotSchemaFile(SNAPSHOT).toJavaIOFile(), Charset.defaultCharset());
schema = schema.substring(schema.indexOf("CREATE TABLE")); // trim to ensure order
String expected = "CREATE TABLE IF NOT EXISTS " + keyspace() + "." + tableName + " (\n" +
" pk1 varint PRIMARY KEY,\n" +
" reg1 int,\n" +
" reg3 int,\n" +
" reg2 int\n" +
") WITH ID = " + cfs.metadata.id + "\n";
assertThat(schema,
allOf(startsWith(expected),
containsString("ALTER TABLE " + keyspace() + "." + tableName + " DROP reg2 USING TIMESTAMP 10000;"),
containsString("ALTER TABLE " + keyspace() + "." + tableName + " DROP reg3 USING TIMESTAMP 10000;")));
JsonNode manifest = JsonUtils.JSON_OBJECT_MAPPER.readTree(cfs.getDirectories().getSnapshotManifestFile(SNAPSHOT).toJavaIOFile());
JsonNode files = manifest.get("files");
Assert.assertTrue(files.isArray());
Assert.assertEquals(1, files.size());
}
@Test
public void testSystemKsSnapshot()
{