Skip to content

Commit

Permalink
HBASE-24478 The regionInfo parameter for MasterProcedureScheduler#wai… (
Browse files Browse the repository at this point in the history
#1819)

Signed-off-by: Guangxu Cheng <gxcheng@apache.org>
Signed-off-by: clarax <clarax98007@gmail.com>
  • Loading branch information
songxincun authored Jun 16, 2020
1 parent 3ac99ad commit 3558ee0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -700,12 +700,12 @@ public boolean waitRegion(final Procedure<?> procedure, final RegionInfo regionI
* Suspend the procedure if the specified set of regions are already locked.
* @param procedure the procedure trying to acquire the lock on the regions
* @param table the table name of the regions we are trying to lock
* @param regionInfo the list of regions we are trying to lock
* @param regionInfos the list of regions we are trying to lock
* @return true if the procedure has to wait for the regions to be available
*/
public boolean waitRegions(final Procedure<?> procedure, final TableName table,
final RegionInfo... regionInfo) {
Arrays.sort(regionInfo, RegionInfo.COMPARATOR);
final RegionInfo... regionInfos) {
Arrays.sort(regionInfos, RegionInfo.COMPARATOR);
schedLock();
try {
assert table != null;
Expand All @@ -715,14 +715,14 @@ public boolean waitRegions(final Procedure<?> procedure, final TableName table,

// acquire region xlocks or wait
boolean hasLock = true;
final LockAndQueue[] regionLocks = new LockAndQueue[regionInfo.length];
for (int i = 0; i < regionInfo.length; ++i) {
assert regionInfo[i] != null;
assert regionInfo[i].getTable() != null;
assert regionInfo[i].getTable().equals(table): regionInfo[i] + " " + procedure;
assert i == 0 || regionInfo[i] != regionInfo[i - 1] : "duplicate region: " + regionInfo[i];

regionLocks[i] = locking.getRegionLock(regionInfo[i].getEncodedName());
final LockAndQueue[] regionLocks = new LockAndQueue[regionInfos.length];
for (int i = 0; i < regionInfos.length; ++i) {
assert regionInfos[i] != null;
assert regionInfos[i].getTable() != null;
assert regionInfos[i].getTable().equals(table): regionInfos[i] + " " + procedure;
assert i == 0 || regionInfos[i] != regionInfos[i - 1] : "duplicate region: " + regionInfos[i];

regionLocks[i] = locking.getRegionLock(regionInfos[i].getEncodedName());
if (!regionLocks[i].tryExclusiveLock(procedure)) {
LOG.info("Waiting on xlock for {} held by pid={}", procedure,
regionLocks[i].getExclusiveLockProcIdOwner());
Expand Down Expand Up @@ -758,26 +758,26 @@ public void wakeRegion(final Procedure<?> procedure, final RegionInfo regionInfo
/**
* Wake the procedures waiting for the specified regions
* @param procedure the procedure that was holding the regions
* @param regionInfo the list of regions the procedure was holding
* @param regionInfos the list of regions the procedure was holding
*/
public void wakeRegions(final Procedure<?> procedure,final TableName table,
final RegionInfo... regionInfo) {
Arrays.sort(regionInfo, RegionInfo.COMPARATOR);
final RegionInfo... regionInfos) {
Arrays.sort(regionInfos, RegionInfo.COMPARATOR);
schedLock();
try {
int numProcs = 0;
final Procedure<?>[] nextProcs = new Procedure[regionInfo.length];
for (int i = 0; i < regionInfo.length; ++i) {
assert regionInfo[i].getTable().equals(table);
assert i == 0 || regionInfo[i] != regionInfo[i - 1] : "duplicate region: " + regionInfo[i];
final Procedure<?>[] nextProcs = new Procedure[regionInfos.length];
for (int i = 0; i < regionInfos.length; ++i) {
assert regionInfos[i].getTable().equals(table);
assert i == 0 || regionInfos[i] != regionInfos[i - 1] : "duplicate region: " + regionInfos[i];

LockAndQueue regionLock = locking.getRegionLock(regionInfo[i].getEncodedName());
LockAndQueue regionLock = locking.getRegionLock(regionInfos[i].getEncodedName());
if (regionLock.releaseExclusiveLock(procedure)) {
if (!regionLock.isWaitingQueueEmpty()) {
// release one procedure at the time since regions has an xlock
nextProcs[numProcs++] = regionLock.removeFirst();
} else {
locking.removeRegionLock(regionInfo[i].getEncodedName());
locking.removeRegionLock(regionInfos[i].getEncodedName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,30 +850,30 @@ public ProcedureEvent<?> getEvent() {
}

public static class TestRegionProcedure extends TestTableProcedure {
private final RegionInfo[] regionInfo;
private final RegionInfo[] regionInfos;

public TestRegionProcedure() {
throw new UnsupportedOperationException("recovery should not be triggered here");
}

public TestRegionProcedure(long procId, TableName tableName, TableOperationType opType,
RegionInfo... regionInfo) {
this(-1, procId, tableName, opType, regionInfo);
RegionInfo... regionInfos) {
this(-1, procId, tableName, opType, regionInfos);
}

public TestRegionProcedure(long parentProcId, long procId, TableName tableName,
TableOperationType opType, RegionInfo... regionInfo) {
this(-1, parentProcId, procId, tableName, opType, regionInfo);
TableOperationType opType, RegionInfo... regionInfos) {
this(-1, parentProcId, procId, tableName, opType, regionInfos);
}

public TestRegionProcedure(long rootProcId, long parentProcId, long procId, TableName tableName,
TableOperationType opType, RegionInfo... regionInfo) {
TableOperationType opType, RegionInfo... regionInfos) {
super(rootProcId, parentProcId, procId, tableName, opType);
this.regionInfo = regionInfo;
this.regionInfos = regionInfos;
}

public RegionInfo[] getRegionInfo() {
return regionInfo;
return regionInfos;
}

@Override
Expand Down

0 comments on commit 3558ee0

Please sign in to comment.