diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/InternalCell.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/InternalCell.java new file mode 100644 index 0000000..613c45d --- /dev/null +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/InternalCell.java @@ -0,0 +1,50 @@ +/** + * 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 java.io.OutputStream; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; + +/** + * Extension to {@link Cell} with server side required functions. Server side Cell implementations + * must implement this. + * @see SettableSequenceId + * @see SettableTimestamp + */ +@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) +public interface InternalCell extends SettableSequenceId, SettableTimestamp { + + /** + * Write this cell to an OutputStream. + * @param out Stream to which cell has to be written + * @return how many bytes are written. + * @throws IOException + */ + int write(OutputStream out) throws IOException; + + /** + * Write this cell to an OutputStream. + * @param out Stream to which cell has to be written + * @param withTags Whether to write tags. + * @return how many bytes are written. + * @throws IOException + */ + int write(OutputStream out, boolean withTags) throws IOException; +} 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 c1734cc..ba2fcfc 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 @@ -80,8 +80,7 @@ import com.google.common.annotations.VisibleForTesting; * length and actual tag bytes length. */ @InterfaceAudience.Private -public class KeyValue implements Cell, HeapSize, Cloneable, SettableSequenceId, - SettableTimestamp, Streamable { +public class KeyValue implements Cell, HeapSize, Cloneable, InternalCell { private static final ArrayList EMPTY_ARRAY_LIST = new ArrayList(); private static final Log LOG = LogFactory.getLog(KeyValue.class); diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java index c9da738..9e5c098 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java @@ -596,8 +596,8 @@ public class KeyValueUtil { public static void oswrite(final Cell cell, final OutputStream out, final boolean withTags) throws IOException { - if (cell instanceof Streamable) { - ((Streamable)cell).write(out, withTags); + if (cell instanceof InternalCell) { + ((InternalCell)cell).write(out, withTags); } else { short rlen = cell.getRowLength(); byte flen = cell.getFamilyLength(); 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 d060b02..fc5c4d6 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 @@ -32,8 +32,7 @@ import org.apache.hadoop.hbase.util.ClassSize; * memory. */ @InterfaceAudience.Private -public class OffheapKeyValue extends ByteBufferedCell - implements HeapSize, SettableSequenceId, Streamable { +public class OffheapKeyValue extends ByteBufferedCell implements HeapSize, InternalCell { protected final ByteBuffer buf; protected final int offset; @@ -262,4 +261,18 @@ public class OffheapKeyValue extends ByteBufferedCell public String toString() { return CellUtil.toString(this, true); } + + @Override + public void setTimestamp(long ts) throws IOException { + // This Cell implementation is not yet used in write path. + // TODO when doing HBASE-15179 + throw new UnsupportedOperationException(); + } + + @Override + public void setTimestamp(byte[] ts, int tsOffset) throws IOException { + // This Cell implementation is not yet used in write path. + // TODO when doing HBASE-15179 + throw new UnsupportedOperationException(); + } } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableSequenceId.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableSequenceId.java index 352028a..9d57f2f 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableSequenceId.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableSequenceId.java @@ -24,8 +24,10 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience; /** * Using this Interface one can mark a Cell as Sequence stampable.
* 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 InternalCell} instead */ @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) +@Deprecated public interface SettableSequenceId { /** diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableTimestamp.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableTimestamp.java index 6dac5ae..f54be85 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableTimestamp.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableTimestamp.java @@ -24,8 +24,10 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience; /** * Using this Interface one can mark a Cell as timestamp changeable.
* 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 InternalCell} instead */ @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) +@Deprecated public interface SettableTimestamp { /** diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/Streamable.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/Streamable.java deleted file mode 100644 index be91a56..0000000 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/Streamable.java +++ /dev/null @@ -1,47 +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 java.io.OutputStream; - -import org.apache.hadoop.hbase.classification.InterfaceAudience; - -/** - * This marks a Cell as streamable to a given OutputStream. - */ -@InterfaceAudience.Private -public interface Streamable { - - /** - * Write this cell to an OutputStream. - * @param out Stream to which cell has to be written - * @return how many bytes are written. - * @throws IOException - */ - int write(OutputStream out) throws IOException; - - /** - * Write this cell to an OutputStream. - * @param out Stream to which cell has to be written - * @param withTags Whether to write tags. - * @return how many bytes are written. - * @throws IOException - */ - int write(OutputStream out, boolean withTags) throws IOException; -} \ No newline at end of file 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 d873f7e..0d36dd6 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 @@ -28,11 +28,10 @@ import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.InternalCell; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue.Type; import org.apache.hadoop.hbase.KeyValueUtil; -import org.apache.hadoop.hbase.SettableSequenceId; -import org.apache.hadoop.hbase.Streamable; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.io.HeapSize; import org.apache.hadoop.hbase.io.TagCompressionContext; @@ -289,8 +288,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder { */ // 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. - protected static class OnheapDecodedCell implements Cell, HeapSize, SettableSequenceId, - Streamable { + protected static class OnheapDecodedCell implements Cell, HeapSize, InternalCell { private static final long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT + (3 * ClassSize.REFERENCE) + (2 * Bytes.SIZEOF_LONG) + (7 * Bytes.SIZEOF_INT) + (Bytes.SIZEOF_SHORT) + (2 * Bytes.SIZEOF_BYTE) + (3 * ClassSize.ARRAY)); @@ -463,10 +461,22 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder { } return lenToWrite + Bytes.SIZEOF_INT; } + + @Override + public void setTimestamp(long ts) throws IOException { + // This is not used in actual flow. Throwing UnsupportedOperationException + throw new UnsupportedOperationException(); + } + + @Override + public void setTimestamp(byte[] ts, int tsOffset) throws IOException { + // This is not used in actual flow. Throwing UnsupportedOperationException + throw new UnsupportedOperationException(); + } } protected static class OffheapDecodedCell extends ByteBufferedCell implements HeapSize, - SettableSequenceId, Streamable { + InternalCell { private static final long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT + (3 * ClassSize.REFERENCE) + (2 * Bytes.SIZEOF_LONG) + (7 * Bytes.SIZEOF_INT) + (Bytes.SIZEOF_SHORT) + (2 * Bytes.SIZEOF_BYTE) + (3 * ClassSize.BYTE_BUFFER)); @@ -686,6 +696,18 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder { } return lenToWrite + Bytes.SIZEOF_INT; } + + @Override + public void setTimestamp(long ts) throws IOException { + // This is not used in actual flow. Throwing UnsupportedOperationException + throw new UnsupportedOperationException(); + } + + @Override + public void setTimestamp(byte[] ts, int tsOffset) throws IOException { + // This is not used in actual flow. Throwing UnsupportedOperationException + throw new UnsupportedOperationException(); + } } protected abstract static class