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-28644 Use ExtendedCell instead of Cell in KeyValueScanner #5985

Merged
merged 1 commit into from
Jun 21, 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 @@ -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 @@ -129,15 +129,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 @@ -213,6 +216,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 @@ -150,7 +152,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 @@ -273,6 +275,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
10 changes: 6 additions & 4 deletions hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public static Cell createCell(final byte[] row, final byte[] family, final byte[
*/
@Deprecated
public static Cell createCell(Cell cell, List<Tag> tags) {
return PrivateCellUtil.createCell(cell, tags);
return PrivateCellUtil.createCell((ExtendedCell) cell, tags);
}

/**
Expand All @@ -571,7 +571,7 @@ public static Cell createCell(Cell cell, List<Tag> tags) {
*/
@Deprecated
public static Cell createCell(Cell cell, byte[] tags) {
return PrivateCellUtil.createCell(cell, tags);
return PrivateCellUtil.createCell((ExtendedCell) cell, tags);
}

/**
Expand All @@ -581,7 +581,7 @@ public static Cell createCell(Cell cell, byte[] tags) {
*/
@Deprecated
public static Cell createCell(Cell cell, byte[] value, byte[] tags) {
return PrivateCellUtil.createCell(cell, value, tags);
return PrivateCellUtil.createCell((ExtendedCell) cell, value, tags);
}

/** Returns CellScanner interface over <code>cellIterables</code> */
Expand Down Expand Up @@ -1690,6 +1690,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