org.apache.hadoop.hbase.regionserver.transactional
Class TransactionalRegion

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

public class TransactionalRegion
extends HRegion

Regionserver which provides transactional support for atomic transactions. This is achieved with optimistic concurrency control (see http://www.seas.upenn.edu/~zives/cis650/papers/opt-cc.pdf). We keep track read and write sets for each transaction, and hold off on processing the writes. To decide to commit a transaction we check its read sets with all transactions that have committed while it was running for overlaps.

Because transactions can span multiple regions, all regions must agree to commit a transactions. The client side of this commit protocol is encoded in org.apache.hadoop.hbase.client.transactional.TransactionManger

In the event of an failure of the client mid-commit, (after we voted yes), we will have to consult the transaction log to determine the final decision of the transaction. This is not yet implemented.


Field Summary
 
Fields inherited from class org.apache.hadoop.hbase.regionserver.HRegion
stores
 
Fields inherited from interface org.apache.hadoop.hbase.HConstants
ALL_META_COLUMNS, ALL_VERSIONS, COL_REGIONINFO, COL_REGIONINFO_ARRAY, COL_SERVER, COL_SPLITA, COL_SPLITB, COL_STARTCODE, COLUMN_FAMILY, COLUMN_FAMILY_ARRAY, COLUMN_FAMILY_HISTORIAN, COLUMN_FAMILY_HISTORIAN_STR, COLUMN_FAMILY_STR, DEFAULT_CLIENT_RETRIES, DEFAULT_HOST, DEFAULT_MASTER_ADDRESS, DEFAULT_MASTER_INFOPORT, DEFAULT_MASTER_PORT, DEFAULT_MAX_FILE_SIZE, DEFAULT_REGION_SERVER_CLASS, DEFAULT_REGIONSERVER_ADDRESS, DEFAULT_REGIONSERVER_INFOPORT, DEFAULT_SIZE_RESERVATION_BLOCK, EMPTY_BYTE_ARRAY, EMPTY_END_ROW, EMPTY_START_ROW, FILE_SYSTEM_VERSION, FOREVER, HBASE_CLIENT_RETRIES_NUMBER_KEY, HBASE_DIR, HREGION_LOGDIR_NAME, HREGION_OLDLOGFILE_NAME, IN_MEMORY, LAST_ROW, LATEST_TIMESTAMP, MAJOR_COMPACTION_PERIOD, MASTER_ADDRESS, MAX_ROW_LENGTH, META_ROW_DELIMITER, META_TABLE_NAME, MODIFY_CLOSE_REGION, MODIFY_TABLE_COMPACT, MODIFY_TABLE_FLUSH, MODIFY_TABLE_MAJOR_COMPACT, MODIFY_TABLE_SET_HTD, MODIFY_TABLE_SPLIT, NAME, NINES, REGION_SERVER_CLASS, REGION_SERVER_IMPL, REGIONSERVER_ADDRESS, RETRY_BACKOFF, ROOT_TABLE_NAME, THREAD_WAKE_FREQUENCY, UTF8_ENCODING, VERSION_FILE_NAME, VERSIONS, WEEK_IN_SECONDS, ZERO_L, ZEROES
 
Constructor Summary
TransactionalRegion(org.apache.hadoop.fs.Path basedir, HLog log, org.apache.hadoop.fs.FileSystem fs, HBaseConfiguration conf, HRegionInfo regionInfo, FlushRequester flushListener)
           
 
Method Summary
 void abort(long transactionId)
          Commit the transaction.
 void batchUpdate(long transactionId, BatchUpdate b)
          Add a write to the transaction.
 void beginTransaction(long transactionId)
           
 void commit(long transactionId)
          Commit the transaction.
 boolean commitRequest(long transactionId)
           
 void deleteAll(long transactionId, byte[] row, long timestamp)
          Add a delete to the transaction.
protected  void doReconstructionLog(org.apache.hadoop.fs.Path oldLogFile, long minSeqId, long maxSeqId, org.apache.hadoop.util.Progressable reporter)
           
 Cell get(long transactionId, byte[] row, byte[] column)
          Fetch a single data item.
 Cell[] get(long transactionId, byte[] row, byte[] column, int numVersions)
          Fetch multiple versions of a single data item
 Cell[] get(long transactionId, byte[] row, byte[] column, long timestamp, int numVersions)
          Fetch multiple versions of a single data item, with timestamp.
protected  long getCompleteCacheFlushSequenceId(long currentSequenceId)
          We need to make sure that we don't complete a cache flush between running transactions.
 Map<byte[],Cell> getFull(long transactionId, byte[] row, Set<byte[]> columns, long ts)
          Fetch all the columns for the indicated row at a specified timestamp.
 InternalScanner getScanner(long transactionId, byte[][] cols, byte[] 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.
 
Methods inherited from class org.apache.hadoop.hbase.regionserver.HRegion
addRegionToMETA, batchUpdate, batchUpdate, batchUpdate, batchUpdate, checkAndSave, checkReadOnly, cleanRegionInMETA, close, compactStores, createHRegion, deleteAll, deleteAll, deleteAllByRegex, deleteFamily, deleteFamilyByRegex, deleteRegion, equals, exists, flushcache, get, getBaseDir, getClosestRowBefore, getConf, getEndKey, getFilesystem, getFull, getLargestHStoreSize, getLastFlushTime, getLog, getRegionDir, getRegionDir, getRegionDir, getRegionId, getRegionInfo, getRegionName, getScanner, getStartKey, getStore, getTableDesc, hashCode, initialize, instantiateHStore, isClosed, isClosing, makeColumnFamilyDirs, merge, mergeAdjacent, offlineRegionInMETA, openHRegion, removeRegionFromMETA, rowIsInRange, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TransactionalRegion

public TransactionalRegion(org.apache.hadoop.fs.Path basedir,
                           HLog log,
                           org.apache.hadoop.fs.FileSystem fs,
                           HBaseConfiguration conf,
                           HRegionInfo regionInfo,
                           FlushRequester flushListener)
Parameters:
basedir -
log -
fs -
conf -
regionInfo -
flushListener -
Method Detail

doReconstructionLog

protected void doReconstructionLog(org.apache.hadoop.fs.Path oldLogFile,
                                   long minSeqId,
                                   long maxSeqId,
                                   org.apache.hadoop.util.Progressable reporter)
                            throws UnsupportedEncodingException,
                                   IOException
Overrides:
doReconstructionLog in class HRegion
Throws:
UnsupportedEncodingException
IOException

getCompleteCacheFlushSequenceId

protected long getCompleteCacheFlushSequenceId(long currentSequenceId)
We need to make sure that we don't complete a cache flush between running transactions. If we did, then we would not find all log messages needed to restore the transaction, as some of them would be before the last "complete" flush id.

Overrides:
getCompleteCacheFlushSequenceId in class HRegion
Returns:
sequence id to complete the cache flush with

beginTransaction

public void beginTransaction(long transactionId)
                      throws IOException
Parameters:
transactionId -
Throws:
IOException

get

public Cell get(long transactionId,
                byte[] row,
                byte[] column)
         throws IOException
Fetch a single data item.

Parameters:
transactionId -
row -
column -
Returns:
column value
Throws:
IOException

get

public Cell[] get(long transactionId,
                  byte[] row,
                  byte[] column,
                  int numVersions)
           throws IOException
Fetch multiple versions of a single data item

Parameters:
transactionId -
row -
column -
numVersions -
Returns:
array of values one element per version
Throws:
IOException

get

public Cell[] get(long transactionId,
                  byte[] row,
                  byte[] column,
                  long timestamp,
                  int numVersions)
           throws IOException
Fetch multiple versions of a single data item, with timestamp.

Parameters:
transactionId -
row -
column -
timestamp -
numVersions -
Returns:
array of values one element per version that matches the timestamp
Throws:
IOException

getFull

public Map<byte[],Cell> getFull(long transactionId,
                                byte[] row,
                                Set<byte[]> columns,
                                long ts)
                         throws IOException
Fetch all the columns for the indicated row at a specified timestamp. Returns a TreeMap that maps column names to values.

Parameters:
transactionId -
row -
columns - Array of columns you'd like to retrieve. When null, get all.
ts -
Returns:
Map values
Throws:
IOException

getScanner

public InternalScanner getScanner(long transactionId,
                                  byte[][] cols,
                                  byte[] 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:
transactionId -
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 in the column qualifier. A column qualifier is judged to be a regex if it contains at least one of the following characters: \+|^&*$[]]}{)(.
firstRow - row which is the starting point of the scan
timestamp - only return rows whose timestamp is <= this value
filter - row filter
Returns:
InternalScanner
Throws:
IOException

batchUpdate

public void batchUpdate(long transactionId,
                        BatchUpdate b)
                 throws IOException
Add a write to the transaction. Does not get applied until commit process.

Parameters:
transactionId -
b -
Throws:
IOException

deleteAll

public void deleteAll(long transactionId,
                      byte[] row,
                      long timestamp)
               throws IOException
Add a delete to the transaction. Does not get applied until commit process. FIXME, not sure about this approach

Parameters:
transactionId -
row -
timestamp -
Throws:
IOException

commitRequest

public boolean commitRequest(long transactionId)
                      throws IOException
Parameters:
transactionId -
Returns:
true if commit is successful
Throws:
IOException

commit

public void commit(long transactionId)
            throws IOException
Commit the transaction.

Parameters:
transactionId -
Throws:
IOException

abort

public void abort(long transactionId)
           throws IOException
Commit the transaction.

Parameters:
transactionId -
Throws:
IOException


Copyright © 2008 The Apache Software Foundation