Skip to content

Commit 71c4054

Browse files
authored
HBASE-28587 Remove deprecated methods in Cell (#6125)
Signed-off-by: Xin Sun <sunxin@apache.org>
1 parent d716705 commit 71c4054

File tree

41 files changed

+263
-289
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+263
-289
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/filter/KeyOnlyFilter.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Optional;
2727
import org.apache.hadoop.hbase.ByteBufferExtendedCell;
2828
import org.apache.hadoop.hbase.Cell;
29+
import org.apache.hadoop.hbase.DoNotRetryIOException;
2930
import org.apache.hadoop.hbase.ExtendedCell;
3031
import org.apache.hadoop.hbase.HConstants;
3132
import org.apache.hadoop.hbase.KeyValue;
@@ -68,11 +69,15 @@ public boolean filterRowKey(Cell cell) throws IOException {
6869
}
6970

7071
@Override
71-
public Cell transformCell(Cell cell) {
72-
return createKeyOnlyCell(cell);
72+
public Cell transformCell(Cell cell) throws IOException {
73+
if (cell instanceof ExtendedCell) {
74+
return createKeyOnlyCell((ExtendedCell) cell);
75+
}
76+
throw new DoNotRetryIOException(
77+
"Customized cell implementation is not support: " + cell.getClass().getName());
7378
}
7479

75-
private Cell createKeyOnlyCell(Cell c) {
80+
private Cell createKeyOnlyCell(ExtendedCell c) {
7681
if (c instanceof ByteBufferExtendedCell) {
7782
return new KeyOnlyByteBufferExtendedCell((ByteBufferExtendedCell) c, lenAsVal);
7883
} else {
@@ -147,11 +152,11 @@ public int hashCode() {
147152
}
148153

149154
static class KeyOnlyCell implements ExtendedCell {
150-
private Cell cell;
155+
private ExtendedCell cell;
151156
private int keyLen;
152157
private boolean lenAsVal;
153158

154-
public KeyOnlyCell(Cell c, boolean lenAsVal) {
159+
public KeyOnlyCell(ExtendedCell c, boolean lenAsVal) {
155160
this.cell = c;
156161
this.lenAsVal = lenAsVal;
157162
this.keyLen = KeyValueUtil.keyLength(c);

hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,10 +1315,11 @@ public static MutationProto toMutation(final MutationType type, final Mutation m
13151315
}
13161316
ColumnValue.Builder columnBuilder = ColumnValue.newBuilder();
13171317
QualifierValue.Builder valueBuilder = QualifierValue.newBuilder();
1318-
for (Map.Entry<byte[], List<Cell>> family : mutation.getFamilyCellMap().entrySet()) {
1318+
for (Map.Entry<byte[], List<ExtendedCell>> family : ClientInternalHelper
1319+
.getExtendedFamilyCellMap(mutation).entrySet()) {
13191320
columnBuilder.clear();
13201321
columnBuilder.setFamily(UnsafeByteOperations.unsafeWrap(family.getKey()));
1321-
for (Cell cell : family.getValue()) {
1322+
for (ExtendedCell cell : family.getValue()) {
13221323
valueBuilder.clear();
13231324
valueBuilder.setQualifier(UnsafeByteOperations.unsafeWrap(cell.getQualifierArray(),
13241325
cell.getQualifierOffset(), cell.getQualifierLength()));
@@ -1420,13 +1421,13 @@ public static ClientProtos.Result toResult(final Result result, boolean encodeTa
14201421
return toResult(result.getExists(), result.isStale());
14211422
}
14221423

1423-
Cell[] cells = result.rawCells();
1424+
ExtendedCell[] cells = ClientInternalHelper.getExtendedRawCells(result);
14241425
if (cells == null || cells.length == 0) {
14251426
return result.isStale() ? EMPTY_RESULT_PB_STALE : EMPTY_RESULT_PB;
14261427
}
14271428

14281429
ClientProtos.Result.Builder builder = ClientProtos.Result.newBuilder();
1429-
for (Cell c : cells) {
1430+
for (ExtendedCell c : cells) {
14301431
builder.addCell(toCell(c, encodeTags));
14311432
}
14321433

@@ -1980,7 +1981,7 @@ public static void toIOException(ServiceException se) throws IOException {
19801981
throw new IOException(se);
19811982
}
19821983

1983-
public static CellProtos.Cell toCell(final Cell kv, boolean encodeTags) {
1984+
public static CellProtos.Cell toCell(final ExtendedCell kv, boolean encodeTags) {
19841985
// Doing this is going to kill us if we do it for all data passed.
19851986
// St.Ack 20121205
19861987
CellProtos.Cell.Builder kvbuilder = CellProtos.Cell.newBuilder();
@@ -1991,7 +1992,7 @@ public static CellProtos.Cell toCell(final Cell kv, boolean encodeTags) {
19911992
((ByteBufferExtendedCell) kv).getFamilyPosition(), kv.getFamilyLength()));
19921993
kvbuilder.setQualifier(wrap(((ByteBufferExtendedCell) kv).getQualifierByteBuffer(),
19931994
((ByteBufferExtendedCell) kv).getQualifierPosition(), kv.getQualifierLength()));
1994-
kvbuilder.setCellType(CellProtos.CellType.valueOf(kv.getTypeByte()));
1995+
kvbuilder.setCellType(CellProtos.CellType.forNumber(kv.getTypeByte()));
19951996
kvbuilder.setTimestamp(kv.getTimestamp());
19961997
kvbuilder.setValue(wrap(((ByteBufferExtendedCell) kv).getValueByteBuffer(),
19971998
((ByteBufferExtendedCell) kv).getValuePosition(), kv.getValueLength()));
@@ -2006,7 +2007,7 @@ public static CellProtos.Cell toCell(final Cell kv, boolean encodeTags) {
20062007
kv.getFamilyLength()));
20072008
kvbuilder.setQualifier(UnsafeByteOperations.unsafeWrap(kv.getQualifierArray(),
20082009
kv.getQualifierOffset(), kv.getQualifierLength()));
2009-
kvbuilder.setCellType(CellProtos.CellType.valueOf(kv.getTypeByte()));
2010+
kvbuilder.setCellType(CellProtos.CellType.forNumber(kv.getTypeByte()));
20102011
kvbuilder.setTimestamp(kv.getTimestamp());
20112012
kvbuilder.setValue(UnsafeByteOperations.unsafeWrap(kv.getValueArray(), kv.getValueOffset(),
20122013
kv.getValueLength()));

hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestOperation.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.hadoop.hbase.CellComparatorImpl;
3131
import org.apache.hadoop.hbase.CellUtil;
3232
import org.apache.hadoop.hbase.CompareOperator;
33+
import org.apache.hadoop.hbase.ExtendedCell;
3334
import org.apache.hadoop.hbase.HBaseClassTestRule;
3435
import org.apache.hadoop.hbase.HConstants;
3536
import org.apache.hadoop.hbase.KeyValue;
@@ -456,7 +457,8 @@ public void testPutCreationWithByteBuffer() {
456457
Assert.assertEquals(1984L, c.get(0).getTimestamp());
457458
Assert.assertArrayEquals(VALUE, CellUtil.cloneValue(c.get(0)));
458459
Assert.assertEquals(HConstants.LATEST_TIMESTAMP, p.getTimestamp());
459-
Assert.assertEquals(0, CellComparatorImpl.COMPARATOR.compare(c.get(0), new KeyValue(c.get(0))));
460+
Assert.assertEquals(0,
461+
CellComparatorImpl.COMPARATOR.compare(c.get(0), new KeyValue((ExtendedCell) c.get(0))));
460462

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

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

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

491496
@Test

hbase-client/src/test/java/org/apache/hadoop/hbase/shaded/protobuf/TestProtobufUtil.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,7 @@ public void testRegionLockInfo() {
501501
*/
502502
@Test
503503
public void testCellConversionWithTags() {
504-
505-
Cell cell = getCellWithTags();
504+
ExtendedCell cell = getCellWithTags();
506505
CellProtos.Cell protoCell = ProtobufUtil.toCell(cell, true);
507506
assertNotNull(protoCell);
508507

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

517-
private Cell getCellWithTags() {
516+
private ExtendedCell getCellWithTags() {
518517
Tag tag = new ArrayBackedTag(TAG_TYPE, TAG_STR);
519518
ExtendedCellBuilder cellBuilder = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY);
520519
cellBuilder.setRow(Bytes.toBytes("row1"));
@@ -539,7 +538,7 @@ private ExtendedCell getCellFromProtoResult(CellProtos.Cell protoCell, boolean d
539538
*/
540539
@Test
541540
public void testCellConversionWithoutTags() {
542-
Cell cell = getCellWithTags();
541+
ExtendedCell cell = getCellWithTags();
543542
CellProtos.Cell protoCell = ProtobufUtil.toCell(cell, false);
544543
assertNotNull(protoCell);
545544

@@ -555,7 +554,7 @@ public void testCellConversionWithoutTags() {
555554
*/
556555
@Test
557556
public void testTagEncodeFalseDecodeTrue() {
558-
Cell cell = getCellWithTags();
557+
ExtendedCell cell = getCellWithTags();
559558
CellProtos.Cell protoCell = ProtobufUtil.toCell(cell, false);
560559
assertNotNull(protoCell);
561560

@@ -571,7 +570,7 @@ public void testTagEncodeFalseDecodeTrue() {
571570
*/
572571
@Test
573572
public void testTagEncodeTrueDecodeFalse() {
574-
Cell cell = getCellWithTags();
573+
ExtendedCell cell = getCellWithTags();
575574
CellProtos.Cell protoCell = ProtobufUtil.toCell(cell, true);
576575
assertNotNull(protoCell);
577576

hbase-common/src/main/java/org/apache/hadoop/hbase/Cell.java

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,15 @@ public interface Cell extends HeapSize {
114114
// 5) Type
115115

116116
/**
117-
* Return the byte representation of the KeyValue.TYPE of this cell: one of Put, Delete, etc
118-
* @deprecated As of HBase-2.0. Will be removed in HBase-3.0. Use {@link #getType()}.
119-
*/
120-
@Deprecated
121-
byte getTypeByte();
122-
123-
// 6) SequenceId
124-
125-
/**
126-
* A region-specific unique monotonically increasing sequence ID given to each Cell. It always
127-
* exists for cells in the memstore but is not retained forever. It will be kept for
128-
* {@link HConstants#KEEP_SEQID_PERIOD} days, but generally becomes irrelevant after the cell's
129-
* row is no longer involved in any operations that require strict consistency.
130-
* @return seqId (always &gt; 0 if exists), or 0 if it no longer exists
131-
* @deprecated As of HBase-2.0. Will be removed in HBase-3.0.
117+
* Returns the type of cell in a human readable format using {@link Type}.
118+
* <p>
119+
* Note : This does not expose the internal types of Cells like {@link KeyValue.Type#Maximum} and
120+
* {@link KeyValue.Type#Minimum}
121+
* @return The data type this cell: one of Put, Delete, etc
132122
*/
133-
@Deprecated
134-
long getSequenceId();
123+
Type getType();
135124

136-
// 7) Value
125+
// 6) Value
137126

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

154-
/**
155-
* Contiguous raw bytes representing tags that may start at any index in the containing array.
156-
* @return the tags byte array
157-
* @deprecated As of HBase-2.0. Will be removed in HBase-3.0. Tags are are now internal.
158-
*/
159-
@Deprecated
160-
byte[] getTagsArray();
161-
162-
/**
163-
* Return the first offset where the tags start in the Cell
164-
* @deprecated As of HBase-2.0. Will be removed in HBase-3.0. Tags are are now internal.
165-
*/
166-
@Deprecated
167-
int getTagsOffset();
168-
169-
/**
170-
* HBase internally uses 2 bytes to store tags length in Cell. As the tags length is always a
171-
* non-negative number, to make good use of the sign bit, the max of tags length is defined 2 *
172-
* Short.MAX_VALUE + 1 = 65535. As a result, the return type is int, because a short is not
173-
* capable of handling that. Please note that even if the return type is int, the max tags length
174-
* is far less than Integer.MAX_VALUE.
175-
* @return the total length of the tags in the Cell.
176-
* @deprecated As of HBase-2.0. Will be removed in HBase-3.0. Tags are are now internal.
177-
*/
178-
@Deprecated
179-
int getTagsLength();
180-
181-
/**
182-
* Returns the type of cell in a human readable format using {@link Type}. Note : This does not
183-
* expose the internal types of Cells like {@link KeyValue.Type#Maximum} and
184-
* {@link KeyValue.Type#Minimum}
185-
* @return The data type this cell: one of Put, Delete, etc
186-
*/
187-
default Type getType() {
188-
byte byteType = getTypeByte();
189-
Type t = Type.CODE_ARRAY[byteType & 0xff];
190-
if (t != null) {
191-
return t;
192-
}
193-
throw new UnsupportedOperationException("Invalid type of cell " + byteType);
194-
}
195-
196143
/**
197144
* The valid types for user to build the cell. Currently, This is subset of {@link KeyValue.Type}.
198145
*/
@@ -216,13 +163,5 @@ enum Type {
216163
public byte getCode() {
217164
return this.code;
218165
}
219-
220-
private static final Type[] CODE_ARRAY = new Type[256];
221-
222-
static {
223-
for (Type t : Type.values()) {
224-
CODE_ARRAY[t.code & 0xff] = t;
225-
}
226-
}
227166
}
228167
}

hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparatorImpl.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ public int compare(final Cell l, final Cell r, boolean ignoreSequenceid) {
9696
return diff;
9797
}
9898
}
99+
100+
if (ignoreSequenceid) {
101+
return diff;
102+
}
99103
// Negate following comparisons so later edits show up first mvccVersion: later sorts first
100-
return ignoreSequenceid ? diff : Long.compare(r.getSequenceId(), l.getSequenceId());
104+
return Long.compare(PrivateCellUtil.getSequenceId(r), PrivateCellUtil.getSequenceId(l));
101105
}
102106

103107
private int compareKeyValues(final KeyValue left, final KeyValue right) {
@@ -720,11 +724,13 @@ public final int compareWithoutRow(final Cell left, final Cell right) {
720724
int rFamLength = right.getFamilyLength();
721725
int lQualLength = left.getQualifierLength();
722726
int rQualLength = right.getQualifierLength();
723-
if (lFamLength + lQualLength == 0 && left.getTypeByte() == KeyValue.Type.Minimum.getCode()) {
727+
byte leftType = PrivateCellUtil.getTypeByte(left);
728+
byte rightType = PrivateCellUtil.getTypeByte(right);
729+
if (lFamLength + lQualLength == 0 && leftType == KeyValue.Type.Minimum.getCode()) {
724730
// left is "bigger", i.e. it appears later in the sorted order
725731
return 1;
726732
}
727-
if (rFamLength + rQualLength == 0 && right.getTypeByte() == KeyValue.Type.Minimum.getCode()) {
733+
if (rFamLength + rQualLength == 0 && rightType == KeyValue.Type.Minimum.getCode()) {
728734
return -1;
729735
}
730736
if (lFamLength != rFamLength) {
@@ -746,7 +752,7 @@ public final int compareWithoutRow(final Cell left, final Cell right) {
746752
// of higher numbers sort before those of lesser numbers. Maximum (255)
747753
// appears ahead of everything, and minimum (0) appears after
748754
// everything.
749-
return (0xff & right.getTypeByte()) - (0xff & left.getTypeByte());
755+
return (0xff & rightType) - (0xff & leftType);
750756
}
751757

752758
@Override

hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -570,15 +570,13 @@ public static boolean matchingTags(final Cell left, final Cell right) {
570570
* Return true if a delete type, a {@link KeyValue.Type#Delete} or a {KeyValue.Type#DeleteFamily}
571571
* or a {@link KeyValue.Type#DeleteColumn} KeyValue type.
572572
*/
573-
@SuppressWarnings("deprecation")
574573
public static boolean isDelete(final Cell cell) {
575-
return PrivateCellUtil.isDelete(cell.getTypeByte());
574+
return PrivateCellUtil.isDelete(PrivateCellUtil.getTypeByte(cell));
576575
}
577576

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

584582
/**
@@ -629,13 +627,21 @@ public static String getCellKeyAsString(Cell cell, Function<Cell, String> rowCon
629627
sb.append('/');
630628
sb.append(KeyValue.humanReadableTimestamp(cell.getTimestamp()));
631629
sb.append('/');
632-
sb.append(KeyValue.Type.codeToType(cell.getTypeByte()));
630+
if (cell instanceof ExtendedCell) {
631+
sb.append(KeyValue.Type.codeToType(((ExtendedCell) cell).getTypeByte()));
632+
} else {
633+
sb.append(cell.getType());
634+
}
635+
633636
if (!(cell instanceof KeyValue.KeyOnlyKeyValue)) {
634637
sb.append("/vlen=");
635638
sb.append(cell.getValueLength());
636639
}
637-
sb.append("/seqid=");
638-
sb.append(cell.getSequenceId());
640+
if (cell instanceof ExtendedCell) {
641+
sb.append("/seqid=");
642+
sb.append(((ExtendedCell) cell).getSequenceId());
643+
}
644+
639645
return sb.toString();
640646
}
641647

@@ -651,8 +657,12 @@ public static String toString(Cell cell, boolean verbose) {
651657
String value = null;
652658
if (verbose) {
653659
// TODO: pretty print tags as well
654-
if (cell.getTagsLength() > 0) {
655-
tag = Bytes.toStringBinary(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength());
660+
if (cell instanceof RawCell) {
661+
RawCell rawCell = (RawCell) cell;
662+
if (rawCell.getTagsLength() > 0) {
663+
tag = Bytes.toStringBinary(rawCell.getTagsArray(), rawCell.getTagsOffset(),
664+
rawCell.getTagsLength());
665+
}
656666
}
657667
if (!(cell instanceof KeyValue.KeyOnlyKeyValue)) {
658668
value =
@@ -675,7 +685,8 @@ public static String toString(Cell cell, boolean verbose) {
675685

676686
public static boolean equals(Cell a, Cell b) {
677687
return matchingRows(a, b) && matchingFamily(a, b) && matchingQualifier(a, b)
678-
&& matchingTimestamp(a, b) && a.getTypeByte() == b.getTypeByte();
688+
&& matchingTimestamp(a, b)
689+
&& PrivateCellUtil.getTypeByte(a) == PrivateCellUtil.getTypeByte(b);
679690
}
680691

681692
public static boolean matchingTimestamp(Cell a, Cell b) {

0 commit comments

Comments
 (0)