org.apache.hadoop.hbase.master
Class ServerManager

java.lang.Object
  extended by org.apache.hadoop.hbase.master.ServerManager

@InterfaceAudience.Private
public class ServerManager
extends Object

The ServerManager class manages info about region servers.

Maintains lists of online and dead servers. Processes the startups, shutdowns, and deaths of region servers.

Servers are distinguished in two different ways. A given server has a location, specified by hostname and port, and of which there can only be one online at any given time. A server instance is specified by the location (hostname and port) as well as the startcode (timestamp from when the server was started). This is used to differentiate a restarted instance of a given server from the original instance.

If a sever is known not to be running any more, it is called dead. The dead server needs to be handled by a ServerShutdownHandler. If the handler is not enabled yet, the server can't be handled right away so it is queued up. After the handler is enabled, the server will be submitted to a handler to handle. However, the handler may be just partially enabled. If so, the server cannot be fully processed, and be queued up for further processing. A server is fully processed only after the handler is fully enabled and has completed the handling.


Field Summary
static String WAIT_ON_REGIONSERVERS_INTERVAL
           
static String WAIT_ON_REGIONSERVERS_MAXTOSTART
           
static String WAIT_ON_REGIONSERVERS_MINTOSTART
           
static String WAIT_ON_REGIONSERVERS_TIMEOUT
           
 
Constructor Summary
ServerManager(Server master, MasterServices services)
          Constructor.
 
Method Summary
 boolean addServerToDrainList(ServerName sn)
           
 boolean areDeadServersInProgress()
          Checks if any dead servers are currently in progress.
 List<ServerName> createDestinationServersList()
          Calls createDestinationServersList(org.apache.hadoop.hbase.ServerName) without server to exclude.
 List<ServerName> createDestinationServersList(ServerName serverToExclude)
          Creates a list of possible destinations for a region.
 void expireServer(ServerName serverName)
           
 double getAverageLoad()
          Compute the average load across all region servers.
 DeadServer getDeadServers()
           
 List<ServerName> getDrainingServersList()
           
 long getLastFlushedSequenceId(byte[] encodedRegionName)
           
 ServerLoad getLoad(ServerName serverName)
           
 Map<ServerName,ServerLoad> getOnlineServers()
           
 List<ServerName> getOnlineServersList()
           
 boolean isClusterShutdown()
           
 boolean isServerDead(ServerName serverName)
          Check if a server is known to be dead.
 boolean isServerOnline(ServerName serverName)
           
 boolean isServerReachable(ServerName server)
          Check if a region server is reachable and has the expected start code
 void processDeadServer(ServerName serverName)
           
 void processDeadServer(ServerName serverName, boolean shouldSplitHlog)
           
 void registerListener(ServerListener listener)
          Add the listener to the notification list.
 boolean removeServerFromDrainList(ServerName sn)
           
 boolean sendRegionClose(ServerName server, HRegionInfo region, int versionOfClosingNode)
           
 boolean sendRegionClose(ServerName server, HRegionInfo region, int versionOfClosingNode, ServerName dest, boolean transitionInZK)
          Sends an CLOSE RPC to the specified server to close the specified region.
 RegionOpeningState sendRegionOpen(ServerName server, HRegionInfo region, int versionOfOfflineNode, List<ServerName> favoredNodes)
          Sends an OPEN RPC to the specified server to open the specified region.
 List<RegionOpeningState> sendRegionOpen(ServerName server, List<Triple<HRegionInfo,Integer,List<ServerName>>> regionOpenInfos)
          Sends an OPEN RPC to the specified server to open the specified region.
 void sendRegionsMerge(ServerName server, HRegionInfo region_a, HRegionInfo region_b, boolean forcible)
          Sends an MERGE REGIONS RPC to the specified server to merge the specified regions.
 void shutdownCluster()
           
 void stop()
          Stop the ServerManager.
 boolean unregisterListener(ServerListener listener)
          Remove the listener from the notification list.
 void waitForRegionServers(MonitoredTask status)
          Wait for the region servers to report in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WAIT_ON_REGIONSERVERS_MAXTOSTART

public static final String WAIT_ON_REGIONSERVERS_MAXTOSTART
See Also:
Constant Field Values

WAIT_ON_REGIONSERVERS_MINTOSTART

public static final String WAIT_ON_REGIONSERVERS_MINTOSTART
See Also:
Constant Field Values

WAIT_ON_REGIONSERVERS_TIMEOUT

public static final String WAIT_ON_REGIONSERVERS_TIMEOUT
See Also:
Constant Field Values

WAIT_ON_REGIONSERVERS_INTERVAL

public static final String WAIT_ON_REGIONSERVERS_INTERVAL
See Also:
Constant Field Values
Constructor Detail

ServerManager

public ServerManager(Server master,
                     MasterServices services)
              throws IOException
Constructor.

Parameters:
master -
services -
Throws:
ZooKeeperConnectionException
IOException
Method Detail

registerListener

public void registerListener(ServerListener listener)
Add the listener to the notification list.

Parameters:
listener - The ServerListener to register

unregisterListener

public boolean unregisterListener(ServerListener listener)
Remove the listener from the notification list.

Parameters:
listener - The ServerListener to unregister

getLastFlushedSequenceId

public long getLastFlushedSequenceId(byte[] encodedRegionName)

getLoad

public ServerLoad getLoad(ServerName serverName)
Parameters:
serverName -
Returns:
ServerLoad if serverName is known else null

getAverageLoad

public double getAverageLoad()
Compute the average load across all region servers. Currently, this uses a very naive computation - just uses the number of regions being served, ignoring stats about number of requests.

Returns:
the average load

getOnlineServers

public Map<ServerName,ServerLoad> getOnlineServers()
Returns:
Read-only map of servers to serverinfo

getDeadServers

public DeadServer getDeadServers()

areDeadServersInProgress

public boolean areDeadServersInProgress()
Checks if any dead servers are currently in progress.

Returns:
true if any RS are being processed as dead, false if not

expireServer

public void expireServer(ServerName serverName)

processDeadServer

public void processDeadServer(ServerName serverName)

processDeadServer

public void processDeadServer(ServerName serverName,
                              boolean shouldSplitHlog)

removeServerFromDrainList

public boolean removeServerFromDrainList(ServerName sn)

addServerToDrainList

public boolean addServerToDrainList(ServerName sn)

sendRegionOpen

public RegionOpeningState sendRegionOpen(ServerName server,
                                         HRegionInfo region,
                                         int versionOfOfflineNode,
                                         List<ServerName> favoredNodes)
                                  throws IOException
Sends an OPEN RPC to the specified server to open the specified region.

Open should not fail but can if server just crashed.

Parameters:
server - server to open a region
region - region to open
versionOfOfflineNode - that needs to be present in the offline node when RS tries to change the state from OFFLINE to other states.
favoredNodes -
Throws:
IOException

sendRegionOpen

public List<RegionOpeningState> sendRegionOpen(ServerName server,
                                               List<Triple<HRegionInfo,Integer,List<ServerName>>> regionOpenInfos)
                                        throws IOException
Sends an OPEN RPC to the specified server to open the specified region.

Open should not fail but can if server just crashed.

Parameters:
server - server to open a region
regionOpenInfos - info of a list of regions to open
Returns:
a list of region opening states
Throws:
IOException

sendRegionClose

public boolean sendRegionClose(ServerName server,
                               HRegionInfo region,
                               int versionOfClosingNode,
                               ServerName dest,
                               boolean transitionInZK)
                        throws IOException
Sends an CLOSE RPC to the specified server to close the specified region.

A region server could reject the close request because it either does not have the specified region or the region is being split.

Parameters:
server - server to open a region
region - region to open
versionOfClosingNode - the version of znode to compare when RS transitions the znode from CLOSING state.
dest - - if the region is moved to another server, the destination server. null otherwise.
Returns:
true if server acknowledged close, false if not
Throws:
IOException

sendRegionClose

public boolean sendRegionClose(ServerName server,
                               HRegionInfo region,
                               int versionOfClosingNode)
                        throws IOException
Throws:
IOException

sendRegionsMerge

public void sendRegionsMerge(ServerName server,
                             HRegionInfo region_a,
                             HRegionInfo region_b,
                             boolean forcible)
                      throws IOException
Sends an MERGE REGIONS RPC to the specified server to merge the specified regions.

A region server could reject the close request because it either does not have the specified region.

Parameters:
server - server to merge regions
region_a - region to merge
region_b - region to merge
forcible - true if do a compulsory merge, otherwise we will only merge two adjacent regions
Throws:
IOException

isServerReachable

public boolean isServerReachable(ServerName server)
Check if a region server is reachable and has the expected start code


waitForRegionServers

public void waitForRegionServers(MonitoredTask status)
                          throws InterruptedException
Wait for the region servers to report in. We will wait until one of this condition is met: - the master is stopped - the 'hbase.master.wait.on.regionservers.maxtostart' number of region servers is reached - the 'hbase.master.wait.on.regionservers.mintostart' is reached AND there have been no new region server in for 'hbase.master.wait.on.regionservers.interval' time AND the 'hbase.master.wait.on.regionservers.timeout' is reached

Throws:
InterruptedException

getOnlineServersList

public List<ServerName> getOnlineServersList()
Returns:
A copy of the internal list of online servers.

getDrainingServersList

public List<ServerName> getDrainingServersList()
Returns:
A copy of the internal list of draining servers.

isServerOnline

public boolean isServerOnline(ServerName serverName)

isServerDead

public boolean isServerDead(ServerName serverName)
Check if a server is known to be dead. A server can be online, or known to be dead, or unknown to this manager (i.e, not online, not known to be dead either. it is simply not tracked by the master any more, for example, a very old previous instance).


shutdownCluster

public void shutdownCluster()

isClusterShutdown

public boolean isClusterShutdown()

stop

public void stop()
Stop the ServerManager. Currently closes the connection to the master.


createDestinationServersList

public List<ServerName> createDestinationServersList(ServerName serverToExclude)
Creates a list of possible destinations for a region. It contains the online servers, but not the draining or dying servers.

Parameters:
serverToExclude - can be null if there is no server to exclude

createDestinationServersList

public List<ServerName> createDestinationServersList()
Calls createDestinationServersList(org.apache.hadoop.hbase.ServerName) without server to exclude.



Copyright © 2007–2015 The Apache Software Foundation. All rights reserved.