Skip to content

Commit 7fe378b

Browse files
xinglinXing Lin
authored and
Xing Lin
committed
HDFS-17067 Use BlockingThreadPoolExecutorService for nnProbingThreadPool in ObserverReadProxy (apache#5803)
1 parent 0e90c2f commit 7fe378b

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProvider.java

+12-14
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@
2727
import java.util.concurrent.Callable;
2828
import java.util.concurrent.ExecutionException;
2929
import java.util.concurrent.RejectedExecutionException;
30-
import java.util.concurrent.ExecutorService;
3130
import java.util.concurrent.Future;
32-
import java.util.concurrent.ThreadPoolExecutor;
3331
import java.util.concurrent.TimeUnit;
34-
import java.util.concurrent.ArrayBlockingQueue;
3532
import java.util.concurrent.TimeoutException;
3633
import java.util.List;
3734

@@ -54,6 +51,7 @@
5451
import org.apache.hadoop.ipc.RemoteException;
5552
import org.apache.hadoop.ipc.RpcInvocationHandler;
5653
import org.apache.hadoop.ipc.StandbyException;
54+
import org.apache.hadoop.util.BlockingThreadPoolExecutorService;
5755
import org.apache.hadoop.util.Time;
5856
import org.slf4j.Logger;
5957
import org.slf4j.LoggerFactory;
@@ -187,18 +185,8 @@ public class ObserverReadProxyProvider<T>
187185

188186
/**
189187
* Threadpool to send the getHAServiceState requests.
190-
*
191-
* One thread running all the time, with up to 4 threads. Idle threads will be killed after
192-
* 1 minute. At most 1024 requests can be submitted before they start to be rejected.
193-
*
194-
* Each hdfs client will have its own ObserverReadProxyProvider. Thus,
195-
* having 1 thread running should be sufficient in most cases.
196-
* We are not expecting to receive a lot of outstanding RPC calls
197-
* from a single hdfs client, thus setting the queue size to 1024.
198188
*/
199-
private final ExecutorService nnProbingThreadPool =
200-
new ThreadPoolExecutor(1, 4, 1L, TimeUnit.MINUTES,
201-
new ArrayBlockingQueue<Runnable>(1024));
189+
private final BlockingThreadPoolExecutorService nnProbingThreadPool;
202190

203191
/**
204192
* By default ObserverReadProxyProvider uses
@@ -263,6 +251,15 @@ public ObserverReadProxyProvider(
263251
+ "class does not implement {}", uri, ClientProtocol.class.getName());
264252
this.observerReadEnabled = false;
265253
}
254+
255+
/*
256+
* At most 4 threads will be running and each thread will die after 10
257+
* seconds of no use. Up to 132 tasks (4 active + 128 waiting) can be
258+
* submitted simultaneously.
259+
*/
260+
nnProbingThreadPool =
261+
BlockingThreadPoolExecutorService.newInstance(4, 128, 10L, TimeUnit.SECONDS,
262+
"nn-ha-state-probing");
266263
}
267264

268265
public AlignmentContext getAlignmentContext() {
@@ -649,6 +646,7 @@ public synchronized void close() throws IOException {
649646
}
650647
}
651648
failoverProxy.close();
649+
nnProbingThreadPool.shutdown();
652650
}
653651

654652
@Override

0 commit comments

Comments
 (0)