smiklosovic commented on code in PR #4399:
URL: https://github.com/apache/cassandra/pull/4399#discussion_r2411740844
##########
src/java/org/apache/cassandra/io/compress/CompressionMetadata.java:
##########
@@ -139,11 +165,54 @@ private CompressionMetadata(CompressionMetadata copy)
this.compressedFileLength = copy.compressedFileLength;
this.chunkOffsets = copy.chunkOffsets;
this.chunkOffsetsSize = copy.chunkOffsetsSize;
+ this.compressionDictionary = copy.compressionDictionary;
}
public ICompressor compressor()
{
- return parameters.getSstableCompressor();
+ // classic double-checked locking to call resolveCompressor method
just once per CompressionMetadata object
+ ICompressor result = resolvedCompressor;
+ if (result != null)
+ return result;
+
+ synchronized (this)
+ {
+ result = resolvedCompressor;
+ if (result == null)
+ {
+ result = resolveCompressor(parameters.getSstableCompressor(),
compressionDictionary);
+ resolvedCompressor = result;
+ }
+ return result;
+ }
+ }
+
+ static ICompressor resolveCompressor(ICompressor compressor,
CompressionDictionary dictionary)
+ {
+ if (dictionary == null)
+ return compressor;
+
+ // When the attached dictionary can be consumed by the current
dictionary compressor
+ if (compressor instanceof IDictionaryCompressor)
+ {
+ IDictionaryCompressor dictionaryCompressor =
(IDictionaryCompressor) compressor;
+ if (dictionaryCompressor.canConsumeDictionary(dictionary))
+ return
dictionaryCompressor.getOrCopyWithDictionary(dictionary);
+ }
+
+ // When the current compressor is not compatible with the dictionary.
It could happen in the read path when:
+ // 1. The current compressor is not a dictionary compressor, but there
is dictionary attached
+ // 2. The current dictionary compressor is a different type, e.g.
table schema is changed
+ // In those cases, we should get the compatible dictionary compressor
based on the dictionary
+ if (dictionary.kind() == ZSTD)
Review Comment:
or even better
return dictionary.getCompressor();
which would be like
default IDictionaryCompressor getCompressor()
{
return kind().getCompressor(this);
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]