forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Proxy & Client] Configure Netty DNS resolver to match JDK DNS cachin…
…g setting, share DNS resolver instance in Proxy (apache#15219) * Align Netty DNS resolver cache settings with Java DNS cache settings - Netty DNS resolver caches forever by default - this could cause problems with Kubernetes deployments * Share Netty DNSNameResolver in proxy * Remove overriding of ConnectionPool.close since it's not necessary * Address review comment: remove ProxyConnectionPool
- Loading branch information
Showing
7 changed files
with
125 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
pulsar-common/src/main/java/org/apache/pulsar/common/util/netty/DnsResolverUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.common.util.netty; | ||
|
||
import io.netty.resolver.dns.DnsNameResolverBuilder; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class DnsResolverUtil { | ||
private static final int MIN_TTL = 0; | ||
private static final int TTL; | ||
private static final int NEGATIVE_TTL; | ||
|
||
// default TTL value when JDK setting is "forever" (-1) | ||
private static final int DEFAULT_TTL = 60; | ||
|
||
// default negative TTL value when JDK setting is "forever" (-1) | ||
private static final int DEFAULT_NEGATIVE_TTL = 10; | ||
|
||
static { | ||
int ttl = DEFAULT_TTL; | ||
int negativeTtl = DEFAULT_NEGATIVE_TTL; | ||
try { | ||
// use reflection to call sun.net.InetAddressCachePolicy's get and getNegative methods for getting | ||
// effective JDK settings for DNS caching | ||
Class<?> inetAddressCachePolicyClass = Class.forName("sun.net.InetAddressCachePolicy"); | ||
Method getTTLMethod = inetAddressCachePolicyClass.getMethod("get"); | ||
ttl = (Integer) getTTLMethod.invoke(null); | ||
Method getNegativeTTLMethod = inetAddressCachePolicyClass.getMethod("getNegative"); | ||
negativeTtl = (Integer) getNegativeTTLMethod.invoke(null); | ||
} catch (NoSuchMethodException | ClassNotFoundException | InvocationTargetException | ||
| IllegalAccessException e) { | ||
log.warn("Cannot get DNS TTL settings from sun.net.InetAddressCachePolicy class", e); | ||
} | ||
TTL = useDefaultTTLWhenSetToForever(ttl, DEFAULT_TTL); | ||
NEGATIVE_TTL = useDefaultTTLWhenSetToForever(negativeTtl, DEFAULT_NEGATIVE_TTL); | ||
} | ||
|
||
private static int useDefaultTTLWhenSetToForever(int ttl, int defaultTtl) { | ||
return ttl < 0 ? defaultTtl : ttl; | ||
} | ||
|
||
private DnsResolverUtil() { | ||
// utility class with static methods, prevent instantiation | ||
} | ||
|
||
/** | ||
* Configure Netty's {@link DnsNameResolverBuilder}'s ttl and negativeTtl to match the JDK's DNS caching settings. | ||
* If the JDK setting for TTL is forever (-1), the TTL will be set to 60 seconds. | ||
* | ||
* @param dnsNameResolverBuilder The Netty {@link DnsNameResolverBuilder} instance to apply the settings | ||
*/ | ||
public static void applyJdkDnsCacheSettings(DnsNameResolverBuilder dnsNameResolverBuilder) { | ||
dnsNameResolverBuilder.ttl(MIN_TTL, TTL); | ||
dnsNameResolverBuilder.negativeTtl(NEGATIVE_TTL); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 0 additions & 58 deletions
58
pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnectionPool.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters