You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by jg...@apache.org on 2011/01/19 03:37:48 UTC

svn commit: r1060655 - in /hadoop/hdfs/trunk: CHANGES.txt src/java/org/apache/hadoop/hdfs/server/namenode/Checkpointer.java

Author: jghoman
Date: Wed Jan 19 02:37:48 2011
New Revision: 1060655

URL: http://svn.apache.org/viewvc?rev=1060655&view=rev
Log:
HDFS-1572. Checkpointer should trigger checkpoint with specified period.

Modified:
    hadoop/hdfs/trunk/CHANGES.txt
    hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/Checkpointer.java

Modified: hadoop/hdfs/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=1060655&r1=1060654&r2=1060655&view=diff
==============================================================================
--- hadoop/hdfs/trunk/CHANGES.txt (original)
+++ hadoop/hdfs/trunk/CHANGES.txt Wed Jan 19 02:37:48 2011
@@ -490,6 +490,9 @@ Release 0.22.0 - Unreleased
     HDFS-884. DataNode throws IOException if all data directories are 
     unavailable. (Steve Loughran and shv)
 
+    HDFS-1572. Checkpointer should trigger checkpoint with specified period.
+    (jghoman)
+
 Release 0.21.1 - Unreleased
 
   IMPROVEMENTS

Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/Checkpointer.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/Checkpointer.java?rev=1060655&r1=1060654&r2=1060655&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/Checkpointer.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/Checkpointer.java Wed Jan 19 02:37:48 2011
@@ -125,30 +125,26 @@ class Checkpointer extends Daemon {
   // The main work loop
   //
   public void run() {
-    // Check the size of the edit log once every 5 minutes.
-    long periodMSec = 5 * 60;   // 5 minutes
-    if(checkpointPeriod < periodMSec) {
-      periodMSec = checkpointPeriod;
-    }
-    periodMSec *= 1000;
+    final long fiveMinMS = 5 * 60 * 1000; // How often to poll edits size
+    final long periodMS = checkpointPeriod * 1000; // How often to checkpoint, regardless of edits' size
+    long lastCheckpointTimeMS = backupNode.shouldCheckpointAtStartup() ? 0 : now();
+    long lastSizeCheckMS = now();
 
-    long lastCheckpointTime = 0;
-    if(!backupNode.shouldCheckpointAtStartup())
-      lastCheckpointTime = now();
     while(shouldRun) {
       try {
         long now = now();
-        boolean shouldCheckpoint = false;
-        if(now >= lastCheckpointTime + periodMSec) {
-          shouldCheckpoint = true;
-        } else {
-          long size = getJournalSize();
-          if(size >= checkpointSize)
-            shouldCheckpoint = true;
+        boolean editsTooBig = false;
+        boolean periodExpired = now >= lastCheckpointTimeMS + periodMS;
+
+        if(now >= lastSizeCheckMS + fiveMinMS) {
+          editsTooBig = getJournalSize() > checkpointSize;
+          lastSizeCheckMS = now;
         }
-        if(shouldCheckpoint) {
+
+        if(periodExpired || editsTooBig) {
           doCheckpoint();
-          lastCheckpointTime = now;
+          lastCheckpointTimeMS = now;
+          lastSizeCheckMS = now;
         }
       } catch(IOException e) {
         LOG.error("Exception in doCheckpoint: ", e);
@@ -158,7 +154,7 @@ class Checkpointer extends Daemon {
         break;
       }
       try {
-        Thread.sleep(periodMSec);
+        Thread.sleep(Math.min(fiveMinMS, periodMS));
       } catch(InterruptedException ie) {
         // do nothing
       }