Create a daemon thread pool for etcd client & Add name format for ExecutorService (#167)

Signed-off-by: Qishang Zhong <zhongqishang@gmail.com>
This commit is contained in:
Qishang Zhong 2021-04-25 10:41:16 +08:00 committed by GitHub
parent 45f5b91a67
commit 5265d3fd7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 3 deletions

View File

@ -531,7 +531,16 @@ public class PDClient extends AbstractGRPCClient<PDBlockingStub, PDStub>
GetMembersResponse resp = null;
List<URI> pdAddrs = getConf().getPdAddrs();
this.pdAddrs = pdAddrs;
this.etcdClient = Client.builder().endpoints(pdAddrs).build();
this.etcdClient =
Client.builder()
.endpoints(pdAddrs)
.executorService(
Executors.newCachedThreadPool(
new ThreadFactoryBuilder()
.setNameFormat("etcd-conn-manager-pool-%d")
.setDaemon(true)
.build()))
.build();
this.hostMapping = new HostMapping(this.etcdClient, conf.getNetworkMappingName());
for (URI u : pdAddrs) {
resp = getMembers(u);
@ -547,7 +556,10 @@ public class PDClient extends AbstractGRPCClient<PDBlockingStub, PDStub>
createLeaderWrapper(resp.getLeader().getClientUrls(0));
service =
Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder().setDaemon(true).build());
new ThreadFactoryBuilder()
.setNameFormat("PDClient-update-leader-pool-%d")
.setDaemon(true)
.build());
service.scheduleAtFixedRate(
() -> {
// Wrap this with a try catch block in case schedule update fails
@ -562,7 +574,10 @@ public class PDClient extends AbstractGRPCClient<PDBlockingStub, PDStub>
TimeUnit.MINUTES);
tiflashReplicaService =
Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder().setDaemon(true).build());
new ThreadFactoryBuilder()
.setNameFormat("PDClient-tiflash-replica-pool-%d")
.setDaemon(true)
.build());
tiflashReplicaService.scheduleAtFixedRate(
this::updateTiFlashReplicaStatus, 10, 10, TimeUnit.SECONDS);
}