[hbase] 01/06: HBASE-23275: Track active master's address in ActiveMasterManager (#812)
This is an automated email from the ASF dual-hosted git repository. ndimiduk pushed a commit to branch HBASE-18095/client-locate-meta-no-zookeeper in repository https://gitbox.apache.org/repos/asf/hbase.git commit efebb843afe4458599e12cf3390fe534780fac4e Author: Bharath Vissapragada AuthorDate: Wed Nov 20 11:41:36 2019 -0800 HBASE-23275: Track active master's address in ActiveMasterManager (#812) * HBASE-23275: Track active master's address in ActiveMasterManager Currently we just track whether an active master exists. It helps to also track the address of the active master in all the masters to help serve the client RPC requests to know which master is active. Signed-off-by: Nick Dimiduk Signed-off-by: Andrew Purtell --- .../hadoop/hbase/master/ActiveMasterManager.java | 63 +- .../org/apache/hadoop/hbase/master/HMaster.java| 4 ++ .../hbase/master/TestActiveMasterManager.java | 10 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java index 50798ed..99cab62 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java @@ -1,4 +1,4 @@ -/** +/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -17,25 +17,24 @@ * limitations under the License. */ package org.apache.hadoop.hbase.master; - import java.io.IOException; +import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.hadoop.hbase.zookeeper.MasterAddressTracker; -import org.apache.hadoop.hbase.zookeeper.ZKUtil; -import org.apache.hadoop.hbase.zookeeper.ZKWatcher; -import org.apache.hadoop.hbase.zookeeper.ZNodePaths; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ZNodeClearer; import org.apache.hadoop.hbase.exceptions.DeserializationException; import org.apache.hadoop.hbase.monitoring.MonitoredTask; -import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.zookeeper.MasterAddressTracker; import org.apache.hadoop.hbase.zookeeper.ZKListener; +import org.apache.hadoop.hbase.zookeeper.ZKUtil; +import org.apache.hadoop.hbase.zookeeper.ZKWatcher; +import org.apache.hadoop.hbase.zookeeper.ZNodePaths; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.KeeperException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; /** * Handles everything on master-side related to master election. @@ -57,12 +56,18 @@ public class ActiveMasterManager extends ZKListener { final AtomicBoolean clusterHasActiveMaster = new AtomicBoolean(false); final AtomicBoolean clusterShutDown = new AtomicBoolean(false); + // This server's information. private final ServerName sn; private int infoPort; private final Server master; + // Active master's server name. Invalidated anytime active master changes (based on ZK + // notifications) and lazily fetched on-demand. + // ServerName is immutable, so we don't need heavy synchronization around it. + private volatile ServerName activeMasterServerName; + /** - * @param watcher + * @param watcher ZK watcher * @param sn ServerName * @param master In an instance of a Master. */ @@ -107,6 +112,30 @@ public class ActiveMasterManager extends ZKListener { } /** + * Fetches the active master's ServerName from zookeeper. + */ + private void fetchAndSetActiveMasterServerName() { +LOG.debug("Attempting to fetch active master sn from zk"); +try { + activeMasterServerName = MasterAddressTracker.getMasterAddress(watcher); +} catch (IOException | KeeperException e) { + // Log and ignore for now and re-fetch later if needed. + LOG.error("Error fetching active master information", e); +} + } + + public Optional getActiveMasterServerName() { +if (!clusterHasActiveMaster.get()) { + return Optional.empty(); +} +if (activeMasterServerName == null) { + fetchAndSetActiveMasterServerName(); +} +// It could still be null, but return whatever we have. +return Optional.ofNullable(activeMasterServerName); + } + + /** * Handle a change in the master node. Doesn't matter whether this was called * from a nodeCreated or nodeDeleted event because there are no guarantees * that the current state of the master node matches the event at the time of @@ -134,6 +163,9 @@ public class ActiveMasterManager extends ZKListener { // Notify any thread waiting
[hbase] 01/06: HBASE-23275: Track active master's address in ActiveMasterManager (#812)
This is an automated email from the ASF dual-hosted git repository. ndimiduk pushed a commit to branch HBASE-18095/client-locate-meta-no-zookeeper in repository https://gitbox.apache.org/repos/asf/hbase.git commit 9c42b6a17b18086068dc0aa149fe54bc0ed4a212 Author: Bharath Vissapragada AuthorDate: Wed Nov 20 11:41:36 2019 -0800 HBASE-23275: Track active master's address in ActiveMasterManager (#812) * HBASE-23275: Track active master's address in ActiveMasterManager Currently we just track whether an active master exists. It helps to also track the address of the active master in all the masters to help serve the client RPC requests to know which master is active. Signed-off-by: Nick Dimiduk Signed-off-by: Andrew Purtell --- .../hadoop/hbase/master/ActiveMasterManager.java | 63 +- .../org/apache/hadoop/hbase/master/HMaster.java| 4 ++ .../hbase/master/TestActiveMasterManager.java | 10 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java index 50798ed..99cab62 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java @@ -1,4 +1,4 @@ -/** +/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -17,25 +17,24 @@ * limitations under the License. */ package org.apache.hadoop.hbase.master; - import java.io.IOException; +import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.hadoop.hbase.zookeeper.MasterAddressTracker; -import org.apache.hadoop.hbase.zookeeper.ZKUtil; -import org.apache.hadoop.hbase.zookeeper.ZKWatcher; -import org.apache.hadoop.hbase.zookeeper.ZNodePaths; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ZNodeClearer; import org.apache.hadoop.hbase.exceptions.DeserializationException; import org.apache.hadoop.hbase.monitoring.MonitoredTask; -import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.zookeeper.MasterAddressTracker; import org.apache.hadoop.hbase.zookeeper.ZKListener; +import org.apache.hadoop.hbase.zookeeper.ZKUtil; +import org.apache.hadoop.hbase.zookeeper.ZKWatcher; +import org.apache.hadoop.hbase.zookeeper.ZNodePaths; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.KeeperException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; /** * Handles everything on master-side related to master election. @@ -57,12 +56,18 @@ public class ActiveMasterManager extends ZKListener { final AtomicBoolean clusterHasActiveMaster = new AtomicBoolean(false); final AtomicBoolean clusterShutDown = new AtomicBoolean(false); + // This server's information. private final ServerName sn; private int infoPort; private final Server master; + // Active master's server name. Invalidated anytime active master changes (based on ZK + // notifications) and lazily fetched on-demand. + // ServerName is immutable, so we don't need heavy synchronization around it. + private volatile ServerName activeMasterServerName; + /** - * @param watcher + * @param watcher ZK watcher * @param sn ServerName * @param master In an instance of a Master. */ @@ -107,6 +112,30 @@ public class ActiveMasterManager extends ZKListener { } /** + * Fetches the active master's ServerName from zookeeper. + */ + private void fetchAndSetActiveMasterServerName() { +LOG.debug("Attempting to fetch active master sn from zk"); +try { + activeMasterServerName = MasterAddressTracker.getMasterAddress(watcher); +} catch (IOException | KeeperException e) { + // Log and ignore for now and re-fetch later if needed. + LOG.error("Error fetching active master information", e); +} + } + + public Optional getActiveMasterServerName() { +if (!clusterHasActiveMaster.get()) { + return Optional.empty(); +} +if (activeMasterServerName == null) { + fetchAndSetActiveMasterServerName(); +} +// It could still be null, but return whatever we have. +return Optional.ofNullable(activeMasterServerName); + } + + /** * Handle a change in the master node. Doesn't matter whether this was called * from a nodeCreated or nodeDeleted event because there are no guarantees * that the current state of the master node matches the event at the time of @@ -134,6 +163,9 @@ public class ActiveMasterManager extends ZKListener { // Notify any thread waiting