Skip to content

Commit

Permalink
HBASE-28644 Use ExtendedCell instead of Cell in KeyValueScanner (#5976)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Purtell <[email protected]>
(cherry picked from commit 85a8b54)
  • Loading branch information
Apache9 committed Jun 21, 2024
1 parent 7b39d3d commit 11f346c
Show file tree
Hide file tree
Showing 161 changed files with 1,350 additions and 1,158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ private Result(boolean readonly) {
* <strong>Note:</strong> You must ensure that the keyvalues are already sorted.
* @param cells List of cells
*/
public static Result create(List<Cell> cells) {
public static Result create(List<? extends Cell> cells) {
return create(cells, null);
}

public static Result create(List<Cell> cells, Boolean exists) {
public static Result create(List<? extends Cell> cells, Boolean exists) {
return create(cells, exists, false);
}

public static Result create(List<Cell> cells, Boolean exists, boolean stale) {
public static Result create(List<? extends Cell> cells, Boolean exists, boolean stale) {
return create(cells, exists, stale, false);
}

public static Result create(List<Cell> cells, Boolean exists, boolean stale,
public static Result create(List<? extends Cell> cells, Boolean exists, boolean stale,
boolean mayHaveMoreCellsInRow) {
if (exists != null) {
return new Result(null, exists, stale, mayHaveMoreCellsInRow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@ public ReturnCode filterCell(final Cell c) throws IOException {
}

/**
* Give the filter a chance to transform the passed KeyValue. If the Cell is changed a new Cell
* object must be returned.
* Give the filter a chance to transform the passed Cell. If the Cell is changed a new Cell object
* must be returned.
* <p/>
* <strong>NOTICE:</strong> Filter will be evaluate at server side so the returned {@link Cell}
* must be an {@link org.apache.hadoop.hbase.ExtendedCell}, although it is marked as IA.Private.
* @see org.apache.hadoop.hbase.KeyValue#shallowCopy() The transformed KeyValue is what is
* eventually returned to the client. Most filters will return the passed KeyValue unchanged.
* @see org.apache.hadoop.hbase.filter.KeyOnlyFilter#transformCell(Cell) for an example of a
* transformation. Concrete implementers can signal a failure condition in their code by
* throwing an {@link IOException}.
* @param v the KeyValue in question
* @return the changed KeyValue
* @param v the Cell in question
* @return the changed Cell
* @throws IOException in case an I/O or an filter specific failure needs to be signaled.
*/
abstract public Cell transformCell(final Cell v) throws IOException;
Expand Down Expand Up @@ -177,6 +180,8 @@ public enum ReturnCode {
* the next key it must seek to. After receiving the match code SEEK_NEXT_USING_HINT, the
* QueryMatcher would call this function to find out which key it must next seek to. Concrete
* implementers can signal a failure condition in their code by throwing an {@link IOException}.
* <strong>NOTICE:</strong> Filter will be evaluate at server side so the returned {@link Cell}
* must be an {@link org.apache.hadoop.hbase.ExtendedCell}, although it is marked as IA.Private.
* @return KeyValue which must be next seeked. return null if the filter is not sure which key to
* seek to next.
* @throws IOException in case an I/O or an filter specific failure needs to be signaled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import java.util.Optional;
import org.apache.hadoop.hbase.ByteBufferExtendedCell;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.ExtendedCell;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.PrivateCellUtil;
import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.util.Bytes;
Expand Down Expand Up @@ -144,7 +146,7 @@ public int hashCode() {
return Objects.hash(this.lenAsVal);
}

static class KeyOnlyCell implements Cell {
static class KeyOnlyCell implements ExtendedCell {
private Cell cell;
private int keyLen;
private boolean lenAsVal;
Expand Down Expand Up @@ -267,6 +269,21 @@ public int getTagsLength() {
public long heapSize() {
return cell.heapSize();
}

@Override
public void setSequenceId(long seqId) throws IOException {
PrivateCellUtil.setSequenceId(cell, seqId);
}

@Override
public void setTimestamp(long ts) throws IOException {
PrivateCellUtil.setTimestamp(cell, ts);
}

@Override
public void setTimestamp(byte[] ts) throws IOException {
PrivateCellUtil.setTimestamp(cell, ts);
}
}

static class KeyOnlyByteBufferExtendedCell extends ByteBufferExtendedCell {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,8 @@ public static void cloneIfNecessary(ArrayList<Cell> cells) {
}

public static Cell cloneIfNecessary(Cell cell) {
return (cell instanceof ByteBufferExtendedCell ? KeyValueUtil.copyToNewKeyValue(cell) : cell);
return (cell instanceof ByteBufferExtendedCell
? KeyValueUtil.copyToNewKeyValue((ExtendedCell) cell)
: cell);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static KeyValue copyToNewKeyValue(final Cell cell) {
* The position will be set to the beginning of the new ByteBuffer
* @return the Bytebuffer containing the key part of the cell
*/
public static ByteBuffer copyKeyToNewByteBuffer(final Cell cell) {
public static ByteBuffer copyKeyToNewByteBuffer(final ExtendedCell cell) {
byte[] bytes = new byte[keyLength(cell)];
appendKeyTo(cell, bytes, 0);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
Expand All @@ -110,7 +110,7 @@ public static ByteBuffer copyKeyToNewByteBuffer(final Cell cell) {
* Copies the key to a new KeyValue
* @return the KeyValue that consists only the key part of the incoming cell
*/
public static KeyValue toNewKeyCell(final Cell cell) {
public static KeyValue toNewKeyCell(final ExtendedCell cell) {
byte[] bytes = new byte[keyLength(cell)];
appendKeyTo(cell, bytes, 0);
KeyValue kv = new KeyValue.KeyOnlyKeyValue(bytes, 0, bytes.length);
Expand Down Expand Up @@ -163,7 +163,7 @@ public static int appendToByteArray(Cell cell, byte[] output, int offset, boolea
/**
* Copy the Cell content into the passed buf in KeyValue serialization format.
*/
public static int appendTo(Cell cell, ByteBuffer buf, int offset, boolean withTags) {
public static int appendTo(ExtendedCell cell, ByteBuffer buf, int offset, boolean withTags) {
offset = ByteBufferUtils.putInt(buf, offset, keyLength(cell));// Key length
offset = ByteBufferUtils.putInt(buf, offset, cell.getValueLength());// Value length
offset = appendKeyTo(cell, buf, offset);
Expand All @@ -176,7 +176,7 @@ public static int appendTo(Cell cell, ByteBuffer buf, int offset, boolean withTa
return offset;
}

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

@Deprecated
public static List<KeyValue> ensureKeyValues(List<Cell> cells) {
List<KeyValue> lazyList = Lists.transform(cells, new Function<Cell, KeyValue>() {
public static List<KeyValue> ensureKeyValues(List<ExtendedCell> cells) {
List<KeyValue> lazyList = Lists.transform(cells, new Function<ExtendedCell, KeyValue>() {
@Override
public KeyValue apply(Cell arg0) {
public KeyValue apply(ExtendedCell arg0) {
return KeyValueUtil.ensureKeyValue(arg0);
}
});
Expand Down
Loading

0 comments on commit 11f346c

Please sign in to comment.