Skip to content

Commit 961f9a2

Browse files
d-c-manningapurtell
authored andcommitted
HBASE-22935 Fix false warn of stuck MonitoredRPCHandler MonitoredTask
Signed-off-by: Andrew Purtell <[email protected]>
1 parent cb2d464 commit 961f9a2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/MonitoredRPCHandlerImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ public synchronized void setRPC(String methodName, Object [] params,
196196
long queueTime) {
197197
this.methodName = methodName;
198198
this.params = params;
199-
this.rpcStartTime = System.currentTimeMillis();
199+
long now = System.currentTimeMillis();
200+
this.rpcStartTime = now;
201+
setWarnTime(now);
200202
this.rpcQueueTime = queueTime;
201203
this.state = State.RUNNING;
202204
}

hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestTaskMonitor.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,22 @@ public void testDoNotPurgeRPCTask() throws Exception {
140140

141141
@Test
142142
public void testWarnStuckTasks() throws Exception {
143-
final int INTERVAL = 1000;
143+
final int RPC_WARN_TIME = 1500;
144+
final int MONITOR_INTERVAL = 500;
144145
Configuration conf = new Configuration();
145-
conf.setLong(TaskMonitor.RPC_WARN_TIME_KEY, INTERVAL);
146-
conf.setLong(TaskMonitor.MONITOR_INTERVAL_KEY, INTERVAL);
146+
conf.setLong(TaskMonitor.RPC_WARN_TIME_KEY, RPC_WARN_TIME);
147+
conf.setLong(TaskMonitor.MONITOR_INTERVAL_KEY, MONITOR_INTERVAL);
147148
final TaskMonitor tm = new TaskMonitor(conf);
148149
MonitoredRPCHandler t = tm.createRPCStatus("test task");
149-
long then = EnvironmentEdgeManager.currentTime();
150-
t.setRPC("testMethod", new Object[0], then);
151-
Thread.sleep(INTERVAL * 2);
152-
assertTrue("We did not warn", t.getWarnTime() > then);
150+
long beforeSetRPC = EnvironmentEdgeManager.currentTime();
151+
assertTrue("Validating initialization assumption", t.getWarnTime() <= beforeSetRPC);
152+
Thread.sleep(MONITOR_INTERVAL * 2);
153+
t.setRPC("testMethod", new Object[0], beforeSetRPC);
154+
long afterSetRPC = EnvironmentEdgeManager.currentTime();
155+
Thread.sleep(MONITOR_INTERVAL * 2);
156+
assertTrue("Validating no warn after starting RPC", t.getWarnTime() <= afterSetRPC);
157+
Thread.sleep(MONITOR_INTERVAL * 2);
158+
assertTrue("Validating warn after RPC_WARN_TIME", t.getWarnTime() > afterSetRPC);
153159
tm.shutdown();
154160
}
155161

0 commit comments

Comments
 (0)