From d25c8da619622752299369ec627d57f11d53522f Mon Sep 17 00:00:00 2001 From: Andrew Kyle Purtell Date: Mon, 18 May 2009 06:10:06 +0000 Subject: [PATCH] HBASE-1401 close HLog (and open new one) if there hasnt been edits in N minutes/hours; back out changes git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@775824 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 -- .../hadoop/hbase/regionserver/HLog.java | 10 ++++---- .../hadoop/hbase/regionserver/LogRoller.java | 24 ++++--------------- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 87c65defc3f..bd4122c7ee7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -256,8 +256,6 @@ Release 0.20.0 - Unreleased HLog#append?) HBASE-1429 Allow passing of a configuration object to HTablePool HBASE-1432 LuceneDocumentWrapper is not public - HBASE-1401 close HLog (and open new one) if there hasnt been edits in N - minutes/hours OPTIMIZATIONS HBASE-1412 Change values for delete column and column family in KeyValue diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HLog.java b/src/java/org/apache/hadoop/hbase/regionserver/HLog.java index 1f8d6574c5a..6067b9b1ba7 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HLog.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HLog.java @@ -132,6 +132,7 @@ public class HLog implements HConstants, Syncable { private final AtomicLong logSeqNum = new AtomicLong(0); private volatile long filenum = -1; + private volatile long old_filenum = -1; private final AtomicInteger numEntries = new AtomicInteger(0); @@ -273,10 +274,6 @@ public class HLog implements HConstants, Syncable { * @throws IOException */ public byte [] rollWriter() throws FailedLogCloseException, IOException { - // Return if nothing to flush. - if (this.writer != null && this.numEntries.get() <= 0) { - return null; - } byte [] regionToFlush = null; this.cacheFlushLock.lock(); try { @@ -286,6 +283,9 @@ public class HLog implements HConstants, Syncable { synchronized (updateLock) { // Clean up current writer. Path oldFile = cleanupCurrentWriter(this.filenum); + if (this.filenum >= 0) { + this.old_filenum = this.filenum; + } this.filenum = System.currentTimeMillis(); Path newPath = computeFilename(this.filenum); this.writer = SequenceFile.createWriter(this.fs, this.conf, newPath, @@ -587,7 +587,7 @@ public class HLog implements HConstants, Syncable { } } } - + private void requestLogRoll() { if (this.listener != null) { this.listener.logRollRequested(); diff --git a/src/java/org/apache/hadoop/hbase/regionserver/LogRoller.java b/src/java/org/apache/hadoop/hbase/regionserver/LogRoller.java index a88a62a7e2b..f39df019456 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/LogRoller.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/LogRoller.java @@ -40,32 +40,17 @@ class LogRoller extends Thread implements LogRollListener { private final ReentrantLock rollLock = new ReentrantLock(); private final AtomicBoolean rollLog = new AtomicBoolean(false); private final HRegionServer server; - private volatile long lastrolltime = System.currentTimeMillis(); - // Period to roll log. - private final long rollperiod; - + /** @param server */ public LogRoller(final HRegionServer server) { super(); this.server = server; - this.rollperiod = - this.server.conf.getLong("hbase.regionserver.logroll.period", 3600000); } @Override public void run() { while (!server.isStopRequested()) { - long now = System.currentTimeMillis(); - boolean periodic = false; if (!rollLog.get()) { - periodic = (now - this.lastrolltime) < this.rollperiod; - if (periodic) { - // Time for periodic roll - if (LOG.isDebugEnabled()) { - LOG.debug("Hlog roll period " + this.rollperiod + "ms elapsed"); - } - break; - } synchronized (rollLog) { try { rollLog.wait(server.threadWakeFrequency); @@ -77,7 +62,6 @@ class LogRoller extends Thread implements LogRollListener { } rollLock.lock(); // Don't interrupt us. We're working try { - this.lastrolltime = now; byte [] regionToFlush = server.getLog().rollWriter(); if (regionToFlush != null) { scheduleFlush(regionToFlush); @@ -106,7 +90,7 @@ class LogRoller extends Thread implements LogRollListener { } LOG.info("LogRoller exiting."); } - + private void scheduleFlush(final byte [] region) { boolean scheduled = false; HRegion r = this.server.getOnlineRegion(region); @@ -130,7 +114,7 @@ class LogRoller extends Thread implements LogRollListener { rollLog.notifyAll(); } } - + /** * Called by region server to wake up this thread if it sleeping. * It is sleeping if rollLock is not held. @@ -143,4 +127,4 @@ class LogRoller extends Thread implements LogRollListener { rollLock.unlock(); } } -} \ No newline at end of file +}