1- /*
1+ /**
22 *
33 * Licensed to the Apache Software Foundation (ASF) under one
44 * or more contributor license agreements. See the NOTICE file
1717 * limitations under the License.
1818 */
1919package org .apache .hadoop .hbase .master ;
20+
2021import java .io .IOException ;
21- import java .util .Optional ;
2222import java .util .concurrent .atomic .AtomicBoolean ;
23+
24+ import org .apache .hadoop .hbase .zookeeper .MasterAddressTracker ;
25+ import org .apache .hadoop .hbase .zookeeper .ZKUtil ;
26+ import org .apache .hadoop .hbase .zookeeper .ZKWatcher ;
27+ import org .apache .hadoop .hbase .zookeeper .ZNodePaths ;
28+ import org .apache .yetus .audience .InterfaceAudience ;
2329import org .apache .hadoop .hbase .Server ;
2430import org .apache .hadoop .hbase .ServerName ;
2531import org .apache .hadoop .hbase .ZNodeClearer ;
2632import org .apache .hadoop .hbase .exceptions .DeserializationException ;
2733import org .apache .hadoop .hbase .monitoring .MonitoredTask ;
28- import org .apache .hadoop .hbase .zookeeper . MasterAddressTracker ;
34+ import org .apache .hadoop .hbase .shaded . protobuf . ProtobufUtil ;
2935import org .apache .hadoop .hbase .zookeeper .ZKListener ;
30- import org .apache .hadoop .hbase .zookeeper .ZKUtil ;
31- import org .apache .hadoop .hbase .zookeeper .ZKWatcher ;
32- import org .apache .hadoop .hbase .zookeeper .ZNodePaths ;
33- import org .apache .yetus .audience .InterfaceAudience ;
3436import org .apache .zookeeper .KeeperException ;
3537import org .slf4j .Logger ;
3638import org .slf4j .LoggerFactory ;
37- import org .apache .hadoop .hbase .shaded .protobuf .ProtobufUtil ;
3839
3940/**
4041 * Handles everything on master-side related to master election.
@@ -56,18 +57,12 @@ public class ActiveMasterManager extends ZKListener {
5657 final AtomicBoolean clusterHasActiveMaster = new AtomicBoolean (false );
5758 final AtomicBoolean clusterShutDown = new AtomicBoolean (false );
5859
59- // This server's information.
6060 private final ServerName sn ;
6161 private int infoPort ;
6262 private final Server master ;
6363
64- // Active master's server name. Invalidated anytime active master changes (based on ZK
65- // notifications) and lazily fetched on-demand.
66- // ServerName is immutable, so we don't need heavy synchronization around it.
67- private volatile ServerName activeMasterServerName ;
68-
6964 /**
70- * @param watcher ZK watcher
65+ * @param watcher
7166 * @param sn ServerName
7267 * @param master In an instance of a Master.
7368 */
@@ -111,30 +106,6 @@ void handle(final String path) {
111106 }
112107 }
113108
114- /**
115- * Fetches the active master's ServerName from zookeeper.
116- */
117- private void fetchAndSetActiveMasterServerName () {
118- LOG .debug ("Attempting to fetch active master sn from zk" );
119- try {
120- activeMasterServerName = MasterAddressTracker .getMasterAddress (watcher );
121- } catch (IOException | KeeperException e ) {
122- // Log and ignore for now and re-fetch later if needed.
123- LOG .error ("Error fetching active master information" , e );
124- }
125- }
126-
127- public Optional <ServerName > getActiveMasterServerName () {
128- if (!clusterHasActiveMaster .get ()) {
129- return Optional .empty ();
130- }
131- if (activeMasterServerName == null ) {
132- fetchAndSetActiveMasterServerName ();
133- }
134- // It could still be null, but return whatever we have.
135- return Optional .ofNullable (activeMasterServerName );
136- }
137-
138109 /**
139110 * Handle a change in the master node. Doesn't matter whether this was called
140111 * from a nodeCreated or nodeDeleted event because there are no guarantees
@@ -163,9 +134,6 @@ private void handleMasterNodeChange() {
163134 // Notify any thread waiting to become the active master
164135 clusterHasActiveMaster .notifyAll ();
165136 }
166- // Reset the active master sn. Will be re-fetched later if needed.
167- // We don't want to make a synchronous RPC under a monitor.
168- activeMasterServerName = null ;
169137 }
170138 } catch (KeeperException ke ) {
171139 master .abort ("Received an unexpected KeeperException, aborting" , ke );
@@ -183,8 +151,8 @@ private void handleMasterNodeChange() {
183151 * @param checkInterval the interval to check if the master is stopped
184152 * @param startupStatus the monitor status to track the progress
185153 * @return True if no issue becoming active master else false if another
186- * master was running or if some other problem (zookeeper, stop flag has been
187- * set on this Master)
154+ * master was running or if some other problem (zookeeper, stop flag has been
155+ * set on this Master)
188156 */
189157 boolean blockUntilBecomingActiveMaster (
190158 int checkInterval , MonitoredTask startupStatus ) {
@@ -210,14 +178,10 @@ boolean blockUntilBecomingActiveMaster(
210178 // We are the master, return
211179 startupStatus .setStatus ("Successfully registered as active master." );
212180 this .clusterHasActiveMaster .set (true );
213- activeMasterServerName = sn ;
214181 LOG .info ("Registered as active master=" + this .sn );
215182 return true ;
216183 }
217184
218- // Invalidate the active master name so that subsequent requests do not get any stale
219- // master information. Will be re-fetched if needed.
220- activeMasterServerName = null ;
221185 // There is another active master running elsewhere or this is a restart
222186 // and the master ephemeral node has not expired yet.
223187 this .clusterHasActiveMaster .set (true );
@@ -244,8 +208,7 @@ boolean blockUntilBecomingActiveMaster(
244208 ZKUtil .deleteNode (this .watcher , this .watcher .getZNodePaths ().masterAddressZNode );
245209
246210 // We may have failed to delete the znode at the previous step, but
247- // we delete the file anyway: a second attempt to delete the znode is likely to fail
248- // again.
211+ // we delete the file anyway: a second attempt to delete the znode is likely to fail again.
249212 ZNodeClearer .deleteMyEphemeralNodeOnDisk ();
250213 } else {
251214 msg = "Another master is the active master, " + currentMaster +
0 commit comments