org.apache.hadoop.hbase.regionserver
Class HRegion

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

@InterfaceAudience.Private
public class HRegion
extends Object
implements HeapSize

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

Locking at the HRegion level serves only one purpose: preventing the region from being closed (and consequently split) while other operations are ongoing. Each row level operation obtains both a row lock and a region read lock for the duration of the operation. While a scanner is being constructed, getScanner holds a read lock. If the scanner is successfully constructed, it holds a read lock until it is closed. A close takes out a write lock and consequently will block for ongoing operations and will block new operations from starting while the close is in progress.

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

It consists of at least one Store. The number of Stores should be configurable, so that data which is accessed together is stored in the same Store. Right now, we approximate that by building a single Store 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.


Nested Class Summary
static interface HRegion.BulkLoadListener
          Listener class to enable callers of bulkLoadHFile() to perform any necessary pre/post processing of a given bulkload call
static class HRegion.FlushResult
          Objects from this class are created when flushing to describe all the different states that that method ends up in.
static class HRegion.Operation
          Operation enum is used in startRegionOperation() to provide operation context for startRegionOperation to possibly invoke different checks before any region operations.
static class HRegion.RowLock
          Row lock held by a given thread.
 
Field Summary
protected  long completeSequenceId
           
protected  org.apache.hadoop.conf.Configuration conf
           
static long DEEP_OVERHEAD
           
static int DEFAULT_CACHE_FLUSH_INTERVAL
          Default interval for the memstore flush
static long DEFAULT_FLUSH_PER_CHANGES
           
static long FIXED_OVERHEAD
           
static String LOAD_CFS_ON_DEMAND_CONFIG_KEY
           
static org.apache.commons.logging.Log LOG
           
static long MAX_FLUSH_PER_CHANGES
          The following MAX_FLUSH_PER_CHANGES is large enough because each KeyValue has 20+ bytes overhead.
static String MEMSTORE_FLUSH_PER_CHANGES
          Conf key to force a flush if there are already enough changes for one region in memstore
static String MEMSTORE_PERIODIC_FLUSH_INTERVAL
          Conf key for the periodic flush interval
 AtomicLong memstoreSize
           
protected  Map<byte[],Store> stores
           
 
Constructor Summary
HRegion(HRegionFileSystem fs, HLog log, org.apache.hadoop.conf.Configuration confParam, HTableDescriptor htd, RegionServerServices rsServices)
          HRegion constructor.
HRegion(org.apache.hadoop.fs.Path tableDir, HLog log, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.conf.Configuration confParam, HRegionInfo regionInfo, HTableDescriptor htd, RegionServerServices rsServices)
          Deprecated. 
 
Method Summary
 void abortRegionServer(String msg)
           
 long addAndGetGlobalMemstoreSize(long memStoreSize)
          Increase the size of mem store in this region and the size of global mem store
static void addRegionToMETA(HRegion meta, HRegion r)
          Inserts a new region's meta information into the passed meta region.
 void addRegionToSnapshot(HBaseProtos.SnapshotDescription desc, ForeignExceptionSnare exnSnare)
          Complete taking the snapshot on the region.
 Result append(Append append)
           
 Result append(Append append, long nonceGroup, long nonce)
          Perform one or more append operations on a row.
 boolean areWritesEnabled()
           
 OperationStatus[] batchMutate(Mutation[] mutations)
           
 OperationStatus[] batchMutate(Mutation[] mutations, long nonceGroup, long nonce)
          Perform a batch of mutations.
 OperationStatus[] batchReplay(HLogSplitter.MutationReplay[] mutations)
          Replay a batch of mutations.
 boolean bulkLoadHFiles(List<Pair<byte[],String>> familyPaths, boolean assignSeqId)
           
 boolean bulkLoadHFiles(List<Pair<byte[],String>> familyPaths, boolean assignSeqId, HRegion.BulkLoadListener bulkLoadListener)
          Attempts to atomically load a group of hfiles.
 boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, ByteArrayComparable comparator, Mutation w, boolean writeToWAL)
           
 boolean checkAndRowMutate(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, ByteArrayComparable comparator, RowMutations rm, boolean writeToWAL)
           
protected  void checkReadOnly()
           
 byte[] checkSplit()
          Return the splitpoint.
 Map<byte[],List<StoreFile>> close()
          Close down this HRegion.
 Map<byte[],List<StoreFile>> close(boolean abort)
          Close down this HRegion.
static void closeHRegion(HRegion r)
          This will do the necessary cleanup a call to createHRegion(HRegionInfo, Path, Configuration, HTableDescriptor) requires.
 void closeRegionOperation()
          Closes the lock.
 void closeRegionOperation(HRegion.Operation operation)
          Closes the lock.
 boolean compact(CompactionContext compaction, Store store, CompactionThroughputController throughputController)
          Called by compaction thread and after region is opened to compact the HStores if necessary.
 void compactStores()
          This is a helper function that compact all the stores synchronously It is used by utilities and testing
 void compactStores(boolean majorCompaction)
          This is a helper function that compact all the stores synchronously It is used by utilities and testing
static HDFSBlocksDistribution computeHDFSBlocksDistribution(org.apache.hadoop.conf.Configuration conf, HTableDescriptor tableDescriptor, HRegionInfo regionInfo)
          This is a helper function to compute HDFS block distribution on demand
static HDFSBlocksDistribution computeHDFSBlocksDistribution(org.apache.hadoop.conf.Configuration conf, HTableDescriptor tableDescriptor, HRegionInfo regionInfo, org.apache.hadoop.fs.Path tablePath)
          This is a helper function to compute HDFS block distribution on demand
static HRegion createHRegion(HRegionInfo info, org.apache.hadoop.fs.Path rootDir, org.apache.hadoop.conf.Configuration conf, HTableDescriptor hTableDescriptor)
          Convenience method creating new HRegions.
static HRegion createHRegion(HRegionInfo info, org.apache.hadoop.fs.Path rootDir, org.apache.hadoop.conf.Configuration conf, HTableDescriptor hTableDescriptor, HLog hlog)
           
static HRegion createHRegion(HRegionInfo info, org.apache.hadoop.fs.Path rootDir, org.apache.hadoop.conf.Configuration conf, HTableDescriptor hTableDescriptor, HLog hlog, boolean initialize)
          Convenience method creating new HRegions.
static HRegion createHRegion(HRegionInfo info, org.apache.hadoop.fs.Path rootDir, org.apache.hadoop.conf.Configuration conf, HTableDescriptor hTableDescriptor, HLog hlog, boolean initialize, boolean ignoreHLog)
          Convenience method creating new HRegions.
static HRegion createHRegion(HRegionInfo info, org.apache.hadoop.fs.Path rootDir, org.apache.hadoop.fs.Path tableDir, org.apache.hadoop.conf.Configuration conf, HTableDescriptor hTableDescriptor, HLog hlog, boolean initialize, boolean ignoreHLog)
          Convenience method creating new HRegions.
 void delete(Delete delete)
           
protected  void doRegionCompactionPrep()
           
 boolean equals(Object o)
           
 com.google.protobuf.Message execService(com.google.protobuf.RpcController controller, ClientProtos.CoprocessorServiceCall call)
          Executes a single protocol buffer coprocessor endpoint Service method using the registered protocol handlers.
 HRegion.FlushResult flushcache()
          Flush the cache.
 Result get(Get get)
           
 List<Cell> get(Get get, boolean withCoprocessor)
           
 long getBlockedRequestsCount()
           
 Result getClosestRowBefore(byte[] row, byte[] family)
          Return all the data for the row that matches row exactly, or the one that immediately preceeds it, at or immediately before ts.
 AdminProtos.GetRegionInfoResponse.CompactionState getCompactionState()
           
 int getCompactPriority()
           
 KeyValue.KVComparator getComparator()
           
 RegionCoprocessorHost getCoprocessorHost()
           
protected  Durability getEffectiveDurability(Durability d)
          Returns effective durability from the passed durability and the table descriptor.
 byte[] getEndKey()
           
 org.apache.hadoop.fs.FileSystem getFilesystem()
           
 HDFSBlocksDistribution getHDFSBlocksDistribution()
          This function will return the HDFS blocks distribution based on the data captured when HFile is created
 long getLargestHStoreSize()
           
 long getLastFlushTime()
           
 HLog getLog()
           
 Map<byte[],Long> getMaxStoreSeqIdForLogReplay()
          Gets max sequence ids of stores that was read from storage when this region was opened.
 AtomicLong getMemstoreSize()
           
 MetricsRegion getMetrics()
           
 MultiVersionConsistencyControl getMVCC()
           
 long getOpenSeqNum()
          Gets the latest sequence number that was read from storage when this region was opened.
 long getReadpoint(IsolationLevel isolationLevel)
           
static org.apache.hadoop.fs.Path getRegionDir(org.apache.hadoop.fs.Path rootdir, HRegionInfo info)
          Deprecated. 
static org.apache.hadoop.fs.Path getRegionDir(org.apache.hadoop.fs.Path tabledir, String name)
          Deprecated. 
 HRegionFileSystem getRegionFileSystem()
           
 long getRegionId()
           
 HRegionInfo getRegionInfo()
           
 byte[] getRegionName()
           
 String getRegionNameAsString()
           
 ClientProtos.RegionLoadStats getRegionStats()
           
 HRegion.RowLock getRowLock(byte[] row)
          Acqures a lock on the given row.
 HRegion.RowLock getRowLock(byte[] row, boolean waitForLock)
          Tries to acquire a lock on the given row.
protected  HRegion.RowLock getRowLockInternal(byte[] row, boolean waitForLock)
          A version of getRowLock(byte[], boolean) to use when a region operation has already been started (the calling thread has already acquired the region-close-lock).
 RegionScanner getScanner(Scan scan)
          Return an iterator that scans over the HRegion, returning the indicated columns and rows specified by the Scan.
protected  RegionScanner getScanner(Scan scan, List<KeyValueScanner> additionalScanners)
           
 AtomicLong getSequenceId()
           
 long getSmallestReadPoint()
           
 RegionSplitPolicy getSplitPolicy()
           
 byte[] getStartKey()
           
 Store getStore(byte[] column)
          Return HStore instance.
 List<String> getStoreFileList(byte[][] columns)
          Return list of storeFiles for the set of CFs.
protected  ThreadPoolExecutor getStoreFileOpenAndCloseThreadPool(String threadNamePrefix)
           
protected  ThreadPoolExecutor getStoreOpenAndCloseThreadPool(String threadNamePrefix)
           
 Map<byte[],Store> getStores()
           
 HTableDescriptor getTableDesc()
           
 int hashCode()
           
 boolean hasReferences()
           
 long heapSize()
           
 Result increment(Increment increment)
           
 Result increment(Increment increment, long nonceGroup, long nonce)
          Perform one or more increment operations on a row.
 long initialize()
          Deprecated. use HRegion.createHRegion() or HRegion.openHRegion()
protected  HStore instantiateHStore(HColumnDescriptor family)
           
protected  RegionScanner instantiateRegionScanner(Scan scan, List<KeyValueScanner> additionalScanners)
           
protected  HRegion.FlushResult internalFlushcache(HLog wal, long myseqid, MonitoredTask status)
           
protected  HRegion.FlushResult internalFlushcache(MonitoredTask status)
          Flush the memstore.
 boolean isAvailable()
           
 boolean isClosed()
           
 boolean isClosing()
           
 boolean isLoadingCfsOnDemandDefault()
           
 boolean isMergeable()
           
 boolean isRecovering()
           
 boolean isSplittable()
           
static void main(String[] args)
          Facility for dumping and compacting catalog tables.
static HRegion merge(HRegion a, HRegion b)
          Merge two regions whether they are adjacent or not.
static HRegion mergeAdjacent(HRegion srcA, HRegion srcB)
          Merge two HRegions.
 void mutateRow(RowMutations rm)
           
 void mutateRowsWithLocks(Collection<Mutation> mutations, Collection<byte[]> rowsToLock)
          Perform atomic mutations within the region w/o nonces.
 void mutateRowsWithLocks(Collection<Mutation> mutations, Collection<byte[]> rowsToLock, long nonceGroup, long nonce)
          Perform atomic mutations within the region.
 boolean needsCompaction()
          Checks every store to see if one has too many store files
protected  HRegion openHRegion(CancelableProgressable reporter)
          Open HRegion.
static HRegion openHRegion(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootDir, HRegionInfo info, HTableDescriptor htd, HLog wal)
          Open a Region.
static HRegion openHRegion(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootDir, HRegionInfo info, HTableDescriptor htd, HLog wal, RegionServerServices rsServices, CancelableProgressable reporter)
          Open a Region.
static HRegion openHRegion(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootDir, org.apache.hadoop.fs.Path tableDir, HRegionInfo info, HTableDescriptor htd, HLog wal, RegionServerServices rsServices, CancelableProgressable reporter)
          Open a Region.
static HRegion openHRegion(HRegion other, CancelableProgressable reporter)
          Useful when reopening a closed region (normally for unit tests)
static HRegion openHRegion(HRegionInfo info, HTableDescriptor htd, HLog wal, org.apache.hadoop.conf.Configuration conf)
          Open a Region.
static HRegion openHRegion(HRegionInfo info, HTableDescriptor htd, HLog wal, org.apache.hadoop.conf.Configuration conf, RegionServerServices rsServices, CancelableProgressable reporter)
          Open a Region.
static HRegion openHRegion(org.apache.hadoop.fs.Path rootDir, HRegionInfo info, HTableDescriptor htd, HLog wal, org.apache.hadoop.conf.Configuration conf)
          Open a Region.
static HRegion openHRegion(org.apache.hadoop.fs.Path rootDir, HRegionInfo info, HTableDescriptor htd, HLog wal, org.apache.hadoop.conf.Configuration conf, RegionServerServices rsServices, CancelableProgressable reporter)
          Open a Region.
protected  void prepareToSplit()
          Give the region a chance to prepare before it is split.
 void processRowsWithLocks(RowProcessor<?,?> processor, long nonceGroup, long nonce)
          Performs atomic multiple reads and writes on a given row.
 void processRowsWithLocks(RowProcessor<?,?> processor, long timeout, long nonceGroup, long nonce)
          Performs atomic multiple reads and writes on a given row.
 void put(Put put)
           
 boolean registerService(com.google.protobuf.Service instance)
          Registers a new protocol buffer Service subclass as a coprocessor endpoint to be available for handling execService(com.google.protobuf.RpcController, org.apache.hadoop.hbase.protobuf.generated.ClientProtos.CoprocessorServiceCall)} calls.
 void releaseRowLocks(List<HRegion.RowLock> rowLocks)
          If the given list of row locks is not null, releases all locks.
protected  long replayRecoveredEditsIfAny(org.apache.hadoop.fs.Path regiondir, Map<byte[],Long> maxSeqIdInStores, CancelableProgressable reporter, MonitoredTask status)
          Read the edits log put under this region by wal log splitting process.
 void reportCompactionRequestEnd(boolean isMajor, int numFiles, long filesSizeCompacted)
           
 void reportCompactionRequestStart(boolean isMajor)
           
protected  boolean restoreEdit(Store s, KeyValue kv)
          Used by tests
static boolean rowIsInRange(HRegionInfo info, byte[] row)
          Determines if the specified row is within the row range specified by the specified HRegionInfo
 void setClosing(boolean closing)
          Exposed for some very specific unit tests.
 void setCoprocessorHost(RegionCoprocessorHost coprocessorHost)
           
 void setRecovering(boolean newState)
          Reset recovering state of current region
 void startRegionOperation()
          This method needs to be called before any public call that reads or modifies data.
protected  void startRegionOperation(HRegion.Operation op)
           
 String toString()
           
 void updatesLock()
          Lock the updates' readLock first, so that we could safely append logs in coprocessors.
 void updatesUnlock()
          Unlock the updates' readLock after appending logs in coprocessors.
 void waitForFlushesAndCompactions()
          Wait for all current flushes and compactions of the region to complete.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.commons.logging.Log LOG

LOAD_CFS_ON_DEMAND_CONFIG_KEY

public static final String LOAD_CFS_ON_DEMAND_CONFIG_KEY
See Also:
Constant Field Values

completeSequenceId

protected volatile long completeSequenceId

stores

protected final Map<byte[],Store> stores

memstoreSize

public final AtomicLong memstoreSize

conf

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

MEMSTORE_PERIODIC_FLUSH_INTERVAL

public static final String MEMSTORE_PERIODIC_FLUSH_INTERVAL
Conf key for the periodic flush interval

See Also:
Constant Field Values

DEFAULT_CACHE_FLUSH_INTERVAL

public static final int DEFAULT_CACHE_FLUSH_INTERVAL
Default interval for the memstore flush

See Also:
Constant Field Values

MEMSTORE_FLUSH_PER_CHANGES

public static final String MEMSTORE_FLUSH_PER_CHANGES
Conf key to force a flush if there are already enough changes for one region in memstore

See Also:
Constant Field Values

DEFAULT_FLUSH_PER_CHANGES

public static final long DEFAULT_FLUSH_PER_CHANGES
See Also:
Constant Field Values

MAX_FLUSH_PER_CHANGES

public static final long MAX_FLUSH_PER_CHANGES
The following MAX_FLUSH_PER_CHANGES is large enough because each KeyValue has 20+ bytes overhead. Therefore, even 1G empty KVs occupy at least 20GB memstore size for a single region

See Also:
Constant Field Values

FIXED_OVERHEAD

public static final long FIXED_OVERHEAD

DEEP_OVERHEAD

public static final long DEEP_OVERHEAD
Constructor Detail

HRegion

@Deprecated
public HRegion(org.apache.hadoop.fs.Path tableDir,
                          HLog log,
                          org.apache.hadoop.fs.FileSystem fs,
                          org.apache.hadoop.conf.Configuration confParam,
                          HRegionInfo regionInfo,
                          HTableDescriptor htd,
                          RegionServerServices rsServices)
Deprecated. 

HRegion constructor. This constructor should only be used for testing and extensions. Instances of HRegion should be instantiated with the createHRegion(org.apache.hadoop.hbase.HRegionInfo, org.apache.hadoop.fs.Path, org.apache.hadoop.conf.Configuration, org.apache.hadoop.hbase.HTableDescriptor) or openHRegion(org.apache.hadoop.hbase.HRegionInfo, org.apache.hadoop.hbase.HTableDescriptor, org.apache.hadoop.hbase.regionserver.wal.HLog, org.apache.hadoop.conf.Configuration) method.

Parameters:
tableDir - qualified path of directory where region should be located, usually the table directory.
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.
fs - is the filesystem.
confParam - is global configuration settings.
regionInfo - - HRegionInfo that describes the region is new), then read them from the supplied path.
htd - the table descriptor
rsServices - reference to RegionServerServices or null

HRegion

public HRegion(HRegionFileSystem fs,
               HLog log,
               org.apache.hadoop.conf.Configuration confParam,
               HTableDescriptor htd,
               RegionServerServices rsServices)
HRegion constructor. This constructor should only be used for testing and extensions. Instances of HRegion should be instantiated with the createHRegion(org.apache.hadoop.hbase.HRegionInfo, org.apache.hadoop.fs.Path, org.apache.hadoop.conf.Configuration, org.apache.hadoop.hbase.HTableDescriptor) or openHRegion(org.apache.hadoop.hbase.HRegionInfo, org.apache.hadoop.hbase.HTableDescriptor, org.apache.hadoop.hbase.regionserver.wal.HLog, org.apache.hadoop.conf.Configuration) method.

Parameters:
fs - is the filesystem.
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.
confParam - is global configuration settings.
htd - the table descriptor
rsServices - reference to RegionServerServices or null
Method Detail

getBlockedRequestsCount

public long getBlockedRequestsCount()
Returns:
the number of blocked requests count.

getSmallestReadPoint

public long getSmallestReadPoint()
Returns:
The smallest mvcc readPoint across all the scanners in this region. Writes older than this readPoint, are included in every read operation.

initialize

@Deprecated
public long initialize()
                throws IOException
Deprecated. use HRegion.createHRegion() or HRegion.openHRegion()

Initialize this region. Used only by tests and SplitTransaction to reopen the region. You should use createHRegion() or openHRegion()

Returns:
What the next sequence (edit) id should be.
Throws:
IOException - e

hasReferences

public boolean hasReferences()
Returns:
True if this region has references.

getHDFSBlocksDistribution

public HDFSBlocksDistribution getHDFSBlocksDistribution()
This function will return the HDFS blocks distribution based on the data captured when HFile is created

Returns:
The HDFS blocks distribution for the region.

computeHDFSBlocksDistribution

public static HDFSBlocksDistribution computeHDFSBlocksDistribution(org.apache.hadoop.conf.Configuration conf,
                                                                   HTableDescriptor tableDescriptor,
                                                                   HRegionInfo regionInfo)
                                                            throws IOException
This is a helper function to compute HDFS block distribution on demand

Parameters:
conf - configuration
tableDescriptor - HTableDescriptor of the table
regionInfo - encoded name of the region
Returns:
The HDFS blocks distribution for the given region.
Throws:
IOException

computeHDFSBlocksDistribution

public static HDFSBlocksDistribution computeHDFSBlocksDistribution(org.apache.hadoop.conf.Configuration conf,
                                                                   HTableDescriptor tableDescriptor,
                                                                   HRegionInfo regionInfo,
                                                                   org.apache.hadoop.fs.Path tablePath)
                                                            throws IOException
This is a helper function to compute HDFS block distribution on demand

Parameters:
conf - configuration
tableDescriptor - HTableDescriptor of the table
regionInfo - encoded name of the region
tablePath - the table directory
Returns:
The HDFS blocks distribution for the given region.
Throws:
IOException

getMemstoreSize

public AtomicLong getMemstoreSize()

addAndGetGlobalMemstoreSize

public long addAndGetGlobalMemstoreSize(long memStoreSize)
Increase the size of mem store in this region and the size of global mem store

Parameters:
memStoreSize -
Returns:
the size of memstore in this region

getRegionInfo

public HRegionInfo getRegionInfo()
Returns:
a HRegionInfo object for this region

getSplitPolicy

public RegionSplitPolicy getSplitPolicy()
Returns:
split policy for this region.

getMetrics

public MetricsRegion getMetrics()

isClosed

public boolean isClosed()
Returns:
true if region is closed

isClosing

public boolean isClosing()
Returns:
True if closing process has started.

setRecovering

public void setRecovering(boolean newState)
Reset recovering state of current region

Parameters:
newState -

isRecovering

public boolean isRecovering()
Returns:
True if current region is in recovering

isAvailable

public boolean isAvailable()
Returns:
true if region is available (not closed and not closing)

isSplittable

public boolean isSplittable()
Returns:
true if region is splittable

isMergeable

public boolean isMergeable()
Returns:
true if region is mergeable

areWritesEnabled

public boolean areWritesEnabled()

getMVCC

public MultiVersionConsistencyControl getMVCC()

getReadpoint

public long getReadpoint(IsolationLevel isolationLevel)

isLoadingCfsOnDemandDefault

public boolean isLoadingCfsOnDemandDefault()

close

public Map<byte[],List<StoreFile>> 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 all HStoreFile objects. Returns empty vector if already closed and null if judged that it should not close.
Throws:
IOException - e
DroppedSnapshotException - Thrown when replay of wal is required because a Snapshot was not properly persisted. The region is put in closing mode, and the caller MUST abort after this.

close

public Map<byte[],List<StoreFile>> close(boolean abort)
                                  throws IOException
Close down this HRegion. Flush the cache unless abort parameter is true, 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.

Parameters:
abort - true if server is aborting (only during testing)
Returns:
Vector of all the storage files that the HRegion's component HStores make use of. It's a list of HStoreFile objects. Can be null if we are not to close at this time or we are already closed.
Throws:
IOException - e
DroppedSnapshotException - Thrown when replay of wal is required because a Snapshot was not properly persisted. The region is put in closing mode, and the caller MUST abort after this.

setClosing

public void setClosing(boolean closing)
Exposed for some very specific unit tests.


waitForFlushesAndCompactions

public void waitForFlushesAndCompactions()
Wait for all current flushes and compactions of the region to complete.

Exposed for TESTING.


getStoreOpenAndCloseThreadPool

protected ThreadPoolExecutor getStoreOpenAndCloseThreadPool(String threadNamePrefix)

getStoreFileOpenAndCloseThreadPool

protected ThreadPoolExecutor getStoreFileOpenAndCloseThreadPool(String threadNamePrefix)

getStartKey

public byte[] getStartKey()
Returns:
start key for region

getEndKey

public byte[] getEndKey()
Returns:
end key for region

getRegionId

public long getRegionId()
Returns:
region id

getRegionName

public byte[] getRegionName()
Returns:
region name

getRegionNameAsString

public String getRegionNameAsString()
Returns:
region name as string for logging

getTableDesc

public HTableDescriptor getTableDesc()
Returns:
HTableDescriptor for this region

getLog

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

getFilesystem

public org.apache.hadoop.fs.FileSystem getFilesystem()
Returns:
FileSystem being used by this region

getRegionFileSystem

public HRegionFileSystem getRegionFileSystem()
Returns:
the HRegionFileSystem used by this region

getLastFlushTime

public long getLastFlushTime()
Returns:
the last time the region was flushed

getLargestHStoreSize

public long getLargestHStoreSize()
Returns:
returns size of largest HStore.

getComparator

public KeyValue.KVComparator getComparator()
Returns:
KeyValue Comparator

doRegionCompactionPrep

protected void doRegionCompactionPrep()
                               throws IOException
Throws:
IOException

compactStores

public void compactStores(boolean majorCompaction)
                   throws IOException
This is a helper function that compact all the stores synchronously It is used by utilities and testing

Parameters:
majorCompaction - True to force a major compaction regardless of thresholds
Throws:
IOException - e

compactStores

public void compactStores()
                   throws IOException
This is a helper function that compact all the stores synchronously It is used by utilities and testing

Throws:
IOException - e

compact

public boolean compact(CompactionContext compaction,
                       Store store,
                       CompactionThroughputController throughputController)
                throws IOException
Called by compaction thread and after region is opened to compact the HStores if necessary.

This operation could block for a long time, so don't call it from a time-sensitive thread. Note that no locking is necessary at this level because compaction only conflicts with a region split, and that cannot happen because the region server does them sequentially and not in parallel.

Parameters:
compaction - Compaction details, obtained by requestCompaction()
Returns:
whether the compaction completed
Throws:
IOException

flushcache

public HRegion.FlushResult flushcache()
                               throws IOException
Flush the cache. When this method is called the cache will be flushed unless:
  1. the cache is empty
  2. the region is closed.
  3. a flush is already in progress
  4. writes are disabled

This method may block for some time, so it should not be called from a time-sensitive thread.

Returns:
true if the region needs compacting
Throws:
IOException - general io exceptions
DroppedSnapshotException - Thrown when replay of wal is required because a Snapshot was not properly persisted. The region is put in closing mode, and the caller MUST abort after this.

internalFlushcache

protected HRegion.FlushResult internalFlushcache(MonitoredTask status)
                                          throws IOException
Flush the memstore. Flushing the memstore is a little tricky. We have a lot of updates in the memstore, all of which have also been written to the log. We need to write those updates in the memstore out to disk, while being able to process reads/writes as much as possible during the flush operation. Also, the log has to state clearly the point in time at which the memstore was flushed. (That way, during recovery, we know when we can rely on the on-disk flushed structures and when we have to recover the memstore from the log.)

So, we have a three-step process:

This method is protected, but can be accessed via several public routes.

This method may block for some time.

Parameters:
status -
Returns:
object describing the flush's state
Throws:
IOException - general io exceptions
DroppedSnapshotException - Thrown when replay of hlog is required because a Snapshot was not properly persisted.

internalFlushcache

protected HRegion.FlushResult internalFlushcache(HLog wal,
                                                 long myseqid,
                                                 MonitoredTask status)
                                          throws IOException
Parameters:
wal - Null if we're NOT to go via hlog/wal.
myseqid - The seqid to use if wal is null writing out flush file.
status -
Returns:
true if the region needs compacting
Throws:
IOException
See Also:
internalFlushcache(MonitoredTask)

getClosestRowBefore

public Result getClosestRowBefore(byte[] row,
                                  byte[] family)
                           throws IOException
Return all the data for the row that matches row exactly, or the one that immediately preceeds it, at or immediately before ts.

Parameters:
row - row key
family - column family to find on
Returns:
map of values
Throws:
IOException - read exceptions

getScanner

public RegionScanner getScanner(Scan scan)
                         throws IOException
Return an iterator that scans over the HRegion, returning the indicated columns and rows specified by the Scan.

This Iterator must be closed by the caller.

Parameters:
scan - configured Scan
Returns:
RegionScanner
Throws:
IOException - read exceptions

getScanner

protected RegionScanner getScanner(Scan scan,
                                   List<KeyValueScanner> additionalScanners)
                            throws IOException
Throws:
IOException

instantiateRegionScanner

protected RegionScanner instantiateRegionScanner(Scan scan,
                                                 List<KeyValueScanner> additionalScanners)
                                          throws IOException
Throws:
IOException

delete

public void delete(Delete delete)
            throws IOException
Parameters:
delete - delete object
Throws:
IOException - read exceptions

put

public void put(Put put)
         throws IOException
Parameters:
put -
Throws:
IOException

batchMutate

public OperationStatus[] batchMutate(Mutation[] mutations,
                                     long nonceGroup,
                                     long nonce)
                              throws IOException
Perform a batch of mutations. It supports only Put and Delete mutations and will ignore other types passed.

Parameters:
mutations - the list of mutations
Returns:
an array of OperationStatus which internally contains the OperationStatusCode and the exceptionMessage if any.
Throws:
IOException

batchMutate

public OperationStatus[] batchMutate(Mutation[] mutations)
                              throws IOException
Throws:
IOException

batchReplay

public OperationStatus[] batchReplay(HLogSplitter.MutationReplay[] mutations)
                              throws IOException
Replay a batch of mutations.

Parameters:
mutations - mutations to replay.
Returns:
an array of OperationStatus which internally contains the OperationStatusCode and the exceptionMessage if any.
Throws:
IOException

getEffectiveDurability

protected Durability getEffectiveDurability(Durability d)
Returns effective durability from the passed durability and the table descriptor.


checkAndMutate

public boolean checkAndMutate(byte[] row,
                              byte[] family,
                              byte[] qualifier,
                              CompareFilter.CompareOp compareOp,
                              ByteArrayComparable comparator,
                              Mutation w,
                              boolean writeToWAL)
                       throws IOException
Parameters:
row -
family -
qualifier -
compareOp -
comparator -
w -
writeToWAL -
Returns:
true if the new put was executed, false otherwise
Throws:
IOException

checkAndRowMutate

public boolean checkAndRowMutate(byte[] row,
                                 byte[] family,
                                 byte[] qualifier,
                                 CompareFilter.CompareOp compareOp,
                                 ByteArrayComparable comparator,
                                 RowMutations rm,
                                 boolean writeToWAL)
                          throws IOException
Returns:
true if the new put was executed, false otherwise
Throws:
IOException

addRegionToSnapshot

public void addRegionToSnapshot(HBaseProtos.SnapshotDescription desc,
                                ForeignExceptionSnare exnSnare)
                         throws IOException
Complete taking the snapshot on the region. Writes the region info and adds references to the working snapshot directory. TODO for api consistency, consider adding another version with no ForeignExceptionSnare arg. (In the future other cancellable HRegion methods could eventually add a ForeignExceptionSnare, or we could do something fancier).

Parameters:
desc - snasphot description object
exnSnare - ForeignExceptionSnare that captures external exeptions in case we need to bail out. This is allowed to be null and will just be ignored in that case.
Throws:
IOException - if there is an external or internal error causing the snapshot to fail

checkReadOnly

protected void checkReadOnly()
                      throws IOException
Throws:
IOException - Throws exception if region is in read-only mode.

replayRecoveredEditsIfAny

protected long replayRecoveredEditsIfAny(org.apache.hadoop.fs.Path regiondir,
                                         Map<byte[],Long> maxSeqIdInStores,
                                         CancelableProgressable reporter,
                                         MonitoredTask status)
                                  throws UnsupportedEncodingException,
                                         IOException
Read the edits log put under this region by wal log splitting process. Put the recovered edits back up into this region.

We can ignore any log message that has a sequence ID that's equal to or lower than minSeqId. (Because we know such log messages are already reflected in the HFiles.)

While this is running we are putting pressure on memory yet we are outside of our usual accounting because we are not yet an onlined region (this stuff is being run as part of Region initialization). This means that if we're up against global memory limits, we'll not be flagged to flush because we are not online. We can't be flushed by usual mechanisms anyways; we're not yet online so our relative sequenceids are not yet aligned with HLog sequenceids -- not till we come up online, post processing of split edits.

But to help relieve memory pressure, at least manage our own heap size flushing if are in excess of per-region limits. Flushing, though, we have to be careful and avoid using the regionserver/hlog sequenceid. Its running on a different line to whats going on in here in this region context so if we crashed replaying these edits, but in the midst had a flush that used the regionserver log with a sequenceid in excess of whats going on in here in this region and with its split editlogs, then we could miss edits the next time we go to recover. So, we have to flush inline, using seqids that make sense in a this single region context only -- until we online.

Parameters:
regiondir -
maxSeqIdInStores - Any edit found in split editlogs needs to be in excess of the maxSeqId for the store to be applied, else its skipped.
reporter -
Returns:
the sequence id of the last edit added to this region out of the recovered edits log or minSeqId if nothing added from editlogs.
Throws:
UnsupportedEncodingException
IOException

restoreEdit

protected boolean restoreEdit(Store s,
                              KeyValue kv)
Used by tests

Parameters:
s - Store to add edit too.
kv - KeyValue to add.
Returns:
True if we should flush.

instantiateHStore

protected HStore instantiateHStore(HColumnDescriptor family)
                            throws IOException
Throws:
IOException

getStore

public Store getStore(byte[] column)
Return HStore instance. Use with caution. Exposed for use of fixup utilities.

Parameters:
column - Name of column family hosted by this region.
Returns:
Store that goes with the family on passed column. TODO: Make this lookup faster.

getStores

public Map<byte[],Store> getStores()

getStoreFileList

public List<String> getStoreFileList(byte[][] columns)
                              throws IllegalArgumentException
Return list of storeFiles for the set of CFs. Uses closeLock to prevent the race condition where a region closes in between the for loop - closing the stores one by one, some stores will return 0 files.

Returns:
List of storeFiles.
Throws:
IllegalArgumentException

getRowLock

public HRegion.RowLock getRowLock(byte[] row,
                                  boolean waitForLock)
                           throws IOException
Tries to acquire a lock on the given row.

Parameters:
waitForLock - if true, will block until the lock is available. Otherwise, just tries to obtain the lock and returns false if unavailable.
Returns:
the row lock if acquired, null if waitForLock was false and the lock was not acquired
Throws:
IOException - if waitForLock was true and the lock could not be acquired after waiting

getRowLockInternal

protected HRegion.RowLock getRowLockInternal(byte[] row,
                                             boolean waitForLock)
                                      throws IOException
A version of getRowLock(byte[], boolean) to use when a region operation has already been started (the calling thread has already acquired the region-close-lock).

Throws:
IOException

getRowLock

public HRegion.RowLock getRowLock(byte[] row)
                           throws IOException
Acqures a lock on the given row. The same thread may acquire multiple locks on the same row.

Returns:
the acquired row lock
Throws:
IOException - if the lock could not be acquired after waiting

releaseRowLocks

public void releaseRowLocks(List<HRegion.RowLock> rowLocks)
If the given list of row locks is not null, releases all locks.


bulkLoadHFiles

public boolean bulkLoadHFiles(List<Pair<byte[],String>> familyPaths,
                              boolean assignSeqId)
                       throws IOException
Throws:
IOException

bulkLoadHFiles

public boolean bulkLoadHFiles(List<Pair<byte[],String>> familyPaths,
                              boolean assignSeqId,
                              HRegion.BulkLoadListener bulkLoadListener)
                       throws IOException
Attempts to atomically load a group of hfiles. This is critical for loading rows with multiple column families atomically.

Parameters:
familyPaths - List of Pair
bulkLoadListener - Internal hooks enabling massaging/preparation of a file about to be bulk loaded
assignSeqId -
Returns:
true if successful, false if failed recoverably
Throws:
IOException - if failed unrecoverably.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

createHRegion

public static HRegion createHRegion(HRegionInfo info,
                                    org.apache.hadoop.fs.Path rootDir,
                                    org.apache.hadoop.conf.Configuration conf,
                                    HTableDescriptor hTableDescriptor)
                             throws IOException
Convenience method creating new HRegions. Used by createTable and by the bootstrap code in the HMaster constructor. Note, this method creates an HLog for the created region. It needs to be closed explicitly. Use getLog() to get access. When done with a region created using this method, you will need to explicitly close the HLog it created too; it will not be done for you. Not closing the log will leave at least a daemon thread running. Call closeHRegion(HRegion) and it will do necessary cleanup for you.

Parameters:
info - Info for region to create.
rootDir - Root directory for HBase instance
conf -
hTableDescriptor -
Returns:
new HRegion
Throws:
IOException

closeHRegion

public static void closeHRegion(HRegion r)
                         throws IOException
This will do the necessary cleanup a call to createHRegion(HRegionInfo, Path, Configuration, HTableDescriptor) requires. This method will close the region and then close its associated HLog file. You use it if you call the other createHRegion, the one that takes an HLog instance but don't be surprised by the call to the HLog.closeAndDelete() on the HLog the HRegion was carrying.

Parameters:
r -
Throws:
IOException

createHRegion

public static HRegion createHRegion(HRegionInfo info,
                                    org.apache.hadoop.fs.Path rootDir,
                                    org.apache.hadoop.conf.Configuration conf,
                                    HTableDescriptor hTableDescriptor,
                                    HLog hlog,
                                    boolean initialize)
                             throws IOException
Convenience method creating new HRegions. Used by createTable. The HLog for the created region needs to be closed explicitly. Use getLog() to get access.

Parameters:
info - Info for region to create.
rootDir - Root directory for HBase instance
conf -
hTableDescriptor -
hlog - shared HLog
initialize - - true to initialize the region
Returns:
new HRegion
Throws:
IOException

createHRegion

public static HRegion createHRegion(HRegionInfo info,
                                    org.apache.hadoop.fs.Path rootDir,
                                    org.apache.hadoop.conf.Configuration conf,
                                    HTableDescriptor hTableDescriptor,
                                    HLog hlog,
                                    boolean initialize,
                                    boolean ignoreHLog)
                             throws IOException
Convenience method creating new HRegions. Used by createTable. The HLog for the created region needs to be closed explicitly, if it is not null. Use getLog() to get access.

Parameters:
info - Info for region to create.
rootDir - Root directory for HBase instance
conf -
hTableDescriptor -
hlog - shared HLog
initialize - - true to initialize the region
ignoreHLog - - true to skip generate new hlog if it is null, mostly for createTable
Returns:
new HRegion
Throws:
IOException

createHRegion

public static HRegion createHRegion(HRegionInfo info,
                                    org.apache.hadoop.fs.Path rootDir,
                                    org.apache.hadoop.fs.Path tableDir,
                                    org.apache.hadoop.conf.Configuration conf,
                                    HTableDescriptor hTableDescriptor,
                                    HLog hlog,
                                    boolean initialize,
                                    boolean ignoreHLog)
                             throws IOException
Convenience method creating new HRegions. Used by createTable. The HLog for the created region needs to be closed explicitly, if it is not null. Use getLog() to get access.

Parameters:
info - Info for region to create.
rootDir - Root directory for HBase instance
tableDir - table directory
conf -
hTableDescriptor -
hlog - shared HLog
initialize - - true to initialize the region
ignoreHLog - - true to skip generate new hlog if it is null, mostly for createTable
Returns:
new HRegion
Throws:
IOException

createHRegion

public static HRegion createHRegion(HRegionInfo info,
                                    org.apache.hadoop.fs.Path rootDir,
                                    org.apache.hadoop.conf.Configuration conf,
                                    HTableDescriptor hTableDescriptor,
                                    HLog hlog)
                             throws IOException
Throws:
IOException

openHRegion

public static HRegion openHRegion(HRegionInfo info,
                                  HTableDescriptor htd,
                                  HLog wal,
                                  org.apache.hadoop.conf.Configuration conf)
                           throws IOException
Open a Region.

Parameters:
info - Info for region to be opened.
wal - HLog for region to use. This method will call HLog#setSequenceNumber(long) passing the result of the call to HRegion#getMinSequenceId() to ensure the log id is properly kept up. HRegionStore does this every time it opens a new region.
conf -
Returns:
new HRegion
Throws:
IOException

openHRegion

public static HRegion openHRegion(HRegionInfo info,
                                  HTableDescriptor htd,
                                  HLog wal,
                                  org.apache.hadoop.conf.Configuration conf,
                                  RegionServerServices rsServices,
                                  CancelableProgressable reporter)
                           throws IOException
Open a Region.

Parameters:
info - Info for region to be opened
htd - the table descriptor
wal - HLog for region to use. This method will call HLog#setSequenceNumber(long) passing the result of the call to HRegion#getMinSequenceId() to ensure the log id is properly kept up. HRegionStore does this every time it opens a new region.
conf - The Configuration object to use.
rsServices - An interface we can request flushes against.
reporter - An interface we can report progress against.
Returns:
new HRegion
Throws:
IOException

openHRegion

public static HRegion openHRegion(org.apache.hadoop.fs.Path rootDir,
                                  HRegionInfo info,
                                  HTableDescriptor htd,
                                  HLog wal,
                                  org.apache.hadoop.conf.Configuration conf)
                           throws IOException
Open a Region.

Parameters:
rootDir - Root directory for HBase instance
info - Info for region to be opened.
htd - the table descriptor
wal - HLog for region to use. This method will call HLog#setSequenceNumber(long) passing the result of the call to HRegion#getMinSequenceId() to ensure the log id is properly kept up. HRegionStore does this every time it opens a new region.
conf - The Configuration object to use.
Returns:
new HRegion
Throws:
IOException

openHRegion

public static HRegion openHRegion(org.apache.hadoop.fs.Path rootDir,
                                  HRegionInfo info,
                                  HTableDescriptor htd,
                                  HLog wal,
                                  org.apache.hadoop.conf.Configuration conf,
                                  RegionServerServices rsServices,
                                  CancelableProgressable reporter)
                           throws IOException
Open a Region.

Parameters:
rootDir - Root directory for HBase instance
info - Info for region to be opened.
htd - the table descriptor
wal - HLog for region to use. This method will call HLog#setSequenceNumber(long) passing the result of the call to HRegion#getMinSequenceId() to ensure the log id is properly kept up. HRegionStore does this every time it opens a new region.
conf - The Configuration object to use.
rsServices - An interface we can request flushes against.
reporter - An interface we can report progress against.
Returns:
new HRegion
Throws:
IOException

openHRegion

public static HRegion openHRegion(org.apache.hadoop.conf.Configuration conf,
                                  org.apache.hadoop.fs.FileSystem fs,
                                  org.apache.hadoop.fs.Path rootDir,
                                  HRegionInfo info,
                                  HTableDescriptor htd,
                                  HLog wal)
                           throws IOException
Open a Region.

Parameters:
conf - The Configuration object to use.
fs - Filesystem to use
rootDir - Root directory for HBase instance
info - Info for region to be opened.
htd - the table descriptor
wal - HLog for region to use. This method will call HLog#setSequenceNumber(long) passing the result of the call to HRegion#getMinSequenceId() to ensure the log id is properly kept up. HRegionStore does this every time it opens a new region.
Returns:
new HRegion
Throws:
IOException

openHRegion

public static HRegion openHRegion(org.apache.hadoop.conf.Configuration conf,
                                  org.apache.hadoop.fs.FileSystem fs,
                                  org.apache.hadoop.fs.Path rootDir,
                                  HRegionInfo info,
                                  HTableDescriptor htd,
                                  HLog wal,
                                  RegionServerServices rsServices,
                                  CancelableProgressable reporter)
                           throws IOException
Open a Region.

Parameters:
conf - The Configuration object to use.
fs - Filesystem to use
rootDir - Root directory for HBase instance
info - Info for region to be opened.
htd - the table descriptor
wal - HLog for region to use. This method will call HLog#setSequenceNumber(long) passing the result of the call to HRegion#getMinSequenceId() to ensure the log id is properly kept up. HRegionStore does this every time it opens a new region.
rsServices - An interface we can request flushes against.
reporter - An interface we can report progress against.
Returns:
new HRegion
Throws:
IOException

openHRegion

public static HRegion openHRegion(org.apache.hadoop.conf.Configuration conf,
                                  org.apache.hadoop.fs.FileSystem fs,
                                  org.apache.hadoop.fs.Path rootDir,
                                  org.apache.hadoop.fs.Path tableDir,
                                  HRegionInfo info,
                                  HTableDescriptor htd,
                                  HLog wal,
                                  RegionServerServices rsServices,
                                  CancelableProgressable reporter)
                           throws IOException
Open a Region.

Parameters:
conf - The Configuration object to use.
fs - Filesystem to use
rootDir - Root directory for HBase instance
info - Info for region to be opened.
htd - the table descriptor
wal - HLog for region to use. This method will call HLog#setSequenceNumber(long) passing the result of the call to HRegion#getMinSequenceId() to ensure the log id is properly kept up. HRegionStore does this every time it opens a new region.
rsServices - An interface we can request flushes against.
reporter - An interface we can report progress against.
Returns:
new HRegion
Throws:
IOException

openHRegion

public static HRegion openHRegion(HRegion other,
                                  CancelableProgressable reporter)
                           throws IOException
Useful when reopening a closed region (normally for unit tests)

Parameters:
other - original object
reporter - An interface we can report progress against.
Returns:
new HRegion
Throws:
IOException

openHRegion

protected HRegion openHRegion(CancelableProgressable reporter)
                       throws IOException
Open HRegion. Calls initialize and sets sequenceid.

Parameters:
reporter -
Returns:
Returns this
Throws:
IOException

addRegionToMETA

public static void addRegionToMETA(HRegion meta,
                                   HRegion r)
                            throws IOException
Inserts a new region's meta information into the passed meta region. Used by the HMaster bootstrap code adding new table to hbase:meta table.

Parameters:
meta - hbase:meta HRegion to be updated
r - HRegion to add to meta
Throws:
IOException

getRegionDir

@Deprecated
public static org.apache.hadoop.fs.Path getRegionDir(org.apache.hadoop.fs.Path tabledir,
                                                                String name)
Deprecated. 

Computes the Path of the HRegion

Parameters:
tabledir - qualified path for table
name - ENCODED region name
Returns:
Path of HRegion directory

getRegionDir

@Deprecated
public static org.apache.hadoop.fs.Path getRegionDir(org.apache.hadoop.fs.Path rootdir,
                                                                HRegionInfo info)
Deprecated. 

Computes the Path of the HRegion

Parameters:
rootdir - qualified path of HBase root directory
info - HRegionInfo for the region
Returns:
qualified path of region directory

rowIsInRange

public static boolean rowIsInRange(HRegionInfo info,
                                   byte[] row)
Determines if the specified row is within the row range specified by the specified HRegionInfo

Parameters:
info - HRegionInfo that specifies the row range
row - row to be checked
Returns:
true if the row is within the range specified by the HRegionInfo

mergeAdjacent

public static HRegion mergeAdjacent(HRegion srcA,
                                    HRegion srcB)
                             throws IOException
Merge two HRegions. The regions must be adjacent and must not overlap.

Parameters:
srcA -
srcB -
Returns:
new merged HRegion
Throws:
IOException

merge

public static HRegion merge(HRegion a,
                            HRegion b)
                     throws IOException
Merge two regions whether they are adjacent or not.

Parameters:
a - region a
b - region b
Returns:
new merged region
Throws:
IOException

get

public Result get(Get get)
           throws IOException
Parameters:
get - get object
Returns:
result
Throws:
IOException - read exceptions

get

public List<Cell> get(Get get,
                      boolean withCoprocessor)
               throws IOException
Throws:
IOException

mutateRow

public void mutateRow(RowMutations rm)
               throws IOException
Throws:
IOException

mutateRowsWithLocks

public void mutateRowsWithLocks(Collection<Mutation> mutations,
                                Collection<byte[]> rowsToLock)
                         throws IOException
Perform atomic mutations within the region w/o nonces. See mutateRowsWithLocks(Collection, Collection, long, long)

Throws:
IOException

mutateRowsWithLocks

public void mutateRowsWithLocks(Collection<Mutation> mutations,
                                Collection<byte[]> rowsToLock,
                                long nonceGroup,
                                long nonce)
                         throws IOException
Perform atomic mutations within the region.

Parameters:
mutations - The list of mutations to perform. mutations can contain operations for multiple rows. Caller has to ensure that all rows are contained in this region.
rowsToLock - Rows to lock
nonceGroup - Optional nonce group of the operation (client Id)
nonce - Optional nonce of the operation (unique random id to ensure "more idempotence") If multiple rows are locked care should be taken that rowsToLock is sorted in order to avoid deadlocks.
Throws:
IOException

getRegionStats

public ClientProtos.RegionLoadStats getRegionStats()
Returns:
the current load statistics for the the region

processRowsWithLocks

public void processRowsWithLocks(RowProcessor<?,?> processor,
                                 long nonceGroup,
                                 long nonce)
                          throws IOException
Performs atomic multiple reads and writes on a given row.

Parameters:
processor - The object defines the reads and writes to a row.
nonceGroup - Optional nonce group of the operation (client Id)
nonce - Optional nonce of the operation (unique random id to ensure "more idempotence")
Throws:
IOException

processRowsWithLocks

public void processRowsWithLocks(RowProcessor<?,?> processor,
                                 long timeout,
                                 long nonceGroup,
                                 long nonce)
                          throws IOException
Performs atomic multiple reads and writes on a given row.

Parameters:
processor - The object defines the reads and writes to a row.
timeout - The timeout of the processor.process() execution Use a negative number to switch off the time bound
nonceGroup - Optional nonce group of the operation (client Id)
nonce - Optional nonce of the operation (unique random id to ensure "more idempotence")
Throws:
IOException

append

public Result append(Append append)
              throws IOException
Throws:
IOException

append

public Result append(Append append,
                     long nonceGroup,
                     long nonce)
              throws IOException
Perform one or more append operations on a row.

Parameters:
append -
Returns:
new keyvalues after increment
Throws:
IOException

increment

public Result increment(Increment increment)
                 throws IOException
Throws:
IOException

increment

public Result increment(Increment increment,
                        long nonceGroup,
                        long nonce)
                 throws IOException
Perform one or more increment operations on a row.

Parameters:
increment -
Returns:
new keyvalues after increment
Throws:
IOException

heapSize

public long heapSize()
Specified by:
heapSize in interface HeapSize
Returns:
Approximate 'exclusive deep size' of implementing object. Includes count of payload and hosting object sizings.

registerService

public boolean registerService(com.google.protobuf.Service instance)
Registers a new protocol buffer Service subclass as a coprocessor endpoint to be available for handling execService(com.google.protobuf.RpcController, org.apache.hadoop.hbase.protobuf.generated.ClientProtos.CoprocessorServiceCall)} calls.

Only a single instance may be registered per region for a given Service subclass (the instances are keyed on Descriptors.ServiceDescriptor.getFullName(). After the first registration, subsequent calls with the same service name will fail with a return value of false.

Parameters:
instance - the Service subclass instance to expose as a coprocessor endpoint
Returns:
true if the registration was successful, false otherwise

execService

public com.google.protobuf.Message execService(com.google.protobuf.RpcController controller,
                                               ClientProtos.CoprocessorServiceCall call)
                                        throws IOException
Executes a single protocol buffer coprocessor endpoint Service method using the registered protocol handlers. Service implementations must be registered via the registerService(com.google.protobuf.Service) method before they are available.

Parameters:
controller - an RpcContoller implementation to pass to the invoked service
call - a CoprocessorServiceCall instance identifying the service, method, and parameters for the method invocation
Returns:
a protocol buffer Message instance containing the method's result
Throws:
IOException - if no registered service handler is found or an error occurs during the invocation
See Also:
registerService(com.google.protobuf.Service)

prepareToSplit

protected void prepareToSplit()
Give the region a chance to prepare before it is split.


checkSplit

public byte[] checkSplit()
Return the splitpoint. null indicates the region isn't splittable If the splitpoint isn't explicitly specified, it will go over the stores to find the best splitpoint. Currently the criteria of best splitpoint is based on the size of the store.


getCompactPriority

public int getCompactPriority()
Returns:
The priority that this region should have in the compaction queue

needsCompaction

public boolean needsCompaction()
Checks every store to see if one has too many store files

Returns:
true if any store has too many store files

getCoprocessorHost

public RegionCoprocessorHost getCoprocessorHost()
Returns:
the coprocessor host

setCoprocessorHost

public void setCoprocessorHost(RegionCoprocessorHost coprocessorHost)
Parameters:
coprocessorHost - the new coprocessor host

abortRegionServer

public void abortRegionServer(String msg)
                       throws IOException
Throws:
IOException

startRegionOperation

public void startRegionOperation()
                          throws IOException
This method needs to be called before any public call that reads or modifies data. It has to be called just before a try. #closeRegionOperation needs to be called in the try's finally block Acquires a read lock and checks if the region is closing or closed.

Throws:
IOException

startRegionOperation

protected void startRegionOperation(HRegion.Operation op)
                             throws IOException
Parameters:
op - The operation is about to be taken on the region
Throws:
IOException

closeRegionOperation

public void closeRegionOperation()
                          throws IOException
Closes the lock. This needs to be called in the finally block corresponding to the try block of #startRegionOperation

Throws:
IOException

closeRegionOperation

public void closeRegionOperation(HRegion.Operation operation)
                          throws IOException
Closes the lock. This needs to be called in the finally block corresponding to the try block of startRegionOperation(Operation)

Parameters:
operation -
Throws:
IOException

main

public static void main(String[] args)
                 throws IOException
Facility for dumping and compacting catalog tables. Only does catalog tables since these are only tables we for sure know schema on. For usage run:
   ./bin/hbase org.apache.hadoop.hbase.regionserver.HRegion
 

Parameters:
args -
Throws:
IOException

getOpenSeqNum

public long getOpenSeqNum()
Gets the latest sequence number that was read from storage when this region was opened.


getMaxStoreSeqIdForLogReplay

public Map<byte[],Long> getMaxStoreSeqIdForLogReplay()
Gets max sequence ids of stores that was read from storage when this region was opened. WAL Edits with smaller or equal sequence number will be skipped from replay.


getCompactionState

public AdminProtos.GetRegionInfoResponse.CompactionState getCompactionState()
Returns:
if a given region is in compaction now.

reportCompactionRequestStart

public void reportCompactionRequestStart(boolean isMajor)

reportCompactionRequestEnd

public void reportCompactionRequestEnd(boolean isMajor,
                                       int numFiles,
                                       long filesSizeCompacted)

getSequenceId

public AtomicLong getSequenceId()
Returns:
sequenceId.

updatesLock

public void updatesLock()
                 throws RegionTooBusyException,
                        InterruptedIOException
Lock the updates' readLock first, so that we could safely append logs in coprocessors.

Throws:
RegionTooBusyException
InterruptedIOException

updatesUnlock

public void updatesUnlock()
                   throws InterruptedIOException
Unlock the updates' readLock after appending logs in coprocessors.

Throws:
InterruptedIOException


Copyright © 2007–2015 The Apache Software Foundation. All rights reserved.