From 8809f4b85dc797716ba7f40ff1ee10039ffe8c59 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Wed, 2 Aug 2023 07:54:37 +0300 Subject: [PATCH 1/2] Improvement - each AddressResolver created by SequentialDnsAddressResolverFactory should share common DnsCache and DnsCnameCache instances. #5222 Signed-off-by: Sergey Kuznetsov --- .../SequentialDnsAddressResolverFactory.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/redisson/src/main/java/org/redisson/connection/SequentialDnsAddressResolverFactory.java b/redisson/src/main/java/org/redisson/connection/SequentialDnsAddressResolverFactory.java index 5fec788b6..a31087cf6 100644 --- a/redisson/src/main/java/org/redisson/connection/SequentialDnsAddressResolverFactory.java +++ b/redisson/src/main/java/org/redisson/connection/SequentialDnsAddressResolverFactory.java @@ -21,8 +21,7 @@ import io.netty.resolver.AddressResolver; import io.netty.resolver.AddressResolverGroup; import io.netty.resolver.InetSocketAddressResolver; import io.netty.resolver.NameResolver; -import io.netty.resolver.dns.DnsAddressResolverGroup; -import io.netty.resolver.dns.DnsServerAddressStreamProvider; +import io.netty.resolver.dns.*; import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.Promise; import org.redisson.misc.AsyncSemaphore; @@ -91,7 +90,13 @@ public class SequentialDnsAddressResolverFactory implements AddressResolverGroup @Override public AddressResolverGroup create(Class channelType, DnsServerAddressStreamProvider nameServerProvider) { - DnsAddressResolverGroup group = new DnsAddressResolverGroup(channelType, nameServerProvider) { + DnsNameResolverBuilder dnsResolverBuilder = new DnsNameResolverBuilder(); + dnsResolverBuilder.channelType(channelType) + .nameServerProvider(nameServerProvider) + .resolveCache(new DefaultDnsCache(0, Integer.MAX_VALUE, 0)) + .cnameCache(new DefaultDnsCnameCache(0, Integer.MAX_VALUE)); + + DnsAddressResolverGroup group = new DnsAddressResolverGroup(dnsResolverBuilder) { @Override protected AddressResolver newAddressResolver(EventLoop eventLoop, NameResolver resolver) throws Exception { return new LimitedInetSocketAddressResolver(asyncSemaphore, eventLoop, resolver); From ccccd4bd5e84a78cdfb94b17ecd536f0e37262b8 Mon Sep 17 00:00:00 2001 From: Sergey Kuznetsov Date: Wed, 2 Aug 2023 16:36:11 +0200 Subject: [PATCH 2/2] String.replaceFirsts compiles regex pattern on each call, it can be avoided just by getting index of `://` Signed-off-by: Sergey Kuznetsov Signed-off-by: Sergey Kuznetsov --- redisson/src/main/java/org/redisson/misc/RedisURI.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/redisson/src/main/java/org/redisson/misc/RedisURI.java b/redisson/src/main/java/org/redisson/misc/RedisURI.java index e6e4c36f8..c00de8515 100644 --- a/redisson/src/main/java/org/redisson/misc/RedisURI.java +++ b/redisson/src/main/java/org/redisson/misc/RedisURI.java @@ -42,8 +42,7 @@ public class RedisURI { } public RedisURI(String uri) { - if (!uri.startsWith("redis://") - && !uri.startsWith("rediss://")) { + if (!uri.startsWith("redis://") && !uri.startsWith("rediss://")) { throw new IllegalArgumentException("Redis url should start with redis:// or rediss:// (for SSL connection)"); } @@ -73,8 +72,9 @@ public class RedisURI { } private String parseUrl(String uri) { - String urlHost = uri.replaceFirst("redis://", "http://").replaceFirst("rediss://", "http://"); - String ipV6Host = uri.substring(uri.indexOf("://")+3, uri.lastIndexOf(":")); + int hostStartIndex = uri.indexOf("://") + 3; + String urlHost = "http://" + uri.substring(hostStartIndex); + String ipV6Host = uri.substring(hostStartIndex, uri.lastIndexOf(":")); if (ipV6Host.contains("@")) { ipV6Host = ipV6Host.split("@")[1]; }