HBASE-26941 LocalHBaseCluster.waitOnRegionServer should quit while thread is interrupted (#4333)

Signed-off-by: Xin Sun <ddupgs@gmail.com>
(cherry picked from commit 8247b7c722)
This commit is contained in:
Duo Zhang 2022-04-13 10:49:40 +08:00
parent ee4ae11695
commit 29ce27c5d5
3 changed files with 23 additions and 21 deletions

View File

@ -300,7 +300,7 @@ public class LocalHBaseCluster {
* Wait for the specified region server to stop. Removes this thread from list of running threads. * Wait for the specified region server to stop. Removes this thread from list of running threads.
* @return Name of region server that just went down. * @return Name of region server that just went down.
*/ */
public String waitOnRegionServer(int serverNumber) { public String waitOnRegionServer(int serverNumber) throws InterruptedException {
JVMClusterUtil.RegionServerThread regionServerThread = this.regionThreads.get(serverNumber); JVMClusterUtil.RegionServerThread regionServerThread = this.regionThreads.get(serverNumber);
return waitOnRegionServer(regionServerThread); return waitOnRegionServer(regionServerThread);
} }
@ -309,14 +309,11 @@ public class LocalHBaseCluster {
* Wait for the specified region server to stop. Removes this thread from list of running threads. * Wait for the specified region server to stop. Removes this thread from list of running threads.
* @return Name of region server that just went down. * @return Name of region server that just went down.
*/ */
public String waitOnRegionServer(JVMClusterUtil.RegionServerThread rst) { public String waitOnRegionServer(JVMClusterUtil.RegionServerThread rst)
throws InterruptedException {
while (rst.isAlive()) { while (rst.isAlive()) {
try { LOG.info("Waiting on " + rst.getRegionServer().toString());
LOG.info("Waiting on " + rst.getRegionServer().toString()); rst.join();
rst.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
regionThreads.remove(rst); regionThreads.remove(rst);
return rst.getName(); return rst.getName();
@ -372,7 +369,7 @@ public class LocalHBaseCluster {
* Wait for the specified master to stop. Removes this thread from list of running threads. * Wait for the specified master to stop. Removes this thread from list of running threads.
* @return Name of master that just went down. * @return Name of master that just went down.
*/ */
public String waitOnMaster(int serverNumber) { public String waitOnMaster(int serverNumber) throws InterruptedException {
JVMClusterUtil.MasterThread masterThread = this.masterThreads.get(serverNumber); JVMClusterUtil.MasterThread masterThread = this.masterThreads.get(serverNumber);
return waitOnMaster(masterThread); return waitOnMaster(masterThread);
} }
@ -381,14 +378,10 @@ public class LocalHBaseCluster {
* Wait for the specified master to stop. Removes this thread from list of running threads. * Wait for the specified master to stop. Removes this thread from list of running threads.
* @return Name of master that just went down. * @return Name of master that just went down.
*/ */
public String waitOnMaster(JVMClusterUtil.MasterThread masterThread) { public String waitOnMaster(JVMClusterUtil.MasterThread masterThread) throws InterruptedException {
while (masterThread.isAlive()) { while (masterThread.isAlive()) {
try { LOG.info("Waiting on " + masterThread.getMaster().getServerName().toString());
LOG.info("Waiting on " + masterThread.getMaster().getServerName().toString()); masterThread.join();
masterThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
masterThreads.remove(masterThread); masterThreads.remove(masterThread);
return masterThread.getName(); return masterThread.getName();

View File

@ -19,6 +19,7 @@
package org.apache.hadoop.hbase; package org.apache.hadoop.hbase;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -309,7 +310,11 @@ public class MiniHBaseCluster extends HBaseCluster {
@Override @Override
public void waitForRegionServerToStop(ServerName serverName, long timeout) throws IOException { public void waitForRegionServerToStop(ServerName serverName, long timeout) throws IOException {
//ignore timeout for now //ignore timeout for now
waitOnRegionServer(getRegionServerIndex(serverName)); try {
waitOnRegionServer(getRegionServerIndex(serverName));
} catch (InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
} }
@Override @Override
@ -405,7 +410,11 @@ public class MiniHBaseCluster extends HBaseCluster {
@Override @Override
public void waitForMasterToStop(ServerName serverName, long timeout) throws IOException { public void waitForMasterToStop(ServerName serverName, long timeout) throws IOException {
//ignore timeout for now //ignore timeout for now
waitOnMaster(getMasterIndex(serverName)); try {
waitOnMaster(getMasterIndex(serverName));
} catch (InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
} }
/** /**
@ -536,7 +545,7 @@ public class MiniHBaseCluster extends HBaseCluster {
* @param serverNumber * @param serverNumber
* @return Name of region server that just went down. * @return Name of region server that just went down.
*/ */
public String waitOnRegionServer(final int serverNumber) { public String waitOnRegionServer(final int serverNumber) throws InterruptedException {
return this.hbaseCluster.waitOnRegionServer(serverNumber); return this.hbaseCluster.waitOnRegionServer(serverNumber);
} }
@ -647,7 +656,7 @@ public class MiniHBaseCluster extends HBaseCluster {
* @param serverNumber * @param serverNumber
* @return Name of master that just went down. * @return Name of master that just went down.
*/ */
public String waitOnMaster(final int serverNumber) { public String waitOnMaster(final int serverNumber) throws InterruptedException {
return this.hbaseCluster.waitOnMaster(serverNumber); return this.hbaseCluster.waitOnMaster(serverNumber);
} }

View File

@ -59,7 +59,7 @@ public class TestMasterMetricsWrapper {
} }
@Test @Test
public void testInfo() { public void testInfo() throws InterruptedException {
HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
MetricsMasterWrapperImpl info = new MetricsMasterWrapperImpl(master); MetricsMasterWrapperImpl info = new MetricsMasterWrapperImpl(master);
assertEquals( assertEquals(