Skip to content
Open
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 @@ -121,12 +121,16 @@ public ReturnCode filterCell(Cell c) throws IOException {
* @return true means cell should be filtered out, included otherwise.
*/
private boolean compareValue(final CompareOperator op, final ByteArrayComparable comparator,
final Cell cell) {
final Cell cell) throws IOException {
if (op == CompareOperator.NO_OP) {
return true;
}
int compareResult = PrivateCellUtil.compareValue(cell, comparator);
return CompareFilter.compare(op, compareResult);
try {
int compareResult = PrivateCellUtil.compareValue(cell, comparator);
return CompareFilter.compare(op, compareResult);
} catch (RuntimeException e) {
throw CompareFilter.wrapInHBaseIOException(e, comparator);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Objects;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.HBaseIOException;
import org.apache.hadoop.hbase.PrivateCellUtil;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.yetus.audience.InterfaceAudience;
Expand Down Expand Up @@ -123,6 +124,21 @@ public boolean filterRowKey(Cell cell) throws IOException {
return false;
}

/**
* RuntimeException when applying a comparator indicates a code bug or misconfigured
* filter/comparator, we wrap it in `HBaseIOException` to provide a clear exception message/stack
* trace and prevent propagating a runtime exception up the call stack (which would lead to
* unexpected throwable at RpcServer layer and a complicated unclear remote exception on the
* client)
*/
public static HBaseIOException wrapInHBaseIOException(RuntimeException e,
ByteArrayComparable comparator) {
String msg =
String.format("Runtime exception occurred when applying comparator %s during filtering",
comparator.getClass().getSimpleName());
return new HBaseIOException(msg, e);
}

/**
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use
* {@link #compareRow(CompareOperator, ByteArrayComparable, Cell)}
Expand All @@ -138,12 +154,16 @@ protected boolean compareRow(final CompareOp compareOp, final ByteArrayComparabl
}

protected boolean compareRow(final CompareOperator op, final ByteArrayComparable comparator,
final Cell cell) {
final Cell cell) throws IOException {
if (op == CompareOperator.NO_OP) {
return true;
}
int compareResult = PrivateCellUtil.compareRow(cell, comparator);
return compare(op, compareResult);
try {
int compareResult = PrivateCellUtil.compareRow(cell, comparator);
return compare(op, compareResult);
} catch (RuntimeException e) {
throw wrapInHBaseIOException(e, comparator);
}
}

/**
Expand All @@ -161,12 +181,16 @@ protected boolean compareFamily(final CompareOp compareOp, final ByteArrayCompar
}

protected boolean compareFamily(final CompareOperator op, final ByteArrayComparable comparator,
final Cell cell) {
final Cell cell) throws IOException {
if (op == CompareOperator.NO_OP) {
return true;
}
int compareResult = PrivateCellUtil.compareFamily(cell, comparator);
return compare(op, compareResult);
try {
int compareResult = PrivateCellUtil.compareFamily(cell, comparator);
return compare(op, compareResult);
} catch (RuntimeException e) {
throw wrapInHBaseIOException(e, comparator);
}
}

/**
Expand All @@ -185,13 +209,17 @@ protected boolean compareQualifier(final CompareOp compareOp,
}

protected boolean compareQualifier(final CompareOperator op, final ByteArrayComparable comparator,
final Cell cell) {
final Cell cell) throws IOException {
// We do not call through to the non-deprecated method for perf reasons.
if (op == CompareOperator.NO_OP) {
return true;
}
int compareResult = PrivateCellUtil.compareQualifier(cell, comparator);
return compare(op, compareResult);
try {
int compareResult = PrivateCellUtil.compareQualifier(cell, comparator);
return compare(op, compareResult);
} catch (RuntimeException e) {
throw wrapInHBaseIOException(e, comparator);
}
}

/**
Expand All @@ -210,12 +238,16 @@ protected boolean compareValue(final CompareOp compareOp, final ByteArrayCompara
}

protected boolean compareValue(final CompareOperator op, final ByteArrayComparable comparator,
final Cell cell) {
final Cell cell) throws IOException {
if (op == CompareOperator.NO_OP) {
return true;
}
int compareResult = PrivateCellUtil.compareValue(cell, comparator);
return compare(op, compareResult);
try {
int compareResult = PrivateCellUtil.compareValue(cell, comparator);
return compare(op, compareResult);
} catch (RuntimeException e) {
throw wrapInHBaseIOException(e, comparator);
}
}

static boolean compare(final CompareOp op, int compareResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ public boolean filterAllRemaining() {

@Deprecated
@Override
public ReturnCode filterKeyValue(final Cell c) {
public ReturnCode filterKeyValue(final Cell c) throws IOException {
return filterCell(c);
}

@Override
public ReturnCode filterCell(final Cell c) {
public ReturnCode filterCell(final Cell c) throws IOException {
// Check if the column and qualifier match
if (!CellUtil.matchingColumn(c, this.columnFamily, this.columnQualifier)) {
// include non-matches for the time being, they'll be discarded afterwards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public FamilyFilter(final CompareOperator op, final ByteArrayComparable familyCo

@Deprecated
@Override
public ReturnCode filterKeyValue(final Cell c) {
public ReturnCode filterKeyValue(final Cell c) throws IOException {
return filterCell(c);
}

@Override
public ReturnCode filterCell(final Cell c) {
public ReturnCode filterCell(final Cell c) throws IOException {
int familyLength = c.getFamilyLength();
if (familyLength > 0) {
if (compareFamily(getCompareOperator(), this.comparator, c)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public QualifierFilter(final CompareOperator op, final ByteArrayComparable quali

@Deprecated
@Override
public ReturnCode filterKeyValue(final Cell c) {
public ReturnCode filterKeyValue(final Cell c) throws IOException {
return filterCell(c);
}

@Override
public ReturnCode filterCell(final Cell c) {
public ReturnCode filterCell(final Cell c) throws IOException {
if (compareQualifier(getCompareOperator(), this.comparator, c)) {
return ReturnCode.SKIP;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ReturnCode filterCell(final Cell v) {
}

@Override
public boolean filterRowKey(Cell firstRowCell) {
public boolean filterRowKey(Cell firstRowCell) throws IOException {
if (compareRow(getCompareOperator(), this.comparator, firstRowCell)) {
this.filterOutRow = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ public boolean filterRowKey(Cell cell) throws IOException {

@Deprecated
@Override
public ReturnCode filterKeyValue(final Cell c) {
public ReturnCode filterKeyValue(final Cell c) throws IOException {
return filterCell(c);
}

@Override
public ReturnCode filterCell(final Cell c) {
public ReturnCode filterCell(final Cell c) throws IOException {
// System.out.println("REMOVE KEY=" + keyValue.toString() + ", value=" +
// Bytes.toString(keyValue.getValue()));
if (this.matchedColumn) {
Expand All @@ -240,9 +240,13 @@ public ReturnCode filterCell(final Cell c) {
return ReturnCode.INCLUDE;
}

private boolean filterColumnValue(final Cell cell) {
int compareResult = PrivateCellUtil.compareValue(cell, this.comparator);
return CompareFilter.compare(this.op, compareResult);
private boolean filterColumnValue(final Cell cell) throws IOException {
try {
int compareResult = PrivateCellUtil.compareValue(cell, this.comparator);
return CompareFilter.compare(this.op, compareResult);
} catch (RuntimeException e) {
throw CompareFilter.wrapInHBaseIOException(e, this.comparator);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public ValueFilter(final CompareOperator valueCompareOp,

@Deprecated
@Override
public ReturnCode filterKeyValue(final Cell c) {
public ReturnCode filterKeyValue(final Cell c) throws IOException {
return filterCell(c);
}

@Override
public ReturnCode filterCell(final Cell c) {
public ReturnCode filterCell(final Cell c) throws IOException {
if (compareValue(getCompareOperator(), this.comparator, c)) {
return ReturnCode.SKIP;
}
Expand Down
Loading