Skip to content

Commit

Permalink
Set uuid_sstable_identifiers_enabled to true for cassandra-latest.yaml
Browse files Browse the repository at this point in the history
patch by Stefan Miklosovic; reviewed by Branimir Lambov, Jacek Lewandowski for CASSANDRA-19460
  • Loading branch information
smiklosovic committed Mar 12, 2024
1 parent 451b0c0 commit 2f836fa
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
5.0-beta2
* Set uuid_sstable_identifiers_enabled to true in cassandra-latest.yaml (CASSANDRA-19460)
* Revert switching to approxTime in Dispatcher (CASSANDRA-19454)
* Add an optimized default configuration to tests and make it available for new users (CASSANDRA-18753)
* Fix remote JMX under Java17 (CASSANDRA-19453)
Expand Down
2 changes: 1 addition & 1 deletion conf/cassandra_latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ sstable_preemptive_open_interval: 50MiB
# set to true, each newly created sstable will have a UUID based generation identifier and such files are
# not readable by previous Cassandra versions. At some point, this option will become true by default
# and eventually get removed from the configuration.
uuid_sstable_identifiers_enabled: false
uuid_sstable_identifiers_enabled: true

# When enabled, permits Cassandra to zero-copy stream entire eligible
# SSTables between nodes, including every component.
Expand Down
70 changes: 68 additions & 2 deletions src/java/org/apache/cassandra/db/Directories.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.Spliterator;
import java.util.concurrent.ThreadLocalRandom;
Expand Down Expand Up @@ -646,6 +647,29 @@ public static File getSnapshotDirectory(File location, String snapshotName)
}
}

/**
* Returns directory to write a snapshot to. If directory does not exist, then it is NOT created.
*
* If given {@code location} indicates secondary index, this will return
* {@code <cf dir>/snapshots/<snapshot name>/.<index name>}.
* Otherwise, this will return {@code <cf dir>/snapshots/<snapshot name>}.
*
* @param location base directory
* @param snapshotName snapshot name
* @return directory to write a snapshot
*/
public static Optional<File> getSnapshotDirectoryIfExists(File location, String snapshotName)
{
if (isSecondaryIndexFolder(location))
{
return get(location.parent(), SNAPSHOT_SUBDIR, snapshotName, location.name());
}
else
{
return get(location, SNAPSHOT_SUBDIR, snapshotName);
}
}

public File getSnapshotManifestFile(String snapshotName)
{
File snapshotDir = getSnapshotDirectory(getDirectoryForNewSSTables(), snapshotName);
Expand Down Expand Up @@ -673,6 +697,16 @@ public static File getBackupsDirectory(Descriptor desc)
return getBackupsDirectory(desc.directory);
}

/**
* Returns directory to write a backup to. If directory does not exist, then one is created.
*
* If given {@code location} indicates secondary index, this will return
* {@code <cf dir>/backups/.<index name>}.
* Otherwise, this will return {@code <cf dir>/backups/}.
*
* @param location base directory
* @return directory to write a backup
*/
public static File getBackupsDirectory(File location)
{
if (isSecondaryIndexFolder(location))
Expand All @@ -685,6 +719,28 @@ public static File getBackupsDirectory(File location)
}
}

/**
* Returns directory to write a backup to. If directory does not exist, then it is NOT created.
*
* If given {@code location} indicates secondary index, this will return
* {@code <cf dir>/backups/.<index name>}.
* Otherwise, this will return {@code <cf dir>/backups/}.
*
* @param location base directory
* @return directory to write a backup
*/
public static Optional<File> getBackupsDirectoryIfExists(File location)
{
if (isSecondaryIndexFolder(location))
{
return get(location.parent(), BACKUPS_SUBDIR, location.name());
}
else
{
return get(location, BACKUPS_SUBDIR);
}
}

/**
* Checks if the specified table should be stored with local system data.
*
Expand Down Expand Up @@ -1020,15 +1076,19 @@ private void filter()

if (snapshotName != null)
{
LifecycleTransaction.getFiles(getSnapshotDirectory(location, snapshotName).toPath(), getFilter(), onTxnErr);
Optional<File> maybeSnapshotDir = getSnapshotDirectoryIfExists(location, snapshotName);
maybeSnapshotDir.ifPresent(dir -> LifecycleTransaction.getFiles(dir.toPath(), getFilter(), onTxnErr));
continue;
}

if (!onlyBackups)
LifecycleTransaction.getFiles(location.toPath(), getFilter(), onTxnErr);

if (includeBackups)
LifecycleTransaction.getFiles(getBackupsDirectory(location).toPath(), getFilter(), onTxnErr);
{
Optional<File> maybeBackupsDir = getBackupsDirectoryIfExists(location);
maybeBackupsDir.ifPresent(dir -> LifecycleTransaction.getFiles(dir.toPath(), getFilter(), onTxnErr));
}
}

filtered = true;
Expand Down Expand Up @@ -1326,6 +1386,12 @@ else if (!dir.tryCreateDirectories() && !(dir.exists() && dir.isDirectory()))
return dir;
}

public static Optional<File> get(File base, String... subdirs)
{
File dir = subdirs == null || subdirs.length == 0 ? base : new File(base, join(subdirs));
return dir.exists() ? Optional.of(dir) : Optional.empty();
}

private static String join(String... s)
{
return StringUtils.join(s, File.pathSeparator());
Expand Down
2 changes: 2 additions & 0 deletions test/conf/latest_diff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ default_compaction:

concurrent_compactors: 8

uuid_sstable_identifiers_enabled: true

stream_entire_sstables: true

default_secondary_index: sai
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ private InstanceConfig(int num,

.set("concurrent_compactors", "8")

.set("uuid_sstable_identifiers_enabled", "true")

.set("stream_entire_sstables", "true")

.set("default_secondary_index", "sai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.junit.Test;

import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.distributed.Cluster;
import org.apache.cassandra.distributed.api.Feature;
import org.apache.cassandra.io.sstable.Descriptor;
import org.apache.cassandra.io.sstable.SequenceBasedSSTableId;
import org.apache.cassandra.io.sstable.UUIDBasedSSTableId;

import static org.apache.cassandra.Util.getBackups;
import static org.apache.cassandra.distributed.Cluster.build;
Expand Down Expand Up @@ -144,23 +147,30 @@ private void disableCompaction(Cluster cluster, String keyspace, String table)
cluster.get(i).nodetool("disableautocompaction", keyspace, table);
}

private static void assertBackupSSTablesCount(Cluster cluster, int expectedSeqGenIds, boolean enable, String ks, String... tableNames)
private static void assertBackupSSTablesCount(Cluster cluster, int expectedTablesCount, boolean enable, String ks, String... tableNames)
{
for (int i = 1; i < cluster.size() + 1; i++)
{
cluster.get(i).runOnInstance(rethrow(() -> Arrays.stream(tableNames).forEach(tableName -> assertTableMetaIncrementalBackupEnable(ks, tableName, enable))));
cluster.get(i).runOnInstance(rethrow(() -> Arrays.stream(tableNames).forEach(tableName -> assertSSTablesCount(getBackups(ks, tableName), tableName, expectedSeqGenIds))));
cluster.get(i).runOnInstance(rethrow(() -> Arrays.stream(tableNames).forEach(tableName -> assertSSTablesCount(getBackups(ks, tableName), tableName, expectedTablesCount))));
}
}

private static void assertSSTablesCount(Set<Descriptor> descs, String tableName, int expectedSeqGenIds)
private static void assertSSTablesCount(Set<Descriptor> descs, String tableName, int expectedTablesCount)
{
Predicate<Descriptor> descriptorPredicate = descriptor -> {
if (DatabaseDescriptor.isUUIDSSTableIdentifiersEnabled())
return descriptor.id instanceof UUIDBasedSSTableId;
else
return descriptor.id instanceof SequenceBasedSSTableId;
};

List<String> seqSSTables = descs.stream()
.filter(desc -> desc.id instanceof SequenceBasedSSTableId)
.filter(descriptorPredicate)
.map(descriptor -> descriptor.baseFile().toString())
.sorted()
.collect(Collectors.toList());
assertThat(seqSSTables).describedAs("SSTables of %s with sequence based id", tableName).hasSize(expectedSeqGenIds);
assertThat(seqSSTables).describedAs("SSTables of %s with sequence based id", tableName).hasSize(expectedTablesCount);
}

private static void assertTableMetaIncrementalBackupEnable(String ks, String tableName, boolean enable)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/org/apache/cassandra/index/CustomIndexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public void testFailing2iFlush() throws Throwable
}

// SSTables remain uncommitted.
assertEquals(1, getCurrentColumnFamilyStore().getDirectories().getDirectoryForNewSSTables().tryList().length);
assertEquals(0, getCurrentColumnFamilyStore().getDirectories().getDirectoryForNewSSTables().tryList().length);
}

@Test
Expand Down

0 comments on commit 2f836fa

Please sign in to comment.