Skip to content

Commit 30ab723

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 3d22604 commit 30ab723

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
@@ -187,7 +187,9 @@ public synchronized void setRPC(String methodName, Object [] params,
187187
long queueTime) {
188188
this.methodName = methodName;
189189
this.params = params;
190-
this.rpcStartTime = System.currentTimeMillis();
190+
long now = System.currentTimeMillis();
191+
this.rpcStartTime = now;
192+
setWarnTime(now);
191193
this.rpcQueueTime = queueTime;
192194
this.state = State.RUNNING;
193195
}

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
@@ -129,16 +129,22 @@ public void testDoNotPurgeRPCTask() throws Exception {
129129

130130
@Test
131131
public void testWarnStuckTasks() throws Exception {
132-
final int INTERVAL = 1000;
132+
final int RPC_WARN_TIME = 1500;
133+
final int MONITOR_INTERVAL = 500;
133134
Configuration conf = new Configuration();
134-
conf.setLong(TaskMonitor.RPC_WARN_TIME_KEY, INTERVAL);
135-
conf.setLong(TaskMonitor.MONITOR_INTERVAL_KEY, INTERVAL);
135+
conf.setLong(TaskMonitor.RPC_WARN_TIME_KEY, RPC_WARN_TIME);
136+
conf.setLong(TaskMonitor.MONITOR_INTERVAL_KEY, MONITOR_INTERVAL);
136137
final TaskMonitor tm = new TaskMonitor(conf);
137138
MonitoredRPCHandler t = tm.createRPCStatus("test task");
138-
long then = EnvironmentEdgeManager.currentTime();
139-
t.setRPC("testMethod", new Object[0], then);
140-
Thread.sleep(INTERVAL * 2);
141-
assertTrue("We did not warn", t.getWarnTime() > then);
139+
long beforeSetRPC = EnvironmentEdgeManager.currentTime();
140+
assertTrue("Validating initialization assumption", t.getWarnTime() <= beforeSetRPC);
141+
Thread.sleep(MONITOR_INTERVAL * 2);
142+
t.setRPC("testMethod", new Object[0], beforeSetRPC);
143+
long afterSetRPC = EnvironmentEdgeManager.currentTime();
144+
Thread.sleep(MONITOR_INTERVAL * 2);
145+
assertTrue("Validating no warn after starting RPC", t.getWarnTime() <= afterSetRPC);
146+
Thread.sleep(MONITOR_INTERVAL * 2);
147+
assertTrue("Validating warn after RPC_WARN_TIME", t.getWarnTime() > afterSetRPC);
142148
tm.shutdown();
143149
}
144150

0 commit comments

Comments
 (0)