Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-28587 Remove deprecated methods in Cell #6125

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Optional;
import org.apache.hadoop.hbase.ByteBufferExtendedCell;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.ExtendedCell;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
Expand Down Expand Up @@ -68,11 +69,15 @@ public boolean filterRowKey(Cell cell) throws IOException {
}

@Override
public Cell transformCell(Cell cell) {
return createKeyOnlyCell(cell);
public Cell transformCell(Cell cell) throws IOException {
if (cell instanceof ExtendedCell) {
return createKeyOnlyCell((ExtendedCell) cell);
}
throw new DoNotRetryIOException(
"Customized cell implementation is not support: " + cell.getClass().getName());
}

private Cell createKeyOnlyCell(Cell c) {
private Cell createKeyOnlyCell(ExtendedCell c) {
if (c instanceof ByteBufferExtendedCell) {
return new KeyOnlyByteBufferExtendedCell((ByteBufferExtendedCell) c, lenAsVal);
} else {
Expand Down Expand Up @@ -147,11 +152,11 @@ public int hashCode() {
}

static class KeyOnlyCell implements ExtendedCell {
private Cell cell;
private ExtendedCell cell;
private int keyLen;
private boolean lenAsVal;

public KeyOnlyCell(Cell c, boolean lenAsVal) {
public KeyOnlyCell(ExtendedCell c, boolean lenAsVal) {
this.cell = c;
this.lenAsVal = lenAsVal;
this.keyLen = KeyValueUtil.keyLength(c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,10 +1315,11 @@ public static MutationProto toMutation(final MutationType type, final Mutation m
}
ColumnValue.Builder columnBuilder = ColumnValue.newBuilder();
QualifierValue.Builder valueBuilder = QualifierValue.newBuilder();
for (Map.Entry<byte[], List<Cell>> family : mutation.getFamilyCellMap().entrySet()) {
for (Map.Entry<byte[], List<ExtendedCell>> family : ClientInternalHelper
.getExtendedFamilyCellMap(mutation).entrySet()) {
columnBuilder.clear();
columnBuilder.setFamily(UnsafeByteOperations.unsafeWrap(family.getKey()));
for (Cell cell : family.getValue()) {
for (ExtendedCell cell : family.getValue()) {
valueBuilder.clear();
valueBuilder.setQualifier(UnsafeByteOperations.unsafeWrap(cell.getQualifierArray(),
cell.getQualifierOffset(), cell.getQualifierLength()));
Expand Down Expand Up @@ -1420,13 +1421,13 @@ public static ClientProtos.Result toResult(final Result result, boolean encodeTa
return toResult(result.getExists(), result.isStale());
}

Cell[] cells = result.rawCells();
ExtendedCell[] cells = ClientInternalHelper.getExtendedRawCells(result);
if (cells == null || cells.length == 0) {
return result.isStale() ? EMPTY_RESULT_PB_STALE : EMPTY_RESULT_PB;
}

ClientProtos.Result.Builder builder = ClientProtos.Result.newBuilder();
for (Cell c : cells) {
for (ExtendedCell c : cells) {
builder.addCell(toCell(c, encodeTags));
}

Expand Down Expand Up @@ -1980,7 +1981,7 @@ public static void toIOException(ServiceException se) throws IOException {
throw new IOException(se);
}

public static CellProtos.Cell toCell(final Cell kv, boolean encodeTags) {
public static CellProtos.Cell toCell(final ExtendedCell kv, boolean encodeTags) {
// Doing this is going to kill us if we do it for all data passed.
// St.Ack 20121205
CellProtos.Cell.Builder kvbuilder = CellProtos.Cell.newBuilder();
Expand All @@ -1991,7 +1992,7 @@ public static CellProtos.Cell toCell(final Cell kv, boolean encodeTags) {
((ByteBufferExtendedCell) kv).getFamilyPosition(), kv.getFamilyLength()));
kvbuilder.setQualifier(wrap(((ByteBufferExtendedCell) kv).getQualifierByteBuffer(),
((ByteBufferExtendedCell) kv).getQualifierPosition(), kv.getQualifierLength()));
kvbuilder.setCellType(CellProtos.CellType.valueOf(kv.getTypeByte()));
kvbuilder.setCellType(CellProtos.CellType.forNumber(kv.getTypeByte()));
kvbuilder.setTimestamp(kv.getTimestamp());
kvbuilder.setValue(wrap(((ByteBufferExtendedCell) kv).getValueByteBuffer(),
((ByteBufferExtendedCell) kv).getValuePosition(), kv.getValueLength()));
Expand All @@ -2006,7 +2007,7 @@ public static CellProtos.Cell toCell(final Cell kv, boolean encodeTags) {
kv.getFamilyLength()));
kvbuilder.setQualifier(UnsafeByteOperations.unsafeWrap(kv.getQualifierArray(),
kv.getQualifierOffset(), kv.getQualifierLength()));
kvbuilder.setCellType(CellProtos.CellType.valueOf(kv.getTypeByte()));
kvbuilder.setCellType(CellProtos.CellType.forNumber(kv.getTypeByte()));
kvbuilder.setTimestamp(kv.getTimestamp());
kvbuilder.setValue(UnsafeByteOperations.unsafeWrap(kv.getValueArray(), kv.getValueOffset(),
kv.getValueLength()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.ExtendedCell;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
Expand Down Expand Up @@ -456,7 +457,8 @@ public void testPutCreationWithByteBuffer() {
Assert.assertEquals(1984L, c.get(0).getTimestamp());
Assert.assertArrayEquals(VALUE, CellUtil.cloneValue(c.get(0)));
Assert.assertEquals(HConstants.LATEST_TIMESTAMP, p.getTimestamp());
Assert.assertEquals(0, CellComparatorImpl.COMPARATOR.compare(c.get(0), new KeyValue(c.get(0))));
Assert.assertEquals(0,
CellComparatorImpl.COMPARATOR.compare(c.get(0), new KeyValue((ExtendedCell) c.get(0))));

p = new Put(ROW);
p.addColumn(FAMILY, ByteBuffer.wrap(QUALIFIER), 2013L, null);
Expand All @@ -465,7 +467,8 @@ public void testPutCreationWithByteBuffer() {
Assert.assertEquals(2013L, c.get(0).getTimestamp());
Assert.assertArrayEquals(new byte[] {}, CellUtil.cloneValue(c.get(0)));
Assert.assertEquals(HConstants.LATEST_TIMESTAMP, p.getTimestamp());
Assert.assertEquals(0, CellComparatorImpl.COMPARATOR.compare(c.get(0), new KeyValue(c.get(0))));
Assert.assertEquals(0,
CellComparatorImpl.COMPARATOR.compare(c.get(0), new KeyValue((ExtendedCell) c.get(0))));

p = new Put(ByteBuffer.wrap(ROW));
p.addColumn(FAMILY, ByteBuffer.wrap(QUALIFIER), 2001L, null);
Expand All @@ -475,7 +478,8 @@ public void testPutCreationWithByteBuffer() {
Assert.assertArrayEquals(new byte[] {}, CellUtil.cloneValue(c.get(0)));
Assert.assertArrayEquals(ROW, CellUtil.cloneRow(c.get(0)));
Assert.assertEquals(HConstants.LATEST_TIMESTAMP, p.getTimestamp());
Assert.assertEquals(0, CellComparatorImpl.COMPARATOR.compare(c.get(0), new KeyValue(c.get(0))));
Assert.assertEquals(0,
CellComparatorImpl.COMPARATOR.compare(c.get(0), new KeyValue((ExtendedCell) c.get(0))));

p = new Put(ByteBuffer.wrap(ROW), 1970L);
p.addColumn(FAMILY, ByteBuffer.wrap(QUALIFIER), 2001L, null);
Expand All @@ -485,7 +489,8 @@ public void testPutCreationWithByteBuffer() {
Assert.assertArrayEquals(new byte[] {}, CellUtil.cloneValue(c.get(0)));
Assert.assertArrayEquals(ROW, CellUtil.cloneRow(c.get(0)));
Assert.assertEquals(1970L, p.getTimestamp());
Assert.assertEquals(0, CellComparatorImpl.COMPARATOR.compare(c.get(0), new KeyValue(c.get(0))));
Assert.assertEquals(0,
CellComparatorImpl.COMPARATOR.compare(c.get(0), new KeyValue((ExtendedCell) c.get(0))));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,7 @@ public void testRegionLockInfo() {
*/
@Test
public void testCellConversionWithTags() {

Cell cell = getCellWithTags();
ExtendedCell cell = getCellWithTags();
CellProtos.Cell protoCell = ProtobufUtil.toCell(cell, true);
assertNotNull(protoCell);

Expand All @@ -514,7 +513,7 @@ public void testCellConversionWithTags() {
assertEquals(TAG_STR, Tag.getValueAsString(decodedTag));
}

private Cell getCellWithTags() {
private ExtendedCell getCellWithTags() {
Tag tag = new ArrayBackedTag(TAG_TYPE, TAG_STR);
ExtendedCellBuilder cellBuilder = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY);
cellBuilder.setRow(Bytes.toBytes("row1"));
Expand All @@ -539,7 +538,7 @@ private ExtendedCell getCellFromProtoResult(CellProtos.Cell protoCell, boolean d
*/
@Test
public void testCellConversionWithoutTags() {
Cell cell = getCellWithTags();
ExtendedCell cell = getCellWithTags();
CellProtos.Cell protoCell = ProtobufUtil.toCell(cell, false);
assertNotNull(protoCell);

Expand All @@ -555,7 +554,7 @@ public void testCellConversionWithoutTags() {
*/
@Test
public void testTagEncodeFalseDecodeTrue() {
Cell cell = getCellWithTags();
ExtendedCell cell = getCellWithTags();
CellProtos.Cell protoCell = ProtobufUtil.toCell(cell, false);
assertNotNull(protoCell);

Expand All @@ -571,7 +570,7 @@ public void testTagEncodeFalseDecodeTrue() {
*/
@Test
public void testTagEncodeTrueDecodeFalse() {
Cell cell = getCellWithTags();
ExtendedCell cell = getCellWithTags();
CellProtos.Cell protoCell = ProtobufUtil.toCell(cell, true);
assertNotNull(protoCell);

Expand Down
75 changes: 7 additions & 68 deletions hbase-common/src/main/java/org/apache/hadoop/hbase/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,15 @@ public interface Cell extends HeapSize {
// 5) Type

/**
* Return the byte representation of the KeyValue.TYPE of this cell: one of Put, Delete, etc
* @deprecated As of HBase-2.0. Will be removed in HBase-3.0. Use {@link #getType()}.
*/
@Deprecated
byte getTypeByte();

// 6) SequenceId

/**
* 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 &gt; 0 if exists), or 0 if it no longer exists
* @deprecated As of HBase-2.0. Will be removed in HBase-3.0.
* Returns the type of cell in a human readable format using {@link Type}.
* <p>
* Note : This does not expose the internal types of Cells like {@link KeyValue.Type#Maximum} and
* {@link KeyValue.Type#Minimum}
* @return The data type this cell: one of Put, Delete, etc
*/
@Deprecated
long getSequenceId();
Type getType();

// 7) Value
// 6) Value

/**
* Contiguous raw bytes that may start at any index in the containing array. Max length is
Expand All @@ -151,48 +140,6 @@ public interface Cell extends HeapSize {
/** Returns Serialized size (defaults to include tag length if has some tags). */
int getSerializedSize();

/**
* 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. Tags are are now internal.
*/
@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. Tags are are now internal.
*/
@Deprecated
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.
* @deprecated As of HBase-2.0. Will be removed in HBase-3.0. Tags are are now internal.
*/
@Deprecated
int getTagsLength();

/**
* Returns the type of cell in a human readable format using {@link Type}. Note : This does not
* expose the internal types of Cells like {@link KeyValue.Type#Maximum} and
* {@link KeyValue.Type#Minimum}
* @return The data type this cell: one of Put, Delete, etc
*/
default Type getType() {
byte byteType = getTypeByte();
Type t = Type.CODE_ARRAY[byteType & 0xff];
if (t != null) {
return t;
}
throw new UnsupportedOperationException("Invalid type of cell " + byteType);
}

/**
* The valid types for user to build the cell. Currently, This is subset of {@link KeyValue.Type}.
*/
Expand All @@ -216,13 +163,5 @@ enum Type {
public byte getCode() {
return this.code;
}

private static final Type[] CODE_ARRAY = new Type[256];

static {
for (Type t : Type.values()) {
CODE_ARRAY[t.code & 0xff] = t;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ public int compare(final Cell l, final Cell r, boolean ignoreSequenceid) {
return diff;
}
}

if (ignoreSequenceid) {
return diff;
}
// Negate following comparisons so later edits show up first mvccVersion: later sorts first
return ignoreSequenceid ? diff : Long.compare(r.getSequenceId(), l.getSequenceId());
return Long.compare(PrivateCellUtil.getSequenceId(r), PrivateCellUtil.getSequenceId(l));
}

private int compareKeyValues(final KeyValue left, final KeyValue right) {
Expand Down Expand Up @@ -720,11 +724,13 @@ public final int compareWithoutRow(final Cell left, final Cell right) {
int rFamLength = right.getFamilyLength();
int lQualLength = left.getQualifierLength();
int rQualLength = right.getQualifierLength();
if (lFamLength + lQualLength == 0 && left.getTypeByte() == KeyValue.Type.Minimum.getCode()) {
byte leftType = PrivateCellUtil.getTypeByte(left);
byte rightType = PrivateCellUtil.getTypeByte(right);
if (lFamLength + lQualLength == 0 && leftType == KeyValue.Type.Minimum.getCode()) {
// left is "bigger", i.e. it appears later in the sorted order
return 1;
}
if (rFamLength + rQualLength == 0 && right.getTypeByte() == KeyValue.Type.Minimum.getCode()) {
if (rFamLength + rQualLength == 0 && rightType == KeyValue.Type.Minimum.getCode()) {
return -1;
}
if (lFamLength != rFamLength) {
Expand All @@ -746,7 +752,7 @@ public final int compareWithoutRow(final Cell left, final Cell right) {
// of higher numbers sort before those of lesser numbers. Maximum (255)
// appears ahead of everything, and minimum (0) appears after
// everything.
return (0xff & right.getTypeByte()) - (0xff & left.getTypeByte());
return (0xff & rightType) - (0xff & leftType);
}

@Override
Expand Down
31 changes: 21 additions & 10 deletions hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -570,15 +570,13 @@ public static boolean matchingTags(final Cell left, final Cell right) {
* Return true if a delete type, a {@link KeyValue.Type#Delete} or a {KeyValue.Type#DeleteFamily}
* or a {@link KeyValue.Type#DeleteColumn} KeyValue type.
*/
@SuppressWarnings("deprecation")
public static boolean isDelete(final Cell cell) {
return PrivateCellUtil.isDelete(cell.getTypeByte());
return PrivateCellUtil.isDelete(PrivateCellUtil.getTypeByte(cell));
}

/** Returns True if this cell is a Put. */
@SuppressWarnings("deprecation")
public static boolean isPut(Cell cell) {
return cell.getTypeByte() == KeyValue.Type.Put.getCode();
return PrivateCellUtil.getTypeByte(cell) == KeyValue.Type.Put.getCode();
}

/**
Expand Down Expand Up @@ -629,13 +627,21 @@ public static String getCellKeyAsString(Cell cell, Function<Cell, String> rowCon
sb.append('/');
sb.append(KeyValue.humanReadableTimestamp(cell.getTimestamp()));
sb.append('/');
sb.append(KeyValue.Type.codeToType(cell.getTypeByte()));
if (cell instanceof ExtendedCell) {
sb.append(KeyValue.Type.codeToType(((ExtendedCell) cell).getTypeByte()));
} else {
sb.append(cell.getType());
}

if (!(cell instanceof KeyValue.KeyOnlyKeyValue)) {
sb.append("/vlen=");
sb.append(cell.getValueLength());
}
sb.append("/seqid=");
sb.append(cell.getSequenceId());
if (cell instanceof ExtendedCell) {
sb.append("/seqid=");
sb.append(((ExtendedCell) cell).getSequenceId());
}

return sb.toString();
}

Expand All @@ -651,8 +657,12 @@ public static String toString(Cell cell, boolean verbose) {
String value = null;
if (verbose) {
// TODO: pretty print tags as well
if (cell.getTagsLength() > 0) {
tag = Bytes.toStringBinary(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength());
if (cell instanceof RawCell) {
RawCell rawCell = (RawCell) cell;
if (rawCell.getTagsLength() > 0) {
tag = Bytes.toStringBinary(rawCell.getTagsArray(), rawCell.getTagsOffset(),
rawCell.getTagsLength());
}
}
if (!(cell instanceof KeyValue.KeyOnlyKeyValue)) {
value =
Expand All @@ -675,7 +685,8 @@ public static String toString(Cell cell, boolean verbose) {

public static boolean equals(Cell a, Cell b) {
return matchingRows(a, b) && matchingFamily(a, b) && matchingQualifier(a, b)
&& matchingTimestamp(a, b) && a.getTypeByte() == b.getTypeByte();
&& matchingTimestamp(a, b)
&& PrivateCellUtil.getTypeByte(a) == PrivateCellUtil.getTypeByte(b);
}

public static boolean matchingTimestamp(Cell a, Cell b) {
Expand Down
Loading