Skip to content

Commit f8b2ac0

Browse files
committed
HBASE-26941 LocalHBaseCluster.waitOnRegionServer should quit while thread is interrupted (#4333)
Signed-off-by: Xin Sun <ddupgs@gmail.com> (cherry picked from commit 8247b7c)
1 parent 5dc93d7 commit f8b2ac0

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public Configuration getConfiguration() {
300300
* Wait for the specified region server to stop. Removes this thread from list of running threads.
301301
* @return Name of region server that just went down.
302302
*/
303-
public String waitOnRegionServer(int serverNumber) {
303+
public String waitOnRegionServer(int serverNumber) throws InterruptedException {
304304
JVMClusterUtil.RegionServerThread regionServerThread = this.regionThreads.get(serverNumber);
305305
return waitOnRegionServer(regionServerThread);
306306
}
@@ -309,14 +309,11 @@ public String waitOnRegionServer(int serverNumber) {
309309
* Wait for the specified region server to stop. Removes this thread from list of running threads.
310310
* @return Name of region server that just went down.
311311
*/
312-
public String waitOnRegionServer(JVMClusterUtil.RegionServerThread rst) {
312+
public String waitOnRegionServer(JVMClusterUtil.RegionServerThread rst)
313+
throws InterruptedException {
313314
while (rst.isAlive()) {
314-
try {
315-
LOG.info("Waiting on " + rst.getRegionServer().toString());
316-
rst.join();
317-
} catch (InterruptedException e) {
318-
e.printStackTrace();
319-
}
315+
LOG.info("Waiting on " + rst.getRegionServer().toString());
316+
rst.join();
320317
}
321318
regionThreads.remove(rst);
322319
return rst.getName();
@@ -372,7 +369,7 @@ public List<JVMClusterUtil.MasterThread> getLiveMasters() {
372369
* Wait for the specified master to stop. Removes this thread from list of running threads.
373370
* @return Name of master that just went down.
374371
*/
375-
public String waitOnMaster(int serverNumber) {
372+
public String waitOnMaster(int serverNumber) throws InterruptedException {
376373
JVMClusterUtil.MasterThread masterThread = this.masterThreads.get(serverNumber);
377374
return waitOnMaster(masterThread);
378375
}
@@ -381,14 +378,10 @@ public String waitOnMaster(int serverNumber) {
381378
* Wait for the specified master to stop. Removes this thread from list of running threads.
382379
* @return Name of master that just went down.
383380
*/
384-
public String waitOnMaster(JVMClusterUtil.MasterThread masterThread) {
381+
public String waitOnMaster(JVMClusterUtil.MasterThread masterThread) throws InterruptedException {
385382
while (masterThread.isAlive()) {
386-
try {
387-
LOG.info("Waiting on " + masterThread.getMaster().getServerName().toString());
388-
masterThread.join();
389-
} catch (InterruptedException e) {
390-
e.printStackTrace();
391-
}
383+
LOG.info("Waiting on " + masterThread.getMaster().getServerName().toString());
384+
masterThread.join();
392385
}
393386
masterThreads.remove(masterThread);
394387
return masterThread.getName();

hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.hadoop.hbase;
2020

2121
import java.io.IOException;
22+
import java.io.InterruptedIOException;
2223
import java.security.PrivilegedAction;
2324
import java.util.ArrayList;
2425
import java.util.HashSet;
@@ -309,7 +310,11 @@ public void resumeRegionServer(ServerName serverName) throws IOException {
309310
@Override
310311
public void waitForRegionServerToStop(ServerName serverName, long timeout) throws IOException {
311312
//ignore timeout for now
312-
waitOnRegionServer(getRegionServerIndex(serverName));
313+
try {
314+
waitOnRegionServer(getRegionServerIndex(serverName));
315+
} catch (InterruptedException e) {
316+
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
317+
}
313318
}
314319

315320
@Override
@@ -405,7 +410,11 @@ public void stopMaster(ServerName serverName) throws IOException {
405410
@Override
406411
public void waitForMasterToStop(ServerName serverName, long timeout) throws IOException {
407412
//ignore timeout for now
408-
waitOnMaster(getMasterIndex(serverName));
413+
try {
414+
waitOnMaster(getMasterIndex(serverName));
415+
} catch (InterruptedException e) {
416+
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
417+
}
409418
}
410419

411420
/**
@@ -536,7 +545,7 @@ public JVMClusterUtil.RegionServerThread resumeRegionServer(int serverNumber) {
536545
* @param serverNumber
537546
* @return Name of region server that just went down.
538547
*/
539-
public String waitOnRegionServer(final int serverNumber) {
548+
public String waitOnRegionServer(final int serverNumber) throws InterruptedException {
540549
return this.hbaseCluster.waitOnRegionServer(serverNumber);
541550
}
542551

@@ -647,7 +656,7 @@ public JVMClusterUtil.MasterThread stopMaster(int serverNumber,
647656
* @param serverNumber
648657
* @return Name of master that just went down.
649658
*/
650-
public String waitOnMaster(final int serverNumber) {
659+
public String waitOnMaster(final int serverNumber) throws InterruptedException {
651660
return this.hbaseCluster.waitOnMaster(serverNumber);
652661
}
653662

hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetricsWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static void teardown() throws Exception {
5959
}
6060

6161
@Test
62-
public void testInfo() {
62+
public void testInfo() throws InterruptedException {
6363
HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
6464
MetricsMasterWrapperImpl info = new MetricsMasterWrapperImpl(master);
6565
assertEquals(

0 commit comments

Comments
 (0)