HBASE-21247 Custom WAL Provider cannot be specified by configuration whose value is outside the enums in Providers
This commit is contained in:
parent
c8574ba3c5
commit
7395ffac44
|
@ -260,8 +260,18 @@ public class WALFactory {
|
|||
if (provider != null) {
|
||||
return provider;
|
||||
}
|
||||
provider = createProvider(getProviderClass(META_WAL_PROVIDER,
|
||||
conf.get(WAL_PROVIDER, DEFAULT_WAL_PROVIDER)));
|
||||
Class<? extends WALProvider> clz = null;
|
||||
if (conf.get(META_WAL_PROVIDER) == null) {
|
||||
try {
|
||||
clz = conf.getClass(WAL_PROVIDER, Providers.defaultProvider.clazz, WALProvider.class);
|
||||
} catch (Throwable t) {
|
||||
// the WAL provider should be an enum. Proceed
|
||||
}
|
||||
}
|
||||
if (clz == null){
|
||||
clz = getProviderClass(META_WAL_PROVIDER, conf.get(WAL_PROVIDER, DEFAULT_WAL_PROVIDER));
|
||||
}
|
||||
provider = createProvider(clz);
|
||||
provider.init(this, conf, AbstractFSWALProvider.META_WAL_PROVIDER_ID);
|
||||
provider.addWALActionsListener(new MetricsWAL());
|
||||
if (metaProvider.compareAndSet(null, provider)) {
|
||||
|
|
|
@ -27,6 +27,8 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
|
@ -87,6 +89,7 @@ public class IOTestProvider implements WALProvider {
|
|||
private volatile FSHLog log;
|
||||
|
||||
private String providerId;
|
||||
protected AtomicBoolean initialized = new AtomicBoolean(false);
|
||||
|
||||
private List<WALActionsListener> listeners = new ArrayList<>();
|
||||
/**
|
||||
|
@ -97,7 +100,7 @@ public class IOTestProvider implements WALProvider {
|
|||
*/
|
||||
@Override
|
||||
public void init(WALFactory factory, Configuration conf, String providerId) throws IOException {
|
||||
if (factory != null) {
|
||||
if (!initialized.compareAndSet(false, true)) {
|
||||
throw new IllegalStateException("WALProvider.init should only be called once.");
|
||||
}
|
||||
this.factory = factory;
|
||||
|
|
|
@ -742,4 +742,28 @@ public class TestWALFactory {
|
|||
WALFactory.WAL_PROVIDER, Providers.multiwal.name());
|
||||
assertEquals(Providers.multiwal.clazz, multiwalProviderClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomProvider() throws IOException {
|
||||
final Configuration config = new Configuration();
|
||||
config.set(WALFactory.WAL_PROVIDER, IOTestProvider.class.getName());
|
||||
final WALFactory walFactory = new WALFactory(config, this.currentServername.toString());
|
||||
Class<? extends WALProvider> walProvider = walFactory.getProviderClass(
|
||||
WALFactory.WAL_PROVIDER, Providers.filesystem.name());
|
||||
assertEquals(IOTestProvider.class, walProvider);
|
||||
WALProvider metaWALProvider = walFactory.getMetaProvider();
|
||||
assertEquals(IOTestProvider.class, metaWALProvider.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomMetaProvider() throws IOException {
|
||||
final Configuration config = new Configuration();
|
||||
config.set(WALFactory.META_WAL_PROVIDER, IOTestProvider.class.getName());
|
||||
final WALFactory walFactory = new WALFactory(config, this.currentServername.toString());
|
||||
Class<? extends WALProvider> walProvider = walFactory.getProviderClass(
|
||||
WALFactory.WAL_PROVIDER, Providers.filesystem.name());
|
||||
assertEquals(Providers.filesystem.clazz, walProvider);
|
||||
WALProvider metaWALProvider = walFactory.getMetaProvider();
|
||||
assertEquals(IOTestProvider.class, metaWALProvider.getClass());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue