hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r776017 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/regionserver/HLog.java src/java/org/apache/hadoop/hbase/regionserver/LogRoller.java
Date Mon, 18 May 2009 17:36:34 GMT
Author: stack
Date: Mon May 18 17:36:33 2009
New Revision: 776017

URL: http://svn.apache.org/viewvc?rev=776017&view=rev
Log:
HBASE-1401 close HLog (and open new one) if there hasnt been edits in N minutes/hours

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HLog.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/LogRoller.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=776017&r1=776016&r2=776017&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Mon May 18 17:36:33 2009
@@ -256,6 +256,8 @@
                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

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HLog.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HLog.java?rev=776017&r1=776016&r2=776017&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HLog.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HLog.java Mon May 18
17:36:33 2009
@@ -132,7 +132,6 @@
   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);
 
@@ -274,6 +273,10 @@
    * @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 {
@@ -283,9 +286,6 @@
       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 @@
       }
     }
   }
-  
+
   private void requestLogRoll() {
     if (this.listener != null) {
       this.listener.logRollRequested();

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/LogRoller.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/LogRoller.java?rev=776017&r1=776016&r2=776017&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/LogRoller.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/LogRoller.java Mon May
18 17:36:33 2009
@@ -40,28 +40,43 @@
   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()) {
-        synchronized (rollLog) {
-          try {
-            rollLog.wait(server.threadWakeFrequency);
-          } catch (InterruptedException e) {
-            continue;
+        periodic = (now - this.lastrolltime) > this.rollperiod;
+        if (!periodic) {
+          synchronized (rollLog) {
+            try {
+              rollLog.wait(server.threadWakeFrequency);
+            } catch (InterruptedException e) {
+              // Fall through
+            }
           }
+          continue;
+        }
+        // Time for periodic roll
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("Hlog roll period " + this.rollperiod + "ms elapsed");
         }
-        continue;
       }
       rollLock.lock();          // Don't interrupt us. We're working
       try {
+        this.lastrolltime = now;
         byte [] regionToFlush = server.getLog().rollWriter();
         if (regionToFlush != null) {
           scheduleFlush(regionToFlush);
@@ -90,7 +105,7 @@
     }
     LOG.info("LogRoller exiting.");
   }
-  
+
   private void scheduleFlush(final byte [] region) {
     boolean scheduled = false;
     HRegion r = this.server.getOnlineRegion(region);
@@ -114,7 +129,7 @@
       rollLog.notifyAll();
     }
   }
-  
+
   /**
    * Called by region server to wake up this thread if it sleeping.
    * It is sleeping if rollLock is not held.



Mime
View raw message