Skip to content

Commit 664bca2

Browse files
committed
HBASE-28644 Use ExtendedCell instead of Cell in KeyValueScanner
1 parent 317ad3c commit 664bca2

161 files changed

Lines changed: 1350 additions & 1158 deletions

File tree

Some content is hidden

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

hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,19 @@ private Result(boolean readonly) {
125125
* <strong>Note:</strong> You must ensure that the keyvalues are already sorted.
126126
* @param cells List of cells
127127
*/
128-
public static Result create(List<Cell> cells) {
128+
public static Result create(List<? extends Cell> cells) {
129129
return create(cells, null);
130130
}
131131

132-
public static Result create(List<Cell> cells, Boolean exists) {
132+
public static Result create(List<? extends Cell> cells, Boolean exists) {
133133
return create(cells, exists, false);
134134
}
135135

136-
public static Result create(List<Cell> cells, Boolean exists, boolean stale) {
136+
public static Result create(List<? extends Cell> cells, Boolean exists, boolean stale) {
137137
return create(cells, exists, stale, false);
138138
}
139139

140-
public static Result create(List<Cell> cells, Boolean exists, boolean stale,
140+
public static Result create(List<? extends Cell> cells, Boolean exists, boolean stale,
141141
boolean mayHaveMoreCellsInRow) {
142142
if (exists != null) {
143143
return new Result(null, exists, stale, mayHaveMoreCellsInRow);

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,18 @@ public ReturnCode filterCell(final Cell c) throws IOException {
9393
}
9494

9595
/**
96-
* Give the filter a chance to transform the passed KeyValue. If the Cell is changed a new Cell
97-
* object must be returned.
96+
* Give the filter a chance to transform the passed Cell. If the Cell is changed a new Cell object
97+
* must be returned.
98+
* <p/>
99+
* <strong>NOTICE:</strong> Filter will be evaluate at server side so the returned {@link Cell}
100+
* must be an {@link org.apache.hadoop.hbase.ExtendedCell}, although it is marked as IA.Private.
98101
* @see org.apache.hadoop.hbase.KeyValue#shallowCopy() The transformed KeyValue is what is
99102
* eventually returned to the client. Most filters will return the passed KeyValue unchanged.
100103
* @see org.apache.hadoop.hbase.filter.KeyOnlyFilter#transformCell(Cell) for an example of a
101104
* transformation. Concrete implementers can signal a failure condition in their code by
102105
* throwing an {@link IOException}.
103-
* @param v the KeyValue in question
104-
* @return the changed KeyValue
106+
* @param v the Cell in question
107+
* @return the changed Cell
105108
* @throws IOException in case an I/O or an filter specific failure needs to be signaled.
106109
*/
107110
abstract public Cell transformCell(final Cell v) throws IOException;
@@ -177,6 +180,8 @@ public enum ReturnCode {
177180
* the next key it must seek to. After receiving the match code SEEK_NEXT_USING_HINT, the
178181
* QueryMatcher would call this function to find out which key it must next seek to. Concrete
179182
* implementers can signal a failure condition in their code by throwing an {@link IOException}.
183+
* <strong>NOTICE:</strong> Filter will be evaluate at server side so the returned {@link Cell}
184+
* must be an {@link org.apache.hadoop.hbase.ExtendedCell}, although it is marked as IA.Private.
180185
* @return KeyValue which must be next seeked. return null if the filter is not sure which key to
181186
* seek to next.
182187
* @throws IOException in case an I/O or an filter specific failure needs to be signaled.

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
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.ExtendedCell;
2930
import org.apache.hadoop.hbase.HConstants;
3031
import org.apache.hadoop.hbase.KeyValue;
3132
import org.apache.hadoop.hbase.KeyValueUtil;
33+
import org.apache.hadoop.hbase.PrivateCellUtil;
3234
import org.apache.hadoop.hbase.Tag;
3335
import org.apache.hadoop.hbase.exceptions.DeserializationException;
3436
import org.apache.hadoop.hbase.util.Bytes;
@@ -144,7 +146,7 @@ public int hashCode() {
144146
return Objects.hash(this.lenAsVal);
145147
}
146148

147-
static class KeyOnlyCell implements Cell {
149+
static class KeyOnlyCell implements ExtendedCell {
148150
private Cell cell;
149151
private int keyLen;
150152
private boolean lenAsVal;
@@ -267,6 +269,21 @@ public int getTagsLength() {
267269
public long heapSize() {
268270
return cell.heapSize();
269271
}
272+
273+
@Override
274+
public void setSequenceId(long seqId) throws IOException {
275+
PrivateCellUtil.setSequenceId(cell, seqId);
276+
}
277+
278+
@Override
279+
public void setTimestamp(long ts) throws IOException {
280+
PrivateCellUtil.setTimestamp(cell, ts);
281+
}
282+
283+
@Override
284+
public void setTimestamp(byte[] ts) throws IOException {
285+
PrivateCellUtil.setTimestamp(cell, ts);
286+
}
270287
}
271288

272289
static class KeyOnlyByteBufferExtendedCell extends ByteBufferExtendedCell {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,8 @@ public static void cloneIfNecessary(ArrayList<Cell> cells) {
827827
}
828828

829829
public static Cell cloneIfNecessary(Cell cell) {
830-
return (cell instanceof ByteBufferExtendedCell ? KeyValueUtil.copyToNewKeyValue(cell) : cell);
830+
return (cell instanceof ByteBufferExtendedCell
831+
? KeyValueUtil.copyToNewKeyValue((ExtendedCell) cell)
832+
: cell);
831833
}
832834
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static KeyValue copyToNewKeyValue(final Cell cell) {
9999
* The position will be set to the beginning of the new ByteBuffer
100100
* @return the Bytebuffer containing the key part of the cell
101101
*/
102-
public static ByteBuffer copyKeyToNewByteBuffer(final Cell cell) {
102+
public static ByteBuffer copyKeyToNewByteBuffer(final ExtendedCell cell) {
103103
byte[] bytes = new byte[keyLength(cell)];
104104
appendKeyTo(cell, bytes, 0);
105105
ByteBuffer buffer = ByteBuffer.wrap(bytes);
@@ -110,7 +110,7 @@ public static ByteBuffer copyKeyToNewByteBuffer(final Cell cell) {
110110
* Copies the key to a new KeyValue
111111
* @return the KeyValue that consists only the key part of the incoming cell
112112
*/
113-
public static KeyValue toNewKeyCell(final Cell cell) {
113+
public static KeyValue toNewKeyCell(final ExtendedCell cell) {
114114
byte[] bytes = new byte[keyLength(cell)];
115115
appendKeyTo(cell, bytes, 0);
116116
KeyValue kv = new KeyValue.KeyOnlyKeyValue(bytes, 0, bytes.length);
@@ -163,7 +163,7 @@ public static int appendToByteArray(Cell cell, byte[] output, int offset, boolea
163163
/**
164164
* Copy the Cell content into the passed buf in KeyValue serialization format.
165165
*/
166-
public static int appendTo(Cell cell, ByteBuffer buf, int offset, boolean withTags) {
166+
public static int appendTo(ExtendedCell cell, ByteBuffer buf, int offset, boolean withTags) {
167167
offset = ByteBufferUtils.putInt(buf, offset, keyLength(cell));// Key length
168168
offset = ByteBufferUtils.putInt(buf, offset, cell.getValueLength());// Value length
169169
offset = appendKeyTo(cell, buf, offset);
@@ -176,7 +176,7 @@ public static int appendTo(Cell cell, ByteBuffer buf, int offset, boolean withTa
176176
return offset;
177177
}
178178

179-
public static int appendKeyTo(Cell cell, ByteBuffer buf, int offset) {
179+
public static int appendKeyTo(ExtendedCell cell, ByteBuffer buf, int offset) {
180180
offset = ByteBufferUtils.putShort(buf, offset, cell.getRowLength());// RK length
181181
offset = CellUtil.copyRowTo(cell, buf, offset);// Row bytes
182182
offset = ByteBufferUtils.putByte(buf, offset, cell.getFamilyLength());// CF length
@@ -433,10 +433,10 @@ public static KeyValue ensureKeyValue(final Cell cell) {
433433
}
434434

435435
@Deprecated
436-
public static List<KeyValue> ensureKeyValues(List<Cell> cells) {
437-
List<KeyValue> lazyList = Lists.transform(cells, new Function<Cell, KeyValue>() {
436+
public static List<KeyValue> ensureKeyValues(List<ExtendedCell> cells) {
437+
List<KeyValue> lazyList = Lists.transform(cells, new Function<ExtendedCell, KeyValue>() {
438438
@Override
439-
public KeyValue apply(Cell arg0) {
439+
public KeyValue apply(ExtendedCell arg0) {
440440
return KeyValueUtil.ensureKeyValue(arg0);
441441
}
442442
});

0 commit comments

Comments
 (0)