hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jxi...@apache.org
Subject svn commit: r1363416 - /hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java
Date Thu, 19 Jul 2012 16:36:50 GMT
Author: jxiang
Date: Thu Jul 19 16:36:49 2012
New Revision: 1363416

URL: http://svn.apache.org/viewvc?rev=1363416&view=rev
Log:
HBASE-6420 Gracefully shutdown logsyncer

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java?rev=1363416&r1=1363415&r2=1363416&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java Thu
Jul 19 16:36:49 2012
@@ -41,6 +41,7 @@ import java.util.TreeSet;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentSkipListMap;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.Lock;
@@ -980,7 +981,6 @@ public class HLog implements Syncable {
    */
   public void close() throws IOException {
     try {
-      logSyncerThread.interrupt();
       logSyncerThread.close();
       // Make sure we synced everything
       logSyncerThread.join(this.optionalFlushInterval*2);
@@ -1193,8 +1193,8 @@ public class HLog implements Syncable {
    class LogSyncer extends HasThread {
 
     private final long optionalFlushInterval;
-    
-    private boolean closeLogSyncer = false;
+
+    private AtomicBoolean closeLogSyncer = new AtomicBoolean(false);
 
     // List of pending writes to the HLog. There corresponds to transactions
     // that have not yet returned to the client. We keep them cached here
@@ -1213,11 +1213,13 @@ public class HLog implements Syncable {
       try {
         // awaiting with a timeout doesn't always
         // throw exceptions on interrupt
-        while(!this.isInterrupted() && !closeLogSyncer) {
+        while(!this.isInterrupted() && !closeLogSyncer.get()) {
 
           try {
             if (unflushedEntries.get() <= syncedTillHere) {
-              Thread.sleep(this.optionalFlushInterval);
+              synchronized (closeLogSyncer) {
+                closeLogSyncer.wait(this.optionalFlushInterval);
+              }
             }
             sync();
           } catch (IOException e) {
@@ -1256,9 +1258,12 @@ public class HLog implements Syncable {
         writer.append(e);
       }
     }
-    
-    void close(){
-      closeLogSyncer = true;
+
+    void close() {
+      synchronized (closeLogSyncer) {
+        closeLogSyncer.set(true);
+        closeLogSyncer.notifyAll();
+      }
     }
   }
 



Mime
View raw message