From 56576044862170e31544a87ae715b90163e33d6f Mon Sep 17 00:00:00 2001 From: Tsz-Wo Nicholas Sze Date: Thu, 10 Oct 2024 08:01:27 -0700 Subject: [PATCH] HDDS-11556. Add a getTypeClass method to Codec. (#7295) --- .../hadoop/hdds/protocol/DatanodeDetails.java | 3 ++- .../hadoop/hdds/scm/container/ContainerID.java | 2 +- .../hdds/scm/container/ContainerInfo.java | 3 ++- .../hadoop/hdds/scm/pipeline/Pipeline.java | 1 + .../hadoop/hdds/scm/pipeline/PipelineID.java | 2 +- .../hadoop/hdds/utils/db/BooleanCodec.java | 5 +++++ .../org/apache/hadoop/hdds/utils/db/Codec.java | 3 +++ .../hadoop/hdds/utils/db/DelegatedCodec.java | 14 +++++++++++--- .../hadoop/hdds/utils/db/IntegerCodec.java | 5 +++++ .../apache/hadoop/hdds/utils/db/LongCodec.java | 5 +++++ .../hadoop/hdds/utils/db/Proto2Codec.java | 7 +++++++ .../hadoop/hdds/utils/db/Proto3Codec.java | 7 +++++++ .../apache/hadoop/hdds/utils/db/ShortCodec.java | 5 +++++ .../hadoop/hdds/utils/db/StringCodecBase.java | 5 +++++ .../apache/hadoop/hdds/utils/db/UuidCodec.java | 5 +++++ .../container/common/helpers/BlockData.java | 3 ++- .../container/common/helpers/ChunkInfoList.java | 1 + .../metadata/SchemaOneChunkInfoListCodec.java | 5 +++++ .../container/metadata/SchemaOneKeyCodec.java | 5 +++++ .../common/helpers/MoveDataNodePair.java | 1 + .../security/x509/certificate/CertInfo.java | 3 ++- .../hadoop/hdds/utils/TransactionInfo.java | 1 + .../hadoop/hdds/utils/db/ByteArrayCodec.java | 5 +++++ .../hadoop/hdds/utils/db/ByteStringCodec.java | 5 +++++ .../compaction/log/CompactionLogEntry.java | 3 ++- .../hdds/scm/metadata/BigIntegerCodec.java | 5 +++++ .../hdds/scm/metadata/X509CertificateCodec.java | 5 +++++ .../metadata/OldPipelineIDCodecForTesting.java | 4 ++++ .../OldX509CertificateCodecForTesting.java | 5 +++++ .../hadoop/ozone/om/helpers/OmBucketInfo.java | 3 ++- .../ozone/om/helpers/OmDBAccessIdInfo.java | 1 + .../ozone/om/helpers/OmDBTenantState.java | 1 + .../ozone/om/helpers/OmDBUserPrincipalInfo.java | 10 +++++----- .../ozone/om/helpers/OmDirectoryInfo.java | 3 ++- .../hadoop/ozone/om/helpers/OmKeyInfo.java | 3 ++- .../ozone/om/helpers/OmMultipartKeyInfo.java | 3 ++- .../hadoop/ozone/om/helpers/OmVolumeArgs.java | 3 ++- .../ozone/om/helpers/RepeatedOmKeyInfo.java | 3 ++- .../hadoop/ozone/om/helpers/S3SecretValue.java | 3 ++- .../ozone/om/helpers/SnapshotDiffJob.java | 5 +++++ .../hadoop/ozone/om/helpers/SnapshotInfo.java | 6 +++--- .../ozone/snapshot/SnapshotDiffReportOzone.java | 1 + .../ozone/om/codec/TokenIdentifierCodec.java | 5 +++++ .../hadoop/ozone/om/helpers/OmPrefixInfo.java | 3 ++- .../ozone/recon/codec/NSSummaryCodec.java | 5 +++++ .../recon/scm/ContainerReplicaHistoryList.java | 8 ++++---- .../ozone/recon/scm/ReconSCMDBDefinition.java | 2 +- .../recon/spi/impl/ContainerKeyPrefixCodec.java | 17 +++++++++-------- .../recon/spi/impl/KeyPrefixContainerCodec.java | 15 ++++++++------- 49 files changed, 177 insertions(+), 46 deletions(-) diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java index 01f508d257c..602bc0d2632 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java @@ -74,7 +74,8 @@ public class DatanodeDetails extends NodeImpl implements private static final Codec CODEC = new DelegatedCodec<>( Proto2Codec.get(ExtendedDatanodeDetailsProto.getDefaultInstance()), DatanodeDetails::getFromProtoBuf, - DatanodeDetails::getExtendedProtoBufMessage); + DatanodeDetails::getExtendedProtoBufMessage, + DatanodeDetails.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerID.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerID.java index 88522f2f9f4..90f690da5a1 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerID.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerID.java @@ -37,7 +37,7 @@ public final class ContainerID implements Comparable { private static final Codec CODEC = new DelegatedCodec<>( LongCodec.get(), ContainerID::valueOf, c -> c.id, - DelegatedCodec.CopyType.SHALLOW); + ContainerID.class, DelegatedCodec.CopyType.SHALLOW); public static final ContainerID MIN = ContainerID.valueOf(0); diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerInfo.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerInfo.java index 6bf2d5500c8..90eb8b47de1 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerInfo.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerInfo.java @@ -46,7 +46,8 @@ public final class ContainerInfo implements Comparable { private static final Codec CODEC = new DelegatedCodec<>( Proto2Codec.get(HddsProtos.ContainerInfoProto.getDefaultInstance()), ContainerInfo::fromProtobuf, - ContainerInfo::getProtobuf); + ContainerInfo::getProtobuf, + ContainerInfo.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/Pipeline.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/Pipeline.java index 54a32e9c340..6c5b4aff57f 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/Pipeline.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/Pipeline.java @@ -68,6 +68,7 @@ public final class Pipeline { Proto2Codec.get(HddsProtos.Pipeline.getDefaultInstance()), Pipeline::getFromProtobufSetCreationTimestamp, p -> p.getProtobufMessage(ClientVersion.CURRENT_VERSION), + Pipeline.class, DelegatedCodec.CopyType.UNSUPPORTED); public static Codec getCodec() { diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineID.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineID.java index 5ca35456261..92e01735d53 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineID.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineID.java @@ -34,7 +34,7 @@ public final class PipelineID { private static final Codec CODEC = new DelegatedCodec<>( UuidCodec.get(), PipelineID::valueOf, c -> c.id, - DelegatedCodec.CopyType.SHALLOW); + PipelineID.class, DelegatedCodec.CopyType.SHALLOW); public static Codec getCodec() { return CODEC; diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/BooleanCodec.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/BooleanCodec.java index 2ec396c0ffa..6d416ea2ef3 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/BooleanCodec.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/BooleanCodec.java @@ -36,6 +36,11 @@ private BooleanCodec() { // singleton } + @Override + public Class getTypeClass() { + return Boolean.class; + } + @Override public boolean supportCodecBuffer() { return true; diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Codec.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Codec.java index 46779648e67..54bbf42c468 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Codec.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Codec.java @@ -30,6 +30,9 @@ public interface Codec { byte[] EMPTY_BYTE_ARRAY = {}; + /** @return the class of the {@link T}. */ + Class getTypeClass(); + /** * Does this {@link Codec} support the {@link CodecBuffer} methods? * If this method returns true, this class must implement both diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/DelegatedCodec.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/DelegatedCodec.java index 8d6f3c32e53..2ed92e66d2e 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/DelegatedCodec.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/DelegatedCodec.java @@ -47,6 +47,7 @@ public enum CopyType { private final Codec delegate; private final CheckedFunction forward; private final CheckedFunction backward; + private final Class clazz; private final CopyType copyType; /** @@ -60,18 +61,25 @@ public enum CopyType { public DelegatedCodec(Codec delegate, CheckedFunction forward, CheckedFunction backward, - CopyType copyType) { + Class clazz, CopyType copyType) { this.delegate = delegate; this.forward = forward; this.backward = backward; + this.clazz = clazz; this.copyType = copyType; } /** The same as new DelegatedCodec(delegate, forward, backward, DEEP). */ public DelegatedCodec(Codec delegate, CheckedFunction forward, - CheckedFunction backward) { - this(delegate, forward, backward, CopyType.DEEP); + CheckedFunction backward, + Class clazz) { + this(delegate, forward, backward, clazz, CopyType.DEEP); + } + + @Override + public Class getTypeClass() { + return clazz; } @Override diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/IntegerCodec.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/IntegerCodec.java index 50488053159..d31be6fe976 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/IntegerCodec.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/IntegerCodec.java @@ -36,6 +36,11 @@ private IntegerCodec() { // singleton } + @Override + public Class getTypeClass() { + return Integer.class; + } + @Override public boolean supportCodecBuffer() { return true; diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/LongCodec.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/LongCodec.java index 9e776cc18f7..cf481980008 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/LongCodec.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/LongCodec.java @@ -33,6 +33,11 @@ public static LongCodec get() { private LongCodec() { } + @Override + public Class getTypeClass() { + return Long.class; + } + @Override public boolean supportCodecBuffer() { return true; diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Proto2Codec.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Proto2Codec.java index 96d12d1ebe5..8eb4a307215 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Proto2Codec.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Proto2Codec.java @@ -47,12 +47,19 @@ public static Codec get(T t) { return (Codec) codec; } + private final Class clazz; private final Parser parser; private Proto2Codec(M m) { + this.clazz = (Class) m.getClass(); this.parser = (Parser) m.getParserForType(); } + @Override + public Class getTypeClass() { + return clazz; + } + @Override public boolean supportCodecBuffer() { return true; diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Proto3Codec.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Proto3Codec.java index 30245e033e0..c1eb693a007 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Proto3Codec.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Proto3Codec.java @@ -47,12 +47,19 @@ public static Codec get(T t) { return (Codec) codec; } + private final Class clazz; private final Parser parser; private Proto3Codec(M m) { + this.clazz = (Class) m.getClass(); this.parser = (Parser) m.getParserForType(); } + @Override + public Class getTypeClass() { + return clazz; + } + @Override public boolean supportCodecBuffer() { return true; diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/ShortCodec.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/ShortCodec.java index f6482e5712c..beb296a29d1 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/ShortCodec.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/ShortCodec.java @@ -37,6 +37,11 @@ private ShortCodec() { // singleton } + @Override + public Class getTypeClass() { + return Short.class; + } + @Override public boolean supportCodecBuffer() { return true; diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/StringCodecBase.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/StringCodecBase.java index 1df55237937..e35be632dc4 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/StringCodecBase.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/StringCodecBase.java @@ -59,6 +59,11 @@ abstract class StringCodecBase implements Codec { this.fixedLength = max == encoder.averageBytesPerChar(); } + @Override + public final Class getTypeClass() { + return String.class; + } + CharsetEncoder newEncoder() { return charset.newEncoder() .onMalformedInput(CodingErrorAction.REPORT) diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/UuidCodec.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/UuidCodec.java index dfccaa0ab75..d05b748b52a 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/UuidCodec.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/UuidCodec.java @@ -40,6 +40,11 @@ public static int getSerializedSize() { private UuidCodec() { } + @Override + public Class getTypeClass() { + return UUID.class; + } + @Override public boolean supportCodecBuffer() { return true; diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/BlockData.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/BlockData.java index ea5c5453f3f..b3ee5991737 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/BlockData.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/BlockData.java @@ -39,7 +39,8 @@ public class BlockData { private static final Codec CODEC = new DelegatedCodec<>( Proto3Codec.get(ContainerProtos.BlockData.getDefaultInstance()), BlockData::getFromProtoBuf, - BlockData::getProtoBufMessage); + BlockData::getProtoBufMessage, + BlockData.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ChunkInfoList.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ChunkInfoList.java index 832ab40d30f..ab5d39e9c3d 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ChunkInfoList.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ChunkInfoList.java @@ -36,6 +36,7 @@ public class ChunkInfoList { Proto3Codec.get(ContainerProtos.ChunkInfoList.getDefaultInstance()), ChunkInfoList::getFromProtoBuf, ChunkInfoList::getProtoBufMessage, + ChunkInfoList.class, DelegatedCodec.CopyType.SHALLOW); public static Codec getCodec() { diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/metadata/SchemaOneChunkInfoListCodec.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/metadata/SchemaOneChunkInfoListCodec.java index 1be5a3819c8..25a49eaabe4 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/metadata/SchemaOneChunkInfoListCodec.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/metadata/SchemaOneChunkInfoListCodec.java @@ -57,6 +57,11 @@ private SchemaOneChunkInfoListCodec() { // singleton } + @Override + public Class getTypeClass() { + return ChunkInfoList.class; + } + @Override public byte[] toPersistedFormat(ChunkInfoList chunkList) { return chunkList.getProtoBufMessage().toByteArray(); diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/metadata/SchemaOneKeyCodec.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/metadata/SchemaOneKeyCodec.java index 2f1660f4d2e..add24874a31 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/metadata/SchemaOneKeyCodec.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/metadata/SchemaOneKeyCodec.java @@ -48,6 +48,11 @@ private SchemaOneKeyCodec() { // singleton } + @Override + public Class getTypeClass() { + return String.class; + } + @Override public byte[] toPersistedFormat(String stringObject) throws IOException { try { diff --git a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/MoveDataNodePair.java b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/MoveDataNodePair.java index 42e8f8202cb..4690054a87d 100644 --- a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/MoveDataNodePair.java +++ b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/MoveDataNodePair.java @@ -36,6 +36,7 @@ public class MoveDataNodePair { Proto2Codec.get(MoveDataNodePairProto.getDefaultInstance()), MoveDataNodePair::getFromProtobuf, pair -> pair.getProtobufMessage(ClientVersion.CURRENT_VERSION), + MoveDataNodePair.class, DelegatedCodec.CopyType.SHALLOW); public static Codec getCodec() { diff --git a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/CertInfo.java b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/CertInfo.java index b78604643e5..154f1c2d858 100644 --- a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/CertInfo.java +++ b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/CertInfo.java @@ -39,7 +39,8 @@ public final class CertInfo implements Comparable, Serializable { private static final Codec CODEC = new DelegatedCodec<>( Proto2Codec.get(CertInfoProto.getDefaultInstance()), CertInfo::fromProtobuf, - CertInfo::getProtobuf); + CertInfo::getProtobuf, + CertInfo.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/TransactionInfo.java b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/TransactionInfo.java index 29531f31518..8387934261c 100644 --- a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/TransactionInfo.java +++ b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/TransactionInfo.java @@ -45,6 +45,7 @@ public final class TransactionInfo implements Comparable { StringCodec.get(), TransactionInfo::valueOf, TransactionInfo::toString, + TransactionInfo.class, DelegatedCodec.CopyType.SHALLOW); public static Codec getCodec() { diff --git a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/ByteArrayCodec.java b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/ByteArrayCodec.java index f62d3ac19cf..bb5eef70d25 100644 --- a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/ByteArrayCodec.java +++ b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/ByteArrayCodec.java @@ -33,6 +33,11 @@ private ByteArrayCodec() { // singleton } + @Override + public Class getTypeClass() { + return byte[].class; + } + @Override public byte[] toPersistedFormat(byte[] bytes) { return bytes; diff --git a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/ByteStringCodec.java b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/ByteStringCodec.java index 997bdf6cf2e..20e373317b1 100644 --- a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/ByteStringCodec.java +++ b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/ByteStringCodec.java @@ -34,6 +34,11 @@ public static ByteStringCodec get() { private ByteStringCodec() { } + @Override + public Class getTypeClass() { + return ByteString.class; + } + @Override public boolean supportCodecBuffer() { return true; diff --git a/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/compaction/log/CompactionLogEntry.java b/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/compaction/log/CompactionLogEntry.java index c27763b9788..04980821ba9 100644 --- a/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/compaction/log/CompactionLogEntry.java +++ b/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/compaction/log/CompactionLogEntry.java @@ -38,7 +38,8 @@ public final class CompactionLogEntry implements private static final Codec CODEC = new DelegatedCodec<>( Proto2Codec.get(CompactionLogEntryProto.getDefaultInstance()), CompactionLogEntry::getFromProtobuf, - CompactionLogEntry::getProtobuf); + CompactionLogEntry::getProtobuf, + CompactionLogEntry.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/BigIntegerCodec.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/BigIntegerCodec.java index 5a7e86e99cc..ab753096716 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/BigIntegerCodec.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/BigIntegerCodec.java @@ -38,6 +38,11 @@ private BigIntegerCodec() { // singleton } + @Override + public Class getTypeClass() { + return BigInteger.class; + } + @Override public byte[] toPersistedFormat(BigInteger object) throws IOException { return object.toByteArray(); diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/X509CertificateCodec.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/X509CertificateCodec.java index 3e7db16c2a0..e0279e8f2f0 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/X509CertificateCodec.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/X509CertificateCodec.java @@ -51,6 +51,11 @@ private X509CertificateCodec() { // singleton } + @Override + public Class getTypeClass() { + return X509Certificate.class; + } + @Override public boolean supportCodecBuffer() { return true; diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/metadata/OldPipelineIDCodecForTesting.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/metadata/OldPipelineIDCodecForTesting.java index fb80fbbee78..f09bb43d4cf 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/metadata/OldPipelineIDCodecForTesting.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/metadata/OldPipelineIDCodecForTesting.java @@ -30,6 +30,10 @@ * Codec to serialize / deserialize PipelineID. */ public class OldPipelineIDCodecForTesting implements Codec { + @Override + public Class getTypeClass() { + return PipelineID.class; + } @Override public byte[] toPersistedFormat(PipelineID object) throws IOException { diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/metadata/OldX509CertificateCodecForTesting.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/metadata/OldX509CertificateCodecForTesting.java index 67593dc7778..3a8fc9a9632 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/metadata/OldX509CertificateCodecForTesting.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/metadata/OldX509CertificateCodecForTesting.java @@ -45,6 +45,11 @@ private OldX509CertificateCodecForTesting() { // singleton } + @Override + public Class getTypeClass() { + return X509Certificate.class; + } + @Override public byte[] toPersistedFormat(X509Certificate object) throws IOException { try { diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmBucketInfo.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmBucketInfo.java index 5a83f6dbba6..42c97211c97 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmBucketInfo.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmBucketInfo.java @@ -48,7 +48,8 @@ public final class OmBucketInfo extends WithObjectID implements Auditable, CopyO private static final Codec CODEC = new DelegatedCodec<>( Proto2Codec.get(BucketInfo.getDefaultInstance()), OmBucketInfo::getFromProtobuf, - OmBucketInfo::getProtobuf); + OmBucketInfo::getProtobuf, + OmBucketInfo.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBAccessIdInfo.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBAccessIdInfo.java index 8ca0054b347..862cce21fe9 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBAccessIdInfo.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBAccessIdInfo.java @@ -34,6 +34,7 @@ public final class OmDBAccessIdInfo { Proto2Codec.get(ExtendedUserAccessIdInfo.getDefaultInstance()), OmDBAccessIdInfo::getFromProtobuf, OmDBAccessIdInfo::getProtobuf, + OmDBAccessIdInfo.class, DelegatedCodec.CopyType.SHALLOW); public static Codec getCodec() { diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBTenantState.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBTenantState.java index bb356eafdd9..a1d51cab361 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBTenantState.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBTenantState.java @@ -34,6 +34,7 @@ public final class OmDBTenantState implements Comparable { Proto2Codec.get(TenantState.getDefaultInstance()), OmDBTenantState::getFromProtobuf, OmDBTenantState::getProtobuf, + OmDBTenantState.class, DelegatedCodec.CopyType.SHALLOW); public static Codec getCodec() { diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBUserPrincipalInfo.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBUserPrincipalInfo.java index 75b01a04171..4d93fc54134 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBUserPrincipalInfo.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDBUserPrincipalInfo.java @@ -33,11 +33,11 @@ * principal. */ public final class OmDBUserPrincipalInfo { - private static final Codec CODEC - = new DelegatedCodec<>( - Proto2Codec.get(TenantUserPrincipalInfo.getDefaultInstance()), - OmDBUserPrincipalInfo::getFromProtobuf, - OmDBUserPrincipalInfo::getProtobuf); + private static final Codec CODEC = new DelegatedCodec<>( + Proto2Codec.get(TenantUserPrincipalInfo.getDefaultInstance()), + OmDBUserPrincipalInfo::getFromProtobuf, + OmDBUserPrincipalInfo::getProtobuf, + OmDBUserPrincipalInfo.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDirectoryInfo.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDirectoryInfo.java index 55e138dbd10..69ed1b613bd 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDirectoryInfo.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDirectoryInfo.java @@ -40,7 +40,8 @@ public class OmDirectoryInfo extends WithParentObjectId private static final Codec CODEC = new DelegatedCodec<>( Proto2Codec.get(DirectoryInfo.getDefaultInstance()), OmDirectoryInfo::getFromProtobuf, - OmDirectoryInfo::getProtobuf); + OmDirectoryInfo::getProtobuf, + OmDirectoryInfo.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java index 0507a27de61..5c480860d2b 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java @@ -65,7 +65,8 @@ private static Codec newCodec(boolean ignorePipeline) { return new DelegatedCodec<>( Proto2Codec.get(KeyInfo.getDefaultInstance()), OmKeyInfo::getFromProtobuf, - k -> k.getProtobuf(ignorePipeline, ClientVersion.CURRENT_VERSION)); + k -> k.getProtobuf(ignorePipeline, ClientVersion.CURRENT_VERSION), + OmKeyInfo.class); } public static Codec getCodec(boolean ignorePipeline) { diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmMultipartKeyInfo.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmMultipartKeyInfo.java index 61402ee28e6..7c1e01d2ae5 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmMultipartKeyInfo.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmMultipartKeyInfo.java @@ -42,7 +42,8 @@ public final class OmMultipartKeyInfo extends WithObjectID implements CopyObject private static final Codec CODEC = new DelegatedCodec<>( Proto2Codec.get(MultipartKeyInfo.getDefaultInstance()), OmMultipartKeyInfo::getFromProto, - OmMultipartKeyInfo::getProto); + OmMultipartKeyInfo::getProto, + OmMultipartKeyInfo.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmVolumeArgs.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmVolumeArgs.java index 499b4878362..65182a860d9 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmVolumeArgs.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmVolumeArgs.java @@ -46,7 +46,8 @@ public final class OmVolumeArgs extends WithObjectID private static final Codec CODEC = new DelegatedCodec<>( Proto2Codec.get(VolumeInfo.getDefaultInstance()), OmVolumeArgs::getFromProtobuf, - OmVolumeArgs::getProtobuf); + OmVolumeArgs::getProtobuf, + OmVolumeArgs.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/RepeatedOmKeyInfo.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/RepeatedOmKeyInfo.java index f1dd1e9eeba..2d0f92a1f0c 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/RepeatedOmKeyInfo.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/RepeatedOmKeyInfo.java @@ -47,7 +47,8 @@ private static Codec newCodec(boolean ignorePipeline) { return new DelegatedCodec<>( Proto2Codec.get(RepeatedKeyInfo.getDefaultInstance()), RepeatedOmKeyInfo::getFromProto, - k -> k.getProto(ignorePipeline, ClientVersion.CURRENT_VERSION)); + k -> k.getProto(ignorePipeline, ClientVersion.CURRENT_VERSION), + RepeatedOmKeyInfo.class); } public static Codec getCodec(boolean ignorePipeline) { diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/S3SecretValue.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/S3SecretValue.java index 20c145bd0c0..7ea932c5716 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/S3SecretValue.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/S3SecretValue.java @@ -31,7 +31,8 @@ public final class S3SecretValue { private static final Codec CODEC = new DelegatedCodec<>( Proto2Codec.get(S3Secret.getDefaultInstance()), S3SecretValue::fromProtobuf, - S3SecretValue::getProtobuf); + S3SecretValue::getProtobuf, + S3SecretValue.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotDiffJob.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotDiffJob.java index 0d221dc1cd4..c3c8efc11ad 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotDiffJob.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotDiffJob.java @@ -261,6 +261,11 @@ private static final class SnapshotDiffJobCodec .setSerializationInclusion(JsonInclude.Include.NON_NULL) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + @Override + public Class getTypeClass() { + return SnapshotDiffJob.class; + } + @Override public byte[] toPersistedFormat(SnapshotDiffJob object) throws IOException { diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotInfo.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotInfo.java index 7feefdb0b22..cf0a60dd353 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotInfo.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotInfo.java @@ -56,10 +56,10 @@ */ public final class SnapshotInfo implements Auditable, CopyObject { private static final Codec CODEC = new DelegatedCodec<>( - Proto2Codec.get( - OzoneManagerProtocolProtos.SnapshotInfo.getDefaultInstance()), + Proto2Codec.get(OzoneManagerProtocolProtos.SnapshotInfo.getDefaultInstance()), SnapshotInfo::getFromProtobuf, - SnapshotInfo::getProtobuf); + SnapshotInfo::getProtobuf, + SnapshotInfo.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/snapshot/SnapshotDiffReportOzone.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/snapshot/SnapshotDiffReportOzone.java index a9e89033129..83300d5689a 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/snapshot/SnapshotDiffReportOzone.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/snapshot/SnapshotDiffReportOzone.java @@ -47,6 +47,7 @@ public class SnapshotDiffReportOzone Proto2Codec.get(DiffReportEntryProto.getDefaultInstance()), SnapshotDiffReportOzone::fromProtobufDiffReportEntry, SnapshotDiffReportOzone::toProtobufDiffReportEntry, + DiffReportEntry.class, DelegatedCodec.CopyType.SHALLOW); public static Codec getDiffReportEntryCodec() { diff --git a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/TokenIdentifierCodec.java b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/TokenIdentifierCodec.java index ba54a44ac79..edf65ae2247 100644 --- a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/TokenIdentifierCodec.java +++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/TokenIdentifierCodec.java @@ -42,6 +42,11 @@ private TokenIdentifierCodec() { // singleton } + @Override + public Class getTypeClass() { + return OzoneTokenIdentifier.class; + } + @Override public byte[] toPersistedFormat(OzoneTokenIdentifier object) { Preconditions diff --git a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java index 30fe6d69b76..a2fdfb99c54 100644 --- a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java +++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java @@ -42,7 +42,8 @@ public final class OmPrefixInfo extends WithObjectID implements CopyObject CODEC = new DelegatedCodec<>( Proto2Codec.get(PersistedPrefixInfo.getDefaultInstance()), OmPrefixInfo::getFromProtobuf, - OmPrefixInfo::getProtobuf); + OmPrefixInfo::getProtobuf, + OmPrefixInfo.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/codec/NSSummaryCodec.java b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/codec/NSSummaryCodec.java index f3b273451a2..aa6c5a765d1 100644 --- a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/codec/NSSummaryCodec.java +++ b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/codec/NSSummaryCodec.java @@ -58,6 +58,11 @@ private NSSummaryCodec() { // singleton } + @Override + public Class getTypeClass() { + return NSSummary.class; + } + @Override public byte[] toPersistedFormat(NSSummary object) throws IOException { Set childDirs = object.getChildDir(); diff --git a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ContainerReplicaHistoryList.java b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ContainerReplicaHistoryList.java index 5895d3e133c..7afed9c1ce9 100644 --- a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ContainerReplicaHistoryList.java +++ b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ContainerReplicaHistoryList.java @@ -34,11 +34,11 @@ * For Recon DB table definition. */ public class ContainerReplicaHistoryList { - private static final Codec CODEC - = new DelegatedCodec<>(Proto2Codec.get( - ContainerReplicaHistoryListProto.getDefaultInstance()), + private static final Codec CODEC = new DelegatedCodec<>( + Proto2Codec.get(ContainerReplicaHistoryListProto.getDefaultInstance()), ContainerReplicaHistoryList::fromProto, - ContainerReplicaHistoryList::toProto); + ContainerReplicaHistoryList::toProto, + ContainerReplicaHistoryList.class); public static Codec getCodec() { return CODEC; diff --git a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java index 1ea2f7b1312..fa6d6f925dd 100644 --- a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java +++ b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java @@ -35,7 +35,7 @@ public class ReconSCMDBDefinition extends SCMDBDefinition { private static final Codec UUID_CODEC = new DelegatedCodec<>( StringCodec.get(), UUID::fromString, UUID::toString, - DelegatedCodec.CopyType.SHALLOW); + UUID.class, DelegatedCodec.CopyType.SHALLOW); public static final String RECON_SCM_DB_NAME = "recon-scm.db"; diff --git a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ContainerKeyPrefixCodec.java b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ContainerKeyPrefixCodec.java index 01a630a5235..500c01bfde2 100644 --- a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ContainerKeyPrefixCodec.java +++ b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ContainerKeyPrefixCodec.java @@ -18,9 +18,6 @@ package org.apache.hadoop.ozone.recon.spi.impl; -import static org.apache.commons.compress.utils.CharsetNames.UTF_8; - -import java.io.IOException; import java.nio.ByteBuffer; import org.apache.commons.lang3.ArrayUtils; @@ -31,6 +28,8 @@ import com.google.common.base.Preconditions; import com.google.common.primitives.Longs; +import static java.nio.charset.StandardCharsets.UTF_8; + /** * Codec to serialize/deserialize {@link ContainerKeyPrefix}. */ @@ -51,8 +50,12 @@ private ContainerKeyPrefixCodec() { } @Override - public byte[] toPersistedFormat(ContainerKeyPrefix containerKeyPrefix) - throws IOException { + public Class getTypeClass() { + return ContainerKeyPrefix.class; + } + + @Override + public byte[] toPersistedFormat(ContainerKeyPrefix containerKeyPrefix) { Preconditions.checkNotNull(containerKeyPrefix, "Null object can't be converted to byte array."); byte[] containerIdBytes = Longs.toByteArray(containerKeyPrefix @@ -76,9 +79,7 @@ public byte[] toPersistedFormat(ContainerKeyPrefix containerKeyPrefix) } @Override - public ContainerKeyPrefix fromPersistedFormat(byte[] rawData) - throws IOException { - + public ContainerKeyPrefix fromPersistedFormat(byte[] rawData) { // First 8 bytes is the containerId. long containerIdFromDB = ByteBuffer.wrap(ArrayUtils.subarray( rawData, 0, Long.BYTES)).getLong(); diff --git a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/KeyPrefixContainerCodec.java b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/KeyPrefixContainerCodec.java index 7baca152b28..70b1d65837c 100644 --- a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/KeyPrefixContainerCodec.java +++ b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/KeyPrefixContainerCodec.java @@ -24,10 +24,9 @@ import org.apache.hadoop.hdds.utils.db.Codec; import org.apache.hadoop.ozone.recon.api.types.KeyPrefixContainer; -import java.io.IOException; import java.nio.ByteBuffer; -import static org.apache.commons.compress.utils.CharsetNames.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; /** * Codec to serialize/deserialize {@link KeyPrefixContainer}. @@ -49,8 +48,12 @@ private KeyPrefixContainerCodec() { private static final String KEY_DELIMITER = "_"; @Override - public byte[] toPersistedFormat(KeyPrefixContainer keyPrefixContainer) - throws IOException { + public Class getTypeClass() { + return KeyPrefixContainer.class; + } + + @Override + public byte[] toPersistedFormat(KeyPrefixContainer keyPrefixContainer) { Preconditions.checkNotNull(keyPrefixContainer, "Null object can't be converted to byte array."); byte[] keyPrefixBytes = keyPrefixContainer.getKeyPrefix().getBytes(UTF_8); @@ -75,9 +78,7 @@ public byte[] toPersistedFormat(KeyPrefixContainer keyPrefixContainer) } @Override - public KeyPrefixContainer fromPersistedFormat(byte[] rawData) - throws IOException { - + public KeyPrefixContainer fromPersistedFormat(byte[] rawData) { // When reading from byte[], we can always expect to have the key, version // and version parts in the byte array. byte[] keyBytes = ArrayUtils.subarray(rawData,