org.apache.hadoop.hbase
Class HRegion

java.lang.Object
  extended by org.apache.hadoop.hbase.HRegion
All Implemented Interfaces:
HConstants

public class HRegion
extends Object
implements HConstants

HRegion stores data for a certain region of a table. It stores all columns for each row. A given table consists of one or more HRegions.

We maintain multiple HStores for a single HRegion.

An HStore is a set of rows with some column data; together, they make up all the data for the rows.

Each HRegion has a 'startKey' and 'endKey'.

The first is inclusive, the second is exclusive (except for the final region) The endKey of region 0 is the same as startKey for region 1 (if it exists). The startKey for the first region is null. The endKey for the final region is null.

The HStores have no locking built-in. All row-level locking and row-level atomicity is provided by the HRegion.

An HRegion is defined by its table and its key extent.

It consists of at least one HStore. The number of HStores should be configurable, so that data which is accessed together is stored in the same HStore. Right now, we approximate that by building a single HStore for each column family. (This config info will be communicated via the tabledesc.) The HTableDescriptor contains metainfo about the HRegion's table. regionName is a unique identifier for this HRegion. (startKey, endKey] defines the keyspace for this HRegion.


Field Summary
 
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
 
Constructor Summary
HRegion(Path rootDir, HLog log, FileSystem fs, Configuration conf, HRegionInfo regionInfo, Path initialFiles)
          HRegion constructor.
 
Method Summary
 void abort(long lockid)
          Abort a pending set of writes.
 Vector<HStoreFile> close()
          Close down this HRegion.
 void commit(long lockid, long timestamp)
          Commit a pending set of writes to the memcache.
 void delete(long lockid, Text targetCol)
          Delete a value or write a value.
 Configuration getConf()
           
 Text getEndKey()
           
 FileSystem getFilesystem()
           
 HLog getLog()
           
 Path getRegionDir()
           
 long getRegionId()
           
 Text getRegionName()
           
 Path getRootDir()
           
 HInternalScannerInterface getScanner(Text[] cols, Text firstRow, long timestamp, RowFilterInterface filter)
          Return an iterator that scans over the HRegion, returning the indicated columns for only the rows that match the data filter.
 Text getStartKey()
           
 HTableDescriptor getTableDesc()
           
 void put(long lockid, Text targetCol, byte[] val)
          Put a cell value into the locked row.
 long startUpdate(Text row)
          The caller wants to apply a series of writes to a single row in the HRegion.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HRegion

public HRegion(Path rootDir,
               HLog log,
               FileSystem fs,
               Configuration conf,
               HRegionInfo regionInfo,
               Path initialFiles)
        throws IOException
HRegion constructor.

Parameters:
log - The HLog is the outbound log for any updates to the HRegion (There's a single HLog for all the HRegions on a single HRegionServer.) The log file is a logfile from the previous execution that's custom-computed for this HRegion. The HRegionServer computes and sorts the appropriate log info for this HRegion. If there is a previous log file (implying that the HRegion has been written-to before), then read it from the supplied path.
rootDir - root directory for HBase instance
fs - is the filesystem.
conf - is global configuration settings.
regionInfo - - HRegionInfo that describes the region
initialFiles - If there are initial files (implying that the HRegion is new), then read them from the supplied path.
Throws:
IOException
Method Detail

close

public Vector<HStoreFile> close()
                         throws IOException
Close down this HRegion. Flush the cache, shut down each HStore, don't service any more calls. This method could take some time to execute, so don't call it from a time-sensitive thread.

Returns:
Vector of all the storage files that the HRegion's component HStores make use of. It's a list of HStoreFile objects.
Throws:
IOException

getStartKey

public Text getStartKey()
Returns:
start key for region

getEndKey

public Text getEndKey()
Returns:
end key for region

getRegionId

public long getRegionId()
Returns:
region id

getRegionName

public Text getRegionName()
Returns:
region name

getRootDir

public Path getRootDir()
Returns:
root directory path

getTableDesc

public HTableDescriptor getTableDesc()
Returns:
HTableDescriptor for this region

getLog

public HLog getLog()
Returns:
HLog in use for this region

getConf

public Configuration getConf()
Returns:
Configuration object

getRegionDir

public Path getRegionDir()
Returns:
region directory Path

getFilesystem

public FileSystem getFilesystem()
Returns:
FileSystem being used by this region

getScanner

public HInternalScannerInterface getScanner(Text[] cols,
                                            Text firstRow,
                                            long timestamp,
                                            RowFilterInterface filter)
                                     throws IOException
Return an iterator that scans over the HRegion, returning the indicated columns for only the rows that match the data filter. This Iterator must be closed by the caller.

Parameters:
cols - columns desired in result set
firstRow - row which is the starting point of the scan
timestamp - only return rows whose timestamp is <= this value
filter - row filter
Returns:
HScannerInterface
Throws:
IOException

startUpdate

public long startUpdate(Text row)
                 throws IOException
The caller wants to apply a series of writes to a single row in the HRegion. The caller will invoke startUpdate(), followed by a series of calls to put/delete, then finally either abort() or commit().

Note that we rely on the external caller to properly abort() or commit() every transaction. If the caller is a network client, there should be a lease-system in place that automatically aborts() transactions after a specified quiet period.

Parameters:
row - Row to update
Returns:
lockid
Throws:
IOException
See Also:
put(long, Text, byte[])

put

public void put(long lockid,
                Text targetCol,
                byte[] val)
         throws IOException
Put a cell value into the locked row. The user indicates the row-lock, the target column, and the desired value. This stuff is set into a temporary memory area until the user commits the change, at which point it's logged and placed into the memcache. This method really just tests the input, then calls an internal localput() method.

Parameters:
lockid - lock id obtained from startUpdate
targetCol - name of column to be updated
val - new value for column
Throws:
IOException

delete

public void delete(long lockid,
                   Text targetCol)
            throws IOException
Delete a value or write a value. This is a just a convenience method for put().

Parameters:
lockid - lock id obtained from startUpdate
targetCol - name of column to be deleted
Throws:
IOException

abort

public void abort(long lockid)
           throws IOException
Abort a pending set of writes. This dumps from memory all in-progress writes associated with the given row-lock. These values have not yet been placed in memcache or written to the log.

Parameters:
lockid - lock id obtained from startUpdate
Throws:
IOException

commit

public void commit(long lockid,
                   long timestamp)
            throws IOException
Commit a pending set of writes to the memcache. This also results in writing to the change log. Once updates hit the change log, they are safe. They will either be moved into an HStore in the future, or they will be recovered from the log.

Parameters:
lockid - Lock for row we're to commit.
timestamp - the time to associate with this change
Throws:
IOException


Copyright © 2006 The Apache Software Foundation