HBASE-8849 - CellCodec should write and read the memstoreTS/mvccVersion (Ram)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1511043 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
344b028f0e
commit
23cd5cf78b
|
@ -128,6 +128,17 @@ public final class CellUtil {
|
|||
return new KeyValue(row, family, qualifier, timestamp,
|
||||
KeyValue.Type.codeToType(type), value);
|
||||
}
|
||||
|
||||
public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier,
|
||||
final long timestamp, final byte type, final byte[] value, final long memstoreTS) {
|
||||
// I need a Cell Factory here. Using KeyValue for now. TODO.
|
||||
// TODO: Make a new Cell implementation that just carries these
|
||||
// byte arrays.
|
||||
KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp,
|
||||
KeyValue.Type.codeToType(type), value);
|
||||
keyValue.setMvccVersion(memstoreTS);
|
||||
return keyValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cellScannerables
|
||||
|
@ -283,4 +294,4 @@ public final class CellUtil {
|
|||
// Serialization is probably preceded by a length (it is in the KeyValueCodec at least).
|
||||
Bytes.SIZEOF_INT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,7 @@ import org.apache.hadoop.hbase.util.Bytes;
|
|||
|
||||
/**
|
||||
* Basic Cell codec that just writes out all the individual elements of a Cell. Uses ints
|
||||
* delimiting all lengths. Profligate. Needs tune up. Does not write the mvcc stamp.
|
||||
* Use a different codec if you want that in the stream.
|
||||
* delimiting all lengths. Profligate. Needs tune up.
|
||||
*/
|
||||
public class CellCodec implements Codec {
|
||||
static class CellEncoder extends BaseEncoder {
|
||||
|
@ -52,6 +51,8 @@ public class CellCodec implements Codec {
|
|||
this.out.write(cell.getTypeByte());
|
||||
// Value
|
||||
write(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
|
||||
// MvccVersion
|
||||
this.out.write(Bytes.toBytes(cell.getMvccVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +83,11 @@ public class CellCodec implements Codec {
|
|||
long timestamp = Bytes.toLong(longArray);
|
||||
byte type = (byte) this.in.read();
|
||||
byte [] value = readByteArray(in);
|
||||
return CellUtil.createCell(row, family, qualifier, timestamp, type, value);
|
||||
// Read memstore version
|
||||
byte[] memstoreTSArray = new byte[Bytes.SIZEOF_LONG];
|
||||
IOUtils.readFully(this.in, memstoreTSArray);
|
||||
long memstoreTS = Bytes.toLong(memstoreTSArray);
|
||||
return CellUtil.createCell(row, family, qualifier, timestamp, type, value, memstoreTS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,4 +113,4 @@ public class CellCodec implements Codec {
|
|||
public Encoder getEncoder(OutputStream os) {
|
||||
return new CellEncoder(os);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ public class TestCellCodec {
|
|||
Codec.Encoder encoder = codec.getEncoder(dos);
|
||||
final KeyValue kv =
|
||||
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
|
||||
kv.setMvccVersion(Long.MAX_VALUE);
|
||||
encoder.write(kv);
|
||||
encoder.flush();
|
||||
dos.close();
|
||||
|
@ -121,4 +122,4 @@ public class TestCellCodec {
|
|||
dis.close();
|
||||
assertEquals(offset, cis.getCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue