Skip to content

Commit

Permalink
Added requested tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudenw authored and smiklosovic committed Aug 10, 2023
1 parent cdfb78e commit b5e3bf3
Show file tree
Hide file tree
Showing 5 changed files with 476 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/java/org/apache/cassandra/io/compress/LZ4Compressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ public static LZ4Compressor create(Map<String, String> args) throws Configuratio
if (compressorType.equals(LZ4_FAST_COMPRESSOR) && args.get(LZ4_HIGH_COMPRESSION_LEVEL) != null)
logger.warn("'{}' parameter is ignored when '{}' is '{}'", LZ4_HIGH_COMPRESSION_LEVEL, LZ4_COMPRESSOR_TYPE, LZ4_FAST_COMPRESSOR);
if (compressorType.equals(LZ4_HIGH_COMPRESSOR))
logger.info("The ZstdCompressor may be preferable to LZ4 in 'high' mode. Zstd will typically " +
"compress much faster while achieving better ratio, but it may decompress more slowly,");
logger.info("The {} may be preferable to LZ4 in 'high' mode. Zstd will typically " +
"compress much faster while achieving better ratio, but it may decompress more slowly.",
ZstdCompressor.class.getSimpleName());

instance = new LZ4Compressor(compressorType, compressionLevel);
LZ4Compressor instanceFromMap = instances.putIfAbsent(compressorTypeAndLevel, instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private static CompressionParams buildCompressionParams(TableMetadata metadata,
if (!compressor.recommendedUses().contains(ICompressor.Uses.FAST_COMPRESSION))
{
// The default compressor is generally fast (LZ4 with 16KiB block size)
compressionParams = CompressionParams.defaultParams();
compressionParams = CompressionParams.DEFAULT;
break;
}
// else fall through
Expand Down
11 changes: 9 additions & 2 deletions src/java/org/apache/cassandra/schema/CompressionParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ public final class CompressionParams
DEFAULT_MIN_COMPRESS_RATIO,
emptyMap());

private static final CompressionParams DEFAULT = new CompressionParams(LZ4Compressor.create(Collections.emptyMap()),
// The default compressor is generally fast (LZ4 with 16KiB block size)
public static final CompressionParams DEFAULT = new CompressionParams(LZ4Compressor.create(Collections.emptyMap()),
DEFAULT_CHUNK_LENGTH,
calcMaxCompressedLength(DEFAULT_CHUNK_LENGTH, DEFAULT_MIN_COMPRESS_RATIO),
DEFAULT_MIN_COMPRESS_RATIO,
emptyMap());

private static CompressionParams CALCULATED_DEFAULT;

@VisibleForTesting
static final String TOO_MANY_CHUNK_LENGTH = format("Only one of '%s' or '%s' may be specified", CHUNK_LENGTH, CHUNK_LENGTH_IN_KB);

Expand Down Expand Up @@ -149,7 +152,11 @@ public ICompressor create(Map<String,String> options) {

public static CompressionParams defaultParams()
{
return fromParameterizedClass(DatabaseDescriptor.getSSTableCompression());
CompressionParams result = CALCULATED_DEFAULT;
if (result == null)
result = CALCULATED_DEFAULT = fromParameterizedClass(DatabaseDescriptor.getSSTableCompression());

return result;
}

public static CompressionParams fromParameterizedClass(ParameterizedClass options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,10 @@ public void setUncaughtExceptionsFilter(BiPredicate<Integer, Throwable> ignoreUn
@Override
public void close()
{
close(true);
}

public void close(boolean deleteRoot) {
logger.info("Closing cluster {}", this.clusterId);
FBUtilities.closeQuietly(instanceInitializer);
FBUtilities.waitOnFutures(instances.stream()
Expand All @@ -1057,7 +1061,7 @@ public void close()
instanceMap.clear();
PathUtils.setDeletionListener(ignore -> {});
// Make sure to only delete directory when threads are stopped
if (Files.exists(root))
if (deleteRoot && Files.exists(root))
PathUtils.deleteRecursive(root);
Thread.setDefaultUncaughtExceptionHandler(previousHandler);
previousHandler = null;
Expand Down
Loading

0 comments on commit b5e3bf3

Please sign in to comment.