stefan-egli commented on code in PR #1473:
URL: https://github.com/apache/jackrabbit-oak/pull/1473#discussion_r1629695860
##########
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java:
##########
@@ -38,24 +44,58 @@
import org.apache.jackrabbit.oak.plugins.memory.StringPropertyState;
import org.apache.jackrabbit.oak.plugins.value.Conversions;
import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* PropertyState implementation with lazy parsing of the JSOP encoded value.
*/
final class DocumentPropertyState implements PropertyState {
+ private static final Logger LOG =
LoggerFactory.getLogger(DocumentPropertyState.class);
+
private final DocumentNodeStore store;
private final String name;
- private final String value;
+ private String value;
private PropertyState parsed;
+ private byte[] compressedValue;
+ private final Compression compression;
+
+ private static final int DEFAULT_COMPRESSION_THRESHOLD =
Integer.getInteger("oak.mongo.compressionThreshold", 1024);
DocumentPropertyState(DocumentNodeStore store, String name, String value) {
+ this(store, name, value, Compression.GZIP);
+ }
+
+ DocumentPropertyState(DocumentNodeStore store, String name, String value,
Compression compression) {
this.store = store;
this.name = name;
- this.value = value;
+ this.compression = compression;
+ int size = value.getBytes().length;
+ if (compression != null && size > DEFAULT_COMPRESSION_THRESHOLD ) {
+ try {
+ compressedValue =
compress(value.getBytes(StandardCharsets.UTF_8));
+ this.value = null;
+ } catch (IOException e) {
+ LOG.warn("Failed to compress property {} value: ", name, e);
+ this.value = value;
+ this.compressedValue = null;
+ }
+ } else {
+ this.value = value;
+ compressedValue = null;
+ }
Review Comment:
```suggestion
String localValue = value;
String localCompressedValue = null;
if (compression != null && size > DEFAULT_COMPRESSION_THRESHOLD ) {
try {
localCompressedValue =
compress(value.getBytes(StandardCharsets.UTF_8));
localValue = null;
} catch (IOException e) {
LOG.warn("Failed to compress property {} value: ", name, e);
}
}
this.value = localValue;
this.compressedValue = localCompressedValue;
```
A last-minute idea : what about making `value` and `compressedValue` `final`
again and assign them like shown above? Having them final would make it
somewhat stronger and clearer in my view. Wdyt?
##########
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java:
##########
@@ -38,24 +44,58 @@
import org.apache.jackrabbit.oak.plugins.memory.StringPropertyState;
import org.apache.jackrabbit.oak.plugins.value.Conversions;
import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* PropertyState implementation with lazy parsing of the JSOP encoded value.
*/
final class DocumentPropertyState implements PropertyState {
+ private static final Logger LOG =
LoggerFactory.getLogger(DocumentPropertyState.class);
+
private final DocumentNodeStore store;
private final String name;
- private final String value;
+ private String value;
private PropertyState parsed;
+ private byte[] compressedValue;
+ private final Compression compression;
+
+ private static final int DEFAULT_COMPRESSION_THRESHOLD =
Integer.getInteger("oak.mongo.compressionThreshold", 1024);
Review Comment:
Two more things came to mind:
* we should have a way to disable compression - eg by making this value
`-1`. Currently that is not the case.
* are we sure we want the default to be 1024? We could choose -1 instead
until we are confident this change should be on by default.
--
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]