diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-11-10 20:23:53 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-11-10 20:25:24 +0100 |
commit | c272d764d842f04d864bcca5b57468ec7e8aad92 (patch) | |
tree | 5626b49fc39c09c479bd4867eaa1994e7b2bc194 /document/src/main/java/com/yahoo | |
parent | 566108512ea68568354c6798180ff1a750c6b6aa (diff) |
GC dompression support in java.
Diffstat (limited to 'document/src/main/java/com/yahoo')
4 files changed, 53 insertions, 94 deletions
diff --git a/document/src/main/java/com/yahoo/document/BaseStructDataType.java b/document/src/main/java/com/yahoo/document/BaseStructDataType.java index 97357f3fa7c..1bce5d716a4 100755 --- a/document/src/main/java/com/yahoo/document/BaseStructDataType.java +++ b/document/src/main/java/com/yahoo/document/BaseStructDataType.java @@ -18,8 +18,6 @@ public abstract class BaseStructDataType extends StructuredDataType { protected Map<Integer, Field> fieldIds = new LinkedHashMap<>(); protected Map<String, Field> fields = new LinkedHashMap<>(); - protected Compressor compressor = new Compressor(CompressionType.NONE); - BaseStructDataType(String name) { super(name); } @@ -101,27 +99,25 @@ public abstract class BaseStructDataType extends StructuredDataType { return fields.size(); } - /** Returns the compressor to use to compress data of this type */ - public Compressor getCompressor() { return compressor; } + /** Returns the compressor to use to compress data of this type + * @deprecated Will go away on Vespa 8 + */ + @Deprecated + public Compressor getCompressor() { return new Compressor(CompressionType.NONE); } - /** Returns a view of the configuration of the compressor used to compress this type */ + /** Returns a view of the configuration of the compressor used to compress this type + * @deprecated Will go away on Vespa 8 + */ + @Deprecated public CompressionConfig getCompressionConfig() { - // CompressionConfig accepts a percentage (but exposes a factor) ... - float compressionThresholdPercentage = (float)compressor.compressionThresholdFactor() * 100; - - return new CompressionConfig(compressor.type(), - compressor.level(), - compressionThresholdPercentage, - compressor.compressMinSizeBytes()); + return new CompressionConfig(); } - /** Set the config to the compressor used to compress data of this type */ - public void setCompressionConfig(CompressionConfig config) { - CompressionType type = config.type; - compressor = new Compressor(type, - config.compressionLevel, - config.thresholdFactor(), - (int)config.minsize); - } + /** + * Set the config to the compressor used to compress data of this type + * @deprecated Ignored and will go away on Vespa 8 + */ + @Deprecated + public void setCompressionConfig(CompressionConfig config) { } } diff --git a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java index db0566aecc1..a0ac3cb6620 100644 --- a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java +++ b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java @@ -10,7 +10,6 @@ import java.util.logging.Level; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -24,17 +23,14 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub private final static Logger log = Logger.getLogger(DocumentTypeManagerConfigurer.class.getName()); - private DocumentTypeManager managerToConfigure; + private final DocumentTypeManager managerToConfigure; public DocumentTypeManagerConfigurer(DocumentTypeManager manager) { this.managerToConfigure = manager; } - private static CompressionConfig makeCompressionConfig(DocumentmanagerConfig.Datatype.Structtype cfg) { - return new CompressionConfig(toCompressorType(cfg.compresstype()), cfg.compresslevel(), - cfg.compressthreshold(), cfg.compressminsize()); - } - + /** Deprecated and will go away on Vespa 8 */ + @Deprecated public static CompressionType toCompressorType(DocumentmanagerConfig.Datatype.Structtype.Compresstype.Enum value) { switch (value) { case NONE: return CompressionType.NONE; @@ -43,7 +39,6 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub } throw new IllegalArgumentException("Compression type " + value + " is not supported"); } - /** * <p>Makes the DocumentTypeManager subscribe on its config.</p> * @@ -73,8 +68,7 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub setupAnnotationRefTypes(config, manager); log.log(Level.FINE, "Configuring document manager with " + config.datatype().size() + " data types."); - ArrayList<DocumentmanagerConfig.Datatype> failed = new ArrayList<>(); - failed.addAll(config.datatype()); + ArrayList<DocumentmanagerConfig.Datatype> failed = new ArrayList<>(config.datatype()); while (!failed.isEmpty()) { ArrayList<DocumentmanagerConfig.Datatype> tmp = failed; failed = new ArrayList<>(); @@ -82,7 +76,7 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub DocumentmanagerConfig.Datatype thisDataType = tmp.get(i); int id = thisDataType.id(); try { - registerTypeIdMapping(config, manager, thisDataType, id); + registerTypeIdMapping(manager, thisDataType, id); } catch (IllegalArgumentException e) { failed.add(thisDataType); } @@ -95,24 +89,24 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub manager.replaceTemporaryTypes(); } - private static void registerTypeIdMapping(DocumentmanagerConfig config, DocumentTypeManager manager, DocumentmanagerConfig.Datatype thisDataType, int id) { - for (Object o : thisDataType.arraytype()) { - registerArrayType(manager, id, (DocumentmanagerConfig.Datatype.Arraytype) o); + private static void registerTypeIdMapping(DocumentTypeManager manager, DocumentmanagerConfig.Datatype thisDataType, int id) { + for (var o : thisDataType.arraytype()) { + registerArrayType(manager, id, o); } - for (Object o : thisDataType.maptype()) { - registerMapType(manager, id, (DocumentmanagerConfig.Datatype.Maptype) o); + for (var o : thisDataType.maptype()) { + registerMapType(manager, id, o); } - for (Object o : thisDataType.weightedsettype()) { - registerWeightedSetType(manager, id, (DocumentmanagerConfig.Datatype.Weightedsettype) o); + for (var o : thisDataType.weightedsettype()) { + registerWeightedSetType(manager, id, o); } - for (Object o : thisDataType.structtype()) { - registerStructType(config, manager, id, (DocumentmanagerConfig.Datatype.Structtype) o); + for (var o : thisDataType.structtype()) { + registerStructType(manager, id, o); } - for (Object o : thisDataType.documenttype()) { - registerDocumentType(manager, (DocumentmanagerConfig.Datatype.Documenttype) o); + for (var o : thisDataType.documenttype()) { + registerDocumentType(manager, o); } - for (Object o : thisDataType.referencetype()) { - registerReferenceType(manager, id, (DocumentmanagerConfig.Datatype.Referencetype) o); + for (var o : thisDataType.referencetype()) { + registerReferenceType(manager, id, o); } } @@ -139,20 +133,17 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub manager.register(type); } - @SuppressWarnings("deprecation") private static void registerDocumentType(DocumentTypeManager manager, DocumentmanagerConfig.Datatype.Documenttype doc) { StructDataType header = (StructDataType) manager.getDataType(doc.headerstruct(), ""); var importedFields = doc.importedfield().stream() .map(f -> f.name()) .collect(Collectors.toUnmodifiableSet()); DocumentType type = new DocumentType(doc.name(), header, importedFields); - for (Object j : doc.inherits()) { - DocumentmanagerConfig.Datatype.Documenttype.Inherits parent = - (DocumentmanagerConfig.Datatype.Documenttype.Inherits) j; + for (var parent : doc.inherits()) { DataTypeName name = new DataTypeName(parent.name()); DocumentType parentType = manager.getDocumentType(name); if (parentType == null) { - throw new IllegalArgumentException("Could not find document type '" + name.toString() + "'."); + throw new IllegalArgumentException("Could not find document type '" + name + "'."); } type.inherit(parentType); } @@ -164,18 +155,11 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub manager.register(type); } - private static void registerStructType(DocumentmanagerConfig config, DocumentTypeManager manager, int id, + private static void registerStructType(DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Structtype struct) { StructDataType type = new StructDataType(id, struct.name()); - if (config.enablecompression()) { - CompressionConfig comp = makeCompressionConfig(struct); - type.setCompressionConfig(comp); - } - - for (Object j : struct.field()) { - DocumentmanagerConfig.Datatype.Structtype.Field field = - (DocumentmanagerConfig.Datatype.Structtype.Field) j; + for (var field : struct.field()) { DataType fieldType = (field.datatype() == id) ? manager.getDataTypeAndReturnTemporary(field.datatype(), field.detailedtype()) : manager.getDataType(field.datatype(), field.detailedtype()); @@ -231,8 +215,7 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub for (int i = 0; i < config.datatype().size(); i++) { DocumentmanagerConfig.Datatype thisDataType = config.datatype(i); int id = thisDataType.id(); - for (Object o : thisDataType.annotationreftype()) { - DocumentmanagerConfig.Datatype.Annotationreftype annRefType = (DocumentmanagerConfig.Datatype.Annotationreftype) o; + for (var annRefType : thisDataType.annotationreftype()) { AnnotationType annotationType = manager.getAnnotationTypeRegistry().getType(annRefType.annotation()); if (annotationType == null) { throw new IllegalArgumentException("Found reference to " + annRefType.annotation() + ", which does not exist!"); @@ -275,11 +258,10 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub for (int i = 0; i < config.datatype().size(); i++) { DocumentmanagerConfig.Datatype thisDataType = config.datatype(i); int id = thisDataType.id(); - for (Object o : thisDataType.structtype()) { - DocumentmanagerConfig.Datatype.Structtype struct = (DocumentmanagerConfig.Datatype.Structtype) o; + for (var struct : thisDataType.structtype()) { StructDataType thisStruct = (StructDataType) manager.getDataType(id, ""); - for (DocumentmanagerConfig.Datatype.Structtype.Inherits parent : struct.inherits()) { + for (var parent : struct.inherits()) { StructDataType parentStruct = (StructDataType) manager.getDataType(parent.name()); thisStruct.inherit(parentStruct); } diff --git a/document/src/main/java/com/yahoo/document/datatypes/Struct.java b/document/src/main/java/com/yahoo/document/datatypes/Struct.java index fd13885ac36..b47dbe69199 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/Struct.java +++ b/document/src/main/java/com/yahoo/document/datatypes/Struct.java @@ -65,25 +65,20 @@ public class Struct extends StructuredFieldValue { return this.version; } + /** @deprecated Will go away on Vespa 8 */ + @Deprecated public com.yahoo.compress.CompressionType getCompressionType() { - if (getDataType().getCompressionConfig() == null) { - return com.yahoo.compress.CompressionType.NONE; - } - return getDataType().getCompressionConfig().type; + return com.yahoo.compress.CompressionType.NONE; } - public int getCompressionLevel() { - if ( getDataType().getCompressionConfig() == null) { - return 9; - } - return getDataType().getCompressionConfig().compressionLevel; - } + /** @deprecated Will go away on Vespa 8 */ + @Deprecated + public int getCompressionLevel() { return 9; } + /** @deprecated Will go away on Vespa 8 */ + @Deprecated public float getCompressionThreshold() { - if (getDataType().getCompressionConfig() == null) { - return .95f; - } - return getDataType().getCompressionConfig().threshold; + return .95f; } @Override diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java index cbcd0c64bd0..09e41a0e8bf 100644 --- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java +++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java @@ -1,7 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.serialization; -import com.yahoo.compress.Compressor; +import com.yahoo.compress.CompressionType; import com.yahoo.document.ArrayDataType; import com.yahoo.document.CollectionDataType; @@ -53,7 +53,6 @@ import com.yahoo.document.update.TensorModifyUpdate; import com.yahoo.document.update.TensorRemoveUpdate; import com.yahoo.document.update.ValueUpdate; import com.yahoo.io.GrowableByteBuffer; -import com.yahoo.tensor.serialization.TypedBinaryFormat; import com.yahoo.vespa.objects.BufferSerializer; import com.yahoo.vespa.objects.FieldBase; @@ -344,19 +343,10 @@ public class VespaDocumentSerializer6 extends BufferSerializer implements Docume buffer.flip(); buf = bigBuffer; - int uncompressedSize = buffer.remaining(); - Compressor.Compression compression = - s.getDataType().getCompressor().compress(buffer.getByteBuffer().array(), buffer.remaining()); - // Actual serialization starts here. int lenPos = buf.position(); putInt(null, 0); // Move back to this after compression is done. - buf.put(compression.type().getCode()); - - if (compression.data() != null && compression.type().isCompressed()) { - buf.putInt2_4_8Bytes(uncompressedSize); - } - + buf.put(CompressionType.NONE.getCode()); buf.putInt1_4Bytes(s.getFieldCount()); for (int i = 0; i < s.getFieldCount(); ++i) { @@ -365,11 +355,7 @@ public class VespaDocumentSerializer6 extends BufferSerializer implements Docume } int pos = buf.position(); - if (compression.data() != null && compression.type().isCompressed()) { - put(null, compression.data()); - } else { - put(null, buffer.getByteBuffer()); - } + put(null, buffer.getByteBuffer()); int dataLength = buf.position() - pos; int posNow = buf.position(); |