From 659a8803fcfd5cd23e9c3b6f254a26ed2979509d Mon Sep 17 00:00:00 2001 From: Will Dey Date: Tue, 12 Nov 2024 23:05:08 -0500 Subject: [PATCH] test --- .../cassandra/db/ColumnFamilyStoreTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java index a4f25844ce..48995baad0 100644 --- a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java +++ b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.CharacterCodingException; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -118,6 +120,7 @@ public class ColumnFamilyStoreTest public static final String CF_STANDARD5 = "Standard5"; public static final String CF_STANDARD6 = "Standard6"; public static final String CF_STANDARD7 = "Standard7"; + public static final String CF_STANDARD8 = "Standard8"; public static final String CF_STANDARDINT = "StandardInteger1"; public static final String CF_SUPER1 = "Super1"; public static final String CF_SUPER6 = "Super6"; @@ -148,6 +151,7 @@ public static void defineSchema() throws ConfigurationException SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD5), SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD6), SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD7), + SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD8), SchemaLoader.indexCFMD(KEYSPACE1, CF_INDEX1, true), SchemaLoader.indexCFMD(KEYSPACE1, CF_INDEX2, false), SchemaLoader.superCFMD(KEYSPACE1, CF_SUPER1, LongType.instance), @@ -2002,6 +2006,38 @@ public void testRemoveUnusedSstablesOnlyRemovesFiltered() throws IOException assertEquals(expected, sstables.keySet()); } + @Test + public void testRemoveUnusedSstablesDoesNotTouchProductsWhenAncestorDoesNotExist() throws IOException + { + final String ks = KEYSPACE1; + final String cf = CF_STANDARD8; + + final CFMetaData cfmeta = Schema.instance.getCFMetaData(ks, cf); + Keyspace.open(KEYSPACE1).getColumnFamilyStore(cf).disableAutoCompaction(); + Directories dir = new Directories(cfmeta); + + int gen1 = writeNextGenerationSstable(ImmutableSet.of(), dir, cfmeta); + int gen2 = writeNextGenerationSstable(ImmutableSet.of(), dir, cfmeta); + int gen3 = writeNextGenerationSstable(ImmutableSet.of(gen1, gen2), dir, cfmeta); + int gen4 = writeNextGenerationSstable(ImmutableSet.of(), dir, cfmeta); + int gen5 = writeNextGenerationSstable(ImmutableSet.of(gen4), dir, cfmeta); + + Map> sstables = dir.sstableLister().list(); + Descriptor sstable3Desc = sstables.keySet().iterator().next().withGeneration(gen3); + assertEquals(5, sstables.size()); + assertTrue(sstables.containsKey(sstable3Desc)); + + Files.delete(Paths.get(sstables.keySet().iterator().next().withGeneration(gen3).filenameFor(Component.DATA))); + + ColumnFamilyStore.removeUnusedSstables(cfmeta, ImmutableMap.of()); + + sstables = dir.sstableLister().list(); + ImmutableSet products = ImmutableSet.of( + sstable3Desc.withGeneration(gen3), + sstable3Desc.withGeneration(gen5)); + assertTrue(sstables.keySet().containsAll(products)); + } + @Test public void testLoadNewSSTablesAvoidsOverwrites() throws Throwable {