Class SchemaOneKeyCodec
java.lang.Object
org.apache.hadoop.ozone.container.metadata.SchemaOneKeyCodec
- All Implemented Interfaces:
org.apache.hadoop.hdds.utils.db.Codec<String>
public final class SchemaOneKeyCodec
extends Object
implements org.apache.hadoop.hdds.utils.db.Codec<String>
Containers written using schema version 1 wrote unprefixed block ID keys
as longs, and metadata or prefixed block IDs as Strings. This was done
before codecs were introduced, so callers could serialize their data
however they wanted. This codec handles this by checking for string
prefixes in the data, and determining which format it should be
encoded/decoded to/from.
-
Field Summary
Fields inherited from interface org.apache.hadoop.hdds.utils.db.Codec
EMPTY_BYTE_ARRAY -
Method Summary
Modifier and TypeMethodDescriptioncopyObject(String object) fromPersistedFormat(byte[] rawData) Determines whether the byte array was originally stored as a string or a long, decodes the data in the corresponding format, and returns it as a String.static org.apache.hadoop.hdds.utils.db.Codec<String> get()byte[]toPersistedFormat(String stringObject) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hadoop.hdds.utils.db.Codec
fromCodecBuffer, fromPersistedFormatImpl, supportCodecBuffer, toCodecBuffer, toDirectCodecBuffer, toHeapCodecBuffer, toPersistedFormatImpl
-
Method Details
-
get
-
getTypeClass
- Specified by:
getTypeClassin interfaceorg.apache.hadoop.hdds.utils.db.Codec<String>
-
toPersistedFormat
public byte[] toPersistedFormat(String stringObject) throws org.apache.hadoop.hdds.utils.db.CodecException - Specified by:
toPersistedFormatin interfaceorg.apache.hadoop.hdds.utils.db.Codec<String>- Throws:
org.apache.hadoop.hdds.utils.db.CodecException
-
fromPersistedFormat
Determines whether the byte array was originally stored as a string or a long, decodes the data in the corresponding format, and returns it as a String. Data is determined to have been stored as a string if it matches the known format of a metadata key or a prefixed block ID key. If the data does not match one of these formats, it will be parsed as a long only if it is 8 bytes long. Otherwise, it will be parsed as a String.Note that it is technically possible, although highly unlikely, that
rawDatawas originally encoded as a long, but also happens to match the regex of a known string format when decoded. In this case this method will decode the data as a string. Log trace messages have been added to help debug these errors if necessary.- Specified by:
fromPersistedFormatin interfaceorg.apache.hadoop.hdds.utils.db.Codec<String>- Parameters:
rawData- Byte array from the key/value store. Should not be null.
-
copyObject
- Specified by:
copyObjectin interfaceorg.apache.hadoop.hdds.utils.db.Codec<String>
-