Package io.datarouter.bytes.kvfile
Class KvFileEntry
java.lang.Object
io.datarouter.bytes.kvfile.KvFileEntry
A generic KeyValue, plus a version represented as bytes. Entries are compared by key+version.
Empty fields:
- A key is generally required for any useful workload.
- The version can be an empty byte[] if keys are unique.
- The value can be an empty byte[] if all information is contained in the key.
The bytes are interpreted lexicographically using Arrays::compareUnsigned.
Many of these can be written to an OutputStream to be persisted for backup or further processing.
Encodes KvFileEntry objects to bytes using the format:
- varInt: total length of the all following fields
- the total length is redundant, but can help split the InputStream faster for passing decoding to other threads
- it can also help identify corruption, if the lengths don't add up
- varInt: keyLength
- bytes: key
- varInt: versionLength
- bytes: version
- byte: opType
- varInt: valueLength
- bytes: value
-
Constructor Summary
ConstructorsConstructorDescriptionKvFileEntry(byte[] bytes, int offset, int length, int keyOffset, int keyLength, int versionOffset, int versionLength, KvFileOp op, int valueOffset, int valueLength) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]static intcompareKey(KvFileEntry left, KvFileEntry right) static intcompareKeyVersionOpOptimized(KvFileEntry left, KvFileEntry right) static intcompareVersion(KvFileEntry left, KvFileEntry right) byte[]byte[]byte[]byte[]static KvFileEntrystatic booleanequalsKeyOptimized(KvFileEntry left, KvFileEntry right) static booleanequalsVersion(KvFileEntry left, KvFileEntry right) intlength()intoffset()op()static KvFileEntryputWithLongVersion(byte[] key, long version, byte[] value) toString()
-
Constructor Details
-
KvFileEntry
public KvFileEntry(byte[] bytes, int offset, int length, int keyOffset, int keyLength, int versionOffset, int versionLength, KvFileOp op, int valueOffset, int valueLength)
-
-
Method Details
-
create
-
putWithLongVersion
-
equalsKeyOptimized
-
equalsVersion
-
compareKey
-
compareVersion
-
compareKeyVersionOpOptimized
-
backingBytes
public byte[] backingBytes() -
copyOfBytes
public byte[] copyOfBytes() -
offset
public int offset() -
length
public int length() -
copyOfKey
public byte[] copyOfKey() -
copyOfVersion
public byte[] copyOfVersion() -
op
-
copyOfValue
public byte[] copyOfValue() -
toString
-