HBASE-18390 Sleep too long when finding region location failed

This commit is contained in:
Phil Yang 2017-07-19 11:34:57 +08:00
parent af359d03b5
commit 980209579b
4 changed files with 2 additions and 50 deletions

View File

@ -73,20 +73,6 @@ public class ConnectionUtils {
}
/**
* Adds / subs an up to 50% jitter to a pause time. Minimum is 1.
* @param pause the expected pause.
* @param jitter the jitter ratio, between 0 and 1, exclusive.
*/
public static long addJitter(final long pause, final float jitter) {
float lag = pause * (ThreadLocalRandom.current().nextFloat() - 0.5f) * jitter;
long newPause = pause + (long) lag;
if (newPause <= 0) {
return 1;
}
return newPause;
}
/**
* @param conn The connection for which to replace the generator.
* @param cnm Replaces the nonce generator used, for testing.

View File

@ -50,8 +50,6 @@ public abstract class RegionAdminServiceCallable<T> implements RetryingCallable<
protected final byte[] row;
protected final int replicaId;
protected final static int MIN_WAIT_DEAD_SERVER = 10000;
public RegionAdminServiceCallable(ClusterConnection connection,
RpcControllerFactory rpcControllerFactory, TableName tableName, byte[] row) {
this(connection, rpcControllerFactory, null, tableName, row);
@ -138,12 +136,7 @@ public abstract class RegionAdminServiceCallable<T> implements RetryingCallable<
@Override
public long sleep(long pause, int tries) {
long sleep = ConnectionUtils.getPauseTime(pause, tries);
if (sleep < MIN_WAIT_DEAD_SERVER
&& (location == null || connection.isDeadServer(location.getServerName()))) {
sleep = ConnectionUtils.addJitter(MIN_WAIT_DEAD_SERVER, 0.10f);
}
return sleep;
return ConnectionUtils.getPauseTime(pause, tries);
}
public static RegionLocations getRegionLocations(

View File

@ -51,8 +51,6 @@ public abstract class RegionServerCallable<T> implements RetryingCallable<T> {
protected HRegionLocation location;
private ClientService.BlockingInterface stub;
protected final static int MIN_WAIT_DEAD_SERVER = 10000;
/**
* @param connection Connection to use.
* @param tableName Table name to which <code>row</code> belongs.
@ -134,12 +132,7 @@ public abstract class RegionServerCallable<T> implements RetryingCallable<T> {
@Override
public long sleep(long pause, int tries) {
long sleep = ConnectionUtils.getPauseTime(pause, tries);
if (sleep < MIN_WAIT_DEAD_SERVER
&& (location == null || getConnection().isDeadServer(location.getServerName()))) {
sleep = ConnectionUtils.addJitter(MIN_WAIT_DEAD_SERVER, 0.10f);
}
return sleep;
return ConnectionUtils.getPauseTime(pause, tries);
}
/**

View File

@ -54,26 +54,6 @@ public class TestConnectionUtils {
assertTrue(retyTimeSet.size() > (retries.length * 0.80));
}
@Test
public void testAddJitter() {
long basePause = 10000;
long maxTimeExpected = (long) (basePause * 1.25f);
long minTimeExpected = (long) (basePause * 0.75f);
int testTries = 100;
Set<Long> timeSet = new TreeSet<Long>();
for (int i = 0; i < testTries; i++) {
long withJitter = ConnectionUtils.addJitter(basePause, 0.5f);
assertTrue(withJitter >= minTimeExpected);
assertTrue(withJitter <= maxTimeExpected);
// Add the long to the set
timeSet.add(withJitter);
}
//Make sure that most are unique. some overlap will happen
assertTrue(timeSet.size() > (testTries * 0.90));
}
@Test
public void testGetPauseTime() {
long pauseTime;