org.apache.hadoop.hbase
Class HRegionServer

java.lang.Object
  extended by org.apache.hadoop.hbase.HRegionServer
All Implemented Interfaces:
Runnable, HConstants, HRegionInterface, VersionedProtocol

public class HRegionServer
extends Object
implements HConstants, HRegionInterface, Runnable

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  Integer cacheFlusherLock
           
protected  Configuration conf
           
protected  boolean fsOk
           
protected  ReentrantReadWriteLock lock
           
protected  HLog log
           
protected  Integer logRollerLock
           
protected  SortedMap<Text,HRegion> onlineRegions
           
static String REGIONSERVER
           
protected  Map<Text,HRegion> retiringRegions
           
protected  HServerInfo serverInfo
           
protected  Integer splitOrCompactLock
           
protected  AtomicBoolean stopRequested
           
protected  int threadWakeFrequency
           
 
Fields inherited from interface org.apache.hadoop.hbase.HConstants
ALL_VERSIONS, COL_REGIONINFO, COL_REGIONINFO_ARRAY, COL_SERVER, COL_SPLITA, COL_SPLITB, COL_STARTCODE, COLUMN_FAMILY, COLUMN_FAMILY_ARRAY, COLUMN_FAMILY_STR, DEFAULT_HBASE_DIR, DEFAULT_HOST, DEFAULT_MASTER_ADDRESS, DEFAULT_MASTER_INFOPORT, DEFAULT_MAX_FILE_SIZE, DEFAULT_REGION_SERVER_CLASS, DEFAULT_REGIONSERVER_ADDRESS, DEFAULT_REGIONSERVER_INFOPORT, EMPTY_START_ROW, EMPTY_TEXT, HBASE_DIR, HREGION_LOGDIR_NAME, HREGION_OLDLOGFILE_NAME, HREGIONDIR_PREFIX, LATEST_TIMESTAMP, MASTER_ADDRESS, META_TABLE_NAME, REGION_SERVER_CLASS, REGIONSERVER_ADDRESS, ROOT_TABLE_NAME, THREAD_WAKE_FREQUENCY, UTF8_ENCODING
 
Fields inherited from interface org.apache.hadoop.hbase.HRegionInterface
versionID
 
Constructor Summary
HRegionServer(Configuration conf)
          Starts a HRegionServer at the default location
HRegionServer(HServerAddress address, Configuration conf)
          Starts a HRegionServer at the specified location
 
Method Summary
 void batchUpdate(Text regionName, long timestamp, BatchUpdate b)
          Applies a batch of updates via one RPC
protected  boolean checkFileSystem()
          Checks to see if the file system is still accessible.
 void close(long scannerId)
          Close a scanner
protected  void commit(Text regionName, long lockid, long timestamp)
           
protected  void delete(Text regionName, long lockid, Text column)
           
 void deleteAll(Text regionName, Text row, Text column, long timestamp)
          Delete all cells that match the passed row and column and whose timestamp is equal-to or older than the passed timestamp.
protected static void doMain(String[] args, Class<? extends HRegionServer> regionServerClass)
          Do class main.
 byte[] get(Text regionName, Text row, Text column)
          Retrieve a single value from the specified region for the specified row and column keys
 byte[][] get(Text regionName, Text row, Text column, int numVersions)
          Get the specified number of versions of the specified row and column
 byte[][] get(Text regionName, Text row, Text column, long timestamp, int numVersions)
          Get the specified number of versions of the specified row and column with the specified timestamp.
 SortedMap<Text,HRegion> getOnlineRegions()
           
 long getProtocolVersion(String protocol, long clientVersion)
          Return protocol version corresponding to protocol interface.
protected  HRegion getRegion(Text regionName)
          Protected utility method for safely obtaining an HRegion handle.
protected  HRegion getRegion(Text regionName, boolean checkRetiringRegions)
          Protected utility method for safely obtaining an HRegion handle.
 HRegionInfo getRegionInfo(Text regionName)
          Get metainfo about an HRegion
protected  List<HRegion> getRegionsToCheck()
           
 AtomicInteger getRequestCount()
           
 MapWritable getRow(Text regionName, Text row)
          Get all the data for the specified row
 HServerInfo getServerInfo()
           
static void main(String[] args)
           
 MapWritable next(long scannerId)
          Get the next set of values
 long openScanner(Text regionName, Text[] cols, Text firstRow, long timestamp, RowFilterInterface filter)
          Opens a remote scanner with a RowFilter.
protected  void put(Text regionName, long lockid, Text column, byte[] val)
           
 void run()
          The HRegionServer sticks in this loop until closed.
protected  long startUpdate(Text regionName, Text row)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stopRequested

protected final AtomicBoolean stopRequested

abortRequested

protected volatile boolean abortRequested

fsOk

protected volatile boolean fsOk

serverInfo

protected final HServerInfo serverInfo

conf

protected final Configuration conf

onlineRegions

protected final SortedMap<Text,HRegion> onlineRegions

retiringRegions

protected final Map<Text,HRegion> retiringRegions

lock

protected final ReentrantReadWriteLock lock

threadWakeFrequency

protected final int threadWakeFrequency

REGIONSERVER

public static final String REGIONSERVER
See Also:
Constant Field Values

splitOrCompactLock

protected final Integer splitOrCompactLock

cacheFlusherLock

protected final Integer cacheFlusherLock

log

protected HLog log

logRollerLock

protected final Integer logRollerLock
Constructor Detail

HRegionServer

public HRegionServer(Configuration conf)
              throws IOException
Starts a HRegionServer at the default location

Parameters:
conf -
Throws:
IOException

HRegionServer

public HRegionServer(HServerAddress address,
                     Configuration conf)
              throws IOException
Starts a HRegionServer at the specified location

Parameters:
address -
conf -
Throws:
IOException
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

getRegionInfo

public HRegionInfo getRegionInfo(Text regionName)
                          throws NotServingRegionException
Get metainfo about an HRegion

Specified by:
getRegionInfo in interface HRegionInterface
Parameters:
regionName - name of the region
Returns:
HRegionInfo object for region
Throws:
NotServingRegionException

get

public byte[] get(Text regionName,
                  Text row,
                  Text column)
           throws IOException
Retrieve a single value from the specified region for the specified row and column keys

Specified by:
get in interface HRegionInterface
Parameters:
regionName - name of region
row - row key
column - column key
Returns:
alue for that region/row/column
Throws:
IOException

get

public byte[][] get(Text regionName,
                    Text row,
                    Text column,
                    int numVersions)
             throws IOException
Get the specified number of versions of the specified row and column

Specified by:
get in interface HRegionInterface
Parameters:
regionName - region name
row - row key
column - column key
numVersions - number of versions to return
Returns:
array of values
Throws:
IOException

get

public byte[][] get(Text regionName,
                    Text row,
                    Text column,
                    long timestamp,
                    int numVersions)
             throws IOException
Get the specified number of versions of the specified row and column with the specified timestamp.

Specified by:
get in interface HRegionInterface
Parameters:
regionName - region name
row - row key
column - column key
timestamp - timestamp
numVersions - number of versions to return
Returns:
array of values
Throws:
IOException

getRow

public MapWritable getRow(Text regionName,
                          Text row)
                   throws IOException
Get all the data for the specified row

Specified by:
getRow in interface HRegionInterface
Parameters:
regionName - region name
row - row key
Returns:
map of values
Throws:
IOException

next

public MapWritable next(long scannerId)
                 throws IOException
Get the next set of values

Specified by:
next in interface HRegionInterface
Parameters:
scannerId - clientId passed to openScanner
Returns:
map of values
Throws:
IOException

batchUpdate

public void batchUpdate(Text regionName,
                        long timestamp,
                        BatchUpdate b)
                 throws IOException
Applies a batch of updates via one RPC

Specified by:
batchUpdate in interface HRegionInterface
Parameters:
regionName - name of the region to update
timestamp - the time to be associated with the changes
b - BatchUpdate
Throws:
IOException

openScanner

public long openScanner(Text regionName,
                        Text[] cols,
                        Text firstRow,
                        long timestamp,
                        RowFilterInterface filter)
                 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
cols - columns to scan. If column name is a column family, all columns of the specified column family are returned. Its also possible to pass a regex for column family name. A column name is judged to be regex if it contains at least one of the following characters: \+|^&*$[]]}{)(.
firstRow - starting row to scan
timestamp - only return values whose timestamp is <= this value
filter - RowFilter for filtering results at the row-level.
Returns:
scannerId scanner identifier used in other calls
Throws:
IOException

close

public void close(long scannerId)
           throws IOException
Close a scanner

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

startUpdate

protected long startUpdate(Text regionName,
                           Text row)
                    throws IOException
Throws:
IOException

put

protected void put(Text regionName,
                   long lockid,
                   Text column,
                   byte[] val)
            throws IOException
Throws:
IOException

delete

protected void delete(Text regionName,
                      long lockid,
                      Text column)
               throws IOException
Throws:
IOException

deleteAll

public void deleteAll(Text regionName,
                      Text row,
                      Text column,
                      long timestamp)
               throws IOException
Delete all cells that match the passed row and column and whose timestamp is equal-to or older than the passed timestamp.

Specified by:
deleteAll in interface HRegionInterface
Parameters:
regionName - region name
row - row key
column - column key
timestamp - Delete all entries that have this timestamp or older
Throws:
IOException

commit

protected void commit(Text regionName,
                      long lockid,
                      long timestamp)
               throws IOException
Throws:
IOException

getServerInfo

public HServerInfo getServerInfo()
Returns:
Info on this server.

getOnlineRegions

public SortedMap<Text,HRegion> getOnlineRegions()
Returns:
Immutable list of this servers regions.

getRequestCount

public AtomicInteger getRequestCount()

getRegion

protected HRegion getRegion(Text 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

getRegion

protected HRegion getRegion(Text regionName,
                            boolean checkRetiringRegions)
                     throws NotServingRegionException
Protected utility method for safely obtaining an HRegion handle.

Parameters:
regionName - Name of online HRegion to return
checkRetiringRegions - Set true if we're to check retiring regions as well as online regions.
Returns:
HRegion for regionName
Throws:
NotServingRegionException

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

getRegionsToCheck

protected List<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
Return protocol version corresponding to protocol interface.

Specified by:
getProtocolVersion in interface VersionedProtocol
Parameters:
protocol - The classname of the protocol interface
clientVersion - The version of the protocol that the client speaks
Returns:
the version that the server will speak
Throws:
IOException

doMain

protected static void doMain(String[] args,
                             Class<? extends HRegionServer> regionServerClass)
Do class main.

Parameters:
args -
regionServerClass - HRegionServer to instantiate.

main

public static void main(String[] args)
Parameters:
args -


Copyright © 2006 The Apache Software Foundation