今天在测试phoenix的二级索引功能时,创建完索引写入数据,出现以下异常:
Caused by: org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException: Failed 1 action: org.apache.phoenix.hbase.index.builder.IndexBuildingFailureException: Failed to build index for unexpected reason!
at org.apache.phoenix.hbase.index.util.IndexManagementUtil.rethrowIndexingException(IndexManagementUtil.java:206)
at org.apache.phoenix.hbase.index.Indexer.preBatchMutate(Indexer.java:351)
at org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost$28.call(RegionCoprocessorHost.java:1010)
at org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost$28.call(RegionCoprocessorHost.java:1007)
at org.apache.hadoop.hbase.coprocessor.CoprocessorHost$ObserverOperationWithoutResult.callObserver(CoprocessorHost.java:540)
at org.apache.hadoop.hbase.coprocessor.CoprocessorHost.execOperation(CoprocessorHost.java:614)
at org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.preBatchMutate(RegionCoprocessorHost.java:1007)
at org.apache.hadoop.hbase.regionserver.HRegion$MutationBatchOperation.prepareMiniBatchOperations(HRegion.java:3487)
at org.apache.hadoop.hbase.regionserver.HRegion.doMiniBatchMutate(HRegion.java:3896)
at org.apache.hadoop.hbase.regionserver.HRegion.batchMutate(HRegion.java:3854)
at org.apache.hadoop.hbase.regionserver.HRegion.batchMutate(HRegion.java:3785)
at org.apache.hadoop.hbase.regionserver.RSRpcServices.doBatchOp(RSRpcServices.java:908)
at org.apache.hadoop.hbase.regionserver.RSRpcServices.doNonAtomicBatchOp(RSRpcServices.java:836)
at org.apache.hadoop.hbase.regionserver.RSRpcServices.doNonAtomicRegionMutation(RSRpcServices.java:799)
at org.apache.hadoop.hbase.regionserver.RSRpcServices.multi(RSRpcServices.java:2551)
at org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos$ClientService$2.callBlockingMethod(ClientProtos.java:42014)
at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:413)
at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:130)
at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:324)
at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:304)
Caused by: java.lang.VerifyError: class org.apache.phoenix.hbase.index.covered.data.IndexMemStore$1 overrides final method compare.(Lorg/apache/hadoop/hbase/Cell;Lorg/apache/hadoop/hbase/Cell;)I
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.phoenix.hbase.index.covered.data.IndexMemStore.<init>(IndexMemStore.java:82)
at org.apache.phoenix.hbase.index.covered.LocalTableState.<init>(LocalTableState.java:57)
at org.apache.phoenix.hbase.index.covered.NonTxIndexBuilder.getIndexUpdate(NonTxIndexBuilder.java:52)
at org.apache.phoenix.hbase.index.builder.IndexBuildManager.getIndexUpdate(IndexBuildManager.java:90)
at org.apache.phoenix.hbase.index.Indexer.preBatchMutateWithExceptions(Indexer.java:503)
at org.apache.phoenix.hbase.index.Indexer.preBatchMutate(Indexer.java:348)
异常信息可以看出是IndexMemStore这个类初始化的时候加载class时碰到了VerifyError,具体来说就是试图覆盖1个被标记为final的方法,先找这个类的代码看看:
public class IndexMemStore implements KeyValueStore {
private static final Log LOG = LogFactory.getLog(IndexMemStore.class);
private IndexKeyValueSkipListSet kvset;
private CellComparator comparator;
public IndexMemStore() {
this(new CellComparatorImpl(){
@Override
public int compare(Cell a, Cell b) {
return super.compare(a, b, true);
}
});
}
覆盖的是CellComparatorImpl的compare方法,该类在hbase-common模块中,我们用的phoenix版本是5.0.0,对应的hbase版本为2.0.0,找到代码看看:
@Override
public int compare(Cell a, Cell b) {
return compare(a, b, false);
}
可以看到这个方法并非final,我们使用的是CDH6.0.1,对应的hbase也是2.0.0版本,莫非有所不同,找到代码看看:
@Override
public final int compare(final Cell a, final Cell b) {
return compare(a, b, false);
}
居然真的有final修饰符,于是查看社区中该类的修改历史,发现是在2.0.1中进行的如上改动,对应的jira:HBASE-20620,可以看到改动记录:
@@ -57,21 +64,17 @@ public class CellComparatorImpl implements CellComparator {
public static final CellComparatorImpl META_COMPARATOR = new MetaCellComparator();
@Override
- public int compare(Cell a, Cell b) {
+ public final int compare(final Cell a, final Cell b) {
return compare(a, b, false);
}
看起来应该是CDH6.0.1中包含了某些hbase2.0.0之后的patch;
解决方法就是修改hbase,把final修饰符去掉即可,然后打包、停服务、换包、起服务,再试已经正常;