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  ReentrantReadWriteLock lock
           
protected  HLog log
           
protected  Integer logRollerLock
           
protected  SortedMap<Text,HRegion> onlineRegions
           
protected  Map<Text,HRegion> retiringRegions
           
protected  HServerInfo serverInfo
           
protected  long splitOrCompactCheckFrequency
           
protected  Integer splitOrCompactLock
           
protected  boolean stopRequested
           
protected  long threadWakeFrequency
           
 
Fields inherited from interface org.apache.hadoop.hbase.HConstants
COL_REGIONINFO, COL_SERVER, COL_STARTCODE, COLUMN_FAMILY, COLUMN_FAMILY_ARRAY, COMPLETE_CACHEFLUSH, DEFAULT_HBASE_DIR, DEFAULT_HOST, DEFAULT_MASTER_ADDRESS, DEFAULT_MAX_FILE_SIZE, DEFAULT_REGION_SERVER_CLASS, DEFAULT_REGIONSERVER_ADDRESS, DELETE_BYTES, HBASE_DIR, HREGION_LOGDIR_NAME, HREGION_OLDLOGFILE_NAME, HREGIONDIR_PREFIX, 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(Path rootDir, HServerAddress address, Configuration conf)
          Starts a HRegionServer at the specified location
 
Method Summary
 void abort(Text regionName, long clientid, long lockid)
          Abort a row mutation
 void batchUpdate(Text regionName, long timestamp, BatchUpdate b)
          Applies a batch of updates via one RPC
 void close(long scannerId)
          Close a scanner
 void commit(Text regionName, long clientid, long lockid, long timestamp)
          Finalize a row mutation
 void delete(Text regionName, long clientid, long lockid, Text column)
          Delete the value for a column
 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.
 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
 KeyedData[] getRow(Text regionName, Text row)
          Get all the data for the specified row
static void main(String[] args)
           
 KeyedData[] 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.
 void put(Text regionName, long clientid, long lockid, Text column, byte[] val)
          Change a value for the specified column
 void renewLease(long lockid, long clientid)
          Renew lease on update
 void run()
          The HRegionServer sticks in this loop until closed.
 long startUpdate(Text regionName, long clientid, Text row)
          Start an atomic row insertion/update.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stopRequested

protected volatile boolean stopRequested

abortRequested

protected volatile boolean abortRequested

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 long threadWakeFrequency

splitOrCompactCheckFrequency

protected final long splitOrCompactCheckFrequency

splitOrCompactLock

protected final Integer splitOrCompactLock

cacheFlusherLock

protected final Integer cacheFlusherLock

log

protected final 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(Path rootDir,
                     HServerAddress address,
                     Configuration conf)
              throws IOException
Starts a HRegionServer at the specified location

Parameters:
rootDir -
address -
conf -
Throws:
IOException
Method Detail

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

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

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

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 KeyedData[] 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:
array of values
Throws:
IOException

next

public KeyedData[] next(long scannerId)
                 throws IOException
Get the next set of values

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

startUpdate

public long startUpdate(Text regionName,
                        long clientid,
                        Text row)
                 throws IOException
Start an atomic row insertion/update. No changes are committed until the call to commit() returns. A call to abort() will abandon any updates in progress. Callers to this method are given a lease for each unique lockid; before the lease expires, either abort() or commit() must be called. If it is not called, the system will automatically call abort() on the client's behalf. The client can gain extra time with a call to renewLease(). Start an atomic row insertion or update

Specified by:
startUpdate in interface HRegionInterface
Parameters:
regionName - region name
clientid - a unique value to identify the client
row - Name of row to start update against.
Returns:
Row lockid.
Throws:
IOException

put

public void put(Text regionName,
                long clientid,
                long lockid,
                Text column,
                byte[] val)
         throws IOException
Change a value for the specified column

Specified by:
put in interface HRegionInterface
Parameters:
regionName - region name
clientid - a unique value to identify the client
lockid - lock id returned from startUpdate
column - column whose value is being set
val - new value for column
Throws:
IOException

delete

public void delete(Text regionName,
                   long clientid,
                   long lockid,
                   Text column)
            throws IOException
Delete the value for a column

Specified by:
delete in interface HRegionInterface
Parameters:
regionName - region name
clientid - a unique value to identify the client
lockid - lock id returned from startUpdate
column - name of column whose value is to be deleted
Throws:
IOException

abort

public void abort(Text regionName,
                  long clientid,
                  long lockid)
           throws IOException
Abort a row mutation

Specified by:
abort in interface HRegionInterface
Parameters:
regionName - region name
clientid - a unique value to identify the client
lockid - lock id returned from startUpdate
Throws:
IOException

commit

public void commit(Text regionName,
                   long clientid,
                   long lockid,
                   long timestamp)
            throws IOException
Finalize a row mutation

Specified by:
commit in interface HRegionInterface
Parameters:
regionName - region name
clientid - a unique value to identify the client
lockid - lock id returned from startUpdate
timestamp - the time (in milliseconds to associate with this change)
Throws:
IOException

renewLease

public void renewLease(long lockid,
                       long clientid)
                throws IOException
Renew lease on update

Specified by:
renewLease in interface HRegionInterface
Parameters:
lockid - lock id returned from startUpdate
clientid - a unique value to identify the client
Throws:
IOException

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

openScanner

public long openScanner(Text regionName,
                        Text[] cols,
                        Text firstRow,
                        long timestamp,
                        RowFilterInterface filter)
                 throws IOException
Opens a remote scanner with a RowFilter.

Specified by:
openScanner in interface HRegionInterface
Parameters:
regionName - name of region to scan
cols - columns to scan
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

main

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


Copyright © 2006 The Apache Software Foundation