diff options
author | Tor Brede Vekterli <vekterli@yahoo-inc.com> | 2017-06-09 18:05:27 +0200 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahoo-inc.com> | 2017-06-12 15:16:33 +0200 |
commit | 462be9cb41a98c630112fcaa9b997fffc1965a81 (patch) | |
tree | bc7572dab430830c0c821a94838e5d7b87f611fa /document | |
parent | d165ec86d13eb7ba8635db3408148e82b7456368 (diff) |
Only write raw compression array if compressable input
If compression type is INCOMPRESSIBLE, would previously end up writing
the entire raw working buffer, which is at least 4096 bytes long.
Diffstat (limited to 'document')
3 files changed, 22 insertions, 2 deletions
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java index 211412be684..6095d4a1545 100644 --- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java +++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java @@ -344,7 +344,7 @@ public class VespaDocumentSerializer42 extends BufferSerializer implements Docum } int pos = buf.position(); - if (compression.data() != null) { + if (compression.data() != null && compression.type().isCompressed()) { put(null, compression.data()); } else { put(null, buffer.getByteBuffer()); diff --git a/document/src/test/java/com/yahoo/document/serialization/VespaDocumentSerializerTestCase.java b/document/src/test/java/com/yahoo/document/serialization/VespaDocumentSerializerTestCase.java index 329d1956e64..8399c0b280e 100644 --- a/document/src/test/java/com/yahoo/document/serialization/VespaDocumentSerializerTestCase.java +++ b/document/src/test/java/com/yahoo/document/serialization/VespaDocumentSerializerTestCase.java @@ -107,6 +107,26 @@ public class VespaDocumentSerializerTestCase { // Should _not_ throw any deserialization exceptions fixture.roundtripSerialize(doc); + // TODO check target values..! + } + + @Test + public void incompressable_structs_are_serialized_without_buffer_size_overhead_bug() { + CompressionFixture fixture = new CompressionFixture(); + + Document doc = new Document(fixture.docType, "id:foo:map_of_structs::flarn"); + Struct nested = new Struct(fixture.nestedType); + nested.setFieldValue("str", new StringFieldValue(fixture.compressableString())); + + MapFieldValue<StringFieldValue, Struct> map = new MapFieldValue<StringFieldValue, Struct>(fixture.mapType); + // Only 1 struct added. Not enough redundant information that header struct containing map itself + // can be compressed. + map.put(new StringFieldValue("foo"), nested); + doc.setFieldValue("map", map); + + GrowableByteBuffer buf = CompressionFixture.asSerialized(doc); + // Explanation of arbitrary value: buffer copy bug meant that incompressable structs were all serialized + // rounded up to 4096 bytes. + assertTrue(buf.remaining() < 4096); } - } diff --git a/document/src/tests/data/serializejava-compressed.dat b/document/src/tests/data/serializejava-compressed.dat Binary files differindex 86875d5f121..453abef81f1 100644 --- a/document/src/tests/data/serializejava-compressed.dat +++ b/document/src/tests/data/serializejava-compressed.dat |