Skip to content

OMID-271 Support HBase 3 #152

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
25 changes: 11 additions & 14 deletions hbase-client/src/main/java/org/apache/omid/transaction/TTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.TableName;
Expand Down Expand Up @@ -499,6 +498,17 @@ public ResultScanner getScanner(Transaction tx, Scan scan) throws IOException {
return snapshotFilter.getScanner(tsscan, transaction);
}

/**
* Return the raw HBase table
*
* This is needed to resolve API incompatibilities between HBase 2 and 3 in Phoenix.
*
* @return the backing table
*/
public Table getHBaseTable() {
return table;
}

/**
*
* @return array of byte
Expand All @@ -516,19 +526,6 @@ public Configuration getConfiguration() {
return table.getConfiguration();
}

/**
* Delegates to {@link Table#getTableDescriptor()}
*
* This deprecated method is implemented for backwards compatibility reasons.
* use {@link TTable#getDescriptor()}
*
* @return HTableDescriptor an instance of HTableDescriptor
* @throws IOException if a remote or network exception occurs.
*/
public HTableDescriptor getTableDescriptor() throws IOException {
return table.getTableDescriptor();
}

/**
* Delegates to {@link Table#getDescriptor()}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
import org.apache.hadoop.hbase.PrivateCellUtil;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.FilterBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.util.List;

/**
Expand All @@ -34,13 +40,31 @@
* Please see TEPHRA-169 for more details.
*/

public class CellSkipFilterBase extends FilterBase {
public class CellSkipFilter extends FilterBase {

private static final Logger LOG = LoggerFactory.getLogger(CellSkipFilter.class);

private final Filter filter;
// remember the previous cell processed by filter when the return code was NEXT_COL or INCLUDE_AND_NEXT_COL
private Cell skipColumn = null;

public CellSkipFilterBase(Filter filter) {
// Using reflection to avoid adding compatibility modules.
private final MethodHandle removedFilterRowKeyMethod;

public CellSkipFilter(Filter filter) {
this.filter = filter;
MethodHandle tmpFilterRowKeyMethod;
try {
tmpFilterRowKeyMethod =
MethodHandles.lookup().findVirtual(filter.getClass(), "filterRowKey",
MethodType.methodType(boolean.class, byte[].class, int.class, int.class));
} catch (Exception e) {
LOG.info(
"Could not get filterRowKey method handle by reflection. This is normal for HBase 3.x",
e);
tmpFilterRowKeyMethod = null;
}
removedFilterRowKeyMethod = tmpFilterRowKeyMethod;
}

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

/**
* This deprecated method is implemented for backwards compatibility reasons.
* use {@link CellSkipFilterBase#filterKeyValue(Cell)}
* use {@link CellSkipFilter#filterKeyValue(Cell)}
*
* No @Override because HBase 3 completely removes this method
*/
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
return filterCell(cell);
}
Expand Down Expand Up @@ -102,11 +127,21 @@ public void reset() throws IOException {

/**
* This deprecated method is implemented for backwards compatibility reasons.
* use {@link CellSkipFilterBase#filterRowKey(Cell)}
* use {@link CellSkipFilter#filterRowKey(Cell)}
*
* No @Override so that this compiles with HBase 3
*/
@Override
public boolean filterRowKey(byte[] buffer, int offset, int length) throws IOException {
return filter.filterRowKey(buffer, offset, length);
// Even though this is deprecated, this is the actual implementation that filterRowKey(Cell)
// calls in FilterBase in HBase 2, so we cannot call filterRowKey(Cell), because that would
// cause infinite recursion
try {
return (boolean) (removedFilterRowKeyMethod.invokeExact(filter, buffer, offset, length));
} catch (IOException e) {
throw e;
} catch (Throwable t) {
throw new UnsupportedOperationException(t);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void stop(CoprocessorEnvironment e) throws IOException {
}


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


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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public class TransactionFilters {
public static Filter getVisibilityFilter(Filter cellFilter,
SnapshotFilterImpl regionAccessWrapper,
HBaseTransaction hbaseTransaction) {
return new CellSkipFilterBase(new TransactionVisibilityFilterBase(cellFilter, regionAccessWrapper, hbaseTransaction));
return new CellSkipFilter(new TransactionVisibilityFilter(cellFilter, regionAccessWrapper, hbaseTransaction));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
package org.apache.omid.transaction;

import org.apache.phoenix.thirdparty.com.google.common.base.Optional;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.collections4.map.LRUMap;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.Cell.Type;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.filter.Filter;
Expand All @@ -31,15 +34,20 @@

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


import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.util.HashMap;

import java.util.List;
import java.util.Map;


public class TransactionVisibilityFilterBase extends FilterBase {
public class TransactionVisibilityFilter extends FilterBase {

private static final Logger LOG = LoggerFactory.getLogger(TransactionVisibilityFilter.class);

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

public TransactionVisibilityFilterBase(Filter cellFilter,
// Using reflection to avoid adding compatibility modules.
private final MethodHandle removedFilterRowKeyMethod;
private final MethodHandle removedSuperFilterRowKeyMethod;

public TransactionVisibilityFilter(Filter cellFilter,
SnapshotFilterImpl snapshotFilter,
HBaseTransaction hbaseTransaction) {
this.userFilter = cellFilter;
Expand All @@ -60,13 +72,37 @@ public TransactionVisibilityFilterBase(Filter cellFilter,
this.hbaseTransaction = hbaseTransaction;
familyDeletionCache = new HashMap<>();

MethodHandle tmpFilterRowKeyMethod;
try {
tmpFilterRowKeyMethod = MethodHandles.lookup().findVirtual(userFilter.getClass(), "filterRowKey", MethodType.methodType(boolean.class, byte[].class, int.class, int.class));
//tmpFilterRowKeyMethod = FilterBase.class.getMethod("filterRowKey", byte[].class, int.class, int.class);
} catch (Exception e) {
if(userFilter != null) {
LOG.info("Could not get filterRowKey method handle by reflection. This is normal for HBase 3.x", e);
}
tmpFilterRowKeyMethod = null;
}
removedFilterRowKeyMethod = tmpFilterRowKeyMethod;

MethodHandle tmpRemovedSuperFilterRowKeyMethod;
try {
tmpRemovedSuperFilterRowKeyMethod = MethodHandles.lookup().findSpecial(FilterBase.class, "filterRowKey",
MethodType.methodType(boolean.class, byte[].class, int.class, int.class),
TransactionVisibilityFilter.class);
} catch (Exception e) {
LOG.info("Could not get super.filterRowKey method handle by reflection. This is normal for HBase 3.x", e);
tmpRemovedSuperFilterRowKeyMethod = null;
}
removedSuperFilterRowKeyMethod = tmpRemovedSuperFilterRowKeyMethod;

}

/**
* This deprecated method is implemented for backwards compatibility reasons.
* use {@link TransactionVisibilityFilterBase#filterCell(Cell)}
* use {@link TransactionVisibilityFilter#filterCell(Cell)}
*
* No @Override so that it compiles with HBase 3.x
*/
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
return filterCell(cell);
}
Expand Down Expand Up @@ -202,16 +238,32 @@ public boolean filterRow() throws IOException {
return super.filterRow();
}

/**
/**
* This deprecated method is implemented for backwards compatibility reasons.
* use {@link TransactionVisibilityFilterBase#filterRowKey(Cell)}
* use {@link TransactionVisibilityFilter#filterRowKey(Cell)}
*
* No @Override so that it compiles with HBase 3.x
*/
@Override
public boolean filterRowKey(byte[] buffer, int offset, int length) throws IOException {
// Even though this is deprecated, this is the actual implementation that filterRowKey(Cell)
// calls in FilterBase in HBase 2, so we cannot call filterRowKey(Cell), because that would
// cause infinite recursion
if (userFilter != null) {
return userFilter.filterRowKey(buffer, offset, length);
try {
return (boolean) (removedFilterRowKeyMethod.invoke(userFilter, buffer, offset, length));
} catch (IOException e) {
throw e;
} catch (Throwable t) {
throw new UnsupportedOperationException(t);
}
}
try {
return (boolean) (removedSuperFilterRowKeyMethod.invokeExact(this, buffer, offset, length));
} catch (IOException e) {
throw e;
} catch (Throwable t) {
throw new UnsupportedOperationException(t);
}
return super.filterRowKey(buffer, offset, length);
}

@Override
Expand Down Expand Up @@ -271,4 +323,5 @@ public byte[] toByteArray() throws IOException {
public Filter getInnerFilter() {
return userFilter;
}

}
Loading