You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2024/06/12 15:28:02 UTC
(jackrabbit-oak) branch trunk updated: Revert "OAK-10803 - Modified DocumentPropertyState.java to compress values ba… (#1473)"
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 5d10c51ff5 Revert "OAK-10803 - Modified DocumentPropertyState.java to compress values ba… (#1473)"
5d10c51ff5 is described below
commit 5d10c51ff53dc05e2d36b2491689412ccd17b15d
Author: Julian Reschke <re...@apache.org>
AuthorDate: Wed Jun 12 16:27:46 2024 +0100
Revert "OAK-10803 - Modified DocumentPropertyState.java to compress values ba… (#1473)"
This reverts commit 163352368343164671231b1ee8f4db75f3925877.
---
.../plugins/document/DocumentPropertyState.java | 62 +----------
.../document/DocumentPropertyStateTest.java | 115 ---------------------
2 files changed, 5 insertions(+), 172 deletions(-)
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java
index b684a69fad..872985e566 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java
@@ -19,11 +19,6 @@ package org.apache.jackrabbit.oak.plugins.document;
import static java.util.Collections.emptyList;
import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
import java.util.List;
import javax.jcr.PropertyType;
@@ -31,7 +26,6 @@ import javax.jcr.PropertyType;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.commons.Compression;
import org.apache.jackrabbit.oak.commons.json.JsopReader;
import org.apache.jackrabbit.oak.commons.json.JsopTokenizer;
import org.apache.jackrabbit.oak.json.TypeCodes;
@@ -44,16 +38,12 @@ import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
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;
@@ -61,40 +51,11 @@ final class DocumentPropertyState implements PropertyState {
private final String value;
private PropertyState parsed;
- private final byte[] compressedValue;
- private final Compression compression;
-
- private static final int DEFAULT_COMPRESSION_THRESHOLD = Integer.getInteger("oak.mongo.compressionThreshold", -1);
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.compression = compression;
- int size = value.getBytes().length;
- String localValue = value;
- byte[] 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;
- }
-
- private byte[] compress(byte[] value) throws IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- OutputStream compressionOutputStream = compression.getOutputStream(out);
- compressionOutputStream.write(value);
- compressionOutputStream.close();
- return out.toByteArray();
+ this.value = value;
}
@NotNull
@@ -155,20 +116,7 @@ final class DocumentPropertyState implements PropertyState {
*/
@NotNull
String getValue() {
- return value != null ? value : decompress(this.compressedValue);
- }
-
- private String decompress(byte[] value) {
- try {
- return new String(compression.getInputStream(new ByteArrayInputStream(value)).readAllBytes(), StandardCharsets.UTF_8);
- } catch (IOException e) {
- LOG.error("Failed to decompress property {} value: ", getName(), e);
- return "\"{}\"";
- }
- }
-
- private byte[] getCompressedValue() {
- return compressedValue;
+ return value;
}
//------------------------------------------------------------< Object >--
@@ -180,7 +128,7 @@ final class DocumentPropertyState implements PropertyState {
} else if (object instanceof DocumentPropertyState) {
DocumentPropertyState other = (DocumentPropertyState) object;
return this.name.equals(other.name)
- && this.getValue().equals(other.getValue());
+ && this.value.equals(other.value);
}
// fall back to default equality check in AbstractPropertyState
return object instanceof PropertyState
@@ -201,7 +149,7 @@ final class DocumentPropertyState implements PropertyState {
private PropertyState parsed() {
if (parsed == null) {
- JsopReader reader = new JsopTokenizer(getValue());
+ JsopReader reader = new JsopTokenizer(value);
if (reader.matches('[')) {
parsed = readArrayProperty(name, reader);
} else {
@@ -329,4 +277,4 @@ final class DocumentPropertyState implements PropertyState {
}
return createProperty(name, values, Type.fromTag(type, true));
}
-}
\ No newline at end of file
+}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyStateTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyStateTest.java
index b3184975ab..557a0c1d1f 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyStateTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyStateTest.java
@@ -18,41 +18,26 @@ package org.apache.jackrabbit.oak.plugins.document;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.List;
-import java.util.Objects;
import java.util.Set;
-import org.apache.commons.lang3.RandomStringUtils;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.commons.Compression;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.reflections.util.Utils;
import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList;
import static org.apache.jackrabbit.guava.common.collect.Sets.newHashSet;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.*;
public class DocumentPropertyStateTest {
private static final int BLOB_SIZE = 16 * 1024;
- public static final int COMPRESSED_SIZE = 543;
- private static final String TEST_NODE = "test";
- private static final String STRING_HUGEVALUE = RandomStringUtils.random(1050, "dummytest");
@Rule
public DocumentMKBuilderProvider builderProvider = new DocumentMKBuilderProvider();
@@ -96,104 +81,4 @@ public class DocumentPropertyStateTest {
assertEquals(0, reads.size());
}
- @Test
- public void multiValuedAboveThresholdSize() throws Exception {
- NodeBuilder builder = ns.getRoot().builder();
- List<Blob> blobs = newArrayList();
- for (int i = 0; i < 13; i++) {
- blobs.add(builder.createBlob(new RandomStream(BLOB_SIZE, i)));
- }
- builder.child(TEST_NODE).setProperty("p", blobs, Type.BINARIES);
- TestUtils.merge(ns, builder);
-
- PropertyState p = ns.getRoot().getChildNode(TEST_NODE).getProperty("p");
- assertEquals(Type.BINARIES, Objects.requireNonNull(p).getType());
- assertEquals(13, p.count());
-
- reads.clear();
- assertEquals(BLOB_SIZE, p.size(0));
- // must not read the blob via stream
- assertEquals(0, reads.size());
- }
-
- @Test
- public void stringBelowThresholdSize() throws Exception {
- NodeBuilder builder = ns.getRoot().builder();
- builder.child(TEST_NODE).setProperty("p", "dummy", Type.STRING);
- TestUtils.merge(ns, builder);
-
- PropertyState p = ns.getRoot().getChildNode(TEST_NODE).getProperty("p");
- assertEquals(Type.STRING, Objects.requireNonNull(p).getType());
- assertEquals(1, p.count());
-
- reads.clear();
- assertEquals(5, p.size(0));
- // must not read the string via stream
- assertEquals(0, reads.size());
- }
-
- @Test
- public void stringAboveThresholdSize() throws Exception {
- NodeBuilder builder = ns.getRoot().builder();
- builder.child(TEST_NODE).setProperty("p", STRING_HUGEVALUE, Type.STRING);
- TestUtils.merge(ns, builder);
-
- PropertyState p = ns.getRoot().getChildNode(TEST_NODE).getProperty("p");
- assertEquals(Type.STRING, Objects.requireNonNull(p).getType());
- assertEquals(1, p.count());
-
- reads.clear();
- assertEquals(1050, p.size(0));
- // must not read the string via streams
- assertEquals(0, reads.size());
- }
-
- @Test
- public void compressValueThrowsException() throws IOException {
- DocumentNodeStore mockDocumentStore = mock(DocumentNodeStore.class);
- Compression mockCompression = mock(Compression.class);
- when(mockCompression.getOutputStream(any(OutputStream.class))).thenThrow(new IOException("Compression failed"));
-
- DocumentPropertyState documentPropertyState = new DocumentPropertyState(mockDocumentStore, "p", "\"" + STRING_HUGEVALUE + "\"", mockCompression);
-
- assertEquals(documentPropertyState.getValue(Type.STRING), STRING_HUGEVALUE);
-
- verify(mockCompression, times(1)).getOutputStream(any(OutputStream.class));
-
- }
-
- @Test
- public void uncompressValueThrowsException() throws IOException {
-
- DocumentNodeStore mockDocumentStore = mock(DocumentNodeStore.class);
- Compression mockCompression = mock(Compression.class);
- OutputStream mockOutputStream= mock(OutputStream.class);
- when(mockCompression.getOutputStream(any(OutputStream.class))).thenReturn(mockOutputStream);
- when(mockCompression.getInputStream(any(InputStream.class))).thenThrow(new IOException("Compression failed"));
-
- DocumentPropertyState documentPropertyState = new DocumentPropertyState(mockDocumentStore, "p", STRING_HUGEVALUE, mockCompression);
-
- assertEquals(documentPropertyState.getValue(Type.STRING), "{}");
-
- verify(mockCompression, times(1)).getInputStream(any(InputStream.class));
- }
-
- @Test
- public void stringAboveThresholdSizeNoCompression() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
- DocumentNodeStore store = mock(DocumentNodeStore.class);
-
- DocumentPropertyState state = new DocumentPropertyState(store, "propertyName", "\"" + STRING_HUGEVALUE + "\"", Compression.NONE);
-
- // Get the private method
- Method getCompressedValueMethod = DocumentPropertyState.class.getDeclaredMethod("getCompressedValue");
-
- // Make the method accessible
- getCompressedValueMethod.setAccessible(true);
- byte[] result = (byte[]) getCompressedValueMethod.invoke(state);
-
- assertEquals(result.length, STRING_HUGEVALUE.length() + 2 );
-
- assertEquals(state.getValue(Type.STRING), STRING_HUGEVALUE);
- assertEquals(STRING_HUGEVALUE, state.getValue(Type.STRING));
- }
}