Skip to content

Commit ed3ee97

Browse files
author
Daniel Roudnitsky
committed
HBASE-29672 Handle comparison failures during filtering gracefully
1 parent bab3df9 commit ed3ee97

File tree

9 files changed

+270
-24
lines changed

9 files changed

+270
-24
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.hadoop.hbase.Cell;
2424
import org.apache.hadoop.hbase.CellUtil;
2525
import org.apache.hadoop.hbase.CompareOperator;
26+
import org.apache.hadoop.hbase.DoNotRetryIOException;
2627
import org.apache.hadoop.hbase.PrivateCellUtil;
2728
import org.apache.hadoop.hbase.exceptions.DeserializationException;
2829
import org.apache.hadoop.hbase.util.Bytes;
@@ -121,12 +122,16 @@ public ReturnCode filterCell(Cell c) throws IOException {
121122
* @return true means cell should be filtered out, included otherwise.
122123
*/
123124
private boolean compareValue(final CompareOperator op, final ByteArrayComparable comparator,
124-
final Cell cell) {
125+
final Cell cell) throws DoNotRetryIOException {
125126
if (op == CompareOperator.NO_OP) {
126127
return true;
127128
}
128-
int compareResult = PrivateCellUtil.compareValue(cell, comparator);
129-
return CompareFilter.compare(op, compareResult);
129+
try {
130+
int compareResult = PrivateCellUtil.compareValue(cell, comparator);
131+
return CompareFilter.compare(op, compareResult);
132+
} catch (RuntimeException e) {
133+
throw CompareFilter.wrapInDoNotRetryIOException(e, comparator);
134+
}
130135
}
131136

132137
/**

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

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Objects;
2323
import org.apache.hadoop.hbase.Cell;
2424
import org.apache.hadoop.hbase.CompareOperator;
25+
import org.apache.hadoop.hbase.DoNotRetryIOException;
2526
import org.apache.hadoop.hbase.PrivateCellUtil;
2627
import org.apache.hadoop.hbase.util.Bytes;
2728
import org.apache.yetus.audience.InterfaceAudience;
@@ -80,41 +81,71 @@ public boolean filterRowKey(Cell cell) throws IOException {
8081
return false;
8182
}
8283

84+
/**
85+
* RuntimeException when applying a comparator indicates a code bug or misconfigured
86+
* filter/comparator which is not expected to succeed if a client retries the same request, so we
87+
* wrap it in `DoNotRetryIOException` to prevent client retries and give the client a clean
88+
* exception message/trace
89+
*/
90+
public static DoNotRetryIOException wrapInDoNotRetryIOException(RuntimeException e,
91+
ByteArrayComparable comparator) {
92+
String msg =
93+
String.format("Runtime exception occurred when applying comparator %s during filtering",
94+
comparator.getClass().getSimpleName());
95+
return new DoNotRetryIOException(msg, e);
96+
}
97+
8398
protected boolean compareRow(final CompareOperator op, final ByteArrayComparable comparator,
84-
final Cell cell) {
99+
final Cell cell) throws DoNotRetryIOException {
85100
if (op == CompareOperator.NO_OP) {
86101
return true;
87102
}
88-
int compareResult = PrivateCellUtil.compareRow(cell, comparator);
89-
return compare(op, compareResult);
103+
try {
104+
int compareResult = PrivateCellUtil.compareRow(cell, comparator);
105+
return compare(op, compareResult);
106+
} catch (RuntimeException e) {
107+
throw wrapInDoNotRetryIOException(e, comparator);
108+
}
90109
}
91110

92111
protected boolean compareFamily(final CompareOperator op, final ByteArrayComparable comparator,
93-
final Cell cell) {
112+
final Cell cell) throws DoNotRetryIOException {
94113
if (op == CompareOperator.NO_OP) {
95114
return true;
96115
}
97-
int compareResult = PrivateCellUtil.compareFamily(cell, comparator);
98-
return compare(op, compareResult);
116+
try {
117+
int compareResult = PrivateCellUtil.compareFamily(cell, comparator);
118+
return compare(op, compareResult);
119+
} catch (RuntimeException e) {
120+
throw wrapInDoNotRetryIOException(e, comparator);
121+
}
99122
}
100123

101124
protected boolean compareQualifier(final CompareOperator op, final ByteArrayComparable comparator,
102-
final Cell cell) {
125+
final Cell cell) throws DoNotRetryIOException {
103126
// We do not call through to the non-deprecated method for perf reasons.
104127
if (op == CompareOperator.NO_OP) {
105128
return true;
106129
}
107-
int compareResult = PrivateCellUtil.compareQualifier(cell, comparator);
108-
return compare(op, compareResult);
130+
try {
131+
int compareResult = PrivateCellUtil.compareQualifier(cell, comparator);
132+
return compare(op, compareResult);
133+
} catch (RuntimeException e) {
134+
throw wrapInDoNotRetryIOException(e, comparator);
135+
}
109136
}
110137

111138
protected boolean compareValue(final CompareOperator op, final ByteArrayComparable comparator,
112-
final Cell cell) {
139+
final Cell cell) throws DoNotRetryIOException {
113140
if (op == CompareOperator.NO_OP) {
114141
return true;
115142
}
116-
int compareResult = PrivateCellUtil.compareValue(cell, comparator);
117-
return compare(op, compareResult);
143+
try {
144+
int compareResult = PrivateCellUtil.compareValue(cell, comparator);
145+
return compare(op, compareResult);
146+
} catch (RuntimeException e) {
147+
throw wrapInDoNotRetryIOException(e, comparator);
148+
}
118149
}
119150

120151
static boolean compare(final CompareOperator op, int compareResult) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.hadoop.hbase.Cell;
2727
import org.apache.hadoop.hbase.CellUtil;
2828
import org.apache.hadoop.hbase.CompareOperator;
29+
import org.apache.hadoop.hbase.DoNotRetryIOException;
2930
import org.apache.hadoop.hbase.exceptions.DeserializationException;
3031
import org.apache.hadoop.hbase.util.Bytes;
3132
import org.apache.yetus.audience.InterfaceAudience;
@@ -117,7 +118,7 @@ public boolean filterAllRemaining() {
117118
}
118119

119120
@Override
120-
public ReturnCode filterCell(final Cell c) {
121+
public ReturnCode filterCell(final Cell c) throws DoNotRetryIOException {
121122
// Check if the column and qualifier match
122123
if (!CellUtil.matchingColumn(c, this.columnFamily, this.columnQualifier)) {
123124
// include non-matches for the time being, they'll be discarded afterwards

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import org.apache.hadoop.hbase.Cell;
2323
import org.apache.hadoop.hbase.CompareOperator;
24+
import org.apache.hadoop.hbase.DoNotRetryIOException;
2425
import org.apache.hadoop.hbase.exceptions.DeserializationException;
2526
import org.apache.yetus.audience.InterfaceAudience;
2627

@@ -56,7 +57,7 @@ public FamilyFilter(final CompareOperator op, final ByteArrayComparable familyCo
5657
}
5758

5859
@Override
59-
public ReturnCode filterCell(final Cell c) {
60+
public ReturnCode filterCell(final Cell c) throws DoNotRetryIOException {
6061
int familyLength = c.getFamilyLength();
6162
if (familyLength > 0) {
6263
if (compareFamily(getCompareOperator(), this.comparator, c)) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import org.apache.hadoop.hbase.Cell;
2323
import org.apache.hadoop.hbase.CompareOperator;
24+
import org.apache.hadoop.hbase.DoNotRetryIOException;
2425
import org.apache.hadoop.hbase.exceptions.DeserializationException;
2526
import org.apache.yetus.audience.InterfaceAudience;
2627

@@ -53,7 +54,7 @@ public QualifierFilter(final CompareOperator op, final ByteArrayComparable quali
5354
}
5455

5556
@Override
56-
public ReturnCode filterCell(final Cell c) {
57+
public ReturnCode filterCell(final Cell c) throws DoNotRetryIOException {
5758
if (compareQualifier(getCompareOperator(), this.comparator, c)) {
5859
return ReturnCode.SKIP;
5960
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import org.apache.hadoop.hbase.Cell;
2323
import org.apache.hadoop.hbase.CompareOperator;
24+
import org.apache.hadoop.hbase.DoNotRetryIOException;
2425
import org.apache.hadoop.hbase.exceptions.DeserializationException;
2526
import org.apache.yetus.audience.InterfaceAudience;
2627

@@ -67,7 +68,7 @@ public ReturnCode filterCell(final Cell v) {
6768
}
6869

6970
@Override
70-
public boolean filterRowKey(Cell firstRowCell) {
71+
public boolean filterRowKey(Cell firstRowCell) throws DoNotRetryIOException {
7172
if (compareRow(getCompareOperator(), this.comparator, firstRowCell)) {
7273
this.filterOutRow = true;
7374
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.hadoop.hbase.Cell;
2424
import org.apache.hadoop.hbase.CellUtil;
2525
import org.apache.hadoop.hbase.CompareOperator;
26+
import org.apache.hadoop.hbase.DoNotRetryIOException;
2627
import org.apache.hadoop.hbase.PrivateCellUtil;
2728
import org.apache.hadoop.hbase.exceptions.DeserializationException;
2829
import org.apache.hadoop.hbase.util.Bytes;
@@ -147,7 +148,7 @@ public boolean filterRowKey(Cell cell) throws IOException {
147148
}
148149

149150
@Override
150-
public ReturnCode filterCell(final Cell c) {
151+
public ReturnCode filterCell(final Cell c) throws DoNotRetryIOException {
151152
// System.out.println("REMOVE KEY=" + keyValue.toString() + ", value=" +
152153
// Bytes.toString(keyValue.getValue()));
153154
if (this.matchedColumn) {
@@ -168,9 +169,13 @@ public ReturnCode filterCell(final Cell c) {
168169
return ReturnCode.INCLUDE;
169170
}
170171

171-
private boolean filterColumnValue(final Cell cell) {
172-
int compareResult = PrivateCellUtil.compareValue(cell, this.comparator);
173-
return CompareFilter.compare(this.op, compareResult);
172+
private boolean filterColumnValue(final Cell cell) throws DoNotRetryIOException {
173+
try {
174+
int compareResult = PrivateCellUtil.compareValue(cell, this.comparator);
175+
return CompareFilter.compare(this.op, compareResult);
176+
} catch (RuntimeException e) {
177+
throw CompareFilter.wrapInDoNotRetryIOException(e, this.comparator);
178+
}
174179
}
175180

176181
@Override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import org.apache.hadoop.hbase.Cell;
2323
import org.apache.hadoop.hbase.CompareOperator;
24+
import org.apache.hadoop.hbase.DoNotRetryIOException;
2425
import org.apache.hadoop.hbase.exceptions.DeserializationException;
2526
import org.apache.yetus.audience.InterfaceAudience;
2627

@@ -54,7 +55,7 @@ public ValueFilter(final CompareOperator valueCompareOp,
5455
}
5556

5657
@Override
57-
public ReturnCode filterCell(final Cell c) {
58+
public ReturnCode filterCell(final Cell c) throws DoNotRetryIOException {
5859
if (compareValue(getCompareOperator(), this.comparator, c)) {
5960
return ReturnCode.SKIP;
6061
}

0 commit comments

Comments
 (0)