Prechádzať zdrojové kódy

HADOOP-10404. Commit correct version of patch (cmccabe)
(cherry picked from commit 687d83c9e10a4432c8d54c2cd406c7ccb4392187)

Colin Patrick Mccabe 10 rokov pred
rodič
commit
b5158c8d24

+ 12 - 11
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/unix/DomainSocketWatcher.java

@@ -101,7 +101,7 @@ public final class DomainSocketWatcher implements Closeable {
    */
   private class NotificationHandler implements Handler {
     public boolean handle(DomainSocket sock) {
-      lock.lock();
+      assert(lock.isHeldByCurrentThread());
       try {
         if (LOG.isTraceEnabled()) {
           LOG.trace(this + ": NotificationHandler: doing a read on " +
@@ -125,8 +125,6 @@ public final class DomainSocketWatcher implements Closeable {
         }
         closed = true;
         return true;
-      } finally {
-        lock.unlock();
       }
     }
   }
@@ -349,15 +347,13 @@ public final class DomainSocketWatcher implements Closeable {
    * Wake up the DomainSocketWatcher thread.
    */
   private void kick() {
-    lock.lock();
+    assert(lock.isHeldByCurrentThread());
     try {
       notificationSockets[0].getOutputStream().write(0);
     } catch (IOException e) {
       if (!closed) {
         LOG.error(this + ": error writing to notificationSockets[0]", e);
       }
-    } finally {
-      lock.unlock();
     }
   }
 
@@ -467,12 +463,17 @@ public final class DomainSocketWatcher implements Closeable {
       } catch (IOException e) {
         LOG.error(toString() + " terminating on IOException", e);
       } finally {
-        kick(); // allow the handler for notificationSockets[0] to read a byte
-        for (Entry entry : entries.values()) {
-          sendCallback("close", entries, fdSet, entry.getDomainSocket().fd);
+        lock.lock();
+        try {
+          kick(); // allow the handler for notificationSockets[0] to read a byte
+          for (Entry entry : entries.values()) {
+            sendCallback("close", entries, fdSet, entry.getDomainSocket().fd);
+          }
+          entries.clear();
+          fdSet.close();
+        } finally {
+          lock.unlock();
         }
-        entries.clear();
-        fdSet.close();
       }
     }
   });