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
This commit is contained in:
Michael Stack 2008-12-05 05:26:28 +00:00
parent 2987febc16
commit 4024f5f128
3 changed files with 17 additions and 7 deletions

View File

@ -99,6 +99,8 @@ Release 0.19.0 - Unreleased
HBASE-1039 Compaction fails if bloomfilters are enabled HBASE-1039 Compaction fails if bloomfilters are enabled
HBASE-1027 Make global flusher check work with percentages rather than HBASE-1027 Make global flusher check work with percentages rather than
hard code memory sizes hard code memory sizes
HBASE-1000 Sleeper.sleep does not go back to sleep when interrupted
and no stop flag given.
IMPROVEMENTS IMPROVEMENTS
HBASE-901 Add a limit to key length, check key and value length on client side HBASE-901 Add a limit to key length, check key and value length on client side

View File

@ -59,19 +59,21 @@ public abstract class Chore extends Thread {
this.sleeper.sleep(); this.sleeper.sleep();
} }
this.sleeper.sleep(); this.sleeper.sleep();
while(!this.stop.get()) { while (!this.stop.get()) {
long startTime = System.currentTimeMillis();
try { try {
long startTime = System.currentTimeMillis();
chore(); chore();
this.sleeper.sleep(startTime);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Caught exception", e); LOG.error("Caught exception", e);
if (this.stop.get()) {
continue;
}
} }
this.sleeper.sleep(startTime);
} }
} catch (Throwable t) { } catch (Throwable t) {
LOG.fatal("Caught error. Starting shutdown.", t); LOG.fatal("Caught error. Starting shutdown.", t);
this.stop.set(true); this.stop.set(true);
} finally { } finally {
LOG.info(getName() + " exiting"); LOG.info(getName() + " exiting");
} }
@ -97,4 +99,4 @@ public abstract class Chore extends Thread {
protected void sleep() { protected void sleep() {
this.sleeper.sleep(); this.sleeper.sleep();
} }
} }

View File

@ -66,11 +66,14 @@ public class Sleeper {
LOG.warn("Calculated wait time > " + this.period + LOG.warn("Calculated wait time > " + this.period +
"; setting to this.period: " + System.currentTimeMillis() + ", " + "; setting to this.period: " + System.currentTimeMillis() + ", " +
startTime); startTime);
waitTime = this.period;
} }
if (waitTime > 0) { while (waitTime > 0) {
long woke = -1;
try { try {
Thread.sleep(waitTime); Thread.sleep(waitTime);
long slept = System.currentTimeMillis() - now; woke = System.currentTimeMillis();
long slept = woke - now;
if (slept > (10 * this.period)) { if (slept > (10 * this.period)) {
LOG.warn("We slept " + slept + "ms, ten times longer than scheduled: " + LOG.warn("We slept " + slept + "ms, ten times longer than scheduled: " +
this.period); this.period);
@ -82,6 +85,9 @@ public class Sleeper {
return; return;
} }
} }
// Recalculate waitTime.
woke = (woke == -1)? System.currentTimeMillis(): woke;
waitTime = this.period - (woke - startTime);
} }
} }
} }