Class KeyValue
- All Implemented Interfaces:
Cloneable
,Cell
,ExtendedCell
,HeapSize
,RawCell
- Direct Known Subclasses:
KeyValue.KeyOnlyKeyValue
,NoTagsKeyValue
,SizeCachedKeyValue
HBase applications and users should use the Cell interface and avoid directly using KeyValue and member functions not defined in Cell.
If being used client-side, the primary methods to access individual fields are
getRowArray()
, getFamilyArray()
, getQualifierArray()
,
getTimestamp()
, and getValueArray()
. These methods allocate new byte arrays and
return copies. Avoid their use server-side.
Instances of this class are immutable. They do not implement Comparable but Comparators are provided. Comparators change with context, whether user table or a catalog table comparison. Its critical you use the appropriate comparator. There are Comparators for normal HFiles, Meta's Hfiles, and bloom filter keys.
KeyValue wraps a byte array and takes offsets and lengths into passed array at where to start
interpreting the content as KeyValue. The KeyValue format inside a byte array is:
<keylength> <valuelength> <key> <value>
Key is further
decomposed as: <rowlength> <row> <columnfamilylength>
<columnfamily> <columnqualifier>
<timestamp> <keytype>
The rowlength
maximum is
Short.MAX_SIZE
, column family length maximum is Byte.MAX_SIZE
, and
column qualifier + key length must be < Integer.MAX_SIZE
. The column does not
contain the family/qualifier delimiter, COLUMN_FAMILY_DELIMITER
KeyValue can optionally contain Tags. When it contains tags, it is added in the byte array after
the value part. The format for this part is: <tagslength><tagsbytes>
.
tagslength
maximum is Short.MAX_SIZE
. The tagsbytes
contain one or more tags where as each tag is of the form
<taglength><tagtype><tagbytes>
. tagtype
is one byte
and taglength
maximum is Short.MAX_SIZE
and it includes 1 byte type
length and actual tag bytes length.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A simple form of KeyValue that creates a keyvalue with only the key part of the byte[] Mainly used in places where we need to compare two cells.static interface
Avoids redundant comparisons for better performance.static enum
Key type. -
Field Summary
Modifier and TypeFieldDescriptionprotected byte[]
static final byte[]
static final char
Colon character in UTF-8static final int
Size of the family length field in bytesstatic final int
static final int
static final int
Size of the key length field in bytesstatic final int
static final int
protected int
private static final org.slf4j.Logger
static final KeyValue
Lowest possible key.protected int
static final int
static final int
Size of the row length field in bytesstatic final int
private long
static final int
Size of the tags length field in bytesstatic final int
Size of the timestamp field in bytesstatic final int
static final int
Size of the key type field in bytesFields inherited from interface org.apache.hadoop.hbase.ExtendedCell
CELL_NOT_BASED_ON_CHUNK
Fields inherited from interface org.apache.hadoop.hbase.RawCell
MAX_TAGS_LENGTH
-
Constructor Summary
ConstructorDescriptionKeyValue()
Writable Constructor -- DO NOT USEKeyValue
(byte[] bytes) Creates a KeyValue from the start of the specified byte array.KeyValue
(byte[] row, byte[] family, byte[] qualifier) Constructs KeyValue structure filled with null value.KeyValue
(byte[] row, byte[] family, byte[] qualifier, byte[] value) Constructs KeyValue structure as a put filled with specified values and LATEST_TIMESTAMP.KeyValue
(byte[] row, byte[] family, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags) KeyValue
(byte[] row, byte[] family, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, List<Tag> tags) Constructs KeyValue structure filled with specified values.KeyValue
(byte[] row, byte[] family, byte[] qualifier, long timestamp, byte[] value) Constructs KeyValue structure filled with specified values.Constructs KeyValue structure filled with specified values.Constructs KeyValue structure filled with specified values.KeyValue
(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type) Constructs KeyValue structure filled with specified values.KeyValue
(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value) Constructs KeyValue structure filled with specified values.KeyValue
(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value, byte[] tags) Constructs KeyValue structure filled with specified values.KeyValue
(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value, List<Tag> tags) Constructs KeyValue structure filled with specified values.KeyValue
(byte[] bytes, int offset) Creates a KeyValue from the specified byte array and offset.KeyValue
(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, Tag[] tags) Constructs KeyValue structure filled with specified values.KeyValue
(byte[] bytes, int offset, int length) Creates a KeyValue from the specified byte array, starting at offset, and for lengthlength
.KeyValue
(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength) Constructs KeyValue structure filled with specified values.KeyValue
(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags, int tagsOffset, int tagsLength) KeyValue
(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, List<Tag> tags) Constructs KeyValue structure filled with specified values.KeyValue
(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, ByteBuffer qualifier, long ts, KeyValue.Type type, ByteBuffer value, List<Tag> tags) KeyValue
(byte[] bytes, int offset, int length, long ts) Creates a KeyValue from the specified byte array, starting at offset, and for lengthlength
.KeyValue
(byte[] row, long timestamp) Constructs KeyValue structure filled with null value.KeyValue
(byte[] row, long timestamp, KeyValue.Type type) Constructs KeyValue structure filled with null value.KeyValue
(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength) Constructs an empty KeyValue structure, with specified sizes.KeyValue
(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength, int tagsLength) Constructs an empty KeyValue structure, with specified sizes. -
Method Summary
Modifier and TypeMethodDescriptionprivate int
(package private) static void
checkParameters
(byte[] row, int rlength, byte[] family, int flength, int qlength, int vlength) Checks the parameters passed to a constructor.clone()
Clones a KeyValue.static KeyValue
Create a KeyValue readinglength
fromin
static KeyValue
Create a KeyValue reading fromin
private static byte[]
createByteArray
(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags, int tagsOffset, int tagsLength) Write KeyValue format into a byte array.private static byte[]
createByteArray
(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, Object qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, Object value, int voffset, int vlength, List<Tag> tags) private static byte[]
createEmptyByteArray
(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength, int tagsLength) Create an empty byte[] representing a KeyValue All lengths are preset and can be filled in later.createKeyOnly
(boolean lenAsVal) Creates a new KeyValue that only contains the key portion (the value is set to be null).Does a deep copy of the contents to a new memory area and returns it as a new cell.boolean
Needed doing 'contains' on List.byte[]
To be used only in tests where the Cells are clearly assumed to be of type KeyValue and that we need access to the backing array to do some test case related assertions.static int
getDelimiter
(byte[] b, int offset, int length, int delimiter) Find index of passed delimiter walking from start of buffer forwards.static int
getDelimiterInReverse
(byte[] b, int offset, int length, int delimiter) Find index of passed delimiter walking from end of buffer backwards.byte[]
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)byte
Returns Family lengthbyte
getFamilyLength
(int famLenPos) Returns Family length(package private) int
getFamilyLengthPosition
(int rowLength) int
Returns Family offset(package private) int
getFamilyOffset
(int familyLenPosition) Returns Family offsetbyte[]
getKey()
Do not use unless you have to.static long
getKeyDataStructureSize
(int rlength, int flength, int qlength) Computes the number of bytes that aKeyValue
instance with the provided characteristics would take up in its underlying data structure for the key.int
Returns Length of key portion.int
Returns Key offset in backing buffer..static long
getKeyValueDataStructureSize
(int klength, int vlength, int tagsLength) Computes the number of bytes that aKeyValue
instance with the provided characteristics would take up for its underlying data structure.static long
getKeyValueDataStructureSize
(int rlength, int flength, int qlength, int vlength) Computes the number of bytes that aKeyValue
instance with the provided characteristics would take up for its underlying data structure.static long
getKeyValueDataStructureSize
(int rlength, int flength, int qlength, int vlength, int tagsLength) Computes the number of bytes that aKeyValue
instance with the provided characteristics would take up for its underlying data structure.int
Returns Length of bytes this KeyValue occupies ingetBuffer()
.private static int
getLength
(byte[] bytes, int offset) Determines the total length of the KeyValue stored in the specified byte array and offset.int
Returns Offset intogetBuffer()
at which this KeyValue starts.byte[]
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)int
Returns Qualifier lengthprivate int
getQualifierLength
(int rlength, int flength) Returns Qualifier length(package private) int
getQualifierLength
(int keyLength, int rlength, int flength) Returns Qualifier lengthint
Returns Qualifier offsetprivate int
getQualifierOffset
(int foffset) Returns Qualifier offset(package private) int
getQualifierOffset
(int foffset, int flength) Returns Qualifier offsetbyte[]
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)short
Returns Row lengthint
Returns Row offsetlong
used to achieve atomic operations in the memstore.int
Returns Serialized size (defaults to include tag length).int
getSerializedSize
(boolean withTags) KeyValue formatbyte[]
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)int
Return the total length of the tag bytesint
Return the offset where the tag data starts.long
Return the timestamp.(package private) long
getTimestamp
(int keylength) Return the timestamp.int
Returns Timestamp offsetprivate int
getTimestampOffset
(int keylength) Return the timestamp offsetbyte
Returns KeyValue.TYPE byte representation(package private) byte
getTypeByte
(int keyLength) Return the KeyValue.TYPE byte representationbyte[]
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)int
Returns Value lengthint
Returns the value offsetint
hashCode()
In line withequals(Object)
, only uses the key portion, not the value.long
heapSize()
HeapSize implementationstatic String
humanReadableTimestamp
(long timestamp) boolean
Returns True if this KeyValue has a LATEST_TIMESTAMP timestamp.static String
keyToString
(byte[] k) Return key as a String, empty string if k is null.static String
keyToString
(byte[] b, int o, int l) Use for logging.void
setSequenceId
(long seqId) Sets with the given seqId.void
setTimestamp
(byte[] ts) Sets with the given timestamp.void
setTimestamp
(long ts) Sets with the given timestamp.Creates a shallow copy of this KeyValue, reusing the data byte buffer.toString()
Produces a string map for this key/value pair.boolean
updateLatestStamp
(byte[] now) Update the timestamp.int
write
(OutputStream out, boolean withTags) Write this cell to an OutputStream in aKeyValue
format.void
write
(ByteBuffer buf, int offset) Write this Cell into the given buf's offset in aKeyValue
format.static long
write
(KeyValue kv, DataOutput out) Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.static int
writeByteArray
(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, Tag[] tags) Write KeyValue format into the provided byte array.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.hadoop.hbase.ExtendedCell
getChunkId, getType
-
Field Details
-
LOG
-
FIXED_OVERHEAD
-
COLUMN_FAMILY_DELIMITER
Colon character in UTF-8- See Also:
-
COLUMN_FAMILY_DELIM_ARRAY
-
KEY_LENGTH_SIZE
Size of the key length field in bytes- See Also:
-
TYPE_SIZE
Size of the key type field in bytes- See Also:
-
ROW_LENGTH_SIZE
Size of the row length field in bytes- See Also:
-
FAMILY_LENGTH_SIZE
Size of the family length field in bytes- See Also:
-
TIMESTAMP_SIZE
Size of the timestamp field in bytes- See Also:
-
TIMESTAMP_TYPE_SIZE
- See Also:
-
KEY_INFRASTRUCTURE_SIZE
- See Also:
-
ROW_OFFSET
- See Also:
-
ROW_KEY_OFFSET
- See Also:
-
KEYVALUE_INFRASTRUCTURE_SIZE
- See Also:
-
TAGS_LENGTH_SIZE
Size of the tags length field in bytes- See Also:
-
KEYVALUE_WITH_TAGS_INFRASTRUCTURE_SIZE
- See Also:
-
LOWESTKEY
Lowest possible key. Makes a Key with highest possible Timestamp, empty row and column. No key can be equal or lower than this one in memstore or in store file. -
bytes
-
offset
-
length
-
seqId
-
-
Constructor Details
-
KeyValue
public KeyValue()Writable Constructor -- DO NOT USE -
KeyValue
Creates a KeyValue from the start of the specified byte array. Presumesbytes
content is formatted as a KeyValue blob.- Parameters:
bytes
- byte array
-
KeyValue
Creates a KeyValue from the specified byte array and offset. Presumesbytes
content starting atoffset
is formatted as a KeyValue blob.- Parameters:
bytes
- byte arrayoffset
- offset to start of KeyValue
-
KeyValue
Creates a KeyValue from the specified byte array, starting at offset, and for lengthlength
.- Parameters:
bytes
- byte arrayoffset
- offset to start of the KeyValuelength
- length of the KeyValue
-
KeyValue
Creates a KeyValue from the specified byte array, starting at offset, and for lengthlength
.- Parameters:
bytes
- byte arrayoffset
- offset to start of the KeyValuelength
- length of the KeyValuets
- timestamp
-
KeyValue
Constructs KeyValue structure filled with null value. Sets type toKeyValue.Type.Maximum
- Parameters:
row
- - row key (arbitrary byte array)timestamp
- version timestamp
-
KeyValue
Constructs KeyValue structure filled with null value.- Parameters:
row
- - row key (arbitrary byte array)timestamp
- version timestamp
-
KeyValue
Constructs KeyValue structure filled with null value. Sets type toKeyValue.Type.Maximum
- Parameters:
row
- - row key (arbitrary byte array)family
- family namequalifier
- column qualifier
-
KeyValue
Constructs KeyValue structure as a put filled with specified values and LATEST_TIMESTAMP.- Parameters:
row
- - row key (arbitrary byte array)family
- family namequalifier
- column qualifier
-
KeyValue
Constructs KeyValue structure filled with specified values.- Parameters:
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestamptype
- key type- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
Constructs KeyValue structure filled with specified values.- Parameters:
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestampvalue
- column value- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, byte[] value, Tag[] tags) Constructs KeyValue structure filled with specified values.- Parameters:
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestampvalue
- column valuetags
- tags- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, byte[] value, List<Tag> tags) Constructs KeyValue structure filled with specified values.- Parameters:
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestampvalue
- column valuetags
- tags non-empty list of tags or null- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value) Constructs KeyValue structure filled with specified values.- Parameters:
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestamptype
- key typevalue
- column value- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value, List<Tag> tags) Constructs KeyValue structure filled with specified values.Column is split into two fields, family and qualifier.
- Parameters:
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestamptype
- key typevalue
- column value- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value, byte[] tags) Constructs KeyValue structure filled with specified values.- Parameters:
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestamptype
- key typevalue
- column value- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, List<Tag> tags) Constructs KeyValue structure filled with specified values.- Parameters:
row
- row keyfamily
- family namequalifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevalue
- column valuevoffset
- value offsetvlength
- value length- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags) - Parameters:
row
- row keyfamily
- family namequalifier
- qualifier nameqoffset
- qualifier offsetqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevalue
- column valuevoffset
- value offsetvlength
- value lengthtags
- tags
-
KeyValue
public KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength) Constructs KeyValue structure filled with specified values.Column is split into two fields, family and qualifier.
- Parameters:
row
- row key- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
public KeyValue(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, Tag[] tags) Constructs KeyValue structure filled with specified values. Uses the provided buffer as the data buffer.Column is split into two fields, family and qualifier.
- Parameters:
buffer
- the bytes buffer to useboffset
- buffer offsetrow
- row keyroffset
- row offsetrlength
- row lengthfamily
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevalue
- column valuevoffset
- value offsetvlength
- value lengthtags
- non-empty list of tags or null- Throws:
IllegalArgumentException
- an illegal value was passed or there is insufficient space remaining in the buffer
-
KeyValue
public KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, List<Tag> tags) Constructs KeyValue structure filled with specified values.Column is split into two fields, family and qualifier.
- Parameters:
row
- row keyroffset
- row offsetrlength
- row lengthfamily
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevalue
- column valuevoffset
- value offsetvlength
- value lengthtags
- tags- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags, int tagsOffset, int tagsLength) - Parameters:
row
- row keyroffset
- row offsetrlength
- row lengthfamily
- family namefoffset
- fammily offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevalue
- column valuevoffset
- value offsetvlength
- value lengthtags
- input tags
-
KeyValue
public KeyValue(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength) Constructs an empty KeyValue structure, with specified sizes. This can be used to partially fill up KeyValues.Column is split into two fields, family and qualifier.
- Parameters:
rlength
- row lengthflength
- family lengthqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevlength
- value length- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
public KeyValue(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength, int tagsLength) Constructs an empty KeyValue structure, with specified sizes. This can be used to partially fill up KeyValues.Column is split into two fields, family and qualifier.
- Parameters:
rlength
- row lengthflength
- family lengthqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevlength
- value lengthtagsLength
- length of the tags- Throws:
IllegalArgumentException
- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, ByteBuffer qualifier, long ts, KeyValue.Type type, ByteBuffer value, List<Tag> tags) -
KeyValue
-
-
Method Details
-
getKeyValueDataStructureSize
Computes the number of bytes that aKeyValue
instance with the provided characteristics would take up for its underlying data structure.- Parameters:
rlength
- row lengthflength
- family lengthqlength
- qualifier lengthvlength
- value length- Returns:
- the
KeyValue
data structure length
-
getKeyValueDataStructureSize
public static long getKeyValueDataStructureSize(int rlength, int flength, int qlength, int vlength, int tagsLength) Computes the number of bytes that aKeyValue
instance with the provided characteristics would take up for its underlying data structure.- Parameters:
rlength
- row lengthflength
- family lengthqlength
- qualifier lengthvlength
- value lengthtagsLength
- total length of the tags- Returns:
- the
KeyValue
data structure length
-
getKeyValueDataStructureSize
Computes the number of bytes that aKeyValue
instance with the provided characteristics would take up for its underlying data structure.- Parameters:
klength
- key lengthvlength
- value lengthtagsLength
- total length of the tags- Returns:
- the
KeyValue
data structure length
-
getKeyDataStructureSize
Computes the number of bytes that aKeyValue
instance with the provided characteristics would take up in its underlying data structure for the key.- Parameters:
rlength
- row lengthflength
- family lengthqlength
- qualifier length- Returns:
- the key data structure length
-
getSequenceId
used to achieve atomic operations in the memstore.- Specified by:
getSequenceId
in interfaceExtendedCell
- Returns:
- seqId (always > 0 if exists), or 0 if it no longer exists
-
setSequenceId
Description copied from interface:ExtendedCell
Sets with the given seqId.- Specified by:
setSequenceId
in interfaceExtendedCell
- Parameters:
seqId
- sequence ID
-
createEmptyByteArray
private static byte[] createEmptyByteArray(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength, int tagsLength) Create an empty byte[] representing a KeyValue All lengths are preset and can be filled in later.- Parameters:
rlength
- row lengthflength
- family lengthqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevlength
- value length- Returns:
- The newly created byte array.
-
checkParameters
static void checkParameters(byte[] row, int rlength, byte[] family, int flength, int qlength, int vlength) throws IllegalArgumentException Checks the parameters passed to a constructor.- Parameters:
row
- row keyrlength
- row lengthfamily
- family nameflength
- family lengthqlength
- qualifier lengthvlength
- value length- Throws:
IllegalArgumentException
- an illegal value was passed
-
writeByteArray
public static int writeByteArray(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, Tag[] tags) Write KeyValue format into the provided byte array.- Parameters:
buffer
- the bytes buffer to useboffset
- buffer offsetrow
- row keyroffset
- row offsetrlength
- row lengthfamily
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevalue
- column valuevoffset
- value offsetvlength
- value length- Returns:
- The number of useful bytes in the buffer.
- Throws:
IllegalArgumentException
- an illegal value was passed or there is insufficient space remaining in the buffer
-
createByteArray
private static byte[] createByteArray(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags, int tagsOffset, int tagsLength) Write KeyValue format into a byte array.- Parameters:
row
- row keyroffset
- row offsetrlength
- row lengthfamily
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevalue
- column valuevoffset
- value offsetvlength
- value length- Returns:
- The newly created byte array.
-
createByteArray
private static byte[] createByteArray(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, Object qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, Object value, int voffset, int vlength, List<Tag> tags) - Parameters:
qualifier
- can be a ByteBuffer or a byte[], or null.value
- can be a ByteBuffer or a byte[], or null.
-
equals
Needed doing 'contains' on List. Only compares the key portion, not the value. -
hashCode
In line withequals(Object)
, only uses the key portion, not the value. -
calculateHashForKey
-
clone
Clones a KeyValue. This creates a copy, re-allocating the buffer.- Overrides:
clone
in classObject
- Returns:
- Fully copied clone of this KeyValue
- Throws:
CloneNotSupportedException
- if cloning of keyValue is not supported
-
shallowCopy
Creates a shallow copy of this KeyValue, reusing the data byte buffer. http://en.wikipedia.org/wiki/Object_copy- Returns:
- Shallow copy of this KeyValue
-
toString
-
keyToString
Return key as a String, empty string if k is null. -
toStringMap
Produces a string map for this key/value pair. Useful for programmatic use and manipulation of the data stored in an WALKey, for example, printing as JSON. Values are left out due to their tendency to be large. If needed, they can be added manually.- Returns:
- the Map<String,?> containing data from this key
-
keyToString
Use for logging.- Parameters:
b
- Key portion of a KeyValue.o
- Offset to start of keyl
- Length of key.- Returns:
- Key as a String.
-
humanReadableTimestamp
-
getBuffer
To be used only in tests where the Cells are clearly assumed to be of type KeyValue and that we need access to the backing array to do some test case related assertions.- Returns:
- The byte array backing this KeyValue.
-
getOffset
Returns Offset intogetBuffer()
at which this KeyValue starts. -
getLength
Returns Length of bytes this KeyValue occupies ingetBuffer()
. -
getLength
Determines the total length of the KeyValue stored in the specified byte array and offset. Includes all headers.- Parameters:
bytes
- byte arrayoffset
- offset to start of the KeyValue- Returns:
- length of entire KeyValue, in bytes
-
getKeyOffset
Returns Key offset in backing buffer.. -
getKeyString
-
getKeyLength
Returns Length of key portion. -
getValueArray
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)- Specified by:
getValueArray
in interfaceCell
- Returns:
- The array containing the value bytes.
-
getValueOffset
Returns the value offset- Specified by:
getValueOffset
in interfaceCell
-
getValueLength
Returns Value length- Specified by:
getValueLength
in interfaceCell
-
getRowArray
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)- Specified by:
getRowArray
in interfaceCell
- Returns:
- The array containing the row bytes.
-
getRowOffset
Returns Row offset- Specified by:
getRowOffset
in interfaceCell
-
getRowLength
Returns Row length- Specified by:
getRowLength
in interfaceCell
-
getFamilyArray
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)- Specified by:
getFamilyArray
in interfaceCell
- Returns:
- the array containing the family bytes.
-
getFamilyOffset
Returns Family offset- Specified by:
getFamilyOffset
in interfaceCell
-
getFamilyOffset
Returns Family offset -
getFamilyLength
Returns Family length- Specified by:
getFamilyLength
in interfaceCell
-
getFamilyLength
Returns Family length -
getFamilyLengthPosition
-
getQualifierArray
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)- Specified by:
getQualifierArray
in interfaceCell
- Returns:
- The array containing the qualifier bytes.
-
getQualifierOffset
Returns Qualifier offset- Specified by:
getQualifierOffset
in interfaceCell
-
getQualifierOffset
Returns Qualifier offset -
getQualifierOffset
Returns Qualifier offset -
getQualifierLength
Returns Qualifier length- Specified by:
getQualifierLength
in interfaceCell
-
getQualifierLength
Returns Qualifier length -
getQualifierLength
Returns Qualifier length -
getTimestampOffset
Returns Timestamp offset -
getTimestampOffset
Return the timestamp offset -
isLatestTimestamp
Returns True if this KeyValue has a LATEST_TIMESTAMP timestamp. -
updateLatestStamp
Update the timestamp.- Parameters:
now
- Time to set intothis
IFF timestamp ==HConstants.LATEST_TIMESTAMP
(else, its a noop).- Returns:
- True is we modified this.
-
setTimestamp
Description copied from interface:ExtendedCell
Sets with the given timestamp.- Specified by:
setTimestamp
in interfaceExtendedCell
- Parameters:
ts
- timestamp
-
setTimestamp
Description copied from interface:ExtendedCell
Sets with the given timestamp.- Specified by:
setTimestamp
in interfaceExtendedCell
- Parameters:
ts
- buffer containing the timestamp value
-
getKey
Do not use unless you have to. Used internally for compacting and testing. UsegetRowArray()
,getFamilyArray()
,getQualifierArray()
, andgetValueArray()
if accessing a KeyValue client-side.- Returns:
- Copy of the key portion only.
-
getTimestamp
Return the timestamp.- Specified by:
getTimestamp
in interfaceCell
-
getTimestamp
Return the timestamp. -
getTypeByte
Returns KeyValue.TYPE byte representation- Specified by:
getTypeByte
in interfaceExtendedCell
-
getTypeByte
Return the KeyValue.TYPE byte representation -
getTagsOffset
Return the offset where the tag data starts.- Specified by:
getTagsOffset
in interfaceRawCell
-
getTagsLength
Return the total length of the tag bytes- Specified by:
getTagsLength
in interfaceRawCell
- Returns:
- the total length of the tags in the Cell.
-
getTagsArray
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)- Specified by:
getTagsArray
in interfaceRawCell
- Returns:
- the tags byte array
-
createKeyOnly
Creates a new KeyValue that only contains the key portion (the value is set to be null). TODO only used by KeyOnlyFilter -- move there.- Parameters:
lenAsVal
- replace value with the actual value length (false=empty)
-
getDelimiter
Find index of passed delimiter walking from start of buffer forwards.- Parameters:
b
- the kv serialized byte[] to processdelimiter
- input delimeter to fetch index from start- Returns:
- Index of delimiter having started from start of
b
moving rightward.
-
getDelimiterInReverse
Find index of passed delimiter walking from end of buffer backwards.- Parameters:
b
- the kv serialized byte[] to processoffset
- the offset in the byte[]length
- the length in the byte[]delimiter
- input delimeter to fetch index from end- Returns:
- Index of delimiter
-
create
Create a KeyValue reading fromin
- Parameters:
in
- Where to read bytes from. Creates a byte array to hold the KeyValue backing bytes copied from the steam.- Returns:
- KeyValue created by deserializing from
in
OR if we find a length of zero, we will return null which can be useful marking a stream as done. - Throws:
IOException
- if any IO error happen
-
create
Create a KeyValue readinglength
fromin
- Parameters:
length
- length of the Keyin
- Input to read from- Returns:
- Created KeyValue OR if we find a length of zero, we will return null which can be useful marking a stream as done.
- Throws:
IOException
- if any IO error happen
-
write
Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.- Parameters:
kv
- the KeyValue on which write is being requestedout
- OutputStream to write keyValue to- Returns:
- Length written on stream
- Throws:
IOException
- if any IO error happen- See Also:
-
write
Description copied from interface:ExtendedCell
Write this cell to an OutputStream in aKeyValue
format.
KeyValue format
<4 bytes keylength> <4 bytes valuelength> <2 bytes rowlength> <row> <1 byte columnfamilylength> <columnfamily> <columnqualifier> <8 bytes timestamp> <1 byte keytype> <value> <2 bytes tagslength> <tags>
- Specified by:
write
in interfaceExtendedCell
- Parameters:
out
- Stream to which cell has to be writtenwithTags
- Whether to write tags.- Returns:
- how many bytes are written.
- Throws:
IOException
-
getSerializedSize
Description copied from interface:ExtendedCell
KeyValue format<4 bytes keylength> <4 bytes valuelength> <2 bytes rowlength> <row> <1 byte columnfamilylength> <columnfamily> <columnqualifier> <8 bytes timestamp> <1 byte keytype> <value> <2 bytes tagslength> <tags>
- Specified by:
getSerializedSize
in interfaceExtendedCell
- Parameters:
withTags
- Whether to write tags.- Returns:
- Bytes count required to serialize this Cell in a
KeyValue
format.
-
getSerializedSize
Description copied from interface:ExtendedCell
Returns Serialized size (defaults to include tag length).- Specified by:
getSerializedSize
in interfaceCell
- Specified by:
getSerializedSize
in interfaceExtendedCell
-
write
Description copied from interface:ExtendedCell
Write this Cell into the given buf's offset in aKeyValue
format.- Specified by:
write
in interfaceExtendedCell
- Parameters:
buf
- The buffer where to write the Cell.offset
- The offset within buffer, to write the Cell.
-
heapSize
HeapSize implementation We do not count the bytes in the rowCache because it should be empty for a KeyValue in the MemStore. -
deepClone
Description copied from interface:ExtendedCell
Does a deep copy of the contents to a new memory area and returns it as a new cell.- Specified by:
deepClone
in interfaceExtendedCell
- Returns:
- The deep cloned cell
-