Skip to content

Commit 741f7e1

Browse files
committed
OMID-271 Support HBase 3
build with -Dhbase.version=3.0.0-beta-2-SNAPSHOT -Pzk38
1 parent d2fc035 commit 741f7e1

8 files changed

Lines changed: 285 additions & 39 deletions

File tree

hbase-client/src/main/java/org/apache/omid/transaction/TTable.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.apache.hadoop.hbase.Cell;
3232
import org.apache.hadoop.hbase.CellUtil;
3333
import org.apache.hadoop.hbase.HConstants;
34-
import org.apache.hadoop.hbase.HTableDescriptor;
3534
import org.apache.hadoop.hbase.KeyValue;
3635
import org.apache.hadoop.hbase.KeyValueUtil;
3736
import org.apache.hadoop.hbase.TableName;
@@ -527,19 +526,6 @@ public Configuration getConfiguration() {
527526
return table.getConfiguration();
528527
}
529528

530-
/**
531-
* Delegates to {@link Table#getTableDescriptor()}
532-
*
533-
* This deprecated method is implemented for backwards compatibility reasons.
534-
* use {@link TTable#getDescriptor()}
535-
*
536-
* @return HTableDescriptor an instance of HTableDescriptor
537-
* @throws IOException if a remote or network exception occurs.
538-
*/
539-
public HTableDescriptor getTableDescriptor() throws IOException {
540-
return table.getTableDescriptor();
541-
}
542-
543529
/**
544530
* Delegates to {@link Table#getDescriptor()}
545531
*

hbase-coprocessor/src/main/java/org/apache/omid/transaction/CellSkipFilterBase.java renamed to hbase-coprocessor/src/main/java/org/apache/omid/transaction/CellSkipFilter.java

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222
import org.apache.hadoop.hbase.PrivateCellUtil;
2323
import org.apache.hadoop.hbase.filter.Filter;
2424
import org.apache.hadoop.hbase.filter.FilterBase;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
2527

2628
import java.io.IOException;
29+
import java.lang.invoke.MethodHandle;
30+
import java.lang.invoke.MethodHandles;
31+
import java.lang.invoke.MethodType;
32+
import java.lang.reflect.Method;
2733
import java.util.List;
2834

2935
/**
@@ -34,13 +40,31 @@
3440
* Please see TEPHRA-169 for more details.
3541
*/
3642

37-
public class CellSkipFilterBase extends FilterBase {
43+
public class CellSkipFilter extends FilterBase {
44+
45+
private static final Logger LOG = LoggerFactory.getLogger(CellSkipFilter.class);
46+
3847
private final Filter filter;
3948
// remember the previous cell processed by filter when the return code was NEXT_COL or INCLUDE_AND_NEXT_COL
4049
private Cell skipColumn = null;
4150

42-
public CellSkipFilterBase(Filter filter) {
51+
// Using reflection to avoid adding compatibility modules.
52+
private final MethodHandle removedFilterRowKeyMethod;
53+
54+
public CellSkipFilter(Filter filter) {
4355
this.filter = filter;
56+
MethodHandle tmpFilterRowKeyMethod;
57+
try {
58+
tmpFilterRowKeyMethod =
59+
MethodHandles.lookup().findVirtual(filter.getClass(), "filterRowKey",
60+
MethodType.methodType(boolean.class, byte[].class, int.class, int.class));
61+
} catch (Exception e) {
62+
LOG.info(
63+
"Could not get filterRowKey method handle by reflection. This is normal for HBase 3.x",
64+
e);
65+
tmpFilterRowKeyMethod = null;
66+
}
67+
removedFilterRowKeyMethod = tmpFilterRowKeyMethod;
4468
}
4569

4670
/**
@@ -59,9 +83,10 @@ private boolean skipCellVersion(Cell cell) {
5983

6084
/**
6185
* This deprecated method is implemented for backwards compatibility reasons.
62-
* use {@link CellSkipFilterBase#filterKeyValue(Cell)}
86+
* use {@link CellSkipFilter#filterKeyValue(Cell)}
87+
*
88+
* No @Override because HBase 3 completely removes this method
6389
*/
64-
@Override
6590
public ReturnCode filterKeyValue(Cell cell) throws IOException {
6691
return filterCell(cell);
6792
}
@@ -102,11 +127,21 @@ public void reset() throws IOException {
102127

103128
/**
104129
* This deprecated method is implemented for backwards compatibility reasons.
105-
* use {@link CellSkipFilterBase#filterRowKey(Cell)}
130+
* use {@link CellSkipFilter#filterRowKey(Cell)}
131+
*
132+
* No @Override so that this compiles with HBase 3
106133
*/
107-
@Override
108134
public boolean filterRowKey(byte[] buffer, int offset, int length) throws IOException {
109-
return filter.filterRowKey(buffer, offset, length);
135+
// Even though this is deprecated, this is the actual implementation that filterRowKey(Cell)
136+
// calls in FilterBase in HBase 2, so we cannot call filterRowKey(Cell), because that would
137+
// cause infinite recursion
138+
try {
139+
return (boolean) (removedFilterRowKeyMethod.invokeExact(filter, buffer, offset, length));
140+
} catch (IOException e) {
141+
throw e;
142+
} catch (Throwable t) {
143+
throw new UnsupportedOperationException(t);
144+
}
110145
}
111146

112147
@Override

hbase-coprocessor/src/main/java/org/apache/omid/transaction/OmidSnapshotFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void stop(CoprocessorEnvironment e) throws IOException {
100100
}
101101

102102

103-
// Don't add an @Override tag since this method doesn't exist in both hbase-1 and hbase-2
103+
@Override
104104
public void postGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) {
105105
SnapshotFilterImpl snapshotFilter = snapshotFilterMap.get(get);
106106
if (snapshotFilter != null) {
@@ -109,7 +109,7 @@ public void postGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get,
109109
}
110110

111111

112-
// Don't add an @Override tag since this method doesn't exist in both hbase-1 and hbase-2
112+
@Override
113113
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results)
114114
throws IOException {
115115

hbase-coprocessor/src/main/java/org/apache/omid/transaction/TransactionFilters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public class TransactionFilters {
2626
public static Filter getVisibilityFilter(Filter cellFilter,
2727
SnapshotFilterImpl regionAccessWrapper,
2828
HBaseTransaction hbaseTransaction) {
29-
return new CellSkipFilterBase(new TransactionVisibilityFilterBase(cellFilter, regionAccessWrapper, hbaseTransaction));
29+
return new CellSkipFilter(new TransactionVisibilityFilter(cellFilter, regionAccessWrapper, hbaseTransaction));
3030
}
3131
}

hbase-coprocessor/src/main/java/org/apache/omid/transaction/TransactionVisibilityFilterBase.java renamed to hbase-coprocessor/src/main/java/org/apache/omid/transaction/TransactionVisibilityFilter.java

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
package org.apache.omid.transaction;
1919

2020
import org.apache.phoenix.thirdparty.com.google.common.base.Optional;
21-
22-
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
2323
import org.apache.commons.collections4.map.LRUMap;
2424
import org.apache.hadoop.hbase.Cell;
2525
import org.apache.hadoop.hbase.CellUtil;
26+
import org.apache.hadoop.hbase.KeyValue;
27+
import org.apache.hadoop.hbase.KeyValueUtil;
28+
import org.apache.hadoop.hbase.Cell.Type;
2629
import org.apache.hadoop.hbase.client.Get;
2730
import org.apache.hadoop.hbase.client.Result;
2831
import org.apache.hadoop.hbase.filter.Filter;
@@ -31,15 +34,20 @@
3134

3235
import org.apache.hadoop.hbase.util.Bytes;
3336

34-
3537
import java.io.IOException;
38+
import java.lang.invoke.MethodHandle;
39+
import java.lang.invoke.MethodHandles;
40+
import java.lang.invoke.MethodType;
41+
import java.lang.reflect.Method;
3642
import java.util.HashMap;
3743

3844
import java.util.List;
3945
import java.util.Map;
4046

4147

42-
public class TransactionVisibilityFilterBase extends FilterBase {
48+
public class TransactionVisibilityFilter extends FilterBase {
49+
50+
private static final Logger LOG = LoggerFactory.getLogger(TransactionVisibilityFilter.class);
4351

4452
// optional sub-filter to apply to visible cells
4553
private final Filter userFilter;
@@ -51,7 +59,14 @@ public class TransactionVisibilityFilterBase extends FilterBase {
5159
// So no need to keep row name
5260
private final Map<ImmutableBytesWritable, Long> familyDeletionCache;
5361

54-
public TransactionVisibilityFilterBase(Filter cellFilter,
62+
// Using reflection to avoid adding compatibility modules.
63+
private final MethodHandle removedFilterRowKeyMethod;
64+
private final MethodHandle removedSuperFilterRowKeyMethod;
65+
static {
66+
67+
}
68+
69+
public TransactionVisibilityFilter(Filter cellFilter,
5570
SnapshotFilterImpl snapshotFilter,
5671
HBaseTransaction hbaseTransaction) {
5772
this.userFilter = cellFilter;
@@ -60,13 +75,37 @@ public TransactionVisibilityFilterBase(Filter cellFilter,
6075
this.hbaseTransaction = hbaseTransaction;
6176
familyDeletionCache = new HashMap<>();
6277

78+
MethodHandle tmpFilterRowKeyMethod;
79+
try {
80+
tmpFilterRowKeyMethod = MethodHandles.lookup().findVirtual(userFilter.getClass(), "filterRowKey", MethodType.methodType(boolean.class, byte[].class, int.class, int.class));
81+
//tmpFilterRowKeyMethod = FilterBase.class.getMethod("filterRowKey", byte[].class, int.class, int.class);
82+
} catch (Exception e) {
83+
if(userFilter != null) {
84+
LOG.info("Could not get filterRowKey method handle by reflection. This is normal for HBase 3.x", e);
85+
}
86+
tmpFilterRowKeyMethod = null;
87+
}
88+
removedFilterRowKeyMethod = tmpFilterRowKeyMethod;
89+
90+
MethodHandle tmpRemovedSuperFilterRowKeyMethod;
91+
try {
92+
tmpRemovedSuperFilterRowKeyMethod = MethodHandles.lookup().findSpecial(FilterBase.class, "filterRowKey",
93+
MethodType.methodType(boolean.class, byte[].class, int.class, int.class),
94+
TransactionVisibilityFilter.class);
95+
} catch (Exception e) {
96+
LOG.info("Could not get super.filterRowKey method handle by reflection. This is normal for HBase 3.x", e);
97+
tmpRemovedSuperFilterRowKeyMethod = null;
98+
}
99+
removedSuperFilterRowKeyMethod = tmpRemovedSuperFilterRowKeyMethod;
100+
63101
}
64102

65103
/**
66104
* This deprecated method is implemented for backwards compatibility reasons.
67-
* use {@link TransactionVisibilityFilterBase#filterCell(Cell)}
105+
* use {@link TransactionVisibilityFilter#filterCell(Cell)}
106+
*
107+
* No @Override so that it compiles with HBase 3.x
68108
*/
69-
@Override
70109
public ReturnCode filterKeyValue(Cell cell) throws IOException {
71110
return filterCell(cell);
72111
}
@@ -202,16 +241,32 @@ public boolean filterRow() throws IOException {
202241
return super.filterRow();
203242
}
204243

205-
/**
244+
/**
206245
* This deprecated method is implemented for backwards compatibility reasons.
207-
* use {@link TransactionVisibilityFilterBase#filterRowKey(Cell)}
246+
* use {@link TransactionVisibilityFilter#filterRowKey(Cell)}
247+
*
248+
* No @Override so that it compiles with HBase 3.x
208249
*/
209-
@Override
210250
public boolean filterRowKey(byte[] buffer, int offset, int length) throws IOException {
251+
// Even though this is deprecated, this is the actual implementation that filterRowKey(Cell)
252+
// calls in FilterBase in HBase 2, so we cannot call filterRowKey(Cell), because that would
253+
// cause infinite recursion
211254
if (userFilter != null) {
212-
return userFilter.filterRowKey(buffer, offset, length);
255+
try {
256+
return (boolean) (removedFilterRowKeyMethod.invoke(userFilter, buffer, offset, length));
257+
} catch (IOException e) {
258+
throw e;
259+
} catch (Throwable t) {
260+
throw new UnsupportedOperationException(t);
261+
}
262+
}
263+
try {
264+
return (boolean) (removedSuperFilterRowKeyMethod.invokeExact(this, buffer, offset, length));
265+
} catch (IOException e) {
266+
throw e;
267+
} catch (Throwable t) {
268+
throw new UnsupportedOperationException(t);
213269
}
214-
return super.filterRowKey(buffer, offset, length);
215270
}
216271

217272
@Override
@@ -271,4 +326,5 @@ public byte[] toByteArray() throws IOException {
271326
public Filter getInnerFilter() {
272327
return userFilter;
273328
}
329+
274330
}

0 commit comments

Comments
 (0)