diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AsyncFSWAL.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AsyncFSWAL.java index d032d837d99..7c19390349e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AsyncFSWAL.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AsyncFSWAL.java @@ -1,4 +1,4 @@ -/* +/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AsyncFSWALProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AsyncFSWALProvider.java index c920279253c..88b0140b37b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AsyncFSWALProvider.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AsyncFSWALProvider.java @@ -22,6 +22,9 @@ import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutput; +import org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper; +import org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputSaslHelper; import org.apache.hadoop.hbase.regionserver.wal.AsyncFSWAL; import org.apache.hadoop.hbase.regionserver.wal.AsyncProtobufLogWriter; import org.apache.hadoop.hbase.regionserver.wal.WALUtil; @@ -123,4 +126,18 @@ public class AsyncFSWALProvider extends AbstractFSWALProvider { throw new IOException("cannot get log writer", e); } } + + /** + * Test whether we can load the helper classes for async dfs output. + */ + public static boolean load() { + try { + Class.forName(FanOutOneBlockAsyncDFSOutput.class.getName()); + Class.forName(FanOutOneBlockAsyncDFSOutputHelper.class.getName()); + Class.forName(FanOutOneBlockAsyncDFSOutputSaslHelper.class.getName()); + return true; + } catch (Throwable e) { + return false; + } + } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALFactory.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALFactory.java index 24604d988e8..07bcb0ee49b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALFactory.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALFactory.java @@ -123,7 +123,19 @@ public class WALFactory { @VisibleForTesting public Class getProviderClass(String key, String defaultValue) { try { - return Providers.valueOf(conf.get(key, defaultValue)).clazz; + Providers provider = Providers.valueOf(conf.get(key, defaultValue)); + if (provider != Providers.defaultProvider) { + // User gives a wal provider explicitly, just use that one + return provider.clazz; + } + // AsyncFSWAL has better performance in most cases, and also uses less resources, we will try + // to use it if possible. But it deeply hacks into the internal of DFSClient so will be easily + // broken when upgrading hadoop. If it is broken, then we fall back to use FSHLog. + if (AsyncFSWALProvider.load()) { + return AsyncFSWALProvider.class; + } else { + return FSHLogProvider.class; + } } catch (IllegalArgumentException exception) { // Fall back to them specifying a class name // Note that the passed default class shouldn't actually be used, since the above only fails