From cdff80d97655acc894c1fbf3f6a24c1d1b121e52 Mon Sep 17 00:00:00 2001 From: Chia-Ping Tsai Date: Mon, 30 Oct 2017 06:15:48 +0800 Subject: [PATCH] HBASE-19117 Avoid NPE occurring while active master dies --- .../org/apache/hadoop/hbase/master/HMaster.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 7a778f2affd..c45b762b1cf 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -543,13 +543,16 @@ public class HMaster extends HRegionServer implements MasterServices { try { super.run(); } finally { - // If on way out, then we are no longer active master. - this.clusterSchemaService.stopAsync(); - try { - this.clusterSchemaService.awaitTerminated(getConfiguration().getInt(HBASE_MASTER_WAIT_ON_SERVICE_IN_SECONDS, - DEFAULT_HBASE_MASTER_WAIT_ON_SERVICE_IN_SECONDS), TimeUnit.SECONDS); - } catch (TimeoutException te) { - LOG.warn("Failed shutdown of clusterSchemaService", te); + if (this.clusterSchemaService != null) { + // If on way out, then we are no longer active master. + this.clusterSchemaService.stopAsync(); + try { + this.clusterSchemaService.awaitTerminated( + getConfiguration().getInt(HBASE_MASTER_WAIT_ON_SERVICE_IN_SECONDS, + DEFAULT_HBASE_MASTER_WAIT_ON_SERVICE_IN_SECONDS), TimeUnit.SECONDS); + } catch (TimeoutException te) { + LOG.warn("Failed shutdown of clusterSchemaService", te); + } } this.activeMaster = false; }