HBASE-5975 Failed suppression of fs shutdown hook with Hadoop 2.0.0 (Jimmy Xiang)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1336875 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f179f571a3
commit
4bb18e6a92
|
@ -59,7 +59,7 @@ public class ShutdownHook {
|
||||||
* to be executed after the last regionserver referring to a given filesystem
|
* to be executed after the last regionserver referring to a given filesystem
|
||||||
* stops. We keep track of the # of regionserver references in values of the map.
|
* stops. We keep track of the # of regionserver references in values of the map.
|
||||||
*/
|
*/
|
||||||
private final static Map<Thread, Integer> fsShutdownHooks = new HashMap<Thread, Integer>();
|
private final static Map<Runnable, Integer> fsShutdownHooks = new HashMap<Runnable, Integer>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install a shutdown hook that calls stop on the passed Stoppable
|
* Install a shutdown hook that calls stop on the passed Stoppable
|
||||||
|
@ -82,7 +82,7 @@ public class ShutdownHook {
|
||||||
*/
|
*/
|
||||||
public static void install(final Configuration conf, final FileSystem fs,
|
public static void install(final Configuration conf, final FileSystem fs,
|
||||||
final Stoppable stop, final Thread threadToJoin) {
|
final Stoppable stop, final Thread threadToJoin) {
|
||||||
Thread fsShutdownHook = suppressHdfsShutdownHook(fs);
|
Runnable fsShutdownHook = suppressHdfsShutdownHook(fs);
|
||||||
Thread t = new ShutdownHookThread(conf, stop, threadToJoin, fsShutdownHook);
|
Thread t = new ShutdownHookThread(conf, stop, threadToJoin, fsShutdownHook);
|
||||||
ShutdownHookManager.affixShutdownHook(t, 0);
|
ShutdownHookManager.affixShutdownHook(t, 0);
|
||||||
LOG.info("Installed shutdown hook thread: " + t.getName());
|
LOG.info("Installed shutdown hook thread: " + t.getName());
|
||||||
|
@ -94,11 +94,11 @@ public class ShutdownHook {
|
||||||
private static class ShutdownHookThread extends Thread {
|
private static class ShutdownHookThread extends Thread {
|
||||||
private final Stoppable stop;
|
private final Stoppable stop;
|
||||||
private final Thread threadToJoin;
|
private final Thread threadToJoin;
|
||||||
private final Thread fsShutdownHook;
|
private final Runnable fsShutdownHook;
|
||||||
private final Configuration conf;
|
private final Configuration conf;
|
||||||
|
|
||||||
ShutdownHookThread(final Configuration conf, final Stoppable stop,
|
ShutdownHookThread(final Configuration conf, final Stoppable stop,
|
||||||
final Thread threadToJoin, final Thread fsShutdownHook) {
|
final Thread threadToJoin, final Runnable fsShutdownHook) {
|
||||||
super("Shutdownhook:" + threadToJoin.getName());
|
super("Shutdownhook:" + threadToJoin.getName());
|
||||||
this.stop = stop;
|
this.stop = stop;
|
||||||
this.threadToJoin = threadToJoin;
|
this.threadToJoin = threadToJoin;
|
||||||
|
@ -119,8 +119,10 @@ public class ShutdownHook {
|
||||||
int refs = fsShutdownHooks.get(fsShutdownHook);
|
int refs = fsShutdownHooks.get(fsShutdownHook);
|
||||||
if (refs == 1) {
|
if (refs == 1) {
|
||||||
LOG.info("Starting fs shutdown hook thread.");
|
LOG.info("Starting fs shutdown hook thread.");
|
||||||
this.fsShutdownHook.start();
|
Thread fsShutdownHookThread = (fsShutdownHook instanceof Thread) ?
|
||||||
Threads.shutdown(this.fsShutdownHook,
|
(Thread)fsShutdownHook : new Thread(fsShutdownHook);
|
||||||
|
fsShutdownHookThread.start();
|
||||||
|
Threads.shutdown(fsShutdownHookThread,
|
||||||
this.conf.getLong(FS_SHUTDOWN_HOOK_WAIT, 30000));
|
this.conf.getLong(FS_SHUTDOWN_HOOK_WAIT, 30000));
|
||||||
}
|
}
|
||||||
if (refs > 0) {
|
if (refs > 0) {
|
||||||
|
@ -150,7 +152,7 @@ public class ShutdownHook {
|
||||||
* @return The fs shutdown hook
|
* @return The fs shutdown hook
|
||||||
* @throws RuntimeException if we fail to find or grap the shutdown hook.
|
* @throws RuntimeException if we fail to find or grap the shutdown hook.
|
||||||
*/
|
*/
|
||||||
private static Thread suppressHdfsShutdownHook(final FileSystem fs) {
|
private static Runnable suppressHdfsShutdownHook(final FileSystem fs) {
|
||||||
try {
|
try {
|
||||||
// This introspection has been updated to work for hadoop 0.20, 0.21 and for
|
// This introspection has been updated to work for hadoop 0.20, 0.21 and for
|
||||||
// cloudera 0.20. 0.21 and cloudera 0.20 both have hadoop-4829. With the
|
// cloudera 0.20. 0.21 and cloudera 0.20 both have hadoop-4829. With the
|
||||||
|
@ -159,7 +161,7 @@ public class ShutdownHook {
|
||||||
// FileSystem and one in the innner class named Cache that actually gets
|
// FileSystem and one in the innner class named Cache that actually gets
|
||||||
// registered as a shutdown hook. If the latter is present, then we are
|
// registered as a shutdown hook. If the latter is present, then we are
|
||||||
// on 0.21 or cloudera patched 0.20.
|
// on 0.21 or cloudera patched 0.20.
|
||||||
Thread hdfsClientFinalizer = null;
|
Runnable hdfsClientFinalizer = null;
|
||||||
// Look into the FileSystem#Cache class for clientFinalizer
|
// Look into the FileSystem#Cache class for clientFinalizer
|
||||||
Class<?> [] classes = FileSystem.class.getDeclaredClasses();
|
Class<?> [] classes = FileSystem.class.getDeclaredClasses();
|
||||||
Class<?> cache = null;
|
Class<?> cache = null;
|
||||||
|
@ -187,15 +189,12 @@ public class ShutdownHook {
|
||||||
Field cacheField = FileSystem.class.getDeclaredField("CACHE");
|
Field cacheField = FileSystem.class.getDeclaredField("CACHE");
|
||||||
cacheField.setAccessible(true);
|
cacheField.setAccessible(true);
|
||||||
Object cacheInstance = cacheField.get(fs);
|
Object cacheInstance = cacheField.get(fs);
|
||||||
Runnable finalizerRunnable = (Runnable)field.get(cacheInstance);
|
hdfsClientFinalizer = (Runnable)field.get(cacheInstance);
|
||||||
if (!(finalizerRunnable instanceof Thread)) {
|
|
||||||
hdfsClientFinalizer = new Thread(finalizerRunnable);
|
|
||||||
} else hdfsClientFinalizer = (Thread)finalizerRunnable;
|
|
||||||
} else {
|
} else {
|
||||||
// Then we didnt' find clientFinalizer in Cache. Presume clean 0.20 hadoop.
|
// Then we didnt' find clientFinalizer in Cache. Presume clean 0.20 hadoop.
|
||||||
field = FileSystem.class.getDeclaredField(CLIENT_FINALIZER_DATA_METHOD);
|
field = FileSystem.class.getDeclaredField(CLIENT_FINALIZER_DATA_METHOD);
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
hdfsClientFinalizer = (Thread)field.get(null);
|
hdfsClientFinalizer = (Runnable)field.get(null);
|
||||||
}
|
}
|
||||||
if (hdfsClientFinalizer == null) {
|
if (hdfsClientFinalizer == null) {
|
||||||
throw new RuntimeException("Client finalizer is null, can't suppress!");
|
throw new RuntimeException("Client finalizer is null, can't suppress!");
|
||||||
|
|
Loading…
Reference in New Issue