diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/Cell.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/Cell.java index 2b99823..b3663b9 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/Cell.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/Cell.java @@ -148,7 +148,9 @@ public interface Cell { * {@link HConstants#KEEP_SEQID_PERIOD} days, but generally becomes irrelevant after the cell's * row is no longer involved in any operations that require strict consistency. * @return seqId (always > 0 if exists), or 0 if it no longer exists + * @deprecated since 2.0.0. This will be removed in 3.0.0. */ + @Deprecated long getSequenceId(); //7) Value @@ -173,12 +175,18 @@ public interface Cell { /** * Contiguous raw bytes representing tags that may start at any index in the containing array. * @return the tags byte array + * @deprecated As of HBase-2.0. Will be removed in HBase-3.0. + * Use Tag related APIs in {@link RawCell} */ + @Deprecated byte[] getTagsArray(); /** * @return the first offset where the tags start in the Cell + * @deprecated As of HBase-2.0. Will be removed in HBase-3.0. + * Use Tag related APIs in {@link RawCell} */ + @Deprecated int getTagsOffset(); /** @@ -190,6 +198,9 @@ public interface Cell { * less than Integer.MAX_VALUE. * * @return the total length of the tags in the Cell. + * @deprecated As of HBase-2.0. Will be removed in HBase-3.0. + * Use Tag related APIs in {@link RawCell} */ + @Deprecated int getTagsLength(); } 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 a749057..9ca3809 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 @@ -595,7 +595,7 @@ public final class CellUtil { */ @Deprecated public static Cell createCell(Cell cell, List tags) { - return createCell(cell, Tag.fromList(tags)); + return createCell(cell, TagUtil.fromList(tags)); } /** @@ -606,10 +606,7 @@ public final class CellUtil { */ @Deprecated public static Cell createCell(Cell cell, byte[] tags) { - if (cell instanceof ByteBufferCell) { - return new PrivateCellUtil.TagRewriteByteBufferCell((ByteBufferCell) cell, tags); - } - return new PrivateCellUtil.TagRewriteCell(cell, tags); + return PrivateCellUtil.createCell(cell, tags); } /** @@ -619,11 +616,7 @@ public final class CellUtil { */ @Deprecated public static Cell createCell(Cell cell, byte[] value, byte[] tags) { - if (cell instanceof ByteBufferCell) { - return new PrivateCellUtil.ValueAndTagRewriteByteBufferCell((ByteBufferCell) cell, value, - tags); - } - return new PrivateCellUtil.ValueAndTagRewriteCell(cell, value, tags); + return PrivateCellUtil.createCell(cell, value, 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 b5ce095..d477b75 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 @@ -83,4 +83,34 @@ public interface ExtendedCell extends RawCell, SettableSequenceId, SettableTimes default int getChunkId() { return CELL_NOT_BASED_ON_CHUNK; } + + /** + * A region-specific unique monotonically increasing sequence ID given to each Cell. It always + * exists for cells in the memstore but is not retained forever. It will be kept for + * {@link HConstants#KEEP_SEQID_PERIOD} days, but generally becomes irrelevant after the cell's + * row is no longer involved in any operations that require strict consistency. + * @return seqId (always > 0 if exists), or 0 if it no longer exists + */ + long getSequenceId(); + + /** + * Contiguous raw bytes representing tags that may start at any index in the containing array. + * @return the tags byte array + */ + byte[] getTagsArray(); + + /** + * @return the first offset where the tags start in the Cell + */ + int getTagsOffset(); + + /** + * HBase internally uses 2 bytes to store tags length in Cell. As the tags length is always a + * non-negative number, to make good use of the sign bit, the max of tags length is defined 2 * + * Short.MAX_VALUE + 1 = 65535. As a result, the return type is int, because a short is not + * capable of handling that. Please note that even if the return type is int, the max tags length + * is far less than Integer.MAX_VALUE. + * @return the total length of the tags in the Cell. + */ + int getTagsLength(); } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilder.java index 57fa44e..caf76dd 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilder.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilder.java @@ -26,7 +26,7 @@ import org.apache.yetus.audience.InterfaceAudience; * Use {@link ExtendedCellBuilderFactory} to get ExtendedCellBuilder instance. * TODO: ditto for ByteBufferCell? */ -@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) +@InterfaceAudience.Private public interface ExtendedCellBuilder extends CellBuilder { @Override ExtendedCellBuilder setRow(final byte[] row); @@ -62,9 +62,7 @@ public interface ExtendedCellBuilder extends CellBuilder { @Override ExtendedCellBuilder clear(); - // TODO : While creating RawCellBuilder allow 'Tag' to be passed instead of byte[] ExtendedCellBuilder setTags(final byte[] tags); - // TODO : While creating RawCellBuilder allow 'Tag' to be passed instead of byte[] ExtendedCellBuilder setTags(final byte[] tags, int tagsOffset, int tagsLength); /** diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilderFactory.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilderFactory.java index 38778fb..0fa5c2c 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilderFactory.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilderFactory.java @@ -24,25 +24,19 @@ import org.apache.yetus.audience.InterfaceAudience; @InterfaceAudience.Private public final class ExtendedCellBuilderFactory { - public static ExtendedCellBuilder create(CellBuilderType type) { - return create(type, true); - } - /** * Allows creating a cell with the given CellBuilderType. * @param type the type of CellBuilder(DEEP_COPY or SHALLOW_COPY). - * @param allowSeqIdUpdate if seqId can be updated. CPs are not allowed to update - * the seqId * @return the cell that is created */ - public static ExtendedCellBuilder create(CellBuilderType type, boolean allowSeqIdUpdate) { + public static ExtendedCellBuilder create(CellBuilderType type) { switch (type) { case SHALLOW_COPY: // CPs are not allowed to update seqID and they always use DEEP_COPY. So we have not // passing 'allowSeqIdUpdate' to IndividualBytesFieldCellBuilder return new IndividualBytesFieldCellBuilder(); case DEEP_COPY: - return new KeyValueBuilder(allowSeqIdUpdate); + return new KeyValueBuilder(); default: throw new UnsupportedOperationException("The type:" + type + " is unsupported"); } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilderImpl.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilderImpl.java index 4dfb399..49d6e6c 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilderImpl.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCellBuilderImpl.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.util.ArrayUtils; +import org.apache.yetus.audience.InterfaceAudience; @InterfaceAudience.Private public abstract class ExtendedCellBuilderImpl implements ExtendedCellBuilder { @@ -40,12 +40,6 @@ public abstract class ExtendedCellBuilderImpl implements ExtendedCellBuilder { protected byte[] tags = null; protected int tagsOffset = 0; protected int tagsLength = 0; - // Will go away once we do with RawCellBuilder - protected boolean allowSeqIdUpdate = false; - - public ExtendedCellBuilderImpl(boolean allowSeqIdUpdate) { - this.allowSeqIdUpdate = allowSeqIdUpdate; - } @Override public ExtendedCellBuilder setRow(final byte[] row) { @@ -132,11 +126,8 @@ public abstract class ExtendedCellBuilderImpl implements ExtendedCellBuilder { @Override public ExtendedCellBuilder setSequenceId(final long seqId) { - if (allowSeqIdUpdate) { - this.seqId = seqId; - return this; - } - throw new UnsupportedOperationException("SeqId cannot be set on this cell"); + this.seqId = seqId; + return this; } private void checkBeforeBuild() { diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCellBuilder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCellBuilder.java index 62febf8..8a0168e 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCellBuilder.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCellBuilder.java @@ -22,14 +22,6 @@ import org.apache.yetus.audience.InterfaceAudience; @InterfaceAudience.Private class IndividualBytesFieldCellBuilder extends ExtendedCellBuilderImpl { - public IndividualBytesFieldCellBuilder() { - this(true); - } - - public IndividualBytesFieldCellBuilder(boolean allowSeqIdUpdate) { - super(allowSeqIdUpdate); - } - @Override public ExtendedCell innerBuild() { return new IndividualBytesFieldCell(row, rOffset, rLength, diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueBuilder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueBuilder.java index 4f01992..9480b71 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueBuilder.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueBuilder.java @@ -22,14 +22,6 @@ import org.apache.yetus.audience.InterfaceAudience; @InterfaceAudience.Private class KeyValueBuilder extends ExtendedCellBuilderImpl { - KeyValueBuilder() { - this(true); - } - - KeyValueBuilder(boolean allowSeqIdUpdate) { - super(allowSeqIdUpdate); - } - @Override protected ExtendedCell innerBuild() { KeyValue kv = new KeyValue(row, rOffset, rLength, diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/PrivateCellUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/PrivateCellUtil.java index 1acb490..22861d6 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/PrivateCellUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/PrivateCellUtil.java @@ -109,7 +109,7 @@ public final class PrivateCellUtil { * @return A new cell which is having the extra tags also added to it. */ public static Cell createCell(Cell cell, List tags) { - return createCell(cell, Tag.fromList(tags)); + return createCell(cell, TagUtil.fromList(tags)); } /** @@ -930,7 +930,7 @@ public final class PrivateCellUtil { return CellUtil.tagsIterator(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength()); } - private static Iterator tagsIterator(final ByteBuffer tags, final int offset, + public static Iterator tagsIterator(final ByteBuffer tags, final int offset, final int length) { return new Iterator() { private int pos = offset; @@ -2735,5 +2735,4 @@ public final class PrivateCellUtil { public static Cell createFirstDeleteFamilyCellOnRow(final byte[] row, final byte[] fam) { return new FirstOnRowDeleteFamilyCell(row, fam); } - } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCell.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCell.java index 9e25a9a..3d530f3 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCell.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCell.java @@ -65,4 +65,10 @@ public interface RawCell extends Cell { throw new IllegalArgumentException("tagslength " + tagsLength + " > " + MAX_TAGS_LENGTH); } } + + /** + * @return The byte representation of the KeyValue.TYPE of this cell: one of Put, Delete, etc + */ + @Override + byte getTypeByte(); } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCellBuilder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCellBuilder.java new file mode 100644 index 0000000..50953f5 --- /dev/null +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCellBuilder.java @@ -0,0 +1,64 @@ +/* + * 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.util.List; + +import org.apache.yetus.audience.InterfaceAudience; + +/** + * Allows creating a cell with {@link Tag} + */ +@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) +public interface RawCellBuilder extends CellBuilder { + @Override + RawCellBuilder setRow(final byte[] row); + @Override + RawCellBuilder setRow(final byte[] row, final int rOffset, final int rLength); + + @Override + RawCellBuilder setFamily(final byte[] family); + @Override + RawCellBuilder setFamily(final byte[] family, final int fOffset, final int fLength); + + @Override + RawCellBuilder setQualifier(final byte[] qualifier); + @Override + RawCellBuilder setQualifier(final byte[] qualifier, final int qOffset, final int qLength); + + @Override + RawCellBuilder setTimestamp(final long timestamp); + + @Override + RawCellBuilder setType(final DataType type); + + RawCellBuilder setType(final byte type); + + @Override + RawCellBuilder setValue(final byte[] value); + @Override + RawCellBuilder setValue(final byte[] value, final int vOffset, final int vLength); + + RawCellBuilder setTags(final List tags); + + @Override + RawCell build(); + + @Override + RawCellBuilder clear(); +} diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCellBuilderFactory.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCellBuilderFactory.java new file mode 100644 index 0000000..1d2b2b9 --- /dev/null +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCellBuilderFactory.java @@ -0,0 +1,36 @@ +/* + * 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 org.apache.yetus.audience.InterfaceAudience; + + +@InterfaceAudience.Private +public final class RawCellBuilderFactory { + + /** + * @return the cell that is created + */ + public static RawCellBuilder create() { + return new RawKeyValueBuilder(); + } + + private RawCellBuilderFactory() { + } +} diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCellBuilderImpl.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCellBuilderImpl.java new file mode 100644 index 0000000..9bd6b40 --- /dev/null +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/RawCellBuilderImpl.java @@ -0,0 +1,162 @@ +/* + * 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.util.List; + +import org.apache.hadoop.hbase.util.ArrayUtils; +import org.apache.yetus.audience.InterfaceAudience; + +@InterfaceAudience.Private +public abstract class RawCellBuilderImpl implements RawCellBuilder { + protected byte[] row = null; + protected int rOffset = 0; + protected int rLength = 0; + protected byte[] family = null; + protected int fOffset = 0; + protected int fLength = 0; + protected byte[] qualifier = null; + protected int qOffset = 0; + protected int qLength = 0; + protected long timestamp = HConstants.LATEST_TIMESTAMP; + protected KeyValue.Type type = null; + protected byte[] value = null; + protected int vOffset = 0; + protected int vLength = 0; + protected List tags = null; + @Override + public RawCellBuilder setRow(final byte[] row) { + return setRow(row, 0, ArrayUtils.length(row)); + } + + @Override + public RawCellBuilder setRow(final byte[] row, int rOffset, int rLength) { + this.row = row; + this.rOffset = rOffset; + this.rLength = rLength; + return this; + } + + @Override + public RawCellBuilder setFamily(final byte[] family) { + return setFamily(family, 0, ArrayUtils.length(family)); + } + + @Override + public RawCellBuilder setFamily(final byte[] family, int fOffset, int fLength) { + this.family = family; + this.fOffset = fOffset; + this.fLength = fLength; + return this; + } + + @Override + public RawCellBuilder setQualifier(final byte[] qualifier) { + return setQualifier(qualifier, 0, ArrayUtils.length(qualifier)); + } + + @Override + public RawCellBuilder setQualifier(final byte[] qualifier, int qOffset, int qLength) { + this.qualifier = qualifier; + this.qOffset = qOffset; + this.qLength = qLength; + return this; + } + + @Override + public RawCellBuilder setTimestamp(final long timestamp) { + this.timestamp = timestamp; + return this; + } + + @Override + public RawCellBuilder setType(final DataType type) { + this.type = toKeyValueType(type); + return this; + } + + @Override + public RawCellBuilder setType(final byte type) { + this.type = KeyValue.Type.codeToType(type); + return this; + } + + @Override + public RawCellBuilder setValue(final byte[] value) { + return setValue(value, 0, ArrayUtils.length(value)); + } + + @Override + public RawCellBuilder setValue(final byte[] value, int vOffset, int vLength) { + this.value = value; + this.vOffset = vOffset; + this.vLength = vLength; + return this; + } + + @Override + public RawCellBuilder setTags(List tags) { + this.tags = tags; + return this; + } + + private void checkBeforeBuild() { + if (type == null) { + throw new IllegalArgumentException("The type can't be NULL"); + } + } + + protected abstract RawCell innerBuild(); + + @Override + public RawCell build() { + checkBeforeBuild(); + return innerBuild(); + } + + @Override + public RawCellBuilder clear() { + row = null; + rOffset = 0; + rLength = 0; + family = null; + fOffset = 0; + fLength = 0; + qualifier = null; + qOffset = 0; + qLength = 0; + timestamp = HConstants.LATEST_TIMESTAMP; + type = null; + value = null; + vOffset = 0; + vLength = 0; + tags = null; + return this; + } + + private static KeyValue.Type toKeyValueType(DataType type) { + switch (type) { + case Put: return KeyValue.Type.Put; + case Delete: return KeyValue.Type.Delete; + case DeleteColumn: return KeyValue.Type.DeleteColumn; + case DeleteFamilyVersion: return KeyValue.Type.DeleteFamilyVersion; + case DeleteFamily: return KeyValue.Type.DeleteFamily; + default: throw new UnsupportedOperationException("Unsupported data type:" + type); + } + } +} diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/RawKeyValueBuilder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/RawKeyValueBuilder.java new file mode 100644 index 0000000..aa835b4 --- /dev/null +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/RawKeyValueBuilder.java @@ -0,0 +1,35 @@ +/** + * 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 org.apache.yetus.audience.InterfaceAudience; + +@InterfaceAudience.Private +class RawKeyValueBuilder extends RawCellBuilderImpl { + + @Override + protected RawCell innerBuild() { + KeyValue kv = new KeyValue(row, rOffset, rLength, + family, fOffset, fLength, + qualifier, qOffset, qLength, + timestamp, type, + value, vOffset, vLength, + tags); + return kv; + } +} diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/Tag.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/Tag.java index 8709814..6f9bfdc 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/Tag.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/Tag.java @@ -20,7 +20,6 @@ package org.apache.hadoop.hbase; import java.nio.ByteBuffer; -import java.util.List; import org.apache.hadoop.hbase.util.ByteBufferUtils; import org.apache.hadoop.hbase.util.Bytes; @@ -153,38 +152,6 @@ public interface Tag { } /** - * Write a list of tags into a byte array - * @param tags The list of tags - * @return the serialized tag data as bytes - */ - // TODO : Remove this when we move to RawCellBuilder - public static byte[] fromList(List tags) { - if (tags == null || tags.isEmpty()) { - return HConstants.EMPTY_BYTE_ARRAY; - } - int length = 0; - for (Tag tag : tags) { - length += tag.getValueLength() + Tag.INFRASTRUCTURE_SIZE; - } - byte[] b = new byte[length]; - int pos = 0; - int tlen; - for (Tag tag : tags) { - tlen = tag.getValueLength(); - pos = Bytes.putAsShort(b, pos, tlen + Tag.TYPE_LENGTH_SIZE); - pos = Bytes.putByte(b, pos, tag.getType()); - if (tag.hasArray()) { - pos = Bytes.putBytes(b, pos, tag.getValueArray(), tag.getValueOffset(), tlen); - } else { - ByteBufferUtils.copyFromBufferToArray(b, tag.getValueByteBuffer(), tag.getValueOffset(), - pos, tlen); - pos += tlen; - } - } - return b; - } - - /** * Converts the value bytes of the given tag into a long value * @param tag The Tag * @return value as long diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/TagUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/TagUtil.java index 6ad66ba..a3c1716 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/TagUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/TagUtil.java @@ -137,6 +137,37 @@ public final class TagUtil { } /** + * Write a list of tags into a byte array + * @param tags The list of tags + * @return the serialized tag data as bytes + */ + public static byte[] fromList(List tags) { + if (tags == null || tags.isEmpty()) { + return HConstants.EMPTY_BYTE_ARRAY; + } + int length = 0; + for (Tag tag : tags) { + length += tag.getValueLength() + Tag.INFRASTRUCTURE_SIZE; + } + byte[] b = new byte[length]; + int pos = 0; + int tlen; + for (Tag tag : tags) { + tlen = tag.getValueLength(); + pos = Bytes.putAsShort(b, pos, tlen + Tag.TYPE_LENGTH_SIZE); + pos = Bytes.putByte(b, pos, tag.getType()); + if (tag.hasArray()) { + pos = Bytes.putBytes(b, pos, tag.getValueArray(), tag.getValueOffset(), tlen); + } else { + ByteBufferUtils.copyFromBufferToArray(b, tag.getValueByteBuffer(), tag.getValueOffset(), + pos, tlen); + pos += tlen; + } + } + return b; + } + + /** * Iterator returned when no Tags. Used by CellUtil too. */ static final Iterator EMPTY_TAGS_ITR = new Iterator() { diff --git a/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java b/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java index 7f94f93..e7de604 100644 --- a/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java +++ b/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java @@ -54,6 +54,7 @@ public class TestPBCell { pbr.setPosition(0); decoded = CODEC.decode(pbr); assertEquals(encodedLength, pbr.getPosition()); - assertTrue(CellUtil.equals(cell, ProtobufUtil.toCell(ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY), decoded))); + assertTrue(CellUtil.equals(cell, + ProtobufUtil.toCell(ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY), decoded))); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionCoprocessorEnvironment.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionCoprocessorEnvironment.java index ca57fc8..056a9c4 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionCoprocessorEnvironment.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionCoprocessorEnvironment.java @@ -24,8 +24,8 @@ import java.util.concurrent.ConcurrentMap; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CoprocessorEnvironment; -import org.apache.hadoop.hbase.ExtendedCellBuilder; import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.RawCellBuilder; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.RegionInfo; @@ -108,7 +108,7 @@ public interface RegionCoprocessorEnvironment extends CoprocessorEnvironment tags = new ArrayList<>(); tags.add(MobConstants.MOB_REF_TAG); - REF_DELETE_MARKER_TAG_BYTES = Tag.fromList(tags); + REF_DELETE_MARKER_TAG_BYTES = TagUtil.fromList(tags); } /** @@ -502,7 +502,7 @@ public final class MobUtils { // find the original mob files by this table name. For details please see cloning // snapshot for mob files. tags.add(tableNameTag); - return createMobRefCell(cell, fileName, Tag.fromList(tags)); + return createMobRefCell(cell, fileName, TagUtil.fromList(tags)); } public static Cell createMobRefCell(Cell cell, byte[] fileName, byte[] refCellTags) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactor.java index 0cccfa3..cf661db 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactor.java @@ -54,6 +54,7 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.TagType; +import org.apache.hadoop.hbase.TagUtil; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; @@ -131,7 +132,7 @@ public class PartitionedMobCompactor extends MobCompactor { tags.add(MobConstants.MOB_REF_TAG); Tag tableNameTag = new ArrayBackedTag(TagType.MOB_TABLE_NAME_TAG_TYPE, tableName.getName()); tags.add(tableNameTag); - this.refCellTags = Tag.fromList(tags); + this.refCellTags = TagUtil.fromList(tags); cryptoContext = EncryptionUtil.createEncryptionContext(copyOfConf, column); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HMobStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HMobStore.java index 5db7383..9938800 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HMobStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HMobStore.java @@ -39,9 +39,12 @@ import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.ExtendedCellBuilderFactory; import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.RawCell; +import org.apache.hadoop.hbase.RawCellBuilderFactory; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.TagType; +import org.apache.hadoop.hbase.TagUtil; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.filter.Filter; @@ -120,7 +123,7 @@ public class HMobStore extends HStore { Tag tableNameTag = new ArrayBackedTag(TagType.MOB_TABLE_NAME_TAG_TYPE, getTableName().getName()); tags.add(tableNameTag); - this.refCellTags = Tag.fromList(tags); + this.refCellTags = TagUtil.fromList(tags); } /** @@ -356,7 +359,9 @@ public class HMobStore extends HStore { if (result == null) { LOG.warn("The Cell result is null, assemble a new Cell with the same row,family," + "qualifier,timestamp,type and tags but with an empty value to return."); - result = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY) + assert reference instanceof RawCell; + List tags = ((RawCell)reference).getTags(); + result = RawCellBuilderFactory.create() .setRow(reference.getRowArray(), reference.getRowOffset(), reference.getRowLength()) .setFamily(reference.getFamilyArray(), reference.getFamilyOffset(), reference.getFamilyLength()) @@ -365,8 +370,7 @@ public class HMobStore extends HStore { .setTimestamp(reference.getTimestamp()) .setType(reference.getTypeByte()) .setValue(HConstants.EMPTY_BYTE_ARRAY) - .setTags(reference.getTagsArray(), reference.getTagsOffset(), - reference.getTagsLength()) + .setTags(tags) .build(); } return result; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index c767dc5..cc678d2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -7714,7 +7714,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi .setTimestamp(Math.max(currentCell.getTimestamp() + 1, now)) .setType(KeyValue.Type.Put.getCode()) .setValue(newValue, 0, newValue.length) - .setTags(Tag.fromList(tags)) + .setTags(TagUtil.fromList(tags)) .build(); } else { PrivateCellUtil.updateLatestStamp(delta, now); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java index 2188300..87d9265 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java @@ -18,9 +18,6 @@ package org.apache.hadoop.hbase.regionserver; -import com.google.protobuf.Message; -import com.google.protobuf.Service; - import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -41,10 +38,11 @@ import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellBuilderType; import org.apache.hadoop.hbase.CompareOperator; import org.apache.hadoop.hbase.Coprocessor; -import org.apache.hadoop.hbase.ExtendedCellBuilder; import org.apache.hadoop.hbase.ExtendedCellBuilderFactory; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.RawCellBuilder; +import org.apache.hadoop.hbase.RawCellBuilderFactory; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.client.Append; import org.apache.hadoop.hbase.client.Connection; @@ -91,6 +89,9 @@ import org.apache.hadoop.hbase.wal.WALEdit; import org.apache.hadoop.hbase.wal.WALKey; import org.apache.yetus.audience.InterfaceAudience; +import com.google.protobuf.Message; +import com.google.protobuf.Service; + /** * Implements the coprocessor environment and runtime support for coprocessors * loaded within a {@link Region}. @@ -183,10 +184,9 @@ public class RegionCoprocessorHost } @Override - public ExtendedCellBuilder getCellBuilder() { - // do not allow seqId update. + public RawCellBuilder getCellBuilder() { // We always do a DEEP_COPY only - return ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY, false); + return RawCellBuilderFactory.create(); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java index ba2e22c..af7e632 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java @@ -18,11 +18,6 @@ package org.apache.hadoop.hbase.security.visibility; -import com.google.protobuf.ByteString; -import com.google.protobuf.RpcCallback; -import com.google.protobuf.RpcController; -import com.google.protobuf.Service; - import static org.apache.hadoop.hbase.HConstants.OperationStatusCode.SANITY_CHECK_FAILURE; import static org.apache.hadoop.hbase.HConstants.OperationStatusCode.SUCCESS; import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LABELS_TABLE_FAMILY; @@ -115,6 +110,11 @@ import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.util.StringUtils; import org.apache.yetus.audience.InterfaceAudience; +import com.google.protobuf.ByteString; +import com.google.protobuf.RpcCallback; +import com.google.protobuf.RpcController; +import com.google.protobuf.Service; + /** * Coprocessor that has both the MasterObserver and RegionObserver implemented that supports in * visibility labels diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityReplicationEndpoint.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityReplicationEndpoint.java index 4c86323..1a003da 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityReplicationEndpoint.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityReplicationEndpoint.java @@ -28,16 +28,15 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.ArrayBackedTag; import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.PrivateCellUtil; import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.TagType; -import org.apache.yetus.audience.InterfaceAudience; -import org.apache.hadoop.hbase.wal.WALEdit; import org.apache.hadoop.hbase.replication.ReplicationEndpoint; import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; import org.apache.hadoop.hbase.replication.WALEntryFilter; import org.apache.hadoop.hbase.wal.WAL.Entry; +import org.apache.hadoop.hbase.wal.WALEdit; +import org.apache.yetus.audience.InterfaceAudience; @InterfaceAudience.Private public class VisibilityReplicationEndpoint implements ReplicationEndpoint { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java index e8d8b7e..e102cb2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java @@ -42,6 +42,7 @@ import org.apache.hadoop.hbase.CoordinatedStateManager; import org.apache.hadoop.hbase.ExtendedCellBuilder; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HRegionInfo; +import org.apache.hadoop.hbase.RawCellBuilder; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.client.ClusterConnection; @@ -331,7 +332,7 @@ public class TestTokenAuthentication { } @Override - public ExtendedCellBuilder getCellBuilder() { + public RawCellBuilder getCellBuilder() { return null; } });