1
- /*
1
+ /**
2
2
*
3
3
* Licensed to the Apache Software Foundation (ASF) under one
4
4
* or more contributor license agreements. See the NOTICE file
17
17
* limitations under the License.
18
18
*/
19
19
package org .apache .hadoop .hbase .master ;
20
+
20
21
import java .io .IOException ;
21
- import java .util .Optional ;
22
22
import 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 ;
23
29
import org .apache .hadoop .hbase .Server ;
24
30
import org .apache .hadoop .hbase .ServerName ;
25
31
import org .apache .hadoop .hbase .ZNodeClearer ;
26
32
import org .apache .hadoop .hbase .exceptions .DeserializationException ;
27
33
import org .apache .hadoop .hbase .monitoring .MonitoredTask ;
28
- import org .apache .hadoop .hbase .zookeeper . MasterAddressTracker ;
34
+ import org .apache .hadoop .hbase .shaded . protobuf . ProtobufUtil ;
29
35
import 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 ;
34
36
import org .apache .zookeeper .KeeperException ;
35
37
import org .slf4j .Logger ;
36
38
import org .slf4j .LoggerFactory ;
37
- import org .apache .hadoop .hbase .shaded .protobuf .ProtobufUtil ;
38
39
39
40
/**
40
41
* Handles everything on master-side related to master election.
@@ -56,18 +57,12 @@ public class ActiveMasterManager extends ZKListener {
56
57
final AtomicBoolean clusterHasActiveMaster = new AtomicBoolean (false );
57
58
final AtomicBoolean clusterShutDown = new AtomicBoolean (false );
58
59
59
- // This server's information.
60
60
private final ServerName sn ;
61
61
private int infoPort ;
62
62
private final Server master ;
63
63
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
-
69
64
/**
70
- * @param watcher ZK watcher
65
+ * @param watcher
71
66
* @param sn ServerName
72
67
* @param master In an instance of a Master.
73
68
*/
@@ -111,30 +106,6 @@ void handle(final String path) {
111
106
}
112
107
}
113
108
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
-
138
109
/**
139
110
* Handle a change in the master node. Doesn't matter whether this was called
140
111
* from a nodeCreated or nodeDeleted event because there are no guarantees
@@ -163,9 +134,6 @@ private void handleMasterNodeChange() {
163
134
// Notify any thread waiting to become the active master
164
135
clusterHasActiveMaster .notifyAll ();
165
136
}
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 ;
169
137
}
170
138
} catch (KeeperException ke ) {
171
139
master .abort ("Received an unexpected KeeperException, aborting" , ke );
@@ -183,8 +151,8 @@ private void handleMasterNodeChange() {
183
151
* @param checkInterval the interval to check if the master is stopped
184
152
* @param startupStatus the monitor status to track the progress
185
153
* @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)
188
156
*/
189
157
boolean blockUntilBecomingActiveMaster (
190
158
int checkInterval , MonitoredTask startupStatus ) {
@@ -210,14 +178,10 @@ boolean blockUntilBecomingActiveMaster(
210
178
// We are the master, return
211
179
startupStatus .setStatus ("Successfully registered as active master." );
212
180
this .clusterHasActiveMaster .set (true );
213
- activeMasterServerName = sn ;
214
181
LOG .info ("Registered as active master=" + this .sn );
215
182
return true ;
216
183
}
217
184
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 ;
221
185
// There is another active master running elsewhere or this is a restart
222
186
// and the master ephemeral node has not expired yet.
223
187
this .clusterHasActiveMaster .set (true );
@@ -244,8 +208,7 @@ boolean blockUntilBecomingActiveMaster(
244
208
ZKUtil .deleteNode (this .watcher , this .watcher .getZNodePaths ().masterAddressZNode );
245
209
246
210
// 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.
249
212
ZNodeClearer .deleteMyEphemeralNodeOnDisk ();
250
213
} else {
251
214
msg = "Another master is the active master, " + currentMaster +
0 commit comments