From 9fcb2ae8652d1b1fde12812b769f3797c884337c Mon Sep 17 00:00:00 2001 From: Jean-Daniel Cryans Date: Tue, 15 Apr 2014 22:46:47 +0000 Subject: [PATCH] HBASE-10312 Flooding the cluster with administrative actions leads to collapse git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1587742 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/monitoring/TaskMonitor.java | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java index 1281613a88f..d51f354cf59 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.apache.commons.collections.buffer.CircularFifoBuffer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; @@ -51,8 +52,7 @@ public class TaskMonitor { static final int MAX_TASKS = 1000; private static TaskMonitor instance; - private List tasks = - Lists.newArrayList(); + private CircularFifoBuffer tasks = new CircularFifoBuffer(MAX_TASKS); /** * Get singleton instance. @@ -74,9 +74,6 @@ public class TaskMonitor { new PassthroughInvocationHandler(stat)); TaskAndWeakRefPair pair = new TaskAndWeakRefPair(stat, proxy); tasks.add(pair); - if (tasks.size() > MAX_TASKS) { - purgeExpiredTasks(); - } return proxy; } @@ -89,15 +86,10 @@ public class TaskMonitor { new PassthroughInvocationHandler(stat)); TaskAndWeakRefPair pair = new TaskAndWeakRefPair(stat, proxy); tasks.add(pair); - if (tasks.size() > MAX_TASKS) { - purgeExpiredTasks(); - } return proxy; } private synchronized void purgeExpiredTasks() { - int size = 0; - for (Iterator it = tasks.iterator(); it.hasNext();) { TaskAndWeakRefPair pair = it.next(); @@ -114,15 +106,8 @@ public class TaskMonitor { if (canPurge(stat)) { it.remove(); - } else { - size++; } } - - if (size > MAX_TASKS) { - LOG.warn("Too many actions in action monitor! Purging some."); - tasks = tasks.subList(size - MAX_TASKS, size); - } } /** @@ -133,7 +118,9 @@ public class TaskMonitor { public synchronized List getTasks() { purgeExpiredTasks(); ArrayList ret = Lists.newArrayListWithCapacity(tasks.size()); - for (TaskAndWeakRefPair pair : tasks) { + for (Iterator it = tasks.iterator(); + it.hasNext();) { + TaskAndWeakRefPair pair = it.next(); MonitoredTask t = pair.get(); ret.add(t.clone()); }