org.apache.hadoop.hbase.regionserver
Class HRegionServer

java.lang.Object
  extended by org.apache.hadoop.hbase.regionserver.HRegionServer
All Implemented Interfaces:
Runnable, HBaseRPCErrorHandler, PriorityFunction, AdminProtos.AdminService.BlockingInterface, ClientProtos.ClientService.BlockingInterface, LastSequenceId, RegionServerServices

@InterfaceAudience.Private
public class HRegionServer
extends Object
implements ClientProtos.ClientService.BlockingInterface, AdminProtos.AdminService.BlockingInterface, Runnable, RegionServerServices, HBaseRPCErrorHandler, LastSequenceId

HRegionServer makes a set of HRegions available to clients. It checks in with the HMaster. There are many HRegionServers in a single HBase deployment.


Nested Class Summary
protected static class HRegionServer.MovedRegionsCleaner
          Creates a Chore thread to clean the moved region cache.
protected static interface HRegionServer.QosPriority
           
 
Field Summary
protected  boolean abortRequested
           
protected  org.apache.hadoop.hbase.regionserver.MemStoreFlusher cacheFlusher
           
protected  CatalogTracker catalogTracker
           
protected static String CLOSE
           
 CompactSplitThread compactSplitThread
           
protected  org.apache.hadoop.conf.Configuration conf
           
protected  HFileSystem fs
           
protected  boolean fsOk
           
protected  HLog hlog
           
protected  HLog hlogForMeta
           
protected  HeapMemoryManager hMemManager
           
protected  boolean isOnline
           
protected  Leases leases
           
protected  ReentrantReadWriteLock lock
           
static org.apache.commons.logging.Log LOG
           
protected  long maxScannerResultSize
           
protected  Map<String,org.apache.hadoop.hbase.regionserver.HRegionServer.MovedRegionInfo> movedRegions
           
protected  int numRegionsToReport
           
protected  Map<String,HRegion> onlineRegions
          Map of regions currently being served by this region server.
protected static String OPEN
           
protected  Map<String,HRegion> recoveringRegions
          Set of regions currently being in recovering state which means it can accept writes(edits from previous failed region server) but not reads.
static String REGION_SERVER_RPC_SCHEDULER_FACTORY_CLASS
          RPC scheduler to use for the region server.
protected  Map<String,InetSocketAddress[]> regionFavoredNodesMap
          Map of encoded region names to the DataNode locations they should be hosted on We store the value as InetSocketAddress since this is used only in HDFS API (create() that takes favored nodes as hints for placing file blocks).
static String REGIONSERVER
          region server process name
static String REGIONSERVER_CONF
          region server configuration name
protected  ConcurrentMap<byte[],Boolean> regionsInTransitionInRS
           
protected  ReplicationSinkService replicationSinkHandler
           
protected  ReplicationSourceService replicationSourceHandler
           
protected  ExecutorService service
           
protected  boolean stopped
           
protected  TableDescriptors tableDescriptors
          Go here to get table descriptors.
protected  int threadWakeFrequency
           
 
Constructor Summary
HRegionServer(org.apache.hadoop.conf.Configuration conf)
          Starts a HRegionServer at the default location
 
Method Summary
 void abort(String reason)
           
 void abort(String reason, Throwable cause)
          Cause the server to exit without closing the regions it is serving, the log it is using and without notifying the master.
protected  long addScanner(RegionScanner s, HRegion r)
           
protected  void addToMovedRegions(String encodedName, ServerName destination, long closeSeqNum)
           
 void addToOnlineRegions(HRegion region)
          Add to online regions.
protected  Result append(HRegion region, ClientProtos.MutationProto m, CellScanner cellScanner, long nonceGroup)
          Execute an append mutation.
 ClientProtos.BulkLoadHFileResponse bulkLoadHFile(com.google.protobuf.RpcController controller, ClientProtos.BulkLoadHFileRequest request)
          Atomically bulk load several HFiles into an open region
 boolean checkFileSystem()
          Checks to see if the file system is still accessible.
 boolean checkOOME(Throwable e)
          Take actions on the event of an OutOfMemoryError.
protected  void checkOpen()
          Called to verify that this server is up and running.
protected  void cleanMovedRegions()
          Remove the expired entries from the moved regions list.
protected  Throwable cleanup(Throwable t)
           
protected  Throwable cleanup(Throwable t, String msg)
           
protected  void closeAllRegions(boolean abort)
          Closes all regions.
 AdminProtos.CloseRegionResponse closeRegion(com.google.protobuf.RpcController controller, AdminProtos.CloseRegionRequest request)
          Close a region on the region server.
protected  boolean closeRegion(String encodedName, boolean abort, boolean zk, int versionOfClosingNode, ServerName sn)
          Close asynchronously a region, can be called from the master or internally by the regionserver when stopping.
 AdminProtos.CompactRegionResponse compactRegion(com.google.protobuf.RpcController controller, AdminProtos.CompactRegionRequest request)
          Compact a region on the region server.
static HRegionServer constructRegionServer(Class<? extends HRegionServer> regionServerClass, org.apache.hadoop.conf.Configuration conf2)
          Utility for constructing an instance of the passed HRegionServer class.
protected  IOException convertThrowableToIOE(Throwable t, String msg)
           
 ClusterStatusProtos.RegionLoad createRegionLoad(String encodedRegionName)
           
protected  ServerName createRegionServerStatusStub()
          Get the current master from ZooKeeper and open the RPC connection to it.
protected  void doBatchOp(ClientProtos.RegionActionResult.Builder builder, HRegion region, List<ClientProtos.Action> mutations, CellScanner cells)
          Execute a list of Put/Delete mutations.
protected  OperationStatus[] doReplayBatchOp(HRegion region, List<HLogSplitter.MutationReplay> mutations)
          Execute a list of Put/Delete mutations.
 ClientProtos.CoprocessorServiceResponse execRegionServerService(com.google.protobuf.RpcController controller, ClientProtos.CoprocessorServiceRequest serviceRequest)
           
 ClientProtos.CoprocessorServiceResponse execService(com.google.protobuf.RpcController controller, ClientProtos.CoprocessorServiceRequest request)
           
 AdminProtos.FlushRegionResponse flushRegion(com.google.protobuf.RpcController controller, AdminProtos.FlushRegionRequest request)
          Flush a region on the region server.
 ClientProtos.GetResponse get(com.google.protobuf.RpcController controller, ClientProtos.GetRequest request)
          Get data from a table.
 CacheConfig getCacheConfig()
           
 CatalogTracker getCatalogTracker()
           
 double getCompactionPressure()
           
 CompactionRequestor getCompactionRequester()
           
 CompactSplitThread getCompactSplitThread()
           
 org.apache.hadoop.conf.Configuration getConfiguration()
          Gets the configuration object for this server.
 RegionServerCoprocessorHost getCoprocessorHost()
           
 String[] getCoprocessors()
           
 ExecutorService getExecutorService()
           
 InetSocketAddress[] getFavoredNodesForRegion(String encodedRegionName)
          Return the favored nodes for a region given its encoded name.
 org.apache.hadoop.fs.FileSystem getFileSystem()
           
 FlushRequester getFlushRequester()
           
 HRegion getFromOnlineRegions(String encodedRegionName)
          Return HRegion instance.
 HeapMemoryManager getHeapMemoryManager()
           
static String getHostname(org.apache.hadoop.conf.Configuration conf)
           
 InfoServer getInfoServer()
           
 long getLastSequenceId(byte[] encodedRegionName)
           
 Leases getLeases()
           
protected  org.apache.hadoop.hbase.regionserver.LogRoller getLogRoller()
           
 MasterAddressTracker getMasterAddressTracker()
           
protected  List<WALActionsListener> getMetaWALActionListeners()
           
 MetricsRegionServer getMetrics()
           
protected  HRegionInfo[] getMostLoadedRegions()
          Get the top N most loaded regions this server is serving so we can tell the master which regions it can reallocate if we're overloaded.
 ServerNonceManager getNonceManager()
          Only required for "old" log replay; if it's removed, remove this.
 int getNumberOfOnlineRegions()
           
 HRegion getOnlineRegion(byte[] regionName)
           
 AdminProtos.GetOnlineRegionResponse getOnlineRegion(com.google.protobuf.RpcController controller, AdminProtos.GetOnlineRegionRequest request)
           
 List<HRegion> getOnlineRegions(TableName tableName)
          Gets the online regions of the specified table.
 Collection<HRegion> getOnlineRegionsLocalContext()
          For tests, web ui and metrics.
 int getPriority(RPCProtos.RequestHeader header, com.google.protobuf.Message param)
           
 Map<String,HRegion> getRecoveringRegions()
           
protected  HRegion getRegion(byte[] regionName)
          Protected utility method for safely obtaining an HRegion handle.
protected  HRegion getRegion(HBaseProtos.RegionSpecifier regionSpecifier)
          Find the HRegion based on a region specifier
 InetSocketAddress[] getRegionBlockLocations(String encodedRegionName)
           
protected  HRegion getRegionByEncodedName(byte[] regionName, String encodedRegionName)
           
protected  HRegion getRegionByEncodedName(String encodedRegionName)
           
 AdminProtos.GetRegionInfoResponse getRegionInfo(com.google.protobuf.RpcController controller, AdminProtos.GetRegionInfoRequest request)
           
 RegionServerAccounting getRegionServerAccounting()
           
 ConcurrentMap<byte[],Boolean> getRegionsInTransitionInRS()
          Get the regions that are currently being opened or closed in the RS
 ReplicationSinkService getReplicationSinkService()
           
 ReplicationSourceService getReplicationSourceService()
           
protected  org.apache.hadoop.fs.Path getRootDir()
           
 RpcServerInterface getRpcServer()
          Returns a reference to the region server's RPC server
 AdminProtos.GetServerInfoResponse getServerInfo(com.google.protobuf.RpcController controller, AdminProtos.GetServerInfoRequest request)
          Get some information of the region server.
 ServerName getServerName()
           
 long getStartcode()
           
 AdminProtos.GetStoreFileResponse getStoreFile(com.google.protobuf.RpcController controller, AdminProtos.GetStoreFileRequest request)
           
 TableLockManager getTableLockManager()
           
 int getThreadWakeFrequency()
          Interval at which threads should run
 HLog getWAL()
           
 HLog getWAL(HRegionInfo regionInfo)
           
protected  List<WALActionsListener> getWALActionListeners()
          Called by instantiateHLog(Path, String) setting up WAL instance.
 ZooKeeperWatcher getZooKeeper()
          Gets the ZooKeeper instance for this server.
 ZooKeeperWatcher getZooKeeperWatcher()
           
protected  void handleReportForDutyResponse(RegionServerStatusProtos.RegionServerStartupResponse c)
           
protected  Result increment(HRegion region, ClientProtos.MutationProto mutation, CellScanner cells, long nonceGroup)
          Execute an increment mutation.
protected  HLog instantiateHLog(org.apache.hadoop.fs.Path rootdir, String logName)
          Called by setupWALAndReplication() creating WAL instance.
 boolean isAborted()
          Check if the server or client was aborted.
 boolean isOnline()
          Report the status of the server.
 boolean isStopped()
           
 boolean isStopping()
           
protected  void join()
          Wait on all threads to finish.
protected  void kill()
           
static void main(String[] args)
           
 AdminProtos.MergeRegionsResponse mergeRegions(com.google.protobuf.RpcController controller, AdminProtos.MergeRegionsRequest request)
          Merge regions on the region server.
 ClientProtos.MultiResponse multi(com.google.protobuf.RpcController rpcc, ClientProtos.MultiRequest request)
          Execute multiple actions on a table: get, mutate, and/or execCoprocessor
 ClientProtos.MutateResponse mutate(com.google.protobuf.RpcController rpcc, ClientProtos.MutateRequest request)
          Mutate data in a table.
protected  ClientProtos.RegionLoadStats mutateRows(HRegion region, List<ClientProtos.Action> actions, CellScanner cellScanner)
          Mutate a list of rows atomically.
 AdminProtos.OpenRegionResponse openRegion(com.google.protobuf.RpcController controller, AdminProtos.OpenRegionRequest request)
          Open asynchronously a region or a set of regions on the region server.
 void postOpenDeployTasks(HRegion r, CatalogTracker ct)
          Tasks to perform after region open to complete deploy of region on regionserver
 boolean registerService(com.google.protobuf.Service instance)
          Registers a new protocol buffer Service subclass as a coprocessor endpoint to be available for handling
 boolean removeFromOnlineRegions(HRegion r, ServerName destination)
          This method removes HRegion corresponding to hri from the Map of onlineRegions.
 AdminProtos.ReplicateWALEntryResponse replay(com.google.protobuf.RpcController controller, AdminProtos.ReplicateWALEntryRequest request)
          Replay the given changes when distributedLogReplay WAL edits from a failed RS.
 AdminProtos.ReplicateWALEntryResponse replicateWALEntry(com.google.protobuf.RpcController controller, AdminProtos.ReplicateWALEntryRequest request)
          Replicate WAL entries on the region server.
 boolean reportRegionStateTransition(RegionServerStatusProtos.RegionStateTransition.TransitionCode code, HRegionInfo... hris)
          Notify master that a handler requests to change a region state
 boolean reportRegionStateTransition(RegionServerStatusProtos.RegionStateTransition.TransitionCode code, long openSeqNum, HRegionInfo... hris)
          Notify master that a handler requests to change a region state
 AdminProtos.RollWALWriterResponse rollWALWriter(com.google.protobuf.RpcController controller, AdminProtos.RollWALWriterRequest request)
          Roll the WAL writer of the region server.
 void run()
          The HRegionServer sticks in this loop until closed.
 ClientProtos.ScanResponse scan(com.google.protobuf.RpcController controller, ClientProtos.ScanRequest request)
          Scan data in a table.
 AdminProtos.SplitRegionResponse splitRegion(com.google.protobuf.RpcController controller, AdminProtos.SplitRegionRequest request)
          Split a region on the region server.
static Thread startRegionServer(HRegionServer hrs)
           
static Thread startRegionServer(HRegionServer hrs, String name)
           
 void stop(String msg)
          Stop this service.
 AdminProtos.StopServerResponse stopServer(com.google.protobuf.RpcController controller, AdminProtos.StopServerRequest request)
          Stop the region server.
 String toString()
           
protected  void tryRegionServerReport(long reportStartTime, long reportEndTime)
           
 AdminProtos.UpdateFavoredNodesResponse updateFavoredNodes(com.google.protobuf.RpcController controller, AdminProtos.UpdateFavoredNodesRequest request)
           
 void updateRegionFavoredNodesMapping(String encodedRegionName, List<HBaseProtos.ServerName> favoredNodes)
          Used to update the favored nodes mapping when required.
 void waitForServerOnline()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.commons.logging.Log LOG

OPEN

protected static final String OPEN
See Also:
Constant Field Values

CLOSE

protected static final String CLOSE
See Also:
Constant Field Values

regionsInTransitionInRS

protected final ConcurrentMap<byte[],Boolean> regionsInTransitionInRS

REGION_SERVER_RPC_SCHEDULER_FACTORY_CLASS

public static final String REGION_SERVER_RPC_SCHEDULER_FACTORY_CLASS
RPC scheduler to use for the region server.

See Also:
Constant Field Values

maxScannerResultSize

protected long maxScannerResultSize

cacheFlusher

protected org.apache.hadoop.hbase.regionserver.MemStoreFlusher cacheFlusher

hMemManager

protected HeapMemoryManager hMemManager

catalogTracker

protected CatalogTracker catalogTracker

tableDescriptors

protected TableDescriptors tableDescriptors
Go here to get table descriptors.


replicationSourceHandler

protected ReplicationSourceService replicationSourceHandler

replicationSinkHandler

protected ReplicationSinkService replicationSinkHandler

compactSplitThread

public CompactSplitThread compactSplitThread

onlineRegions

protected final Map<String,HRegion> onlineRegions
Map of regions currently being served by this region server. Key is the encoded region name. All access should be synchronized.


regionFavoredNodesMap

protected final Map<String,InetSocketAddress[]> regionFavoredNodesMap
Map of encoded region names to the DataNode locations they should be hosted on We store the value as InetSocketAddress since this is used only in HDFS API (create() that takes favored nodes as hints for placing file blocks). We could have used ServerName here as the value class, but we'd need to convert it to InetSocketAddress at some point before the HDFS API call, and it seems a bit weird to store ServerName since ServerName refers to RegionServers and here we really mean DataNode locations.


recoveringRegions

protected final Map<String,HRegion> recoveringRegions
Set of regions currently being in recovering state which means it can accept writes(edits from previous failed region server) but not reads. A recovering region is also an online region.


leases

protected Leases leases

service

protected ExecutorService service

fsOk

protected volatile boolean fsOk

fs

protected HFileSystem fs

stopped

protected volatile boolean stopped

abortRequested

protected volatile boolean abortRequested

conf

protected final org.apache.hadoop.conf.Configuration conf

lock

protected final ReentrantReadWriteLock lock

threadWakeFrequency

protected final int threadWakeFrequency

numRegionsToReport

protected final int numRegionsToReport

REGIONSERVER

public static final String REGIONSERVER
region server process name

See Also:
Constant Field Values

REGIONSERVER_CONF

public static final String REGIONSERVER_CONF
region server configuration name

See Also:
Constant Field Values

hlog

protected volatile HLog hlog

hlogForMeta

protected volatile HLog hlogForMeta

isOnline

protected volatile boolean isOnline

movedRegions

protected Map<String,org.apache.hadoop.hbase.regionserver.HRegionServer.MovedRegionInfo> movedRegions
Constructor Detail

HRegionServer

public HRegionServer(org.apache.hadoop.conf.Configuration conf)
              throws IOException,
                     InterruptedException
Starts a HRegionServer at the default location

Parameters:
conf -
Throws:
IOException
InterruptedException
Method Detail

getHostname

public static String getHostname(org.apache.hadoop.conf.Configuration conf)
                          throws UnknownHostException
Throws:
UnknownHostException

registerService

public boolean registerService(com.google.protobuf.Service instance)
Description copied from interface: RegionServerServices
Registers a new protocol buffer Service subclass as a coprocessor endpoint to be available for handling

Specified by:
registerService in interface RegionServerServices
Returns:
true if the registration was successful, false

getPriority

public int getPriority(RPCProtos.RequestHeader header,
                       com.google.protobuf.Message param)
Specified by:
getPriority in interface PriorityFunction
Returns:
Priority of this request.

run

public void run()
The HRegionServer sticks in this loop until closed.

Specified by:
run in interface Runnable

tryRegionServerReport

protected void tryRegionServerReport(long reportStartTime,
                                     long reportEndTime)
                              throws IOException
Throws:
IOException

handleReportForDutyResponse

protected void handleReportForDutyResponse(RegionServerStatusProtos.RegionServerStartupResponse c)
                                    throws IOException
Throws:
IOException

getRegionServerAccounting

public RegionServerAccounting getRegionServerAccounting()
Specified by:
getRegionServerAccounting in interface RegionServerServices
Returns:
the RegionServerAccounting for this Region Server

getTableLockManager

public TableLockManager getTableLockManager()
Specified by:
getTableLockManager in interface RegionServerServices
Returns:
RegionServer's instance of TableLockManager

createRegionLoad

public ClusterStatusProtos.RegionLoad createRegionLoad(String encodedRegionName)
Parameters:
encodedRegionName -
Returns:
An instance of RegionLoad.

isOnline

public boolean isOnline()
Report the status of the server. A server is online once all the startup is completed (setting up filesystem, starting service threads, etc.). This method is designed mostly to be useful in tests.

Returns:
true if online, false if not.

instantiateHLog

protected HLog instantiateHLog(org.apache.hadoop.fs.Path rootdir,
                               String logName)
                        throws IOException
Called by setupWALAndReplication() creating WAL instance.

Parameters:
rootdir -
logName -
Returns:
WAL instance.
Throws:
IOException

getWALActionListeners

protected List<WALActionsListener> getWALActionListeners()
Called by instantiateHLog(Path, String) setting up WAL instance. Add any WALActionsListeners you want inserted before WAL startup.

Returns:
List of WALActionsListener that will be passed in to FSHLog on construction.

getMetaWALActionListeners

protected List<WALActionsListener> getMetaWALActionListeners()

getLogRoller

protected org.apache.hadoop.hbase.regionserver.LogRoller getLogRoller()

getMetrics

public MetricsRegionServer getMetrics()

getMasterAddressTracker

public MasterAddressTracker getMasterAddressTracker()
Returns:
Master address tracker instance.

getWAL

public HLog getWAL()

getWAL

public HLog getWAL(HRegionInfo regionInfo)
            throws IOException
Specified by:
getWAL in interface RegionServerServices
Returns:
the HLog for a particular region. Pass null for getting the default (common) WAL
Throws:
IOException

getCatalogTracker

public CatalogTracker getCatalogTracker()
Specified by:
getCatalogTracker in interface RegionServerServices
Returns:
The RegionServer's CatalogTracker

stop

public void stop(String msg)
Description copied from interface: Stoppable
Stop this service.

Parameters:
msg - Why we're stopping.

waitForServerOnline

public void waitForServerOnline()

postOpenDeployTasks

public void postOpenDeployTasks(HRegion r,
                                CatalogTracker ct)
                         throws org.apache.zookeeper.KeeperException,
                                IOException
Description copied from interface: RegionServerServices
Tasks to perform after region open to complete deploy of region on regionserver

Specified by:
postOpenDeployTasks in interface RegionServerServices
Parameters:
r - Region to open.
ct - Instance of CatalogTracker
Throws:
org.apache.zookeeper.KeeperException
IOException

getRpcServer

public RpcServerInterface getRpcServer()
Description copied from interface: RegionServerServices
Returns a reference to the region server's RPC server

Specified by:
getRpcServer in interface RegionServerServices

abort

public void abort(String reason,
                  Throwable cause)
Cause the server to exit without closing the regions it is serving, the log it is using and without notifying the master. Used unit testing and on catastrophic events such as HDFS is yanked out from under hbase or we OOME.

Parameters:
reason - the reason we are aborting
cause - the exception that caused the abort, or null

abort

public void abort(String reason)
See Also:
abort(String, Throwable)

isAborted

public boolean isAborted()
Description copied from interface: Abortable
Check if the server or client was aborted.

Returns:
true if the server or client was aborted, false otherwise

kill

protected void kill()

join

protected void join()
Wait on all threads to finish. Presumption is that all closes and stops have already been called.


reportRegionStateTransition

public boolean reportRegionStateTransition(RegionServerStatusProtos.RegionStateTransition.TransitionCode code,
                                           HRegionInfo... hris)
Description copied from interface: RegionServerServices
Notify master that a handler requests to change a region state

Specified by:
reportRegionStateTransition in interface RegionServerServices

reportRegionStateTransition

public boolean reportRegionStateTransition(RegionServerStatusProtos.RegionStateTransition.TransitionCode code,
                                           long openSeqNum,
                                           HRegionInfo... hris)
Description copied from interface: RegionServerServices
Notify master that a handler requests to change a region state

Specified by:
reportRegionStateTransition in interface RegionServerServices

createRegionServerStatusStub

protected ServerName createRegionServerStatusStub()
Get the current master from ZooKeeper and open the RPC connection to it. To get a fresh connection, the current rssStub must be null. Method will block until a master is available. You can break from this block by requesting the server stop.

Returns:
master + port, or null if server has been stopped

getLastSequenceId

public long getLastSequenceId(byte[] encodedRegionName)
Specified by:
getLastSequenceId in interface LastSequenceId
Parameters:
encodedRegionName - Encoded region name
Returns:
Last flushed sequence Id for region or -1 if it can't be determined

closeAllRegions

protected void closeAllRegions(boolean abort)
Closes all regions. Called on our way out. Assumes that its not possible for new regions to be added to onlineRegions while this method runs.


getInfoServer

public InfoServer getInfoServer()
Returns:
the info server

isStopped

public boolean isStopped()
Returns:
true if a stop has been requested.

isStopping

public boolean isStopping()
Specified by:
isStopping in interface RegionServerServices
Returns:
True if this regionserver is stopping.

getRecoveringRegions

public Map<String,HRegion> getRecoveringRegions()
Specified by:
getRecoveringRegions in interface RegionServerServices
Returns:
set of recovering regions on the hosting region server

getConfiguration

public org.apache.hadoop.conf.Configuration getConfiguration()
Description copied from interface: Server
Gets the configuration object for this server.

Returns:
the configuration

getNumberOfOnlineRegions

public int getNumberOfOnlineRegions()

getOnlineRegionsLocalContext

public Collection<HRegion> getOnlineRegionsLocalContext()
For tests, web ui and metrics. This method will only work if HRegionServer is in the same JVM as client; HRegion cannot be serialized to cross an rpc.


addToOnlineRegions

public void addToOnlineRegions(HRegion region)
Add to online regions.


getStartcode

public long getStartcode()
Returns:
time stamp in millis of when this region server was started

getFlushRequester

public FlushRequester getFlushRequester()
Specified by:
getFlushRequester in interface RegionServerServices
Returns:
reference to FlushRequester

getMostLoadedRegions

protected HRegionInfo[] getMostLoadedRegions()
Get the top N most loaded regions this server is serving so we can tell the master which regions it can reallocate if we're overloaded. TODO: actually calculate which regions are most loaded. (Right now, we're just grabbing the first N regions being served regardless of load.)


getLeases

public Leases getLeases()
Specified by:
getLeases in interface RegionServerServices
Returns:
The RegionServer's "Leases" service

getRootDir

protected org.apache.hadoop.fs.Path getRootDir()
Returns:
Return the rootDir.

getFileSystem

public org.apache.hadoop.fs.FileSystem getFileSystem()
Specified by:
getFileSystem in interface RegionServerServices
Returns:
Return the fs.

toString

public String toString()
Overrides:
toString in class Object

getThreadWakeFrequency

public int getThreadWakeFrequency()
Interval at which threads should run

Returns:
the interval

getZooKeeper

public ZooKeeperWatcher getZooKeeper()
Description copied from interface: Server
Gets the ZooKeeper instance for this server.


getServerName

public ServerName getServerName()
Returns:
The unique server name for this server.

getCompactionRequester

public CompactionRequestor getCompactionRequester()
Specified by:
getCompactionRequester in interface RegionServerServices
Returns:
Implementation of CompactionRequestor or null.

getZooKeeperWatcher

public ZooKeeperWatcher getZooKeeperWatcher()

getCoprocessorHost

public RegionServerCoprocessorHost getCoprocessorHost()

getRegionsInTransitionInRS

public ConcurrentMap<byte[],Boolean> getRegionsInTransitionInRS()
Description copied from interface: RegionServerServices
Get the regions that are currently being opened or closed in the RS

Specified by:
getRegionsInTransitionInRS in interface RegionServerServices
Returns:
map of regions in transition in this RS

getExecutorService

public ExecutorService getExecutorService()
Specified by:
getExecutorService in interface RegionServerServices
Returns:
hbase executor service

startRegionServer

public static Thread startRegionServer(HRegionServer hrs)
                                throws IOException
Parameters:
hrs -
Returns:
Thread the RegionServer is running in correctly named.
Throws:
IOException

startRegionServer

public static Thread startRegionServer(HRegionServer hrs,
                                       String name)
                                throws IOException
Parameters:
hrs -
name -
Returns:
Thread the RegionServer is running in correctly named.
Throws:
IOException

constructRegionServer

public static HRegionServer constructRegionServer(Class<? extends HRegionServer> regionServerClass,
                                                  org.apache.hadoop.conf.Configuration conf2)
Utility for constructing an instance of the passed HRegionServer class.

Parameters:
regionServerClass -
conf2 -
Returns:
HRegionServer instance.

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception
See Also:
HRegionServerCommandLine

getOnlineRegions

public List<HRegion> getOnlineRegions(TableName tableName)
Gets the online regions of the specified table. This method looks at the in-memory onlineRegions. It does not go to hbase:meta. Only returns online regions. If a region on this table has been closed during a disable, etc., it will not be included in the returned list. So, the returned list may not necessarily be ALL regions in this table, its all the ONLINE regions in the table.

Parameters:
tableName -
Returns:
Online regions from tableName

getCoprocessors

public String[] getCoprocessors()

checkOpen

protected void checkOpen()
                  throws IOException
Called to verify that this server is up and running.

Throws:
IOException

closeRegion

protected boolean closeRegion(String encodedName,
                              boolean abort,
                              boolean zk,
                              int versionOfClosingNode,
                              ServerName sn)
                       throws NotServingRegionException,
                              RegionAlreadyInTransitionException
Close asynchronously a region, can be called from the master or internally by the regionserver when stopping. If called from the master, the region will update the znode status.

If an opening was in progress, this method will cancel it, but will not start a new close. The coprocessors are not called in this case. A NotServingRegionException exception is thrown.

If a close was in progress, this new request will be ignored, and an exception thrown.

Parameters:
encodedName - Region to close
abort - True if we are aborting
zk - True if we are to update zk about the region close; if the close was orchestrated by master, then update zk. If the close is being run by the regionserver because its going down, don't update zk.
versionOfClosingNode - the version of znode to compare when RS transitions the znode from CLOSING state.
Returns:
True if closed a region.
Throws:
NotServingRegionException - if the region is not online
RegionAlreadyInTransitionException - if the region is already closing

getOnlineRegion

public HRegion getOnlineRegion(byte[] regionName)
Parameters:
regionName -
Returns:
HRegion for the passed binary regionName or null if named region is not member of the online regions.

getRegionBlockLocations

public InetSocketAddress[] getRegionBlockLocations(String encodedRegionName)

getFromOnlineRegions

public HRegion getFromOnlineRegions(String encodedRegionName)
Return HRegion instance. Only works if caller is in same context, in same JVM. HRegion is not serializable.

Returns:
HRegion for the passed encoded encodedRegionName or null if named region is not member of the online regions.

removeFromOnlineRegions

public boolean removeFromOnlineRegions(HRegion r,
                                       ServerName destination)
This method removes HRegion corresponding to hri from the Map of onlineRegions.

Parameters:
r - Region to remove.
destination - Destination, if any, null otherwise.
Returns:
True if we removed a region from online list.

getRegion

protected HRegion getRegion(byte[] regionName)
                     throws NotServingRegionException
Protected utility method for safely obtaining an HRegion handle.

Parameters:
regionName - Name of online HRegion to return
Returns:
HRegion for regionName
Throws:
NotServingRegionException

getRegionByEncodedName

protected HRegion getRegionByEncodedName(String encodedRegionName)
                                  throws NotServingRegionException
Throws:
NotServingRegionException

getRegionByEncodedName

protected HRegion getRegionByEncodedName(byte[] regionName,
                                         String encodedRegionName)
                                  throws NotServingRegionException
Throws:
NotServingRegionException

cleanup

protected Throwable cleanup(Throwable t)

cleanup

protected Throwable cleanup(Throwable t,
                            String msg)

convertThrowableToIOE

protected IOException convertThrowableToIOE(Throwable t,
                                            String msg)

checkOOME

public boolean checkOOME(Throwable e)
Description copied from interface: HBaseRPCErrorHandler
Take actions on the event of an OutOfMemoryError.

Specified by:
checkOOME in interface HBaseRPCErrorHandler
Parameters:
e - the throwable
Returns:
if the server should be shut down

checkFileSystem

public boolean checkFileSystem()
Checks to see if the file system is still accessible. If not, sets abortRequested and stopRequested

Returns:
false if file system is not available

addScanner

protected long addScanner(RegionScanner s,
                          HRegion r)
                   throws Leases.LeaseStillHeldException
Throws:
Leases.LeaseStillHeldException

get

public ClientProtos.GetResponse get(com.google.protobuf.RpcController controller,
                                    ClientProtos.GetRequest request)
                             throws com.google.protobuf.ServiceException
Get data from a table.

Specified by:
get in interface ClientProtos.ClientService.BlockingInterface
Parameters:
controller - the RPC controller
request - the get request
Throws:
com.google.protobuf.ServiceException

mutate

public ClientProtos.MutateResponse mutate(com.google.protobuf.RpcController rpcc,
                                          ClientProtos.MutateRequest request)
                                   throws com.google.protobuf.ServiceException
Mutate data in a table.

Specified by:
mutate in interface ClientProtos.ClientService.BlockingInterface
Parameters:
rpcc - the RPC controller
request - the mutate request
Throws:
com.google.protobuf.ServiceException

scan

public ClientProtos.ScanResponse scan(com.google.protobuf.RpcController controller,
                                      ClientProtos.ScanRequest request)
                               throws com.google.protobuf.ServiceException
Scan data in a table.

Specified by:
scan in interface ClientProtos.ClientService.BlockingInterface
Parameters:
controller - the RPC controller
request - the scan request
Throws:
com.google.protobuf.ServiceException

bulkLoadHFile

public ClientProtos.BulkLoadHFileResponse bulkLoadHFile(com.google.protobuf.RpcController controller,
                                                        ClientProtos.BulkLoadHFileRequest request)
                                                 throws com.google.protobuf.ServiceException
Atomically bulk load several HFiles into an open region

Specified by:
bulkLoadHFile in interface ClientProtos.ClientService.BlockingInterface
Returns:
true if successful, false is failed but recoverably (no action)
Throws:
IOException - if failed unrecoverably
com.google.protobuf.ServiceException

execService

public ClientProtos.CoprocessorServiceResponse execService(com.google.protobuf.RpcController controller,
                                                           ClientProtos.CoprocessorServiceRequest request)
                                                    throws com.google.protobuf.ServiceException
Specified by:
execService in interface ClientProtos.ClientService.BlockingInterface
Throws:
com.google.protobuf.ServiceException

execRegionServerService

public ClientProtos.CoprocessorServiceResponse execRegionServerService(com.google.protobuf.RpcController controller,
                                                                       ClientProtos.CoprocessorServiceRequest serviceRequest)
                                                                throws com.google.protobuf.ServiceException
Specified by:
execRegionServerService in interface ClientProtos.ClientService.BlockingInterface
Throws:
com.google.protobuf.ServiceException

getReplicationSourceService

public ReplicationSourceService getReplicationSourceService()
Returns:
Return the object that implements the replication source service.

getReplicationSinkService

public ReplicationSinkService getReplicationSinkService()
Returns:
Return the object that implements the replication sink service.

multi

public ClientProtos.MultiResponse multi(com.google.protobuf.RpcController rpcc,
                                        ClientProtos.MultiRequest request)
                                 throws com.google.protobuf.ServiceException
Execute multiple actions on a table: get, mutate, and/or execCoprocessor

Specified by:
multi in interface ClientProtos.ClientService.BlockingInterface
Parameters:
rpcc - the RPC controller
request - the multi request
Throws:
com.google.protobuf.ServiceException

getRegionInfo

public AdminProtos.GetRegionInfoResponse getRegionInfo(com.google.protobuf.RpcController controller,
                                                       AdminProtos.GetRegionInfoRequest request)
                                                throws com.google.protobuf.ServiceException
Specified by:
getRegionInfo in interface AdminProtos.AdminService.BlockingInterface
Throws:
com.google.protobuf.ServiceException

getStoreFile

public AdminProtos.GetStoreFileResponse getStoreFile(com.google.protobuf.RpcController controller,
                                                     AdminProtos.GetStoreFileRequest request)
                                              throws com.google.protobuf.ServiceException
Specified by:
getStoreFile in interface AdminProtos.AdminService.BlockingInterface
Throws:
com.google.protobuf.ServiceException

getOnlineRegion

public AdminProtos.GetOnlineRegionResponse getOnlineRegion(com.google.protobuf.RpcController controller,
                                                           AdminProtos.GetOnlineRegionRequest request)
                                                    throws com.google.protobuf.ServiceException
Specified by:
getOnlineRegion in interface AdminProtos.AdminService.BlockingInterface
Throws:
com.google.protobuf.ServiceException

openRegion

public AdminProtos.OpenRegionResponse openRegion(com.google.protobuf.RpcController controller,
                                                 AdminProtos.OpenRegionRequest request)
                                          throws com.google.protobuf.ServiceException
Open asynchronously a region or a set of regions on the region server. The opening is coordinated by ZooKeeper, and this method requires the znode to be created before being called. As a consequence, this method should be called only from the master.

Different manages states for the region are:

Bulk assign: If there are more than 1 region to open, it will be considered as a bulk assign. For a single region opening, errors are sent through a ServiceException. For bulk assign, errors are put in the response as FAILED_OPENING.

Specified by:
openRegion in interface AdminProtos.AdminService.BlockingInterface
Parameters:
controller - the RPC controller
request - the request
Throws:
com.google.protobuf.ServiceException

updateRegionFavoredNodesMapping

public void updateRegionFavoredNodesMapping(String encodedRegionName,
                                            List<HBaseProtos.ServerName> favoredNodes)
Used to update the favored nodes mapping when required.


getFavoredNodesForRegion

public InetSocketAddress[] getFavoredNodesForRegion(String encodedRegionName)
Return the favored nodes for a region given its encoded name. Look at the comment around regionFavoredNodesMap on why it is InetSocketAddress[]

Parameters:
encodedRegionName -
Returns:
array of favored locations

closeRegion

public AdminProtos.CloseRegionResponse closeRegion(com.google.protobuf.RpcController controller,
                                                   AdminProtos.CloseRegionRequest request)
                                            throws com.google.protobuf.ServiceException
Close a region on the region server.

Specified by:
closeRegion in interface AdminProtos.AdminService.BlockingInterface
Parameters:
controller - the RPC controller
request - the request
Throws:
com.google.protobuf.ServiceException

flushRegion

public AdminProtos.FlushRegionResponse flushRegion(com.google.protobuf.RpcController controller,
                                                   AdminProtos.FlushRegionRequest request)
                                            throws com.google.protobuf.ServiceException
Flush a region on the region server.

Specified by:
flushRegion in interface AdminProtos.AdminService.BlockingInterface
Parameters:
controller - the RPC controller
request - the request
Throws:
com.google.protobuf.ServiceException

splitRegion

public AdminProtos.SplitRegionResponse splitRegion(com.google.protobuf.RpcController controller,
                                                   AdminProtos.SplitRegionRequest request)
                                            throws com.google.protobuf.ServiceException
Split a region on the region server.

Specified by:
splitRegion in interface AdminProtos.AdminService.BlockingInterface
Parameters:
controller - the RPC controller
request - the request
Throws:
com.google.protobuf.ServiceException

mergeRegions

public AdminProtos.MergeRegionsResponse mergeRegions(com.google.protobuf.RpcController controller,
                                                     AdminProtos.MergeRegionsRequest request)
                                              throws com.google.protobuf.ServiceException
Merge regions on the region server.

Specified by:
mergeRegions in interface AdminProtos.AdminService.BlockingInterface
Parameters:
controller - the RPC controller
request - the request
Returns:
merge regions response
Throws:
com.google.protobuf.ServiceException

compactRegion

public AdminProtos.CompactRegionResponse compactRegion(com.google.protobuf.RpcController controller,
                                                       AdminProtos.CompactRegionRequest request)
                                                throws com.google.protobuf.ServiceException
Compact a region on the region server.

Specified by:
compactRegion in interface AdminProtos.AdminService.BlockingInterface
Parameters:
controller - the RPC controller
request - the request
Throws:
com.google.protobuf.ServiceException

replicateWALEntry

public AdminProtos.ReplicateWALEntryResponse replicateWALEntry(com.google.protobuf.RpcController controller,
                                                               AdminProtos.ReplicateWALEntryRequest request)
                                                        throws com.google.protobuf.ServiceException
Replicate WAL entries on the region server.

Specified by:
replicateWALEntry in interface AdminProtos.AdminService.BlockingInterface
Parameters:
controller - the RPC controller
request - the request
Throws:
com.google.protobuf.ServiceException

replay

public AdminProtos.ReplicateWALEntryResponse replay(com.google.protobuf.RpcController controller,
                                                    AdminProtos.ReplicateWALEntryRequest request)
                                             throws com.google.protobuf.ServiceException
Replay the given changes when distributedLogReplay WAL edits from a failed RS. The guarantee is that the given mutations will be durable on the receiving RS if this method returns without any exception.

Specified by:
replay in interface AdminProtos.AdminService.BlockingInterface
Parameters:
controller - the RPC controller
request - the request
Throws:
com.google.protobuf.ServiceException

rollWALWriter

public AdminProtos.RollWALWriterResponse rollWALWriter(com.google.protobuf.RpcController controller,
                                                       AdminProtos.RollWALWriterRequest request)
                                                throws com.google.protobuf.ServiceException
Roll the WAL writer of the region server.

Specified by:
rollWALWriter in interface AdminProtos.AdminService.BlockingInterface
Parameters:
controller - the RPC controller
request - the request
Throws:
com.google.protobuf.ServiceException

stopServer

public AdminProtos.StopServerResponse stopServer(com.google.protobuf.RpcController controller,
                                                 AdminProtos.StopServerRequest request)
                                          throws com.google.protobuf.ServiceException
Stop the region server.

Specified by:
stopServer in interface AdminProtos.AdminService.BlockingInterface
Parameters:
controller - the RPC controller
request - the request
Throws:
com.google.protobuf.ServiceException

getServerInfo

public AdminProtos.GetServerInfoResponse getServerInfo(com.google.protobuf.RpcController controller,
                                                       AdminProtos.GetServerInfoRequest request)
                                                throws com.google.protobuf.ServiceException
Get some information of the region server.

Specified by:
getServerInfo in interface AdminProtos.AdminService.BlockingInterface
Parameters:
controller - the RPC controller
request - the request
Throws:
com.google.protobuf.ServiceException

getRegion

protected HRegion getRegion(HBaseProtos.RegionSpecifier regionSpecifier)
                     throws IOException
Find the HRegion based on a region specifier

Parameters:
regionSpecifier - the region specifier
Returns:
the corresponding region
Throws:
IOException - if the specifier is not null, but failed to find the region

append

protected Result append(HRegion region,
                        ClientProtos.MutationProto m,
                        CellScanner cellScanner,
                        long nonceGroup)
                 throws IOException
Execute an append mutation.

Parameters:
region -
m -
cellScanner -
Returns:
result to return to client if default operation should be bypassed as indicated by RegionObserver, null otherwise
Throws:
IOException

increment

protected Result increment(HRegion region,
                           ClientProtos.MutationProto mutation,
                           CellScanner cells,
                           long nonceGroup)
                    throws IOException
Execute an increment mutation.

Parameters:
region -
mutation -
Returns:
the Result
Throws:
IOException

getNonceManager

public ServerNonceManager getNonceManager()
Description copied from interface: RegionServerServices
Only required for "old" log replay; if it's removed, remove this.

Specified by:
getNonceManager in interface RegionServerServices
Returns:
The RegionServer's NonceManager

doBatchOp

protected void doBatchOp(ClientProtos.RegionActionResult.Builder builder,
                         HRegion region,
                         List<ClientProtos.Action> mutations,
                         CellScanner cells)
Execute a list of Put/Delete mutations.

Parameters:
builder -
region -
mutations -

doReplayBatchOp

protected OperationStatus[] doReplayBatchOp(HRegion region,
                                            List<HLogSplitter.MutationReplay> mutations)
                                     throws IOException
Execute a list of Put/Delete mutations. The function returns OperationStatus instead of constructing MultiResponse to save a possible loop if caller doesn't need MultiResponse.

Parameters:
region -
mutations -
Returns:
an array of OperationStatus which internally contains the OperationStatusCode and the exceptionMessage if any
Throws:
IOException

mutateRows

protected ClientProtos.RegionLoadStats mutateRows(HRegion region,
                                                  List<ClientProtos.Action> actions,
                                                  CellScanner cellScanner)
                                           throws IOException
Mutate a list of rows atomically.

Parameters:
region -
actions -
cellScanner - if non-null, the mutation data -- the Cell content.
Throws:
IOException

addToMovedRegions

protected void addToMovedRegions(String encodedName,
                                 ServerName destination,
                                 long closeSeqNum)

cleanMovedRegions

protected void cleanMovedRegions()
Remove the expired entries from the moved regions list.


getCompactSplitThread

public CompactSplitThread getCompactSplitThread()
Returns:
the underlying CompactSplitThread for the servers

updateFavoredNodes

public AdminProtos.UpdateFavoredNodesResponse updateFavoredNodes(com.google.protobuf.RpcController controller,
                                                                 AdminProtos.UpdateFavoredNodesRequest request)
                                                          throws com.google.protobuf.ServiceException
Specified by:
updateFavoredNodes in interface AdminProtos.AdminService.BlockingInterface
Throws:
com.google.protobuf.ServiceException

getCacheConfig

public CacheConfig getCacheConfig()
Returns:
The cache config instance used by the regionserver.

getHeapMemoryManager

public HeapMemoryManager getHeapMemoryManager()
Specified by:
getHeapMemoryManager in interface RegionServerServices
Returns:
heap memory manager instance

getCompactionPressure

public double getCompactionPressure()
Specified by:
getCompactionPressure in interface RegionServerServices
Returns:
the max compaction pressure of all stores on this regionserver. The value should be greater than or equal to 0.0, and any value greater than 1.0 means we enter the emergency state that some stores have too many store files.
See Also:
Store.getCompactionPressure()


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