DazhuangSu commented on a change in pull request #2651:
URL: https://github.com/apache/hadoop/pull/2651#discussion_r628711047
##########
File path:
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionContext.java
##########
@@ -83,30 +98,38 @@ public synchronized boolean isUsable() {
*/
public synchronized ProxyAndInfo<?> getClient() {
this.numThreads++;
+ this.lastActiveTs = Time.monotonicNow();
return this.client;
}
/**
- * Release this connection. If the connection was closed, close the proxy.
- * Otherwise, mark the connection as not used by us anymore.
+ * Release this connection.
*/
public synchronized void release() {
- if (--this.numThreads == 0 && this.closed) {
- close();
+ if (this.numThreads > 0) {
+ this.numThreads--;
}
}
/**
- * We will not use this connection anymore. If it's not being used, we close
- * it. Otherwise, we let release() do it once we are done with it.
+ * Close a connection. Only idle connections can be closed since
+ * the RPC proxy would be shut down immediately.
+ *
+ * @param force whether the connection should be closed anyway.
+ * @throws IllegalStateException when the connection is not idle
*/
- public synchronized void close() {
- this.closed = true;
- if (this.numThreads == 0) {
- Object proxy = this.client.getProxy();
- // Nobody should be using this anymore so it should close right away
- RPC.stopProxy(proxy);
+ public synchronized void close(boolean force) throws IllegalStateException {
+ if (!force && this.numThreads > 0) {
+ throw new IllegalStateException("Active connection cannot be closed");
Review comment:
@fengnanli @Hexiaoqiao
we shouldn't throw a RuntimeException here.
whenever CleanupTask run into this , throwing a runtime exception will cause
the threadpool(which is used to close idle connection ) in ConnectionManager
to hung.
And no more CleanupTask will be scheduled.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]