HBASE-4716 Improve locking for single column family bulk load
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1196674 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
321d6c3025
commit
0e32567cdd
|
@ -442,6 +442,7 @@ Release 0.92.0 - Unreleased
|
|||
HBASE-3515 [replication] ReplicationSource can miss a log after RS comes out of GC
|
||||
HBASE-4713 Raise debug level to warn on ExecutionException in
|
||||
HConnectionManager$HConnectionImplementation (Lucian George Iordache)
|
||||
HBASE-4716 Improve locking for single column family bulk load
|
||||
|
||||
TESTS
|
||||
HBASE-4450 test for number of blocks read: to serve as baseline for expected
|
||||
|
|
|
@ -2782,6 +2782,34 @@ public class HRegion implements HeapSize { // , Writable{
|
|||
return lid;
|
||||
}
|
||||
|
||||
enum COLUMN_FAMILY_TYPES {
|
||||
NONE, // there is no column family
|
||||
SINGLE,
|
||||
MULTIPLE // there are more than one column family
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the type of column family based on list of family/hfilePath pairs
|
||||
*
|
||||
* @param familyPaths List of Pair<byte[] column family, String hfilePath>
|
||||
*/
|
||||
public static COLUMN_FAMILY_TYPES getColumnFamilyType(
|
||||
List<Pair<byte[], String>> familyPaths) {
|
||||
if (familyPaths == null) return COLUMN_FAMILY_TYPES.NONE;
|
||||
COLUMN_FAMILY_TYPES familyType = COLUMN_FAMILY_TYPES.SINGLE;
|
||||
byte[] family = null;
|
||||
for (Pair<byte[], String> pair : familyPaths) {
|
||||
byte[] fam = pair.getFirst();
|
||||
if (family == null) {
|
||||
family = fam;
|
||||
} else if (!Bytes.equals(family, fam)) {
|
||||
familyType = COLUMN_FAMILY_TYPES.MULTIPLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return familyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to atomically load a group of hfiles. This is critical for loading
|
||||
* rows with multiple column families atomically.
|
||||
|
@ -2790,7 +2818,8 @@ public class HRegion implements HeapSize { // , Writable{
|
|||
*/
|
||||
public void bulkLoadHFiles(List<Pair<byte[], String>> familyPaths)
|
||||
throws IOException {
|
||||
startBulkRegionOperation();
|
||||
// we need writeLock for multi-family bulk load
|
||||
startBulkRegionOperation(getColumnFamilyType(familyPaths) == COLUMN_FAMILY_TYPES.MULTIPLE);
|
||||
this.writeRequestsCount.increment();
|
||||
List<IOException> ioes = new ArrayList<IOException>();
|
||||
List<Pair<byte[], String>> failures = new ArrayList<Pair<byte[], String>>();
|
||||
|
@ -4453,14 +4482,17 @@ public class HRegion implements HeapSize { // , Writable{
|
|||
* Acquires a writelock and checks if the region is closing or closed.
|
||||
* @throws NotServingRegionException when the region is closing or closed
|
||||
*/
|
||||
private void startBulkRegionOperation() throws NotServingRegionException {
|
||||
private void startBulkRegionOperation(boolean writeLockNeeded)
|
||||
throws NotServingRegionException {
|
||||
if (this.closing.get()) {
|
||||
throw new NotServingRegionException(regionInfo.getRegionNameAsString() +
|
||||
" is closing");
|
||||
}
|
||||
lock.writeLock().lock();
|
||||
if (writeLockNeeded) lock.writeLock().lock();
|
||||
else lock.readLock().lock();
|
||||
if (this.closed.get()) {
|
||||
lock.writeLock().unlock();
|
||||
if (writeLockNeeded) lock.writeLock().unlock();
|
||||
else lock.readLock().unlock();
|
||||
throw new NotServingRegionException(regionInfo.getRegionNameAsString() +
|
||||
" is closed");
|
||||
}
|
||||
|
@ -4471,7 +4503,8 @@ public class HRegion implements HeapSize { // , Writable{
|
|||
* to the try block of #startRegionOperation
|
||||
*/
|
||||
private void closeBulkRegionOperation(){
|
||||
lock.writeLock().unlock();
|
||||
if (lock.writeLock().isHeldByCurrentThread()) lock.writeLock().unlock();
|
||||
else lock.readLock().unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue