From 4024f5f128e6f3200b7e8f9fe523f4e91ea76e5c Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Fri, 5 Dec 2008 05:26:28 +0000 Subject: [PATCH] HBASE-1000 Sleeper.sleep does not go back to sleep when interrupted and no stop flag given. git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@723589 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ src/java/org/apache/hadoop/hbase/Chore.java | 12 +++++++----- src/java/org/apache/hadoop/hbase/util/Sleeper.java | 10 ++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index a3f3896cbbd..b47769d1aa6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -99,6 +99,8 @@ Release 0.19.0 - Unreleased HBASE-1039 Compaction fails if bloomfilters are enabled HBASE-1027 Make global flusher check work with percentages rather than hard code memory sizes + HBASE-1000 Sleeper.sleep does not go back to sleep when interrupted + and no stop flag given. IMPROVEMENTS HBASE-901 Add a limit to key length, check key and value length on client side diff --git a/src/java/org/apache/hadoop/hbase/Chore.java b/src/java/org/apache/hadoop/hbase/Chore.java index 417721edb21..e80e633a01e 100644 --- a/src/java/org/apache/hadoop/hbase/Chore.java +++ b/src/java/org/apache/hadoop/hbase/Chore.java @@ -59,19 +59,21 @@ public abstract class Chore extends Thread { this.sleeper.sleep(); } this.sleeper.sleep(); - while(!this.stop.get()) { + while (!this.stop.get()) { + long startTime = System.currentTimeMillis(); try { - long startTime = System.currentTimeMillis(); chore(); - this.sleeper.sleep(startTime); } catch (Exception e) { LOG.error("Caught exception", e); + if (this.stop.get()) { + continue; + } } + this.sleeper.sleep(startTime); } } catch (Throwable t) { LOG.fatal("Caught error. Starting shutdown.", t); this.stop.set(true); - } finally { LOG.info(getName() + " exiting"); } @@ -97,4 +99,4 @@ public abstract class Chore extends Thread { protected void sleep() { this.sleeper.sleep(); } -} \ No newline at end of file +} diff --git a/src/java/org/apache/hadoop/hbase/util/Sleeper.java b/src/java/org/apache/hadoop/hbase/util/Sleeper.java index af5e19a2bfd..7e2aca1150e 100644 --- a/src/java/org/apache/hadoop/hbase/util/Sleeper.java +++ b/src/java/org/apache/hadoop/hbase/util/Sleeper.java @@ -66,11 +66,14 @@ public class Sleeper { LOG.warn("Calculated wait time > " + this.period + "; setting to this.period: " + System.currentTimeMillis() + ", " + startTime); + waitTime = this.period; } - if (waitTime > 0) { + while (waitTime > 0) { + long woke = -1; try { Thread.sleep(waitTime); - long slept = System.currentTimeMillis() - now; + woke = System.currentTimeMillis(); + long slept = woke - now; if (slept > (10 * this.period)) { LOG.warn("We slept " + slept + "ms, ten times longer than scheduled: " + this.period); @@ -82,6 +85,9 @@ public class Sleeper { return; } } + // Recalculate waitTime. + woke = (woke == -1)? System.currentTimeMillis(): woke; + waitTime = this.period - (woke - startTime); } } }