Skip to content

Upgrade to Netty 4.1.36, support native compilation #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cbf9456
Increment idle instead of use after channel is created.
michael-simons Jul 20, 2019
ac6c192
Fix tests.
michael-simons Jul 20, 2019
41359db
Make getRoutingTable procedure aware of multi-databases
Apr 11, 2019
f9a11b7
For routing driver, by default, get the routing table for default-dat…
Apr 15, 2019
aeb08b8
Fixed BoltKit tests due to server version
May 8, 2019
fef68c8
Added more tests
May 8, 2019
f9125a8
Remove routing table when it is stale for too long.
May 10, 2019
098fe4a
Adding more boltkit tests for multi-databases
Jun 27, 2019
d7266e0
Moved `useInitialRouter` to routing table which is only used by a sin…
Jun 28, 2019
b73b0f3
Renamed a few classes and added more java docs
Jun 28, 2019
1264ad1
Changed from `dbms.cluster.routing.getRoutingTable` to `dbms.routing.…
Jul 1, 2019
87b409c
Fix minor doc issues.
michael-simons Jul 1, 2019
3bc94c5
Replaced latch with await(Publisher)
Jul 1, 2019
63f2348
Fix compilation error due to mono has to be mapped to publisher due t…
Jul 2, 2019
74c5505
Fix a few names after review
Jul 2, 2019
d47ad3c
Changed session parameters to builder pattern
Jul 2, 2019
9567e96
Making checking connectivity optional on driver creation.
Jul 1, 2019
2ada852
Remove optional config and always leave to users to call instead.
Jul 3, 2019
1aa3edc
Update cluster tests for 4.0 cluster
Jul 3, 2019
be9fedc
Disable a few tests that are broken on 4.0 servers due to cypher not …
Jul 4, 2019
2bce387
Refined the error message when failed to verify connectivity
Jul 4, 2019
6ef3607
Re-enabling all muted tests.
Jul 4, 2019
8277b06
Upgrade Netty to 4.1.36.
michael-simons Jul 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions driver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.substratevm</groupId>
<artifactId>svm</artifactId>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -229,6 +233,9 @@
<shadedPattern>org.neo4j.driver.internal.shaded.reactor</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<shadeTestJar>true</shadeTestJar>
<createSourcesJar>true</createSourcesJar>
</configuration>
Expand Down
3 changes: 3 additions & 0 deletions driver/src/main/java/org/neo4j/driver/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ RetrySettings retrySettings()
return retrySettings;
}

/**
* @return if the metrics is enabled or not on this driver.
*/
public boolean isMetricsEnabled()
{
return isMetricsEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ enum PoolStatus
/**
* The total acquisition time in milliseconds of all connection acquisition requests since the pool is created.
* See {@link ConnectionPoolMetrics#acquired()} for the total amount of connection acquired since the driver is created.
* The average acquisition time can be calculated using the code bellow:
* The average acquisition time can be calculated using the code below:
* <h2>Example</h2>
* <pre>
* {@code
Expand All @@ -126,7 +126,7 @@ enum PoolStatus
/**
* The total time in milliseconds spent to establishing new socket connections since the pool is created.
* See {@link ConnectionPoolMetrics#created()} for the total amount of connections established since the pool is created.
* The average connection time can be calculated using the code bellow:
* The average connection time can be calculated using the code below:
* <h2>Example</h2>
* <pre>
* {@code
Expand All @@ -150,7 +150,7 @@ enum PoolStatus
/**
* The total time in milliseconds connections are borrowed out of the pool, such as the time spent in user's application code to run cypher queries.
* See {@link ConnectionPoolMetrics#totalInUseCount()} for the total amount of connections that are borrowed out of the pool.
* The average in-use time can be calculated using the code bellow:
* The average in-use time can be calculated using the code below:
* <h2>Example</h2>
* <pre>
* {@code
Expand Down
109 changes: 68 additions & 41 deletions driver/src/main/java/org/neo4j/driver/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
package org.neo4j.driver;

import java.util.concurrent.CompletionStage;
import java.util.function.Consumer;

import org.neo4j.driver.async.AsyncSession;
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.internal.SessionParameters;
import org.neo4j.driver.internal.SessionConfig;
import org.neo4j.driver.reactive.RxSession;
import org.neo4j.driver.types.TypeSystem;
import org.neo4j.driver.util.Experimental;
Expand Down Expand Up @@ -74,21 +73,62 @@ public interface Driver extends AutoCloseable
boolean isEncrypted();

/**
* Create a new general purpose {@link Session} with default {@link SessionParameters session parameters}.
* Create a new general purpose {@link Session} with default {@link SessionConfig session configuration}.
* <p>
* Alias to {@link #session(Consumer)}}.
* Alias to {@link #session(SessionConfig)}}.
*
* @return a new {@link Session} object.
*/
Session session();

/**
* Create a new {@link Session} with a specified {@link SessionParametersTemplate}.
* @param templateConsumer specifies how the session parameter shall be built for this session.
* Create a new {@link Session} with a specified {@link SessionConfig session configuration}.
* Use {@link SessionConfig#forDatabase(String)} to obtain a general purpose session configuration for the specified database.
* @param sessionConfig specifies session configurations for this session.
* @return a new {@link Session} object.
* @see SessionParameters
* @see SessionConfig
*/
Session session( Consumer<SessionParametersTemplate> templateConsumer );
Session session( SessionConfig sessionConfig );

/**
* Create a new general purpose {@link RxSession} with default {@link SessionConfig session configuration}.
* The {@link RxSession} provides a reactive way to run queries and process results.
* <p>
* Alias to {@link #rxSession(SessionConfig)}}.
*
* @return @return a new {@link RxSession} object.
*/
RxSession rxSession();

/**
* Create a new {@link RxSession} with a specified {@link SessionConfig session configuration}.
* Use {@link SessionConfig#forDatabase(String)} to obtain a general purpose session configuration for the specified database.
* The {@link RxSession} provides a reactive way to run queries and process results.
* @param sessionConfig used to customize the session.
* @return @return a new {@link RxSession} object.
*/
RxSession rxSession( SessionConfig sessionConfig );

/**
* Create a new general purpose {@link AsyncSession} with default {@link SessionConfig session configuration}.
* The {@link AsyncSession} provides an asynchronous way to run queries and process results.
* <p>
* Alias to {@link #asyncSession(SessionConfig)}}.
*
* @return @return a new {@link AsyncSession} object.
*/
AsyncSession asyncSession();

/**
* Create a new {@link AsyncSession} with a specified {@link SessionConfig session configuration}.
* Use {@link SessionConfig#forDatabase(String)} to obtain a general purpose session configuration for the specified database.
* The {@link AsyncSession} provides an asynchronous way to run queries and process results.
*
* @param sessionConfig used to customize the session.
* @return a new {@link AsyncSession} object.
*/
AsyncSession asyncSession( SessionConfig sessionConfig );

/**
* Close all the resources assigned to this driver, including open connections and IO threads.
* <p>
Expand All @@ -113,51 +153,38 @@ public interface Driver extends AutoCloseable
* @return the driver metrics if enabled.
* @throws ClientException if the driver metrics reporting is not enabled.
*/
@Experimental
Metrics metrics();

/**
* Create a new general purpose {@link RxSession} with default {@link SessionParameters session parameters}.
* The {@link RxSession} provides a reactive way to run queries and process results.
* <p>
* Alias to {@link #rxSession(Consumer)}}.
* This will return the type system supported by the driver.
* The types supported on a particular server a session is connected against might not contain all of the types defined here.
*
* @return @return a new {@link RxSession} object.
*/
RxSession rxSession();

/**
* Create a new {@link RxSession} with a specified {@link SessionParametersTemplate}.
* The {@link RxSession} provides a reactive way to run queries and process results.
* @param templateConsumer used to customize the session parameters.
* @return @return a new {@link RxSession} object.
* @return type system used by this statement runner for classifying values
*/
RxSession rxSession( Consumer<SessionParametersTemplate> templateConsumer );
@Experimental
TypeSystem defaultTypeSystem();

/**
* Create a new general purpose {@link AsyncSession} with default {@link SessionParameters session parameters}.
* The {@link AsyncSession} provides an asynchronous way to run queries and process results.
* <p>
* Alias to {@link #asyncSession(Consumer)}}.
* This verifies if the driver can connect to a remote server or a cluster
* by establishing a network connection with the remote and possibly exchanging a few data before closing the connection.
*
* @return @return a new {@link AsyncSession} object.
* It throws exception if fails to connect. Use the exception to further understand the cause of the connectivity problem.
* Note: Even if this method throws an exception, the driver still need to be closed via {@link #close()} to free up all resources.
*/
AsyncSession asyncSession();
void verifyConnectivity();

/**
* Create a new {@link AsyncSession} with a specified {@link SessionParametersTemplate}.
* The {@link AsyncSession} provides an asynchronous way to run queries and process results.
* This verifies if the driver can connect to a remote server or cluster
* by establishing a network connection with the remote and possibly exchanging a few data before closing the connection.
*
* @param templateConsumer used to customize the session parameters.
* @return a new {@link AsyncSession} object.
*/
AsyncSession asyncSession( Consumer<SessionParametersTemplate> templateConsumer );

/**
* This will return the type system supported by the driver.
* The types supported on a particular server a session is connected against might not contain all of the types defined here.
* This operation is asynchronous and returns a {@link CompletionStage}. This stage is completed with
* {@code null} when the driver connects to the remote server or cluster successfully.
* It is completed exceptionally if the driver failed to connect the remote server or cluster.
* This exception can be used to further understand the cause of the connectivity problem.
* Note: Even if this method complete exceptionally, the driver still need to be closed via {@link #closeAsync()} to free up all resources.
*
* @return type system used by this statement runner for classifying values
* @return a {@link CompletionStage completion stage} that represents the asynchronous verification.
*/
@Experimental
TypeSystem defaultTypeSystem();
CompletionStage<Void> verifyConnectivityAsync();
}
23 changes: 22 additions & 1 deletion driver/src/main/java/org/neo4j/driver/GraphDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,40 @@ public static Driver routingDriver( Iterable<URI> routingUris, AuthToken authTok

for ( URI uri : routingUris )
{
final Driver driver = driver( uri, authToken, config );
try
{
return driver( uri, authToken, config );
driver.verifyConnectivity();
return driver;
}
catch ( ServiceUnavailableException e )
{
log.warn( "Unable to create routing driver for URI: " + uri, e );
closeDriver( driver, uri, log );
}
catch ( Throwable e )
{
// for any other errors, we first close the driver and then rethrow the original error out.
closeDriver( driver, uri, log );
throw e;
}
}

throw new ServiceUnavailableException( "Failed to discover an available server" );
}

private static void closeDriver( Driver driver, URI uri, Logger log )
{
try
{
driver.close();
}
catch ( Throwable closeError )
{
log.warn( "Unable to close driver towards URI: " + uri, closeError );
}
}

private static void assertRoutingUris( Iterable<URI> uris )
{
for ( URI uri : uris )
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2002-2019 "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.exceptions;

/**
* This error indicate a fatal problem to obtain routing tables such as the routing table for a specified database does not exist.
* This exception should not be retried.
* @since 2.0
*/
public class FatalDiscoveryException extends ClientException
{
public FatalDiscoveryException( String message )
{
super( message );
}

public FatalDiscoveryException( String code, String message )
{
super( code, message );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Restart of server/driver/cluster might be required to recover from this error.
* @since 1.1
*/
public class SecurityException extends Neo4jException
public class SecurityException extends ClientException
{
public SecurityException( String code, String message )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.concurrent.CompletionStage;

import org.neo4j.driver.AccessMode;
import org.neo4j.driver.internal.async.connection.DecoratedConnection;
import org.neo4j.driver.internal.async.connection.DirectConnection;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.spi.ConnectionPool;
import org.neo4j.driver.internal.spi.ConnectionProvider;
Expand All @@ -47,13 +47,14 @@ public class DirectConnectionProvider implements ConnectionProvider
@Override
public CompletionStage<Connection> acquireConnection( String databaseName, AccessMode mode )
{
return connectionPool.acquire( address ).thenApply( connection -> new DecoratedConnection( connection, databaseName, mode ) );
return connectionPool.acquire( address ).thenApply( connection -> new DirectConnection( connection, databaseName, mode ) );
}

@Override
public CompletionStage<Void> verifyConnectivity()
{
// we verify the connection by establishing the connection to the default database
// We verify the connection by establishing a connection with the remote server specified by the address.
// Database name will be ignored as no query is run in this connection and the connection is released immediately.
return acquireConnection( ABSENT_DB_NAME, READ ).thenCompose( Connection::release );
}

Expand Down
Loading