HBASE-22935 Fix false warn of stuck MonitoredRPCHandler MonitoredTask

Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
David Manning 2019-08-27 16:58:02 -07:00 committed by Andrew Purtell
parent 3e2cfc1140
commit f2425c74a9
No known key found for this signature in database
GPG Key ID: 8597754DD5365CCD
2 changed files with 16 additions and 8 deletions

View File

@ -196,7 +196,9 @@ public class MonitoredRPCHandlerImpl extends MonitoredTaskImpl
long queueTime) { long queueTime) {
this.methodName = methodName; this.methodName = methodName;
this.params = params; this.params = params;
this.rpcStartTime = System.currentTimeMillis(); long now = System.currentTimeMillis();
this.rpcStartTime = now;
setWarnTime(now);
this.rpcQueueTime = queueTime; this.rpcQueueTime = queueTime;
this.state = State.RUNNING; this.state = State.RUNNING;
} }

View File

@ -140,16 +140,22 @@ public class TestTaskMonitor {
@Test @Test
public void testWarnStuckTasks() throws Exception { public void testWarnStuckTasks() throws Exception {
final int INTERVAL = 1000; final int RPC_WARN_TIME = 1500;
final int MONITOR_INTERVAL = 500;
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.setLong(TaskMonitor.RPC_WARN_TIME_KEY, INTERVAL); conf.setLong(TaskMonitor.RPC_WARN_TIME_KEY, RPC_WARN_TIME);
conf.setLong(TaskMonitor.MONITOR_INTERVAL_KEY, INTERVAL); conf.setLong(TaskMonitor.MONITOR_INTERVAL_KEY, MONITOR_INTERVAL);
final TaskMonitor tm = new TaskMonitor(conf); final TaskMonitor tm = new TaskMonitor(conf);
MonitoredRPCHandler t = tm.createRPCStatus("test task"); MonitoredRPCHandler t = tm.createRPCStatus("test task");
long then = EnvironmentEdgeManager.currentTime(); long beforeSetRPC = EnvironmentEdgeManager.currentTime();
t.setRPC("testMethod", new Object[0], then); assertTrue("Validating initialization assumption", t.getWarnTime() <= beforeSetRPC);
Thread.sleep(INTERVAL * 2); Thread.sleep(MONITOR_INTERVAL * 2);
assertTrue("We did not warn", t.getWarnTime() > then); t.setRPC("testMethod", new Object[0], beforeSetRPC);
long afterSetRPC = EnvironmentEdgeManager.currentTime();
Thread.sleep(MONITOR_INTERVAL * 2);
assertTrue("Validating no warn after starting RPC", t.getWarnTime() <= afterSetRPC);
Thread.sleep(MONITOR_INTERVAL * 2);
assertTrue("Validating warn after RPC_WARN_TIME", t.getWarnTime() > afterSetRPC);
tm.shutdown(); tm.shutdown();
} }