HBASE-17673 Monitored RPC Handler not shown in the WebUI (Allan Yang)

This commit is contained in:
tedyu 2017-02-28 07:44:35 -08:00
parent 2131c79552
commit 7d38e6126a
2 changed files with 31 additions and 2 deletions

View File

@ -53,6 +53,7 @@ public class TaskMonitor {
private static TaskMonitor instance; private static TaskMonitor instance;
private CircularFifoBuffer tasks = new CircularFifoBuffer(MAX_TASKS); private CircularFifoBuffer tasks = new CircularFifoBuffer(MAX_TASKS);
private List<TaskAndWeakRefPair> rpcTasks = Lists.newArrayList();
/** /**
* Get singleton instance. * Get singleton instance.
@ -88,7 +89,7 @@ public class TaskMonitor {
new Class<?>[] { MonitoredRPCHandler.class }, new Class<?>[] { MonitoredRPCHandler.class },
new PassthroughInvocationHandler<MonitoredRPCHandler>(stat)); new PassthroughInvocationHandler<MonitoredRPCHandler>(stat));
TaskAndWeakRefPair pair = new TaskAndWeakRefPair(stat, proxy); TaskAndWeakRefPair pair = new TaskAndWeakRefPair(stat, proxy);
tasks.add(pair); rpcTasks.add(pair);
return proxy; return proxy;
} }
@ -120,13 +121,20 @@ public class TaskMonitor {
*/ */
public synchronized List<MonitoredTask> getTasks() { public synchronized List<MonitoredTask> getTasks() {
purgeExpiredTasks(); purgeExpiredTasks();
ArrayList<MonitoredTask> ret = Lists.newArrayListWithCapacity(tasks.size()); ArrayList<MonitoredTask> ret = Lists.newArrayListWithCapacity(tasks.size() + rpcTasks
.size());
for (Iterator<TaskAndWeakRefPair> it = tasks.iterator(); for (Iterator<TaskAndWeakRefPair> it = tasks.iterator();
it.hasNext();) { it.hasNext();) {
TaskAndWeakRefPair pair = it.next(); TaskAndWeakRefPair pair = it.next();
MonitoredTask t = pair.get(); MonitoredTask t = pair.get();
ret.add(t.clone()); ret.add(t.clone());
} }
for (Iterator<TaskAndWeakRefPair> it = rpcTasks.iterator();
it.hasNext();) {
TaskAndWeakRefPair pair = it.next();
MonitoredTask t = pair.get();
ret.add(t.clone());
}
return ret; return ret;
} }

View File

@ -100,6 +100,27 @@ public class TestTaskMonitor {
assertEquals("task 10", tm.getTasks().get(0).getDescription()); assertEquals("task 10", tm.getTasks().get(0).getDescription());
} }
@Test
public void testDoNotPurgeRPCTask() throws Exception {
int RPCTaskNums = 10;
for(int i = 0; i < RPCTaskNums; i++) {
TaskMonitor.get().createRPCStatus("PRCTask" + i);
}
for(int i = 0; i < TaskMonitor.MAX_TASKS; i++) {
TaskMonitor.get().createStatus("otherTask" + i);
}
int remainRPCTask = 0;
for(MonitoredTask task :TaskMonitor.get().getTasks()) {
if(task instanceof MonitoredRPCHandler) {
remainRPCTask++;
}
}
assertEquals("RPC Tasks have been purged!", RPCTaskNums, remainRPCTask);
}
} }