You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by sy...@apache.org on 2016/09/19 23:17:48 UTC
[35/50] [abbrv] hbase git commit: HBASE-16640
TimeoutBlockingQueue#remove() should return whether the entry is removed
HBASE-16640 TimeoutBlockingQueue#remove() should return whether the entry is removed
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/e782d0bb
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/e782d0bb
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/e782d0bb
Branch: refs/heads/hbase-12439
Commit: e782d0bbdf265fddfcce5754cf11112e2dbcc4ea
Parents: 8c4b09d
Author: tedyu <yu...@gmail.com>
Authored: Thu Sep 15 17:34:23 2016 -0700
Committer: tedyu <yu...@gmail.com>
Committed: Thu Sep 15 17:34:23 2016 -0700
----------------------------------------------------------------------
.../hadoop/hbase/procedure2/ProcedureExecutor.java | 5 +++--
.../hbase/procedure2/util/TimeoutBlockingQueue.java | 8 +++++---
.../procedure2/util/TestTimeoutBlockingQueue.java | 13 ++++++++-----
3 files changed, 16 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/e782d0bb/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.java
index 5042329..1a9010d 100644
--- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.java
+++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.java
@@ -615,9 +615,10 @@ public class ProcedureExecutor<TEnvironment> {
/**
* Remove a chore procedure from the executor
* @param chore the chore to remove
+ * @return whether the chore is removed
*/
- public void removeChore(final ProcedureInMemoryChore chore) {
- waitingTimeout.remove(chore);
+ public boolean removeChore(final ProcedureInMemoryChore chore) {
+ return waitingTimeout.remove(chore);
}
/**
http://git-wip-us.apache.org/repos/asf/hbase/blob/e782d0bb/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/util/TimeoutBlockingQueue.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/util/TimeoutBlockingQueue.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/util/TimeoutBlockingQueue.java
index fceabb1..2292e63 100644
--- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/util/TimeoutBlockingQueue.java
+++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/util/TimeoutBlockingQueue.java
@@ -92,15 +92,17 @@ public class TimeoutBlockingQueue<E> {
}
}
- public void remove(E e) {
+ public boolean remove(E e) {
+ if (e == null) return false;
lock.lock();
try {
for (int i = 0; i < objects.length; ++i) {
- if (objects[i] == e) {
+ if (e.equals(objects[i])) {
objects[i] = null;
- return;
+ return true;
}
}
+ return false;
} finally {
lock.unlock();
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/e782d0bb/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/util/TestTimeoutBlockingQueue.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/util/TestTimeoutBlockingQueue.java b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/util/TestTimeoutBlockingQueue.java
index 209d1c5..1f901b5 100644
--- a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/util/TestTimeoutBlockingQueue.java
+++ b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/util/TestTimeoutBlockingQueue.java
@@ -137,18 +137,21 @@ public class TestTimeoutBlockingQueue {
TimeoutBlockingQueue<TestObject> queue =
new TimeoutBlockingQueue<TestObject>(2, new TestObjectTimeoutRetriever());
- TestObject[] objs = new TestObject[5];
- for (int i = 0; i < objs.length; ++i) {
+ final int effectiveLen = 5;
+ TestObject[] objs = new TestObject[6];
+ for (int i = 0; i < effectiveLen; ++i) {
objs[i] = new TestObject(0, i * 10);
queue.add(objs[i]);
}
+ objs[effectiveLen] = new TestObject(0, effectiveLen * 10);
queue.dump();
- for (int i = 0; i < objs.length; i += 2) {
- queue.remove(objs[i]);
+ for (int i = 0; i < effectiveLen; i += 2) {
+ assertTrue(queue.remove(objs[i]));
}
+ assertTrue(!queue.remove(objs[effectiveLen]));
- for (int i = 0; i < objs.length; ++i) {
+ for (int i = 0; i < effectiveLen; ++i) {
TestObject x = queue.poll();
assertEquals((i % 2) == 0 ? null : objs[i], x);
}