Skip to content

Commit 2cdda2c

Browse files
authored
Remove analyze DNS name to get/refresh IP for create connection. (#69)
1 parent 9c5870d commit 2cdda2c

File tree

4 files changed

+14
-44
lines changed

4 files changed

+14
-44
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ Changes by Version
22
==================
33
Release Notes.
44

5+
0.7.0-rc4
6+
------------------
7+
8+
### Features
9+
10+
* Remove analyze DNS name to get/refresh IP for create connection.
11+
512
0.7.0-rc3
613
------------------
714

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ BanyanDBClient client = new BanyanDBClient("banyandb.svc:17912", "10.0.12.9:1791
2323
client.connect();
2424
```
2525

26-
These addresses are either IP addresses or DNS names. If DNS names are used, the client will resolve the DNS name to
27-
IP addresses and use them to connect to the server. The client will periodically refresh the IP addresses of the DNS
28-
name. The refresh interval can be configured by `resolveDNSInterval` option.
26+
These addresses are either IP addresses or DNS names.
2927

3028
The client will try to connect to the server in a round-robin manner. The client will periodically refresh the server
3129
addresses. The refresh interval can be configured by `refreshInterval` option.
@@ -43,8 +41,6 @@ options are listed below,
4341
| forceReconnectionThreshold | Threshold of force gRPC reconnection if network issue is encountered | 1 |
4442
| forceTLS | Force use TLS for gRPC | false |
4543
| sslTrustCAPath | SSL: Trusted CA Path | |
46-
| sslCertChainPath | SSL: Cert Chain Path | |
47-
| sslKeyPath | SSL: Cert Key Path | |
4844

4945
## Schema Management
5046

src/main/java/org/apache/skywalking/banyandb/v1/client/Options.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ public class Options {
4545
* Threshold of force gRPC reconnection if network issue is encountered
4646
*/
4747
private long forceReconnectionThreshold = 1;
48-
/**
49-
* Threshold of resolving the DNS
50-
*/
51-
private long resolveDNSInterval = 30 * 60;
48+
5249
/**
5350
* Force use TLS for gRPC
5451
* Default is false
@@ -59,11 +56,11 @@ public class Options {
5956
*/
6057
private String sslTrustCAPath = "";
6158
/**
62-
* SSL: Cert Chain Path
59+
* SSL: Cert Chain Path, BanyanDB server not support mTLS yet
6360
*/
6461
private String sslCertChainPath = "";
6562
/**
66-
* SSL: Cert Key Path
63+
* SSL: Cert Key Path, BanyanDB server not support mTLS yet
6764
*/
6865
private String sslKeyPath = "";
6966

@@ -76,4 +73,4 @@ ChannelManagerSettings buildChannelManagerSettings() {
7673
.setForceReconnectionThreshold(this.forceReconnectionThreshold)
7774
.build();
7875
}
79-
}
76+
}

src/main/java/org/apache/skywalking/banyandb/v1/client/grpc/channel/DefaultChannelFactory.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,27 @@
2525
import io.grpc.netty.NettyChannelBuilder;
2626
import io.netty.handler.ssl.SslContextBuilder;
2727
import io.netty.util.internal.PlatformDependent;
28-
import io.netty.util.internal.SocketUtils;
2928
import lombok.RequiredArgsConstructor;
3029
import lombok.extern.slf4j.Slf4j;
3130
import org.apache.skywalking.banyandb.v1.client.Options;
3231
import org.apache.skywalking.banyandb.v1.client.util.PrivateKeyUtil;
33-
3432
import java.io.File;
3533
import java.io.FileInputStream;
3634
import java.io.IOException;
3735
import java.io.InputStream;
38-
import java.net.InetAddress;
3936
import java.net.InetSocketAddress;
4037
import java.net.SocketAddress;
4138
import java.net.URI;
4239
import java.net.UnknownHostException;
43-
import java.util.Arrays;
44-
import java.util.Comparator;
45-
import java.util.stream.Stream;
4640

4741
@Slf4j
4842
@RequiredArgsConstructor
4943
public class DefaultChannelFactory implements ChannelFactory {
5044
private final URI[] targets;
5145
private final Options options;
52-
private SocketAddress[] addresses;
53-
private long lastTargetsResolvedTime;
5446

5547
@Override
5648
public ManagedChannel create() throws IOException {
57-
if (this.addresses == null ||
58-
System.currentTimeMillis() - this.lastTargetsResolvedTime > this.options.getResolveDNSInterval()) {
59-
resolveTargets();
60-
}
6149
NettyChannelBuilder managedChannelBuilder = NettyChannelBuilder.forAddress(resolveAddress())
6250
.maxInboundMessageSize(options.getMaxInboundMessageSize())
6351
.usePlaintext();
@@ -91,30 +79,12 @@ public ManagedChannel create() throws IOException {
9179
return managedChannelBuilder.build();
9280
}
9381

94-
private void resolveTargets() {
95-
this.addresses = Arrays.stream(this.targets)
96-
.flatMap(target -> {
97-
try {
98-
return Arrays.stream(SocketUtils.allAddressesByName(target.getHost()))
99-
.map(InetAddress::getHostAddress)
100-
.map(ip -> new InetSocketAddress(ip, target.getPort()));
101-
} catch (Throwable t) {
102-
log.error("Failed to resolve the BanyanDB server's address ", t);
103-
}
104-
return Stream.empty();
105-
})
106-
.sorted(Comparator.comparing(InetSocketAddress::toString))
107-
.distinct()
108-
.toArray(InetSocketAddress[]::new);
109-
this.lastTargetsResolvedTime = System.currentTimeMillis();
110-
}
111-
11282
private SocketAddress resolveAddress() throws UnknownHostException {
113-
int numAddresses = this.addresses.length;
83+
int numAddresses = this.targets.length;
11484
if (numAddresses < 1) {
11585
throw new UnknownHostException();
11686
}
11787
int offset = numAddresses == 1 ? 0 : PlatformDependent.threadLocalRandom().nextInt(numAddresses);
118-
return this.addresses[offset];
88+
return new InetSocketAddress(this.targets[offset].getHost(), this.targets[offset].getPort());
11989
}
12090
}

0 commit comments

Comments
 (0)