org.apache.hadoop.hbase.regionserver
Class HRegionServer

java.lang.Object
  extended by org.apache.hadoop.hbase.regionserver.HRegionServer
All Implemented Interfaces:
Runnable, Abortable, HBaseRPCErrorHandler, HBaseRPCProtocolVersion, HRegionInterface, RegionServerServices, Server, Stoppable, org.apache.hadoop.ipc.VersionedProtocol

public class HRegionServer
extends Object
implements HRegionInterface, HBaseRPCErrorHandler, Runnable, RegionServerServices, Server

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


Field Summary
protected  boolean abortRequested
           
protected  org.apache.hadoop.conf.Configuration conf
           
protected  boolean fsOk
           
protected  AtomicBoolean haveRootRegion
           
protected  HLog hlog
           
protected  boolean isOnline
           
protected  ReentrantReadWriteLock lock
           
static org.apache.commons.logging.Log LOG
           
protected  int numRegionsToReport
           
protected  Map<String,HRegion> onlineRegions
          Map of regions currently being served by this region server.
static String REGIONSERVER
          region server process name
protected  HServerInfo serverInfo
           
protected  boolean stopped
           
protected  int threadWakeFrequency
           
 
Fields inherited from interface org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion
versionID
 
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 addRowLock(Integer r, HRegion region)
           
protected  long addScanner(InternalScanner s)
           
 void addToOnlineRegions(HRegion region)
          Add to online regions.
 void bulkLoadHFile(String hfilePath, byte[] regionName, byte[] familyName)
          Bulk load an HFile into an open region
 boolean checkAndDelete(byte[] regionName, byte[] row, byte[] family, byte[] qualifier, byte[] value, Delete delete)
          Atomically checks if a row/family/qualifier value match the expectedValue.
 boolean checkAndPut(byte[] regionName, byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put)
          Atomically checks if a row/family/qualifier value match the expectedValue.
protected  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.
 void close(long scannerId)
          Close a scanner
protected  void closeAllRegions(boolean abort)
          Closes all regions.
 boolean closeRegion(HRegionInfo region)
          Closes the specified region.
 boolean closeRegion(HRegionInfo region, boolean zk)
          Closes the specified region and will use or not use ZK during the close according to the specified flag.
protected  boolean closeRegion(HRegionInfo region, boolean abort, boolean zk)
           
 void compactRegion(HRegionInfo regionInfo, boolean major)
          Compacts the specified region.
static HRegionServer constructRegionServer(Class<? extends HRegionServer> regionServerClass, org.apache.hadoop.conf.Configuration conf2)
          Utility for constructing an instance of the passed HRegionServer class.
 HServerLoad.RegionLoad createRegionLoad(String encodedRegionName)
           
 void delete(byte[] regionName, Delete delete)
          Deletes all the KeyValues that match those found in the Delete object, if their ts <= to the Delete.
 int delete(byte[] regionName, List<Delete> deletes)
          Put an array of deletes into the specified region
protected  void doMetrics()
           
 boolean exists(byte[] regionName, Get get)
          Perform exists operation.
 void flushRegion(HRegionInfo regionInfo)
          Flushes the MemStore of the specified region.
 Result get(byte[] regionName, Get get)
          Perform Get operation.
 CatalogTracker getCatalogTracker()
           
 Result getClosestRowBefore(byte[] regionName, byte[] row, byte[] family)
          Return all the data for the row that matches row exactly, or the one that immediately preceeds it.
 CompactionRequestor getCompactionRequester()
           
 org.apache.hadoop.conf.Configuration getConfiguration()
          Gets the configuration object for this server.
 SortedMap<Long,HRegion> getCopyOfOnlineRegionsSortedBySize()
           
protected  org.apache.hadoop.fs.FileSystem getFileSystem()
           
 FlushRequester getFlushRequester()
           
 HRegion getFromOnlineRegions(String encodedRegionName)
          Return HRegion instance.
 long getGlobalMemStoreSize()
          Return the total size of all memstores in every region.
 HServerInfo getHServerInfo()
          Method used when a master is taking the place of another failed one.
 InfoServer getInfoServer()
           
protected  Leases getLeases()
           
protected  org.apache.hadoop.hbase.regionserver.LogRoller getLogRoller()
           
 RegionServerMetrics 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.
 int getNumberOfOnlineRegions()
           
 HRegion getOnlineRegion(byte[] regionName)
           
 List<HRegionInfo> getOnlineRegions()
           
 Collection<HRegion> getOnlineRegionsLocalContext()
          For tests and web ui.
protected  LinkedBlockingQueue<HMsg> getOutboundMsgs()
           
 long getProtocolVersion(String protocol, long clientVersion)
           
protected  HRegion getRegion(byte[] regionName)
          Protected utility method for safely obtaining an HRegion handle.
 HRegionInfo getRegionInfo(byte[] regionName)
          Get metainfo about an HRegion
 Set<byte[]> getRegionsInTransitionInRS()
          Get the regions that are currently being opened or closed in the RS
protected  Set<HRegion> getRegionsToCheck()
           
 AtomicInteger getRequestCount()
           
protected  org.apache.hadoop.fs.Path getRootDir()
           
 HBaseRpcMetrics getRpcMetrics()
          Return a reference to the metrics instance used for counting RPC calls.
 HServerInfo getServerInfo()
          Return data structure that has Server address and startcode.
 String getServerName()
          Gets the unique server name for this server.
 int getThreadWakeFrequency()
          Interval at which threads should run
 HLog getWAL()
           
protected  List<WALObserver> getWALActionListeners()
          Called by instantiateHLog(Path, Path) setting up WAL instance.
 ZooKeeperWatcher getZooKeeper()
          Gets the ZooKeeper instance for this server.
protected  void handleReportForDutyResponse(org.apache.hadoop.io.MapWritable c)
           
 Result increment(byte[] regionName, Increment increment)
          Increments one or more columns values in a row.
 long incrementColumnValue(byte[] regionName, byte[] row, byte[] family, byte[] qualifier, long amount, boolean writeToWAL)
          Atomically increments a column value.
protected  HLog instantiateHLog(org.apache.hadoop.fs.Path logdir, org.apache.hadoop.fs.Path oldLogDir)
          Called by setupWALAndReplication() creating WAL instance.
 boolean isOnline()
          Report the status of the server.
 boolean isStopped()
           
 boolean isStopping()
           
protected  void join()
          Wait on all threads to finish.
protected  void kill()
           
 long lockRow(byte[] regionName, byte[] row)
          Opens a remote row lock.
static void main(String[] args)
           
protected  void metrics()
           
 MultiResponse multi(MultiAction multi)
          Method used for doing multiple actions(Deletes, Gets and Puts) in one call
 MultiPutResponse multiPut(MultiPut puts)
          Deprecated. Use HRegionServer.multi( MultiAction action) instead
 Result next(long scannerId)
          Get the next set of values
 Result[] next(long scannerId, int nbRows)
          Get the next set of values
 void openRegion(HRegionInfo region)
          Opens the specified region.
 void openRegions(List<HRegionInfo> regions)
          Opens the specified regions.
 long openScanner(byte[] regionName, Scan scan)
          Opens a remote scanner with a RowFilter.
 void postOpenDeployTasks(HRegion r, CatalogTracker ct, boolean daughter)
          Tasks to perform after region open to complete deploy of region on regionserver
 int put(byte[] regionName, List<Put> puts)
          Put an array of puts into the specified region
 void put(byte[] regionName, Put put)
          Put data into the specified region
 boolean removeFromOnlineRegions(String encodedName)
          This method removes HRegion corresponding to hri from the Map of onlineRegions.
 void replicateLogEntries(HLog.Entry[] entries)
          Replicates the given entries.
 void run()
          The HRegionServer sticks in this loop until closed.
 void splitRegion(HRegionInfo regionInfo)
          Splits the specified region.
 void splitRegion(HRegionInfo regionInfo, byte[] splitPoint)
          Splits the specified region.
static Thread startRegionServer(HRegionServer hrs)
           
static Thread startRegionServer(HRegionServer hrs, String name)
           
 void stop(String msg)
          Stop this service.
 String toString()
           
 void unlockRow(byte[] regionName, long lockId)
          Releases a remote row lock.
 
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

stopped

protected volatile boolean stopped

abortRequested

protected volatile boolean abortRequested

fsOk

protected volatile boolean fsOk

serverInfo

protected HServerInfo serverInfo

conf

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

haveRootRegion

protected final AtomicBoolean haveRootRegion

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.


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

hlog

protected volatile HLog hlog

isOnline

protected volatile boolean isOnline
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

run

public void run()
The HRegionServer sticks in this loop until closed. It repeatedly checks in with the HMaster, sending heartbeats & reports, and receiving HRegion load/unload instructions.

Specified by:
run in interface Runnable

handleReportForDutyResponse

protected void handleReportForDutyResponse(org.apache.hadoop.io.MapWritable c)
                                    throws IOException
Throws:
IOException

createRegionLoad

public HServerLoad.RegionLoad createRegionLoad(String encodedRegionName)
Parameters:
encodedRegionName -
Returns:
An instance of RegionLoad.
Throws:
IOException

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

protected 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

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 logdir,
                               org.apache.hadoop.fs.Path oldLogDir)
                        throws IOException
Called by setupWALAndReplication() creating WAL instance.

Parameters:
logdir -
oldLogDir -
Returns:
WAL instance.
Throws:
IOException

getWALActionListeners

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

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

getLogRoller

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

doMetrics

protected void doMetrics()

metrics

protected void metrics()

getMetrics

public RegionServerMetrics getMetrics()
Returns:
Region server metrics instance.

getWAL

public HLog getWAL()
Specified by:
getWAL in interface RegionServerServices
Returns:
the HLog

getCatalogTracker

public CatalogTracker getCatalogTracker()
Specified by:
getCatalogTracker in interface Server
Returns:
Master's instance of CatalogTracker

stop

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

Specified by:
stop in interface Stoppable
Parameters:
msg - Why we're stopping.

postOpenDeployTasks

public void postOpenDeployTasks(HRegion r,
                                CatalogTracker ct,
                                boolean daughter)
                         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
daughter - True if this is daughter of a split
Throws:
org.apache.zookeeper.KeeperException
IOException

getRpcMetrics

public HBaseRpcMetrics getRpcMetrics()
Return a reference to the metrics instance used for counting RPC calls.

Specified by:
getRpcMetrics in interface RegionServerServices
Returns:
Metrics instance.

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.

Specified by:
abort in interface Abortable
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)

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.


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.


getRegionInfo

public HRegionInfo getRegionInfo(byte[] regionName)
                          throws NotServingRegionException,
                                 IOException
Description copied from interface: HRegionInterface
Get metainfo about an HRegion

Specified by:
getRegionInfo in interface HRegionInterface
Parameters:
regionName - name of the region
Returns:
HRegionInfo object for region
Throws:
NotServingRegionException
ConnectException
IOException - This can manifest as an Hadoop ipc RemoteException

getClosestRowBefore

public Result getClosestRowBefore(byte[] regionName,
                                  byte[] row,
                                  byte[] family)
                           throws IOException
Description copied from interface: HRegionInterface
Return all the data for the row that matches row exactly, or the one that immediately preceeds it.

Specified by:
getClosestRowBefore in interface HRegionInterface
Parameters:
regionName - region name
row - row key
family - Column family to look for row in.
Returns:
map of values
Throws:
IOException - e

get

public Result get(byte[] regionName,
                  Get get)
           throws IOException
Perform Get operation.

Specified by:
get in interface HRegionInterface
Parameters:
regionName - name of region to get from
get - Get operation
Returns:
Result
Throws:
IOException - e

exists

public boolean exists(byte[] regionName,
                      Get get)
               throws IOException
Description copied from interface: HRegionInterface
Perform exists operation.

Specified by:
exists in interface HRegionInterface
Parameters:
regionName - name of region to get from
get - Get operation describing cell to test
Returns:
true if exists
Throws:
IOException - e

put

public void put(byte[] regionName,
                Put put)
         throws IOException
Description copied from interface: HRegionInterface
Put data into the specified region

Specified by:
put in interface HRegionInterface
Parameters:
regionName - region name
put - the data to be put
Throws:
IOException - e

put

public int put(byte[] regionName,
               List<Put> puts)
        throws IOException
Description copied from interface: HRegionInterface
Put an array of puts into the specified region

Specified by:
put in interface HRegionInterface
Parameters:
regionName - region name
puts - List of puts to execute
Returns:
The number of processed put's. Returns -1 if all Puts processed successfully.
Throws:
IOException - e

checkAndPut

public boolean checkAndPut(byte[] regionName,
                           byte[] row,
                           byte[] family,
                           byte[] qualifier,
                           byte[] value,
                           Put put)
                    throws IOException
Description copied from interface: HRegionInterface
Atomically checks if a row/family/qualifier value match the expectedValue. If it does, it adds the put. If passed expected value is null, then the check is for non-existance of the row/column.

Specified by:
checkAndPut in interface HRegionInterface
Parameters:
regionName -
row -
family -
qualifier -
value - the expected value
put -
Returns:
true if the new put was execute, false otherwise
Throws:
IOException

checkAndDelete

public boolean checkAndDelete(byte[] regionName,
                              byte[] row,
                              byte[] family,
                              byte[] qualifier,
                              byte[] value,
                              Delete delete)
                       throws IOException
Description copied from interface: HRegionInterface
Atomically checks if a row/family/qualifier value match the expectedValue. If it does, it adds the delete. If passed expected value is null, then the check is for non-existance of the row/column.

Specified by:
checkAndDelete in interface HRegionInterface
Parameters:
regionName -
row -
family -
qualifier -
value - the expected value
delete -
Returns:
true if the new put was execute, false otherwise
Throws:
IOException

openScanner

public long openScanner(byte[] regionName,
                        Scan scan)
                 throws IOException
Description copied from interface: HRegionInterface
Opens a remote scanner with a RowFilter.

Specified by:
openScanner in interface HRegionInterface
Parameters:
regionName - name of region to scan
scan - configured scan object
Returns:
scannerId scanner identifier used in other calls
Throws:
IOException - e

addScanner

protected long addScanner(InternalScanner s)
                   throws Leases.LeaseStillHeldException
Throws:
Leases.LeaseStillHeldException

next

public Result next(long scannerId)
            throws IOException
Description copied from interface: HRegionInterface
Get the next set of values

Specified by:
next in interface HRegionInterface
Parameters:
scannerId - clientId passed to openScanner
Returns:
map of values; returns null if no results.
Throws:
IOException - e

next

public Result[] next(long scannerId,
                     int nbRows)
              throws IOException
Description copied from interface: HRegionInterface
Get the next set of values

Specified by:
next in interface HRegionInterface
Parameters:
scannerId - clientId passed to openScanner
nbRows - the number of rows to fetch
Returns:
Array of Results (map of values); array is empty if done with this region and null if we are NOT to go to the next region (happens when a filter rules that the scan is done).
Throws:
IOException - e

close

public void close(long scannerId)
           throws IOException
Description copied from interface: HRegionInterface
Close a scanner

Specified by:
close in interface HRegionInterface
Parameters:
scannerId - the scanner id returned by openScanner
Throws:
IOException - e

delete

public void delete(byte[] regionName,
                   Delete delete)
            throws IOException
Description copied from interface: HRegionInterface
Deletes all the KeyValues that match those found in the Delete object, if their ts <= to the Delete. In case of a delete with a specific ts it only deletes that specific KeyValue.

Specified by:
delete in interface HRegionInterface
Parameters:
regionName - region name
delete - delete object
Throws:
IOException - e

delete

public int delete(byte[] regionName,
                  List<Delete> deletes)
           throws IOException
Description copied from interface: HRegionInterface
Put an array of deletes into the specified region

Specified by:
delete in interface HRegionInterface
Parameters:
regionName - region name
deletes - delete List to execute
Returns:
The number of processed deletes. Returns -1 if all Deletes processed successfully.
Throws:
IOException - e

lockRow

public long lockRow(byte[] regionName,
                    byte[] row)
             throws IOException
Description copied from interface: HRegionInterface
Opens a remote row lock.

Specified by:
lockRow in interface HRegionInterface
Parameters:
regionName - name of region
row - row to lock
Returns:
lockId lock identifier
Throws:
IOException - e

addRowLock

protected long addRowLock(Integer r,
                          HRegion region)
                   throws Leases.LeaseStillHeldException
Throws:
Leases.LeaseStillHeldException

unlockRow

public void unlockRow(byte[] regionName,
                      long lockId)
               throws IOException
Description copied from interface: HRegionInterface
Releases a remote row lock.

Specified by:
unlockRow in interface HRegionInterface
Parameters:
regionName - region name
lockId - the lock id returned by lockRow
Throws:
IOException - e

bulkLoadHFile

public void bulkLoadHFile(String hfilePath,
                          byte[] regionName,
                          byte[] familyName)
                   throws IOException
Description copied from interface: HRegionInterface
Bulk load an HFile into an open region

Specified by:
bulkLoadHFile in interface HRegionInterface
Throws:
IOException

openRegion

public void openRegion(HRegionInfo region)
                throws IOException
Description copied from interface: HRegionInterface
Opens the specified region.

Specified by:
openRegion in interface HRegionInterface
Parameters:
region - region to open
Throws:
IOException

openRegions

public void openRegions(List<HRegionInfo> regions)
                 throws IOException
Description copied from interface: HRegionInterface
Opens the specified regions.

Specified by:
openRegions in interface HRegionInterface
Parameters:
regions - regions to open
Throws:
IOException

closeRegion

public boolean closeRegion(HRegionInfo region)
                    throws IOException
Description copied from interface: HRegionInterface
Closes the specified region.

Specified by:
closeRegion in interface HRegionInterface
Parameters:
region - region to close
Returns:
true if closing region, false if not
Throws:
IOException

closeRegion

public boolean closeRegion(HRegionInfo region,
                           boolean zk)
                    throws IOException
Description copied from interface: HRegionInterface
Closes the specified region and will use or not use ZK during the close according to the specified flag.

Specified by:
closeRegion in interface HRegionInterface
Parameters:
region - region to close
zk - true if transitions should be done in ZK, false if not
Returns:
true if closing region, false if not
Throws:
IOException

closeRegion

protected boolean closeRegion(HRegionInfo region,
                              boolean abort,
                              boolean zk)
Parameters:
region - 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.
Returns:
True if closed a region.

flushRegion

public void flushRegion(HRegionInfo regionInfo)
                 throws NotServingRegionException,
                        IOException
Description copied from interface: HRegionInterface
Flushes the MemStore of the specified region.

This method is synchronous.

Specified by:
flushRegion in interface HRegionInterface
Parameters:
regionInfo - region to flush
Throws:
NotServingRegionException
IOException

splitRegion

public void splitRegion(HRegionInfo regionInfo)
                 throws NotServingRegionException,
                        IOException
Description copied from interface: HRegionInterface
Splits the specified region.

This method currently flushes the region and then forces a compaction which will then trigger a split. The flush is done synchronously but the compaction is asynchronous.

Specified by:
splitRegion in interface HRegionInterface
Parameters:
regionInfo - region to split
Throws:
NotServingRegionException
IOException

splitRegion

public void splitRegion(HRegionInfo regionInfo,
                        byte[] splitPoint)
                 throws NotServingRegionException,
                        IOException
Description copied from interface: HRegionInterface
Splits the specified region.

This method currently flushes the region and then forces a compaction which will then trigger a split. The flush is done synchronously but the compaction is asynchronous.

Specified by:
splitRegion in interface HRegionInterface
Parameters:
regionInfo - region to split
splitPoint - the explicit row to split on
Throws:
NotServingRegionException
IOException

compactRegion

public void compactRegion(HRegionInfo regionInfo,
                          boolean major)
                   throws NotServingRegionException,
                          IOException
Description copied from interface: HRegionInterface
Compacts the specified region. Performs a major compaction if specified.

This method is asynchronous.

Specified by:
compactRegion in interface HRegionInterface
Parameters:
regionInfo - region to compact
major - true to force major compaction
Throws:
NotServingRegionException
IOException

getInfoServer

public InfoServer getInfoServer()
Returns:
the info server

isStopped

public boolean isStopped()
Specified by:
isStopped in interface Stoppable
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.

getConfiguration

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

Specified by:
getConfiguration in interface Server
Returns:
the configuration

getOnlineRegions

public List<HRegionInfo> getOnlineRegions()
Specified by:
getOnlineRegions in interface HRegionInterface
Returns:
All regions online on this region server

getNumberOfOnlineRegions

public int getNumberOfOnlineRegions()

getOnlineRegionsLocalContext

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

See Also:
getOnlineRegions()

addToOnlineRegions

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


removeFromOnlineRegions

public boolean removeFromOnlineRegions(String encodedName)
This method removes HRegion corresponding to hri from the Map of onlineRegions.

Returns:
True if we removed a region from online list.

getCopyOfOnlineRegionsSortedBySize

public SortedMap<Long,HRegion> getCopyOfOnlineRegionsSortedBySize()
Returns:
A new Map of online regions sorted by region size with the first entry being the biggest.

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.

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.

getRequestCount

public AtomicInteger getRequestCount()
Returns:
the request count

getFlushRequester

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

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

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.)


checkOpen

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

Throws:
IOException

getRegionsToCheck

protected Set<HRegion> getRegionsToCheck()
Returns:
Returns list of non-closed regions hosted on this server. If no regions to check, returns an empty list.

getProtocolVersion

public long getProtocolVersion(String protocol,
                               long clientVersion)
                        throws IOException
Specified by:
getProtocolVersion in interface org.apache.hadoop.ipc.VersionedProtocol
Throws:
IOException

getOutboundMsgs

protected LinkedBlockingQueue<HMsg> getOutboundMsgs()
Returns:
Queue to which you can add outbound messages.

getGlobalMemStoreSize

public long getGlobalMemStoreSize()
Return the total size of all memstores in every region.

Returns:
memstore size in bytes

getLeases

protected Leases getLeases()
Returns:
Return the leases.

getRootDir

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

getFileSystem

protected org.apache.hadoop.fs.FileSystem getFileSystem()
Returns:
Return the fs.

getServerInfo

public HServerInfo getServerInfo()
Description copied from interface: RegionServerServices
Return data structure that has Server address and startcode.

Specified by:
getServerInfo in interface RegionServerServices
Returns:
Info on port this server has bound to, etc.

increment

public Result increment(byte[] regionName,
                        Increment increment)
                 throws IOException
Description copied from interface: HRegionInterface
Increments one or more columns values in a row. Returns the updated keys after the increment.

This operation does not appear atomic to readers. Increments are done under a row lock but readers do not take row locks.

Specified by:
increment in interface HRegionInterface
Parameters:
regionName - region name
increment - increment operation
Returns:
incremented cells
Throws:
IOException

incrementColumnValue

public long incrementColumnValue(byte[] regionName,
                                 byte[] row,
                                 byte[] family,
                                 byte[] qualifier,
                                 long amount,
                                 boolean writeToWAL)
                          throws IOException
Atomically increments a column value. If the column value isn't long-like, this could throw an exception. If passed expected value is null, then the check is for non-existance of the row/column.

Specified by:
incrementColumnValue in interface HRegionInterface
Parameters:
regionName - region name
row - row to check
family - column family
qualifier - column qualifier
amount - long amount to increment
writeToWAL - whether to write the increment to the WAL
Returns:
new incremented column value
Throws:
IOException - e

getHServerInfo

public HServerInfo getHServerInfo()
                           throws IOException
Method used when a master is taking the place of another failed one.

Specified by:
getHServerInfo in interface HRegionInterface
Returns:
The HSI
Throws:
IOException - e

multi

public MultiResponse multi(MultiAction multi)
                    throws IOException
Description copied from interface: HRegionInterface
Method used for doing multiple actions(Deletes, Gets and Puts) in one call

Specified by:
multi in interface HRegionInterface
Returns:
MultiResult
Throws:
IOException

multiPut

public MultiPutResponse multiPut(MultiPut puts)
                          throws IOException
Deprecated. Use HRegionServer.multi( MultiAction action) instead

Description copied from interface: HRegionInterface
Multi put for putting multiple regions worth of puts at once.

Specified by:
multiPut in interface HRegionInterface
Parameters:
puts - the request
Returns:
the reply
Throws:
IOException - e

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.

Specified by:
getZooKeeper in interface Server

getServerName

public String getServerName()
Description copied from interface: Server
Gets the unique server name for this server. If a RegionServer, it returns a concatenation of hostname, port and startcode formatted as <hostname> ',' <port> ',' <startcode>. If the master, it returns <hostname> ':' <port>'.

Specified by:
getServerName in interface Server
Returns:
unique server name

getCompactionRequester

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

getRegionsInTransitionInRS

public Set<byte[]> 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:
set of regions in transition in this RS

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.

replicateLogEntries

public void replicateLogEntries(HLog.Entry[] entries)
                         throws IOException
Description copied from interface: HRegionInterface
Replicates the given entries. The guarantee is that the given entries will be durable on the slave cluster if this method returns without any exception. hbase.replication has to be set to true for this to work.

Specified by:
replicateLogEntries in interface HRegionInterface
Parameters:
entries - entries to replicate
Throws:
IOException

main

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


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.