2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.master
;
20 import java
.io
.IOException
;
21 import org
.apache
.hadoop
.conf
.Configuration
;
22 import org
.apache
.hadoop
.hbase
.Server
;
23 import org
.apache
.hadoop
.hbase
.ServerName
;
24 import org
.apache
.hadoop
.hbase
.monitoring
.MonitoredTask
;
25 import org
.apache
.hadoop
.hbase
.util
.Threads
;
26 import org
.apache
.hadoop
.hbase
.zookeeper
.MasterAddressTracker
;
27 import org
.apache
.hadoop
.hbase
.zookeeper
.ZKWatcher
;
28 import org
.apache
.zookeeper
.KeeperException
;
29 import org
.slf4j
.Logger
;
30 import org
.slf4j
.LoggerFactory
;
33 * An implementation of HMaster that always runs as a stand by and never transitions to active.
35 public class AlwaysStandByHMaster
extends HMaster
{
37 * An implementation of ActiveMasterManager that never transitions it's master to active state. It
38 * always remains as a stand by master. With the master registry implementation (HBASE-18095) it
39 * is expected to have at least one active / standby master always running at any point in time
40 * since they serve as the gateway for client connections.
42 * With this implementation, tests can simulate the scenario of not having an active master yet
43 * the client connections to the cluster succeed.
45 private static class AlwaysStandByMasterManager
extends ActiveMasterManager
{
46 private static final Logger LOG
=
47 LoggerFactory
.getLogger(AlwaysStandByMasterManager
.class);
49 AlwaysStandByMasterManager(ZKWatcher watcher
, ServerName sn
, Server master
) {
50 super(watcher
, sn
, master
);
54 * An implementation that never transitions to an active master.
56 boolean blockUntilBecomingActiveMaster(int checkInterval
, MonitoredTask startupStatus
) {
57 while (!(master
.isAborted() || master
.isStopped())) {
58 startupStatus
.setStatus("Forever looping to stay as a standby master.");
60 activeMasterServerName
= null;
62 if (MasterAddressTracker
.getMasterAddress(watcher
) != null) {
63 clusterHasActiveMaster
.set(true);
65 Threads
.sleepWithoutInterrupt(100);
66 } catch (IOException e
) {
67 // pass, we will get notified when some other active master creates the znode.
69 } catch (KeeperException e
) {
70 master
.abort("Received an unexpected KeeperException, aborting", e
);
73 synchronized (this.clusterHasActiveMaster
) {
74 while (clusterHasActiveMaster
.get() && !master
.isStopped()) {
76 clusterHasActiveMaster
.wait(checkInterval
);
77 } catch (InterruptedException e
) {
78 // We expect to be interrupted when a master dies,
79 // will fall out if so
80 LOG
.debug("Interrupted waiting for master to die", e
);
83 if (clusterShutDown
.get()) {
85 "Cluster went down before this master became active");
93 public AlwaysStandByHMaster(Configuration conf
) throws IOException
{
97 protected ActiveMasterManager
createActiveMasterManager(
98 ZKWatcher zk
, ServerName sn
, org
.apache
.hadoop
.hbase
.Server server
) {
99 return new AlwaysStandByMasterManager(zk
, sn
, server
);