diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java index 484eebd..2e5e0a9 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java @@ -366,9 +366,6 @@ public final class CellUtil { * @return A new cell which is having the extra tags also added to it. */ public static Cell createCell(Cell cell, byte[] tags) { - if (cell instanceof ShareableMemory) { - return new ShareableMemoryTagRewriteCell(cell, tags); - } return new TagRewriteCell(cell, tags); } @@ -558,22 +555,10 @@ public final class CellUtil { public long heapOverhead() { return ((ExtendedCell) this.cell).heapOverhead() + HEAP_SIZE_OVERHEAD; } - } - - /** - * Version of TagRewriteCell where the original Cell is ShareableMemory type. - */ - private static class ShareableMemoryTagRewriteCell extends TagRewriteCell implements - ShareableMemory { - - public ShareableMemoryTagRewriteCell(Cell cell, byte[] tags) { - super(cell, tags); - assert cell instanceof ShareableMemory; - } @Override - public Cell cloneToCell() { - Cell clonedBaseCell = ((ShareableMemory) this.cell).cloneToCell(); + public Cell deepClone() { + Cell clonedBaseCell = ((ExtendedCell) this.cell).deepClone(); return new TagRewriteCell(clonedBaseCell, this.tags); } } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCell.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCell.java index f60da14..1731aa6 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCell.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCell.java @@ -71,4 +71,10 @@ public interface ExtendedCell extends Cell, SettableSequenceId, SettableTimestam * @return The heap size overhead associated with this Cell. */ long heapOverhead(); + + /** + * Does a deep copy of the contents to a new memory area and returns it as a new cell. + * @return The deep cloned cell + */ + Cell deepClone(); } \ No newline at end of file diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index a95f814..9da8a32 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -2815,4 +2815,12 @@ public class KeyValue implements ExtendedCell { public long heapOverhead() { return FIXED_OVERHEAD; } + + @Override + public Cell deepClone() { + byte[] copy = Bytes.copy(this.bytes, this.offset, this.length); + KeyValue kv = new KeyValue(copy, 0, copy.length); + kv.setSequenceId(this.getSequenceId()); + return kv; + } } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/NoTagsKeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/NoTagsKeyValue.java index 715bc1a..6faf035 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/NoTagsKeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/NoTagsKeyValue.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.OutputStream; import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.util.Bytes; /** * An extension of the KeyValue where the tags length is always 0 @@ -48,4 +49,12 @@ public class NoTagsKeyValue extends KeyValue { public int getSerializedSize(boolean withTags) { return this.length; } + + @Override + public Cell deepClone() { + byte[] copy = Bytes.copy(this.bytes, this.offset, this.length); + KeyValue kv = new NoTagsKeyValue(copy, 0, copy.length); + kv.setSequenceId(this.getSequenceId()); + return kv; + } } \ No newline at end of file diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/OffheapKeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/OffheapKeyValue.java index 06a0ed6..cd15192 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/OffheapKeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/OffheapKeyValue.java @@ -296,4 +296,18 @@ public class OffheapKeyValue extends ByteBufferedCell implements ExtendedCell { public long heapOverhead() { return FIXED_OVERHEAD; } + + @Override + public Cell deepClone() { + byte[] copy = new byte[this.length]; + ByteBufferUtils.copyFromBufferToArray(copy, this.buf, this.offset, 0, this.length); + KeyValue kv; + if (this.hasTags) { + kv = new KeyValue(copy, 0, copy.length); + } else { + kv = new NoTagsKeyValue(copy, 0, copy.length); + } + kv.setSequenceId(this.getSequenceId()); + return kv; + } } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodec.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodec.java index 00ce023..afe4e11 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodec.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodec.java @@ -24,15 +24,12 @@ import java.nio.ByteBuffer; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.HBaseInterfaceAudience; -import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValueUtil; import org.apache.hadoop.hbase.NoTagsKeyValue; import org.apache.hadoop.hbase.OffheapKeyValue; -import org.apache.hadoop.hbase.ShareableMemory; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.nio.ByteBuff; import org.apache.hadoop.hbase.util.ByteBufferUtils; -import org.apache.hadoop.hbase.util.Bytes; /** * Codec that does KeyValue version 1 serialization. @@ -109,66 +106,14 @@ public class KeyValueCodec implements Codec { } protected Cell createCell(byte[] buf, int offset, int len) { - return new ShareableMemoryNoTagsKeyValue(buf, offset, len); + return new NoTagsKeyValue(buf, offset, len); } protected Cell createCell(ByteBuffer bb, int pos, int len) { // We know there is not going to be any tags. - return new ShareableMemoryOffheapKeyValue(bb, pos, len, false, 0); + return new OffheapKeyValue(bb, pos, len, false, 0); } - static class ShareableMemoryKeyValue extends KeyValue implements ShareableMemory { - public ShareableMemoryKeyValue(byte[] bytes, int offset, int length) { - super(bytes, offset, length); - } - - @Override - public Cell cloneToCell() { - byte[] copy = Bytes.copy(this.bytes, this.offset, this.length); - KeyValue kv = new KeyValue(copy, 0, copy.length); - kv.setSequenceId(this.getSequenceId()); - return kv; - } - } - - static class ShareableMemoryNoTagsKeyValue extends NoTagsKeyValue implements ShareableMemory { - public ShareableMemoryNoTagsKeyValue(byte[] bytes, int offset, int length) { - super(bytes, offset, length); - } - - @Override - public Cell cloneToCell() { - byte[] copy = Bytes.copy(this.bytes, this.offset, this.length); - KeyValue kv = new NoTagsKeyValue(copy, 0, copy.length); - kv.setSequenceId(this.getSequenceId()); - return kv; - } - } - - static class ShareableMemoryOffheapKeyValue extends OffheapKeyValue implements ShareableMemory { - public ShareableMemoryOffheapKeyValue(ByteBuffer buf, int offset, int length) { - super(buf, offset, length); - } - - public ShareableMemoryOffheapKeyValue(ByteBuffer buf, int offset, int length, boolean hasTags, - long seqId) { - super(buf, offset, length, hasTags, seqId); - } - - @Override - public Cell cloneToCell() { - byte[] copy = new byte[this.length]; - ByteBufferUtils.copyFromBufferToArray(copy, this.buf, this.offset, 0, this.length); - KeyValue kv; - if (this.hasTags) { - kv = new KeyValue(copy, 0, copy.length); - } else { - kv = new NoTagsKeyValue(copy, 0, copy.length); - } - kv.setSequenceId(this.getSequenceId()); - return kv; - } - } } /** diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodecWithTags.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodecWithTags.java index 84c4840..de7f36c 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodecWithTags.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/KeyValueCodecWithTags.java @@ -24,7 +24,9 @@ import java.nio.ByteBuffer; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValueUtil; +import org.apache.hadoop.hbase.OffheapKeyValue; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.nio.ByteBuff; import org.apache.hadoop.hbase.util.ByteBufferUtils; @@ -87,12 +89,12 @@ public class KeyValueCodecWithTags implements Codec { @Override protected Cell createCell(byte[] buf, int offset, int len) { - return new ShareableMemoryKeyValue(buf, offset, len); + return new KeyValue(buf, offset, len); } @Override protected Cell createCell(ByteBuffer bb, int pos, int len) { - return new ShareableMemoryOffheapKeyValue(bb, pos, len); + return new OffheapKeyValue(bb, pos, len); } } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java index 216a82d..9d10a36 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java @@ -473,6 +473,12 @@ abstract class BufferedDataBlockEncoder extends AbstractDataBlockEncoder { public long heapOverhead() { return FIXED_OVERHEAD; } + + @Override + public Cell deepClone() { + // This is not used in actual flow. Throwing UnsupportedOperationException + throw new UnsupportedOperationException(); + } } protected static class OffheapDecodedCell extends ByteBufferedCell implements ExtendedCell { @@ -717,6 +723,12 @@ abstract class BufferedDataBlockEncoder extends AbstractDataBlockEncoder { public long heapOverhead() { return FIXED_OVERHEAD; } + + @Override + public Cell deepClone() { + // This is not used in actual flow. Throwing UnsupportedOperationException + throw new UnsupportedOperationException(); + } } protected abstract static class BufferedEncodedSeeker diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java index a4ea3ee..225dd73 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java @@ -28,7 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparator; -import org.apache.hadoop.hbase.ShareableMemory; +import org.apache.hadoop.hbase.ExtendedCell; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.exceptions.UnexpectedStateException; import org.apache.hadoop.hbase.util.Bytes; @@ -107,11 +107,8 @@ public abstract class AbstractMemStore implements MemStore { } private static Cell deepCopyIfNeeded(Cell cell) { - // When Cell is backed by a shared memory chunk (this can be a chunk of memory where we read the - // req into) the Cell instance will be of type ShareableMemory. Later we will add feature to - // read the RPC request into pooled direct ByteBuffers. - if (cell instanceof ShareableMemory) { - return ((ShareableMemory) cell).cloneToCell(); + if (cell instanceof ExtendedCell) { + return ((ExtendedCell) cell).deepClone(); } return cell; }