reschke commented on code in PR #1473: URL: https://github.com/apache/jackrabbit-oak/pull/1473#discussion_r1616858582
########## oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java: ########## @@ -38,24 +43,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()); Review Comment: value.getBytes() should specify the character encoding to use (note UTF-8 is not ncessarily the default). ########## oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java: ########## @@ -116,7 +155,20 @@ public int count() { */ @NotNull String getValue() { - return value; + return value != null ? value : decompress(this.compressedValue); + } + + private String decompress(byte[] value) { + try { + return new String(compression.getInputStream(new ByteArrayInputStream(value)).readAllBytes()); + } catch (IOException e) { + LOG.error("Failed to decompress property {} value: ", getName(), e); + return "\"{}\""; + } + } + + public byte[] getCompressedValue() { Review Comment: 1. Can we avoid creating a stream wrapper here, even if this needs changes in compression? 2. Constructing a string from bytes should be done with an explicit character encoding, otherwise it's platform/locale dependant. -- 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: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org