You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cm...@apache.org on 2014/03/06 08:57:19 UTC
svn commit: r1574787 -
/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/unix/DomainSocketWatcher.java
Author: cmccabe
Date: Thu Mar 6 07:57:19 2014
New Revision: 1574787
URL: http://svn.apache.org/r1574787
Log:
HDFS-6057. DomainSocketWatcher.watcherThread should be marked as a daemon thread (cmccabe)
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/unix/DomainSocketWatcher.java
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/unix/DomainSocketWatcher.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/unix/DomainSocketWatcher.java?rev=1574787&r1=1574786&r2=1574787&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/unix/DomainSocketWatcher.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/unix/DomainSocketWatcher.java Thu Mar 6 07:57:19 2014
@@ -235,6 +235,7 @@ public final class DomainSocketWatcher i
Preconditions.checkArgument(interruptCheckPeriodMs > 0);
this.interruptCheckPeriodMs = interruptCheckPeriodMs;
notificationSockets = DomainSocket.socketpair();
+ watcherThread.setDaemon(true);
watcherThread.start();
}
@@ -263,6 +264,16 @@ public final class DomainSocketWatcher i
Uninterruptibles.joinUninterruptibly(watcherThread);
}
+ @VisibleForTesting
+ public boolean isClosed() {
+ lock.lock();
+ try {
+ return closed;
+ } finally {
+ lock.unlock();
+ }
+ }
+
/**
* Add a socket.
*
@@ -274,7 +285,11 @@ public final class DomainSocketWatcher i
public void add(DomainSocket sock, Handler handler) {
lock.lock();
try {
- checkNotClosed();
+ if (closed) {
+ handler.handle(sock);
+ IOUtils.cleanup(LOG, sock);
+ return;
+ }
Entry entry = new Entry(sock, handler);
try {
sock.refCount.reference();
@@ -295,7 +310,6 @@ public final class DomainSocketWatcher i
if (!toAdd.contains(entry)) {
break;
}
- checkNotClosed();
}
} finally {
lock.unlock();
@@ -310,7 +324,7 @@ public final class DomainSocketWatcher i
public void remove(DomainSocket sock) {
lock.lock();
try {
- checkNotClosed();
+ if (closed) return;
toRemove.put(sock.fd, sock);
kick();
while (true) {
@@ -322,7 +336,6 @@ public final class DomainSocketWatcher i
if (!toRemove.containsKey(sock.fd)) {
break;
}
- checkNotClosed();
}
} finally {
lock.unlock();
@@ -342,17 +355,6 @@ public final class DomainSocketWatcher i
}
}
- /**
- * Check that the DomainSocketWatcher is not closed.
- * Must be called while holding the lock.
- */
- private void checkNotClosed() {
- Preconditions.checkState(lock.isHeldByCurrentThread());
- if (closed) {
- throw new RuntimeException("DomainSocketWatcher is closed.");
- }
- }
-
private void sendCallback(String caller, TreeMap<Integer, Entry> entries,
FdSet fdSet, int fd) {
if (LOG.isTraceEnabled()) {