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 56d00f574b
commit 6b7ebc019c
4 changed files with 2 additions and 48 deletions

View File

@ -94,20 +94,6 @@ public final class ConnectionUtils {
return normalPause + jitter;
}
/**
* 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

@ -51,7 +51,6 @@ public abstract class RegionAdminServiceCallable<T> implements RetryingCallable<
protected final TableName tableName;
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) {
@ -136,12 +135,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

@ -58,7 +58,6 @@ public abstract class RegionServerCallable<T, S> implements RetryingCallable<T>
* Some subclasses want to set their own location. Make it protected.
*/
protected HRegionLocation location;
protected final static int MIN_WAIT_DEAD_SERVER = 10000;
protected S stub;
/**
@ -185,12 +184,7 @@ public abstract class RegionServerCallable<T, S> implements RetryingCallable<T>
}
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

@ -55,26 +55,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<>();
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;