org.apache.hadoop.hbase.regionserver.wal
Class WALEdit
java.lang.Object
org.apache.hadoop.hbase.regionserver.wal.WALEdit
- All Implemented Interfaces:
- HeapSize, org.apache.hadoop.io.Writable
@InterfaceAudience.Private
public class WALEdit
- extends Object
- implements org.apache.hadoop.io.Writable, HeapSize
WALEdit: Used in HBase's transaction log (WAL) to represent
the collection of edits (KeyValue objects) corresponding to a
single transaction. The class implements "Writable" interface
for serializing/deserializing a set of KeyValue items.
Previously, if a transaction contains 3 edits to c1, c2, c3 for a row R,
the HLog would have three log entries as follows:
:
:
:
This presents problems because row level atomicity of transactions
was not guaranteed. If we crash after few of the above appends make
it, then recovery will restore a partial transaction.
In the new world, all the edits for a given transaction are written
out as a single record, for example:
:
where, the WALEdit is serialized as:
<-1, # of edits, , , ... >
For example:
<-1, 3, , , >
The -1 marker is just a special way of being backward compatible with
an old HLog which would have contained a single .
The deserializer for WALEdit backward compatibly detects if the record
is an old style KeyValue or the new style WALEdit.
Field Summary |
static org.apache.commons.logging.Log |
LOG
|
static byte[] |
METAFAMILY
|
LOG
public static final org.apache.commons.logging.Log LOG
METAFAMILY
public static final byte[] METAFAMILY
WALEdit
public WALEdit()
WALEdit
public WALEdit(boolean isReplay)
isMetaEditFamily
public static boolean isMetaEditFamily(byte[] f)
- Parameters:
f
-
- Returns:
- True is
f
is METAFAMILY
isReplay
public boolean isReplay()
- Returns:
- True when current WALEdit is created by log replay. Replication skips WALEdits from
replay.
setCompressionContext
public void setCompressionContext(org.apache.hadoop.hbase.regionserver.wal.CompressionContext compressionContext)
add
public WALEdit add(KeyValue kv)
isEmpty
public boolean isEmpty()
size
public int size()
getKeyValues
public List<KeyValue> getKeyValues()
getAndRemoveScopes
public NavigableMap<byte[],Integer> getAndRemoveScopes()
readFields
public void readFields(DataInput in)
throws IOException
- Specified by:
readFields
in interface org.apache.hadoop.io.Writable
- Throws:
IOException
write
public void write(DataOutput out)
throws IOException
- Specified by:
write
in interface org.apache.hadoop.io.Writable
- Throws:
IOException
readFromCells
public int readFromCells(Codec.Decoder cellDecoder,
int expectedCount)
throws IOException
- Reads WALEdit from cells.
- Parameters:
cellDecoder
- Cell decoder.expectedCount
- Expected cell count.
- Returns:
- Number of KVs read.
- Throws:
IOException
heapSize
public long heapSize()
- Specified by:
heapSize
in interface HeapSize
- Returns:
- Approximate 'exclusive deep size' of implementing object. Includes
count of payload and hosting object sizings.
toString
public String toString()
- Overrides:
toString
in class Object
createCompaction
public static WALEdit createCompaction(WALProtos.CompactionDescriptor c)
- Create a compacion WALEdit
- Parameters:
c
-
- Returns:
- A WALEdit that has
c
serialized as its value
getCompaction
public static WALProtos.CompactionDescriptor getCompaction(KeyValue kv)
throws IOException
- Deserialized and returns a CompactionDescriptor is the KeyValue contains one.
- Parameters:
kv
- the key value
- Returns:
- deserialized CompactionDescriptor or null.
- Throws:
IOException
Copyright © 2013 The Apache Software Foundation. All Rights Reserved.