HBASE-19430 Remove the SettableTimestamp and SettableSequenceId

This commit is contained in:
Chia-Ping Tsai 2017-12-07 09:29:09 +08:00
parent 97d17ae195
commit d2b1578b73
15 changed files with 284 additions and 230 deletions

View File

@ -296,8 +296,8 @@ public class ByteBufferKeyValue extends ByteBufferCell implements ExtendedCell {
}
@Override
public void setTimestamp(byte[] ts, int tsOffset) throws IOException {
ByteBufferUtils.copyFromArrayToBuffer(this.buf, this.getTimestampOffset(), ts, tsOffset,
public void setTimestamp(byte[] ts) throws IOException {
ByteBufferUtils.copyFromArrayToBuffer(this.buf, this.getTimestampOffset(), ts, 0,
Bytes.SIZEOF_LONG);
}

View File

@ -34,16 +34,16 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.Optional;
import org.apache.hadoop.hbase.KeyValue.Type;
import org.apache.hadoop.hbase.io.HeapSize;
import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hadoop.hbase.util.ByteRange;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceAudience.Private;
import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;
/**
* Utility methods helpful for slinging {@link Cell} instances. Some methods below are for internal
* use only and are marked InterfaceAudience.Private at the method level. Note that all such methods
@ -564,7 +564,7 @@ public final class CellUtil {
* @return A new cell which is having the extra tags also added to it.
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
* Use CP environment to build Cell using {@link ExtendedCellBuilder}
*
*
*/
@Deprecated
public static Cell createCell(Cell cell, List<Tag> tags) {
@ -935,7 +935,7 @@ public final class CellUtil {
}
/**
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
*/
@Deprecated
public static boolean isDeleteFamily(final Cell cell) {
@ -943,7 +943,7 @@ public final class CellUtil {
}
/**
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
*/
@Deprecated
public static boolean isDeleteFamilyVersion(final Cell cell) {
@ -951,7 +951,7 @@ public final class CellUtil {
}
/**
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
*/
@Deprecated
public static boolean isDeleteColumns(final Cell cell) {
@ -959,7 +959,7 @@ public final class CellUtil {
}
/**
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
*/
@Deprecated
public static boolean isDeleteColumnVersion(final Cell cell) {
@ -1112,7 +1112,7 @@ public final class CellUtil {
* Setting a Cell sequenceid is an internal implementation detail not for general public use.
* @param cell
* @param seqId
* @throws IOException when the passed cell is not of type {@link SettableSequenceId}
* @throws IOException when the passed cell is not of type {@link ExtendedCell}
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
*/
@Deprecated
@ -1124,7 +1124,7 @@ public final class CellUtil {
* Sets the given timestamp to the cell.
* @param cell
* @param ts
* @throws IOException when the passed cell is not of type {@link SettableTimestamp}
* @throws IOException when the passed cell is not of type {@link ExtendedCell}
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
*/
@Deprecated
@ -1137,12 +1137,12 @@ public final class CellUtil {
* @param cell
* @param ts buffer containing the timestamp value
* @param tsOffset offset to the new timestamp
* @throws IOException when the passed cell is not of type {@link SettableTimestamp}
* @throws IOException when the passed cell is not of type {@link ExtendedCell}
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
*/
@Deprecated
public static void setTimestamp(Cell cell, byte[] ts, int tsOffset) throws IOException {
PrivateCellUtil.setTimestamp(cell, ts, tsOffset);
PrivateCellUtil.setTimestamp(cell, Bytes.toLong(ts, tsOffset));
}
/**
@ -1151,7 +1151,7 @@ public final class CellUtil {
* @param cell
* @param ts
* @return True if cell timestamp is modified.
* @throws IOException when the passed cell is not of type {@link SettableTimestamp}
* @throws IOException when the passed cell is not of type {@link ExtendedCell}
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
*/
@Deprecated
@ -1166,12 +1166,12 @@ public final class CellUtil {
* @param ts buffer containing the timestamp value
* @param tsOffset offset to the new timestamp
* @return True if cell timestamp is modified.
* @throws IOException when the passed cell is not of type {@link SettableTimestamp}
* @throws IOException when the passed cell is not of type {@link ExtendedCell}
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
*/
@Deprecated
public static boolean updateLatestStamp(Cell cell, byte[] ts, int tsOffset) throws IOException {
return PrivateCellUtil.updateLatestStamp(cell, ts, tsOffset);
return PrivateCellUtil.updateLatestStamp(cell, Bytes.toLong(ts, tsOffset));
}

View File

@ -20,21 +20,18 @@ package org.apache.hadoop.hbase;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import org.apache.hadoop.hbase.io.HeapSize;
import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.yetus.audience.InterfaceAudience;
/**
* Extension to {@link Cell} with server side required functions. Server side Cell implementations
* must implement this.
* @see SettableSequenceId
* @see SettableTimestamp
*/
@InterfaceAudience.Private
public interface ExtendedCell extends RawCell, SettableSequenceId, SettableTimestamp, HeapSize,
Cloneable {
public interface ExtendedCell extends RawCell, HeapSize, Cloneable {
public static int CELL_NOT_BASED_ON_CHUNK = -1;
int CELL_NOT_BASED_ON_CHUNK = -1;
/**
* Write this cell to an OutputStream in a {@link KeyValue} format.
* <br> KeyValue format <br>
@ -48,7 +45,29 @@ public interface ExtendedCell extends RawCell, SettableSequenceId, SettableTimes
* @throws IOException
*/
// TODO remove the boolean param once HBASE-16706 is done.
int write(OutputStream out, boolean withTags) throws IOException;
default int write(OutputStream out, boolean withTags) throws IOException {
// Key length and then value length
ByteBufferUtils.putInt(out, KeyValueUtil.keyLength(this));
ByteBufferUtils.putInt(out, getValueLength());
// Key
PrivateCellUtil.writeFlatKey(this, out);
// Value
out.write(getValueArray());
// Tags length and tags byte array
if (withTags && getTagsLength() > 0) {
// Tags length
out.write((byte)(0xff & (getTagsLength() >> 8)));
out.write((byte)(0xff & getTagsLength()));
// Tags byte array
out.write(getTagsArray(), getTagsOffset(), getTagsLength());
}
return getSerializedSize(withTags);
}
/**
* @param withTags Whether to write tags.
@ -60,20 +79,28 @@ public interface ExtendedCell extends RawCell, SettableSequenceId, SettableTimes
* &lt;tags&gt;</code>
*/
// TODO remove the boolean param once HBASE-16706 is done.
int getSerializedSize(boolean withTags);
default int getSerializedSize(boolean withTags) {
return KeyValueUtil.length(getRowLength(), getFamilyLength(), getQualifierLength(),
getValueLength(), getTagsLength(), withTags);
}
/**
* Write this Cell into the given buf's offset in a {@link KeyValue} format.
* @param buf The buffer where to write the Cell.
* @param offset The offset within buffer, to write the Cell.
*/
void write(ByteBuffer buf, int offset);
default void write(ByteBuffer buf, int offset) {
KeyValueUtil.appendTo(this, buf, offset, true);
}
/**
* Does a deep copy of the contents to a new memory area and returns it as a new cell.
* @return The deep cloned cell
*/
ExtendedCell deepClone();
default ExtendedCell deepClone() {
// When being added to the memstore, deepClone() is called and KeyValue has less heap overhead.
return new KeyValue(this);
}
/**
* Extracts the id of the backing bytebuffer of this cell if it was obtained from fixed sized
@ -83,4 +110,22 @@ public interface ExtendedCell extends RawCell, SettableSequenceId, SettableTimes
default int getChunkId() {
return CELL_NOT_BASED_ON_CHUNK;
}
/**
* Sets with the given seqId.
* @param seqId sequence ID
*/
void setSequenceId(long seqId) throws IOException;
/**
* Sets with the given timestamp.
* @param ts timestamp
*/
void setTimestamp(long ts) throws IOException;
/**
* Sets with the given timestamp.
* @param ts buffer containing the timestamp value
*/
void setTimestamp(byte[] ts) throws IOException;
}

View File

@ -18,16 +18,10 @@
package org.apache.hadoop.hbase;
import org.apache.yetus.audience.InterfaceAudience;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import org.apache.hadoop.hbase.util.ArrayUtils;
import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.ClassSize;
import org.apache.yetus.audience.InterfaceAudience;
@InterfaceAudience.Private
public class IndividualBytesFieldCell implements ExtendedCell {
@ -136,42 +130,6 @@ public class IndividualBytesFieldCell implements ExtendedCell {
}
}
@Override
public int write(OutputStream out, boolean withTags) throws IOException {
// Key length and then value length
ByteBufferUtils.putInt(out, KeyValueUtil.keyLength(this));
ByteBufferUtils.putInt(out, getValueLength());
// Key
PrivateCellUtil.writeFlatKey(this, out);
// Value
out.write(getValueArray());
// Tags length and tags byte array
if (withTags && getTagsLength() > 0) {
// Tags length
out.write((byte)(0xff & (getTagsLength() >> 8)));
out.write((byte)(0xff & getTagsLength()));
// Tags byte array
out.write(tags, tagsOffset, tagsLength);
}
return getSerializedSize(withTags);
}
@Override
public void write(ByteBuffer buf, int offset) {
KeyValueUtil.appendTo(this, buf, offset, true);
}
@Override
public int getSerializedSize(boolean withTags) {
return KeyValueUtil.length(getRowLength(), getFamilyLength(), getQualifierLength(),
getValueLength(), getTagsLength(), withTags);
}
private long heapOverhead() {
return FIXED_OVERHEAD
+ ClassSize.ARRAY // row , can not be null
@ -181,12 +139,6 @@ public class IndividualBytesFieldCell implements ExtendedCell {
+ ((tags == null) ? 0 : ClassSize.ARRAY); // tags , can be null
}
@Override
public ExtendedCell deepClone() {
// When being added to the memstore, deepClone() is called and KeyValue has less heap overhead.
return new KeyValue(this);
}
/**
* Implement Cell interface
*/
@ -320,9 +272,6 @@ public class IndividualBytesFieldCell implements ExtendedCell {
return super.clone(); // only a shadow copy
}
/**
* Implement SettableSequenceId interface
*/
@Override
public void setSequenceId(long seqId) {
if (seqId < 0) {
@ -331,9 +280,6 @@ public class IndividualBytesFieldCell implements ExtendedCell {
this.seqId = seqId;
}
/**
* Implement SettableTimestamp interface
*/
@Override
public void setTimestamp(long ts) {
if (ts < 0) {
@ -343,8 +289,8 @@ public class IndividualBytesFieldCell implements ExtendedCell {
}
@Override
public void setTimestamp(byte[] ts, int tsOffset) {
setTimestamp(Bytes.toLong(ts, tsOffset));
public void setTimestamp(byte[] ts) {
setTimestamp(Bytes.toLong(ts, 0));
}
@Override

View File

@ -1445,8 +1445,8 @@ public class KeyValue implements ExtendedCell {
}
@Override
public void setTimestamp(byte[] ts, int tsOffset) {
Bytes.putBytes(this.bytes, this.getTimestampOffset(), ts, tsOffset, Bytes.SIZEOF_LONG);
public void setTimestamp(byte[] ts) {
Bytes.putBytes(this.bytes, this.getTimestampOffset(), ts, 0, Bytes.SIZEOF_LONG);
}
//---------------------------------------------------------------------------

View File

@ -20,6 +20,7 @@ package org.apache.hadoop.hbase;
import static org.apache.hadoop.hbase.HConstants.EMPTY_BYTE_ARRAY;
import static org.apache.hadoop.hbase.Tag.TAG_LENGTH_SIZE;
import com.google.common.annotations.VisibleForTesting;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
@ -30,7 +31,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import org.apache.hadoop.hbase.KeyValue.Type;
import org.apache.hadoop.hbase.filter.ByteArrayComparable;
import org.apache.hadoop.hbase.io.HeapSize;
@ -43,8 +43,6 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.ClassSize;
import org.apache.yetus.audience.InterfaceAudience;
import com.google.common.annotations.VisibleForTesting;
/**
* Utility methods helpful slinging {@link Cell} instances. It has more powerful and
* rich set of APIs than those in {@link CellUtil} for internal usage.
@ -260,19 +258,19 @@ public final class PrivateCellUtil {
@Override
public void setTimestamp(long ts) throws IOException {
// The incoming cell is supposed to be SettableTimestamp type.
// The incoming cell is supposed to be ExtendedCell type.
PrivateCellUtil.setTimestamp(cell, ts);
}
@Override
public void setTimestamp(byte[] ts, int tsOffset) throws IOException {
// The incoming cell is supposed to be SettableTimestamp type.
PrivateCellUtil.setTimestamp(cell, ts, tsOffset);
public void setTimestamp(byte[] ts) throws IOException {
// The incoming cell is supposed to be ExtendedCell type.
PrivateCellUtil.setTimestamp(cell, ts);
}
@Override
public void setSequenceId(long seqId) throws IOException {
// The incoming cell is supposed to be SettableSequenceId type.
// The incoming cell is supposed to be ExtendedCell type.
PrivateCellUtil.setSequenceId(cell, seqId);
}
@ -442,8 +440,8 @@ public final class PrivateCellUtil {
}
@Override
public void setTimestamp(byte[] ts, int tsOffset) throws IOException {
PrivateCellUtil.setTimestamp(this.cell, ts, tsOffset);
public void setTimestamp(byte[] ts) throws IOException {
PrivateCellUtil.setTimestamp(this.cell, ts);
}
@Override
@ -1251,13 +1249,23 @@ public final class PrivateCellUtil {
* These cells are used in reseeks/seeks to improve the read performance. They are not real cells
* that are returned back to the clients
*/
private static abstract class EmptyCell implements Cell, SettableSequenceId {
private static abstract class EmptyCell implements ExtendedCell {
@Override
public void setSequenceId(long seqId) {
// Fake cells don't need seqId, so leaving it as a noop.
}
@Override
public void setTimestamp(long ts) {
// Fake cells can't be changed timestamp, so leaving it as a noop.
}
@Override
public void setTimestamp(byte[] ts) {
// Fake cells can't be changed timestamp, so leaving it as a noop.
}
@Override
public byte[] getRowArray() {
return EMPTY_BYTE_ARRAY;
@ -1344,13 +1352,23 @@ public final class PrivateCellUtil {
* that are returned back to the clients
*/
private static abstract class EmptyByteBufferCell extends ByteBufferCell
implements SettableSequenceId {
implements ExtendedCell {
@Override
public void setSequenceId(long seqId) {
// Fake cells don't need seqId, so leaving it as a noop.
}
@Override
public void setTimestamp(long ts) {
// Fake cells can't be changed timestamp, so leaving it as a noop.
}
@Override
public void setTimestamp(byte[] ts) {
// Fake cells can't be changed timestamp, so leaving it as a noop.
}
@Override
public byte[] getRowArray() {
return CellUtil.cloneRow(this);
@ -1483,6 +1501,11 @@ public final class PrivateCellUtil {
}
private static class FirstOnRowCell extends EmptyCell {
private static final long FIXED_HEAPSIZE =
ClassSize.OBJECT // object
+ ClassSize.REFERENCE // row array
+ Bytes.SIZEOF_INT // row offset
+ Bytes.SIZEOF_SHORT; // row length
private final byte[] rowArray;
private final int roffset;
private final short rlength;
@ -1493,6 +1516,13 @@ public final class PrivateCellUtil {
this.rlength = rlength;
}
@Override
public long heapSize() {
return ClassSize.align(FIXED_HEAPSIZE)
// array overhead
+ (rlength == 0 ? ClassSize.sizeOfByteArray(rlength) : rlength);
}
@Override
public byte[] getRowArray() {
return this.rowArray;
@ -1520,6 +1550,11 @@ public final class PrivateCellUtil {
}
private static class FirstOnRowByteBufferCell extends EmptyByteBufferCell {
private static final int FIXED_OVERHEAD =
ClassSize.OBJECT // object
+ ClassSize.REFERENCE // row buffer
+ Bytes.SIZEOF_INT // row offset
+ Bytes.SIZEOF_SHORT; // row length
private final ByteBuffer rowBuff;
private final int roffset;
private final short rlength;
@ -1530,6 +1565,14 @@ public final class PrivateCellUtil {
this.rlength = rlength;
}
@Override
public long heapSize() {
if (this.rowBuff.hasArray()) {
return ClassSize.align(FIXED_OVERHEAD + rlength);
}
return ClassSize.align(FIXED_OVERHEAD);
}
@Override
public ByteBuffer getRowByteBuffer() {
return this.rowBuff;
@ -1557,6 +1600,11 @@ public final class PrivateCellUtil {
}
private static class LastOnRowByteBufferCell extends EmptyByteBufferCell {
private static final int FIXED_OVERHEAD =
ClassSize.OBJECT // object
+ ClassSize.REFERENCE // rowBuff
+ Bytes.SIZEOF_INT // roffset
+ Bytes.SIZEOF_SHORT; // rlength
private final ByteBuffer rowBuff;
private final int roffset;
private final short rlength;
@ -1567,6 +1615,14 @@ public final class PrivateCellUtil {
this.rlength = rlength;
}
@Override
public long heapSize() {
if (this.rowBuff.hasArray()) {
return ClassSize.align(FIXED_OVERHEAD + rlength);
}
return ClassSize.align(FIXED_OVERHEAD);
}
@Override
public ByteBuffer getRowByteBuffer() {
return this.rowBuff;
@ -1594,6 +1650,11 @@ public final class PrivateCellUtil {
}
private static class FirstOnRowColByteBufferCell extends FirstOnRowByteBufferCell {
private static final int FIXED_OVERHEAD =
FirstOnRowByteBufferCell.FIXED_OVERHEAD
+ ClassSize.REFERENCE * 2 // family buffer and column buffer
+ Bytes.SIZEOF_INT * 3 // famOffset, colOffset, colLength
+ Bytes.SIZEOF_BYTE; // famLength
private final ByteBuffer famBuff;
private final int famOffset;
private final byte famLength;
@ -1613,6 +1674,19 @@ public final class PrivateCellUtil {
this.colLength = colLength;
}
@Override
public long heapSize() {
if (famBuff.hasArray() && colBuff.hasArray()) {
return ClassSize.align(FIXED_OVERHEAD + famLength + colLength);
} else if (famBuff.hasArray()) {
return ClassSize.align(FIXED_OVERHEAD + famLength);
} else if (colBuff.hasArray()) {
return ClassSize.align(FIXED_OVERHEAD + colLength);
} else {
return ClassSize.align(FIXED_OVERHEAD);
}
}
@Override
public ByteBuffer getFamilyByteBuffer() {
return this.famBuff;
@ -1645,6 +1719,11 @@ public final class PrivateCellUtil {
}
private static class FirstOnRowColCell extends FirstOnRowCell {
private static final long FIXED_HEAPSIZE =
FirstOnRowCell.FIXED_HEAPSIZE
+ Bytes.SIZEOF_BYTE // flength
+ Bytes.SIZEOF_INT * 3 // foffset, qoffset, qlength
+ ClassSize.REFERENCE * 2; // fArray, qArray
private final byte[] fArray;
private final int foffset;
private final byte flength;
@ -1663,6 +1742,14 @@ public final class PrivateCellUtil {
this.qlength = qlength;
}
@Override
public long heapSize() {
return ClassSize.align(FIXED_HEAPSIZE)
// array overhead
+ (flength == 0 ? ClassSize.sizeOfByteArray(flength) : flength)
+ (qlength == 0 ? ClassSize.sizeOfByteArray(qlength) : qlength);
}
@Override
public byte[] getFamilyArray() {
return this.fArray;
@ -1695,7 +1782,9 @@ public final class PrivateCellUtil {
}
private static class FirstOnRowColTSCell extends FirstOnRowColCell {
private static final long FIXED_HEAPSIZE =
FirstOnRowColCell.FIXED_HEAPSIZE
+ Bytes.SIZEOF_LONG; // ts
private long ts;
public FirstOnRowColTSCell(byte[] rArray, int roffset, short rlength, byte[] fArray,
@ -1708,10 +1797,17 @@ public final class PrivateCellUtil {
public long getTimestamp() {
return this.ts;
}
@Override
public long heapSize() {
return ClassSize.align(FIXED_HEAPSIZE);
}
}
private static class FirstOnRowColTSByteBufferCell extends FirstOnRowColByteBufferCell {
private static final int FIXED_OVERHEAD =
FirstOnRowColByteBufferCell.FIXED_OVERHEAD
+ Bytes.SIZEOF_LONG; // ts
private long ts;
public FirstOnRowColTSByteBufferCell(ByteBuffer rBuffer, int roffset, short rlength,
@ -1725,9 +1821,19 @@ public final class PrivateCellUtil {
public long getTimestamp() {
return this.ts;
}
@Override
public long heapSize() {
return ClassSize.align(FIXED_OVERHEAD + super.heapSize());
}
}
private static class LastOnRowCell extends EmptyCell {
private static final long FIXED_OVERHEAD =
ClassSize.OBJECT // object
+ ClassSize.REFERENCE // row array
+ Bytes.SIZEOF_INT // row offset
+ Bytes.SIZEOF_SHORT; // row length
private final byte[] rowArray;
private final int roffset;
private final short rlength;
@ -1738,6 +1844,13 @@ public final class PrivateCellUtil {
this.rlength = rlength;
}
@Override
public long heapSize() {
return ClassSize.align(FIXED_OVERHEAD)
// array overhead
+ (rlength == 0 ? ClassSize.sizeOfByteArray(rlength) : rlength);
}
@Override
public byte[] getRowArray() {
return this.rowArray;
@ -1765,6 +1878,10 @@ public final class PrivateCellUtil {
}
private static class LastOnRowColCell extends LastOnRowCell {
private static final long FIXED_OVERHEAD = LastOnRowCell.FIXED_OVERHEAD
+ ClassSize.REFERENCE * 2 // fArray and qArray
+ Bytes.SIZEOF_INT * 3 // foffset, qoffset, qlength
+ Bytes.SIZEOF_BYTE; // flength
private final byte[] fArray;
private final int foffset;
private final byte flength;
@ -1783,6 +1900,14 @@ public final class PrivateCellUtil {
this.qlength = qlength;
}
@Override
public long heapSize() {
return ClassSize.align(FIXED_OVERHEAD)
// array overhead
+ (flength == 0 ? ClassSize.sizeOfByteArray(flength) : flength)
+ (qlength == 0 ? ClassSize.sizeOfByteArray(qlength) : qlength);
}
@Override
public byte[] getFamilyArray() {
return this.fArray;
@ -1815,6 +1940,11 @@ public final class PrivateCellUtil {
}
private static class LastOnRowColByteBufferCell extends LastOnRowByteBufferCell {
private static final int FIXED_OVERHEAD =
LastOnRowByteBufferCell.FIXED_OVERHEAD
+ ClassSize.REFERENCE * 2 // fBuffer and qBuffer
+ Bytes.SIZEOF_INT * 3 // foffset, qoffset, qlength
+ Bytes.SIZEOF_BYTE; // flength
private final ByteBuffer fBuffer;
private final int foffset;
private final byte flength;
@ -1834,6 +1964,19 @@ public final class PrivateCellUtil {
this.qlength = qlength;
}
@Override
public long heapSize() {
if (fBuffer.hasArray() && qBuffer.hasArray()) {
return ClassSize.align(FIXED_OVERHEAD + flength + qlength);
} else if (fBuffer.hasArray()) {
return ClassSize.align(FIXED_OVERHEAD + flength);
} else if (qBuffer.hasArray()) {
return ClassSize.align(FIXED_OVERHEAD + qlength);
} else {
return ClassSize.align(FIXED_OVERHEAD);
}
}
@Override
public ByteBuffer getFamilyByteBuffer() {
return this.fBuffer;
@ -1866,6 +2009,11 @@ public final class PrivateCellUtil {
}
private static class FirstOnRowDeleteFamilyCell extends EmptyCell {
private static final int FIXED_OVERHEAD =
ClassSize.OBJECT // object
+ ClassSize.REFERENCE * 2 // fBuffer and qBuffer
+ Bytes.SIZEOF_INT * 3 // foffset, qoffset, qlength
+ Bytes.SIZEOF_BYTE; // flength
private final byte[] row;
private final byte[] fam;
@ -1874,6 +2022,15 @@ public final class PrivateCellUtil {
this.fam = fam;
}
@Override
public long heapSize() {
return ClassSize.align(FIXED_OVERHEAD)
// array overhead
+ (getRowLength() == 0 ? ClassSize.sizeOfByteArray(getRowLength()) : getRowLength())
+ (getFamilyLength() == 0 ?
ClassSize.sizeOfByteArray(getFamilyLength()) : getFamilyLength());
}
@Override
public byte[] getRowArray() {
return this.row;
@ -2035,14 +2192,14 @@ public final class PrivateCellUtil {
* sequenceid is an internal implementation detail not for general public use.
* @param cell
* @param seqId
* @throws IOException when the passed cell is not of type {@link SettableSequenceId}
* @throws IOException when the passed cell is not of type {@link ExtendedCell}
*/
public static void setSequenceId(Cell cell, long seqId) throws IOException {
if (cell instanceof SettableSequenceId) {
((SettableSequenceId) cell).setSequenceId(seqId);
if (cell instanceof ExtendedCell) {
((ExtendedCell) cell).setSequenceId(seqId);
} else {
throw new IOException(new UnsupportedOperationException(
"Cell is not of type " + SettableSequenceId.class.getName()));
"Cell is not of type " + ExtendedCell.class.getName()));
}
}
@ -2050,14 +2207,14 @@ public final class PrivateCellUtil {
* Sets the given timestamp to the cell.
* @param cell
* @param ts
* @throws IOException when the passed cell is not of type {@link SettableTimestamp}
* @throws IOException when the passed cell is not of type {@link ExtendedCell}
*/
public static void setTimestamp(Cell cell, long ts) throws IOException {
if (cell instanceof SettableTimestamp) {
((SettableTimestamp) cell).setTimestamp(ts);
if (cell instanceof ExtendedCell) {
((ExtendedCell) cell).setTimestamp(ts);
} else {
throw new IOException(new UnsupportedOperationException(
"Cell is not of type " + SettableTimestamp.class.getName()));
"Cell is not of type " + ExtendedCell.class.getName()));
}
}
@ -2065,15 +2222,14 @@ public final class PrivateCellUtil {
* Sets the given timestamp to the cell.
* @param cell
* @param ts buffer containing the timestamp value
* @param tsOffset offset to the new timestamp
* @throws IOException when the passed cell is not of type {@link SettableTimestamp}
* @throws IOException when the passed cell is not of type {@link ExtendedCell}
*/
public static void setTimestamp(Cell cell, byte[] ts, int tsOffset) throws IOException {
if (cell instanceof SettableTimestamp) {
((SettableTimestamp) cell).setTimestamp(ts, tsOffset);
public static void setTimestamp(Cell cell, byte[] ts) throws IOException {
if (cell instanceof ExtendedCell) {
((ExtendedCell) cell).setTimestamp(ts);
} else {
throw new IOException(new UnsupportedOperationException(
"Cell is not of type " + SettableTimestamp.class.getName()));
"Cell is not of type " + ExtendedCell.class.getName()));
}
}
@ -2083,7 +2239,7 @@ public final class PrivateCellUtil {
* @param cell
* @param ts
* @return True if cell timestamp is modified.
* @throws IOException when the passed cell is not of type {@link SettableTimestamp}
* @throws IOException when the passed cell is not of type {@link ExtendedCell}
*/
public static boolean updateLatestStamp(Cell cell, long ts) throws IOException {
if (cell.getTimestamp() == HConstants.LATEST_TIMESTAMP) {
@ -2098,13 +2254,12 @@ public final class PrivateCellUtil {
* {@link HConstants#LATEST_TIMESTAMP}.
* @param cell
* @param ts buffer containing the timestamp value
* @param tsOffset offset to the new timestamp
* @return True if cell timestamp is modified.
* @throws IOException when the passed cell is not of type {@link SettableTimestamp}
* @throws IOException when the passed cell is not of type {@link ExtendedCell}
*/
public static boolean updateLatestStamp(Cell cell, byte[] ts, int tsOffset) throws IOException {
public static boolean updateLatestStamp(Cell cell, byte[] ts) throws IOException {
if (cell.getTimestamp() == HConstants.LATEST_TIMESTAMP) {
setTimestamp(cell, ts, tsOffset);
setTimestamp(cell, ts);
return true;
}
return false;
@ -2517,7 +2672,7 @@ public final class PrivateCellUtil {
// Serialization is probably preceded by a length (it is in the KeyValueCodec at least).
Bytes.SIZEOF_INT;
}
/**
* @param cell
* @return Sum of the lengths of all the elements in a Cell; does not count in any infrastructure

View File

@ -1,38 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase;
import java.io.IOException;
import org.apache.yetus.audience.InterfaceAudience;
/**
* Using this Interface one can mark a Cell as Sequence stampable. <br>
* Note : Make sure to make Cell implementation of this type in server side.
* @deprecated as of 2.0 and will be removed in 3.0. Use {@link ExtendedCell} instead
*/
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
@Deprecated
public interface SettableSequenceId {
/**
* Sets with the given seqId.
* @param seqId
*/
void setSequenceId(long seqId) throws IOException;
}

View File

@ -1,45 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase;
import java.io.IOException;
import org.apache.yetus.audience.InterfaceAudience;
/**
* Using this Interface one can mark a Cell as timestamp changeable. <br>
* Note : Server side Cell implementations in write path must implement this.
* @deprecated as of 2.0 and will be removed in 3.0. Use {@link ExtendedCell} instead
*/
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
@Deprecated
public interface SettableTimestamp {
/**
* Sets with the given timestamp.
* @param ts
*/
void setTimestamp(long ts) throws IOException;
/**
* Sets with the given timestamp.
* @param ts buffer containing the timestamp value
* @param tsOffset offset to the new timestamp
*/
void setTimestamp(byte[] ts, int tsOffset) throws IOException;
}

View File

@ -21,18 +21,16 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import org.apache.hadoop.hbase.ByteBufferCell;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparator;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.ExtendedCell;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.PrivateCellUtil;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValue.Type;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.PrivateCellUtil;
import org.apache.hadoop.hbase.io.TagCompressionContext;
import org.apache.hadoop.hbase.io.util.LRUDictionary;
import org.apache.hadoop.hbase.io.util.StreamUtils;
@ -42,6 +40,7 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.ClassSize;
import org.apache.hadoop.hbase.util.ObjectIntPair;
import org.apache.hadoop.io.WritableUtils;
import org.apache.yetus.audience.InterfaceAudience;
/**
* Base class for all data block encoders that use a buffer.
@ -278,7 +277,7 @@ abstract class BufferedDataBlockEncoder extends AbstractDataBlockEncoder {
* represented by the valueOffset and valueLength
*/
// We return this as a Cell to the upper layers of read flow and might try setting a new SeqId
// there. So this has to be an instance of SettableSequenceId.
// there. So this has to be an instance of ExtendedCell.
protected static class OnheapDecodedCell implements ExtendedCell {
private static final long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT
+ (3 * ClassSize.REFERENCE) + (2 * Bytes.SIZEOF_LONG) + (7 * Bytes.SIZEOF_INT)
@ -465,7 +464,7 @@ abstract class BufferedDataBlockEncoder extends AbstractDataBlockEncoder {
}
@Override
public void setTimestamp(byte[] ts, int tsOffset) throws IOException {
public void setTimestamp(byte[] ts) throws IOException {
// This is not used in actual flow. Throwing UnsupportedOperationException
throw new UnsupportedOperationException();
}
@ -704,7 +703,7 @@ abstract class BufferedDataBlockEncoder extends AbstractDataBlockEncoder {
}
@Override
public void setTimestamp(byte[] ts, int tsOffset) throws IOException {
public void setTimestamp(byte[] ts) throws IOException {
// This is not used in actual flow. Throwing UnsupportedOperationException
throw new UnsupportedOperationException();
}

View File

@ -18,9 +18,12 @@
package org.apache.hadoop.hbase;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.apache.hadoop.hbase.io.ByteArrayOutputStream;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
@ -29,10 +32,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@Category({MiscTests.class, SmallTests.class})
public class TestIndividualBytesFieldCell {
private static IndividualBytesFieldCell ic0 = null;
@ -168,16 +167,10 @@ public class TestIndividualBytesFieldCell {
assertEquals(kv1.getTagsLength() , ic1.getTagsLength());
}
// Verify if SettableSequenceId interface is implemented
// Verify if ExtendedCell interface is implemented
@Test
public void testIfSettableSequenceIdImplemented() {
assertTrue(ic0 instanceof SettableSequenceId);
}
// Verify if SettableTimestamp interface is implemented
@Test
public void testIfSettableTimestampImplemented() {
assertTrue(ic0 instanceof SettableTimestamp);
public void testIfExtendedCellImplemented() {
assertTrue(ic0 instanceof ExtendedCell);
}
@Test(expected = IllegalArgumentException.class)

View File

@ -334,7 +334,6 @@ public class HFileOutputFormat2
}
// we now have the proper WAL writer. full steam ahead
// TODO : Currently in SettableTimeStamp but this will also move to ExtendedCell
PrivateCellUtil.updateLatestStamp(cell, this.now);
wl.writer.append(kv);
wl.written += length;

View File

@ -236,8 +236,8 @@ public class MapReduceCell extends ByteBufferCell implements ExtendedCell {
}
@Override
public void setTimestamp(byte[] ts, int tsOffset) throws IOException {
PrivateCellUtil.setTimestamp(cell, ts, tsOffset);
public void setTimestamp(byte[] ts) throws IOException {
PrivateCellUtil.setTimestamp(cell, ts);
}
@Override

View File

@ -119,7 +119,7 @@ public interface BlockCache extends Iterable<CachedBlock> {
* @return number of blocks in the cache
*/
long getBlockCount();
/**
* Returns the number of data blocks currently cached in the block cache.
* @return number of blocks in the cache

View File

@ -2876,7 +2876,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
updateDeleteLatestVersionTimeStamp(cell, get, count, byteNow);
}
} else {
PrivateCellUtil.updateLatestStamp(cell, byteNow, 0);
PrivateCellUtil.updateLatestStamp(cell, byteNow);
}
}
}
@ -2888,7 +2888,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
if (result.size() < count) {
// Nothing to delete
PrivateCellUtil.updateLatestStamp(cell, byteNow, 0);
PrivateCellUtil.updateLatestStamp(cell, byteNow);
return;
}
if (result.size() > count) {
@ -4104,7 +4104,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
assert cells instanceof RandomAccess;
int listSize = cells.size();
for (int i = 0; i < listSize; i++) {
PrivateCellUtil.updateLatestStamp(cells.get(i), now, 0);
PrivateCellUtil.updateLatestStamp(cells.get(i), now);
}
}
}

View File

@ -405,7 +405,7 @@ public class VisibilityController implements MasterCoprocessor, RegionCoprocesso
if (result.size() < get.getMaxVersions()) {
// Nothing to delete
PrivateCellUtil.updateLatestStamp(cell, byteNow, 0);
PrivateCellUtil.updateLatestStamp(cell, byteNow);
return;
}
if (result.size() > get.getMaxVersions()) {