-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for initial routers DNS resolution
This update fixes the following issue: #833 The desired behaviour for getting a routing table from the initial router (either on bootstrap or when all known routers have failed) is: - resolve the domain name to all IPs - attempt getting a routing table from all of them until first one succeeds by: - getting a connection - trying to get a successful routing table response Prior to this change, the connection pools were created for host and port pairs. When domain name of the host resolves to multiple IP addresses, such pools provide connections to those IPs as a group. While this works for readers and writers, it negatively impacts the routing table fetching process as there is no guarantee which IP address the provided connection is setup for. This update delivers the following changes: - connection pools for routers are IP address based, which allows for deterministic connection retrieval - the resolved IP address set is kept up-to-date (in case known router IPs change) to make sure that the unused connection pools are flushed - the domain name resolution logic has been made configurable (it is private at the moment and is used to facilitate testing) - the testkit backend has been updated to support the domain name resolution configuration (a new test has been added to testkit to cover the issue described above) - the testkit backend has been updated to support connection timeout driver configuration - several tests have been updated to adopt the new changes
- Loading branch information
1 parent
47db433
commit 4bf4891
Showing
36 changed files
with
825 additions
and
314 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
42 changes: 42 additions & 0 deletions
42
driver/src/main/java/org/neo4j/driver/internal/DefaultDomainNameResolver.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,42 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed 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.neo4j.driver.internal; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
public class DefaultDomainNameResolver implements DomainNameResolver | ||
{ | ||
private static final DefaultDomainNameResolver INSTANCE = new DefaultDomainNameResolver(); | ||
|
||
public static DefaultDomainNameResolver getInstance() | ||
{ | ||
return INSTANCE; | ||
} | ||
|
||
private DefaultDomainNameResolver() | ||
{ | ||
} | ||
|
||
@Override | ||
public InetAddress[] resolve( String name ) throws UnknownHostException | ||
{ | ||
return InetAddress.getAllByName( name ); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
driver/src/main/java/org/neo4j/driver/internal/DomainNameResolver.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,38 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed 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.neo4j.driver.internal; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
/** | ||
* A resolver function used by the driver to resolve domain names. | ||
*/ | ||
@FunctionalInterface | ||
public interface DomainNameResolver | ||
{ | ||
/** | ||
* Resolve the given domain name to a set of addresses. | ||
* | ||
* @param name the name to resolve. | ||
* @return the resolved addresses. | ||
* @throws UnknownHostException must be thrown if the given name can not be resolved to at least one address. | ||
*/ | ||
InetAddress[] resolve( String name ) throws UnknownHostException; | ||
} |
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
67 changes: 67 additions & 0 deletions
67
driver/src/main/java/org/neo4j/driver/internal/async/connection/NettyDomainNameResolver.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,67 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed 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.neo4j.driver.internal.async.connection; | ||
|
||
import io.netty.resolver.InetNameResolver; | ||
import io.netty.util.concurrent.EventExecutor; | ||
import io.netty.util.concurrent.Promise; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.neo4j.driver.internal.DomainNameResolver; | ||
|
||
public class NettyDomainNameResolver extends InetNameResolver | ||
{ | ||
private final DomainNameResolver domainNameResolver; | ||
|
||
public NettyDomainNameResolver( EventExecutor executor, DomainNameResolver domainNameResolver ) | ||
{ | ||
super( executor ); | ||
this.domainNameResolver = domainNameResolver; | ||
} | ||
|
||
@Override | ||
protected void doResolve( String inetHost, Promise<InetAddress> promise ) | ||
{ | ||
try | ||
{ | ||
promise.setSuccess( domainNameResolver.resolve( inetHost )[0] ); | ||
} | ||
catch ( UnknownHostException e ) | ||
{ | ||
promise.setFailure( e ); | ||
} | ||
} | ||
|
||
@Override | ||
protected void doResolveAll( String inetHost, Promise<List<InetAddress>> promise ) | ||
{ | ||
try | ||
{ | ||
promise.setSuccess( Arrays.asList( domainNameResolver.resolve( inetHost ) ) ); | ||
} | ||
catch ( UnknownHostException e ) | ||
{ | ||
promise.setFailure( e ); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...rc/main/java/org/neo4j/driver/internal/async/connection/NettyDomainNameResolverGroup.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,43 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed 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.neo4j.driver.internal.async.connection; | ||
|
||
import io.netty.resolver.AddressResolver; | ||
import io.netty.resolver.AddressResolverGroup; | ||
import io.netty.util.concurrent.EventExecutor; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
import org.neo4j.driver.internal.DomainNameResolver; | ||
|
||
public class NettyDomainNameResolverGroup extends AddressResolverGroup<InetSocketAddress> | ||
{ | ||
private final DomainNameResolver domainNameResolver; | ||
|
||
public NettyDomainNameResolverGroup( DomainNameResolver domainNameResolver ) | ||
{ | ||
this.domainNameResolver = domainNameResolver; | ||
} | ||
|
||
@Override | ||
protected AddressResolver<InetSocketAddress> newResolver( EventExecutor executor ) throws Exception | ||
{ | ||
return new NettyDomainNameResolver( executor, domainNameResolver ).asAddressResolver(); | ||
} | ||
} |
Oops, something went wrong.