Просмотр исходного кода

HDFS-8709. Clarify automatic sync in FSEditLog#logEdit.

(cherry picked from commit 5fddc5177ddad07a735d49c15a63cfc5f74d0891)
(cherry picked from commit efe9ae9fc68e4eec4b7388b971c520328e95fe76)
(cherry picked from commit 3b8cc7c21615d07e62251fd1b9c80f696f590a8f)
Andrew Wang 10 лет назад
Родитель
Сommit
85708329c8

+ 2 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -251,6 +251,8 @@ Release 2.7.3 - 2016-08-25
     HDFS-9019. Adding informative message to sticky bit permission denied
     exception. (xyao)
 
+    HDFS-8709. Clarify automatic sync in FSEditLog#logEdit. (wang)
+
   OPTIMIZATIONS
 
     HDFS-8845. DiskChecker should not traverse the entire tree (Chang Li via

+ 18 - 10
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java

@@ -410,10 +410,14 @@ public class FSEditLog implements LogsPurgeable {
   }
 
   /**
-   * Write an operation to the edit log. Do not sync to persistent
-   * store yet.
+   * Write an operation to the edit log.
+   * <p/>
+   * Additionally, this will sync the edit log if required by the underlying
+   * edit stream's automatic sync policy (e.g. when the buffer is full, or
+   * if a time interval has elapsed).
    */
   void logEdit(final FSEditLogOp op) {
+    boolean needsSync = false;
     synchronized (this) {
       assert isOpenForWrite() :
         "bad state: " + state;
@@ -435,14 +439,16 @@ public class FSEditLog implements LogsPurgeable {
       endTransaction(start);
       
       // check if it is time to schedule an automatic sync
-      if (!shouldForceSync()) {
-        return;
+      needsSync = shouldForceSync();
+      if (needsSync) {
+        isAutoSyncScheduled = true;
       }
-      isAutoSyncScheduled = true;
     }
     
-    // sync buffered edit log entries to persistent store
-    logSync();
+    // Sync the log if an automatic sync is required.
+    if (needsSync) {
+      logSync();
+    }
   }
 
   /**
@@ -1192,11 +1198,13 @@ public class FSEditLog implements LogsPurgeable {
       throws IOException {
     return journalSet.getEditLogManifest(fromTxId);
   }
- 
+
   /**
    * Finalizes the current edit log and opens a new log segment.
-   * @return the transaction id of the BEGIN_LOG_SEGMENT transaction
-   * in the new log.
+   *
+   * @param layoutVersion The layout version of the new edit log segment.
+   * @return the transaction id of the BEGIN_LOG_SEGMENT transaction in the new
+   * log.
    */
   synchronized long rollEditLog() throws IOException {
     LOG.info("Rolling edit logs");