Skip to content
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

Remove deprecated ServerVersion #1126

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions driver/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@
<method>org.reactivestreams.Publisher close()</method>
</difference>

<difference>
<className>org/neo4j/driver/summary/ServerInfo</className>
<differenceType>7002</differenceType>
<method>java.lang.String version()</method>
</difference>

</differences>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.internal.messaging.v44.BoltProtocolV44;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.util.ServerVersion;

public class ImpersonationUtil
{
Expand All @@ -40,7 +39,6 @@ public static Connection ensureImpersonationSupport( Connection connection, Stri

private static boolean supportsImpersonation( Connection connection )
{
return connection.serverVersion().greaterThanOrEqual( ServerVersion.v4_4_0 ) &&
connection.protocol().version().compareTo( BoltProtocolV44.VERSION ) >= 0;
return connection.protocol().version().compareTo( BoltProtocolV44.VERSION ) >= 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.spi.ResponseHandler;
import org.neo4j.driver.internal.util.Clock;
import org.neo4j.driver.internal.util.ServerVersion;

import static java.util.Collections.emptyMap;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.poolId;
Expand All @@ -61,7 +60,6 @@ public class NetworkConnection implements Connection
private final InboundMessageDispatcher messageDispatcher;
private final String serverAgent;
private final BoltServerAddress serverAddress;
private final ServerVersion serverVersion;
private final BoltProtocol protocol;
private final ExtendedChannelPool channelPool;
private final CompletableFuture<Void> releaseFuture;
Expand All @@ -81,7 +79,6 @@ public NetworkConnection( Channel channel, ExtendedChannelPool channelPool, Cloc
this.messageDispatcher = ChannelAttributes.messageDispatcher( channel );
this.serverAgent = ChannelAttributes.serverAgent( channel );
this.serverAddress = ChannelAttributes.serverAddress( channel );
this.serverVersion = ChannelAttributes.serverVersion( channel );
this.protocol = BoltProtocol.forChannel( channel );
this.channelPool = channelPool;
this.releaseFuture = new CompletableFuture<>();
Expand Down Expand Up @@ -213,12 +210,6 @@ public BoltServerAddress serverAddress()
return serverAddress;
}

@Override
public ServerVersion serverVersion()
{
return serverVersion;
}

@Override
public BoltProtocol protocol()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.async.inbound.InboundMessageDispatcher;
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.internal.util.ServerVersion;

import static io.netty.util.AttributeKey.newInstance;

Expand All @@ -37,7 +36,6 @@ public final class ChannelAttributes
private static final AttributeKey<BoltProtocolVersion> PROTOCOL_VERSION = newInstance( "protocolVersion" );
private static final AttributeKey<String> SERVER_AGENT = newInstance( "serverAgent" );
private static final AttributeKey<BoltServerAddress> ADDRESS = newInstance( "serverAddress" );
private static final AttributeKey<ServerVersion> SERVER_VERSION = newInstance( "serverVersion" );
private static final AttributeKey<Long> CREATION_TIMESTAMP = newInstance( "creationTimestamp" );
private static final AttributeKey<Long> LAST_USED_TIMESTAMP = newInstance( "lastUsedTimestamp" );
private static final AttributeKey<InboundMessageDispatcher> MESSAGE_DISPATCHER = newInstance( "messageDispatcher" );
Expand Down Expand Up @@ -101,16 +99,6 @@ public static void setServerAddress( Channel channel, BoltServerAddress address
setOnce( channel, ADDRESS, address );
}

public static ServerVersion serverVersion( Channel channel )
{
return get( channel, SERVER_VERSION );
}

public static void setServerVersion( Channel channel, ServerVersion version )
{
setOnce( channel, SERVER_VERSION, version );
}

public static long creationTimestamp( Channel channel )
{
return get( channel, CREATION_TIMESTAMP );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.neo4j.driver.internal.messaging.Message;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.spi.ResponseHandler;
import org.neo4j.driver.internal.util.ServerVersion;

/**
* This is a connection used by {@link DirectConnectionProvider} to connect to a remote database.
Expand Down Expand Up @@ -125,12 +124,6 @@ public BoltServerAddress serverAddress()
return delegate.serverAddress();
}

@Override
public ServerVersion serverVersion()
{
return delegate.serverVersion();
}

@Override
public BoltProtocol protocol()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.neo4j.driver.internal.messaging.Message;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.spi.ResponseHandler;
import org.neo4j.driver.internal.util.ServerVersion;

/**
* A connection used by the routing driver.
Expand Down Expand Up @@ -123,12 +122,6 @@ public BoltServerAddress serverAddress()
return delegate.serverAddress();
}

@Override
public ServerVersion serverVersion()
{
return delegate.serverVersion();
}

@Override
public BoltProtocol protocol()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.neo4j.driver.internal.DatabaseName;
import org.neo4j.driver.internal.ReadOnlyBookmarkHolder;
import org.neo4j.driver.internal.async.connection.DirectConnection;
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.util.ServerVersion;

import static org.neo4j.driver.Values.value;
import static org.neo4j.driver.internal.DatabaseNameUtil.systemDatabase;
Expand All @@ -56,7 +56,7 @@ BookmarkHolder bookmarkHolder( Bookmark bookmark )
}

@Override
Query procedureQuery(ServerVersion serverVersion, DatabaseName databaseName )
Query procedureQuery( BoltProtocolVersion protocolVersion, DatabaseName databaseName )
{
HashMap<String,Value> map = new HashMap<>();
map.put( ROUTING_CONTEXT, value( context.toMap() ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import org.neo4j.driver.internal.BookmarkHolder;
import org.neo4j.driver.internal.DatabaseName;
import org.neo4j.driver.internal.async.connection.DirectConnection;
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.util.Futures;
import org.neo4j.driver.internal.util.ServerVersion;

import static org.neo4j.driver.Values.parameters;
import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase;
Expand All @@ -61,7 +61,7 @@ public SingleDatabaseRoutingProcedureRunner( RoutingContext context )
public CompletionStage<RoutingProcedureResponse> run( Connection connection, DatabaseName databaseName, Bookmark bookmark, String impersonatedUser )
{
DirectConnection delegate = connection( connection );
Query procedure = procedureQuery( connection.serverVersion(), databaseName );
Query procedure = procedureQuery( connection.protocol().version(), databaseName );
BookmarkHolder bookmarkHolder = bookmarkHolder( bookmark );
return runProcedure( delegate, procedure, bookmarkHolder )
.thenCompose( records -> releaseConnection( delegate, records ) )
Expand All @@ -73,13 +73,13 @@ DirectConnection connection( Connection connection )
return new DirectConnection( connection, defaultDatabase(), AccessMode.WRITE, null );
}

Query procedureQuery(ServerVersion serverVersion, DatabaseName databaseName )
Query procedureQuery( BoltProtocolVersion protocolVersion, DatabaseName databaseName )
{
if ( databaseName.databaseName().isPresent() )
{
throw new FatalDiscoveryException( String.format(
"Refreshing routing table for multi-databases is not supported in server version lower than 4.0. " +
"Current server version: %s. Database name: '%s'", serverVersion, databaseName.description() ) );
"Refreshing routing table for multi-databases is not supported over Bolt protocol lower than 4.0. " +
"Current protocol version: %s. Database name: '%s'", protocolVersion, databaseName.description() ) );
}
return new Query( GET_ROUTING_TABLE, parameters( ROUTING_CONTEXT, context.toMap() ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,12 @@
import java.util.function.Supplier;

import org.neo4j.driver.Value;
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.internal.messaging.v3.BoltProtocolV3;
import org.neo4j.driver.internal.spi.ResponseHandler;

import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setConnectionId;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setConnectionReadTimeout;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerAgent;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerVersion;
import static org.neo4j.driver.internal.util.MetadataExtractor.extractNeo4jServerVersion;
import static org.neo4j.driver.internal.util.MetadataExtractor.extractServer;
import static org.neo4j.driver.internal.util.ServerVersion.fromBoltProtocolVersion;

public class HelloResponseHandler implements ResponseHandler
{
Expand All @@ -46,33 +41,20 @@ public class HelloResponseHandler implements ResponseHandler

private final ChannelPromise connectionInitializedPromise;
private final Channel channel;
private final BoltProtocolVersion protocolVersion;

public HelloResponseHandler( ChannelPromise connectionInitializedPromise, BoltProtocolVersion protocolVersion )
public HelloResponseHandler( ChannelPromise connectionInitializedPromise )
{
this.connectionInitializedPromise = connectionInitializedPromise;
this.channel = connectionInitializedPromise.channel();
this.protocolVersion = protocolVersion;
}

@Override
public void onSuccess( Map<String,Value> metadata )
{
try
{
Value serverValue = extractServer( metadata );
setServerAgent( channel, serverValue.asString() );

// From Server V4 extracting server from metadata in the success message is unreliable
// so we fix the Server version against the Bolt Protocol version for Server V4 and above.
if ( BoltProtocolV3.VERSION.equals( protocolVersion ) )
{
setServerVersion( channel, extractNeo4jServerVersion( metadata ) );
}
else
{
setServerVersion( channel, fromBoltProtocolVersion( protocolVersion ) );
}
String serverAgent = extractServer( metadata ).asString();
setServerAgent( channel, serverAgent );

String connectionId = extractConnectionId( metadata );
setConnectionId( channel, connectionId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
package org.neo4j.driver.internal.handlers;

import io.netty.channel.Channel;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;

import java.util.Map;

import org.neo4j.driver.internal.async.outbound.OutboundMessageHandler;
import org.neo4j.driver.internal.spi.ResponseHandler;
import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.Value;
import org.neo4j.driver.exceptions.UntrustedServerException;
import org.neo4j.driver.internal.spi.ResponseHandler;

import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerVersion;
import static org.neo4j.driver.internal.util.MetadataExtractor.extractNeo4jServerVersion;
import static org.neo4j.driver.internal.util.MetadataExtractor.extractServer;

public class InitResponseHandler implements ResponseHandler
{
Expand All @@ -48,8 +45,13 @@ public void onSuccess( Map<String,Value> metadata )
{
try
{
ServerVersion serverVersion = extractNeo4jServerVersion( metadata );
setServerVersion( channel, serverVersion );
String serverAgent = extractServer( metadata ).asString();

if ( !serverAgent.startsWith( "Neo4j/" ) )
{
throw new UntrustedServerException( "Server does not identify as a genuine Neo4j instance: '" + serverAgent + "'" );
}

connectionInitializedPromise.setSuccess();
}
catch ( Throwable error )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.neo4j.driver.internal.messaging.v4.BoltProtocolV4;
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.util.ServerVersion;

public final class MultiDatabaseUtil
{
Expand All @@ -39,8 +38,7 @@ public static void assertEmptyDatabaseName( DatabaseName databaseName, BoltProto

public static boolean supportsMultiDatabase( Connection connection )
{
return connection.serverVersion().greaterThanOrEqual( ServerVersion.v4_0_0 ) &&
connection.protocol().version().compareTo( BoltProtocolV4.VERSION ) >= 0;
return connection.protocol().version().compareTo( BoltProtocolV4.VERSION ) >= 0;
}

public static boolean supportsRouteMessage( Connection connection )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void initializeChannel( String userAgent, AuthToken authToken, RoutingCon
message = new HelloMessage( userAgent, ( ( InternalAuthToken ) authToken ).toMap(), null );
}

HelloResponseHandler handler = new HelloResponseHandler( channelInitializedPromise, version() );
HelloResponseHandler handler = new HelloResponseHandler( channelInitializedPromise );

messageDispatcher( channel ).enqueue( handler );
channel.writeAndFlush( message, channel.voidPromise() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.neo4j.driver.internal.DatabaseName;
import org.neo4j.driver.internal.messaging.BoltProtocol;
import org.neo4j.driver.internal.messaging.Message;
import org.neo4j.driver.internal.util.ServerVersion;

import static java.lang.String.format;

Expand Down Expand Up @@ -55,8 +54,6 @@ public interface Connection

BoltServerAddress serverAddress();

ServerVersion serverVersion();

BoltProtocol protocol();

default AccessMode mode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@

import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.summary.ServerInfo;

public class InternalServerInfo implements ServerInfo
{
private static final String TO_STRING_FMT = "%s{address='%s'}";

private final String agent;
private final String address;
private final String version;
private final String protocolVersion;

public InternalServerInfo( String agent, BoltServerAddress address, ServerVersion version, BoltProtocolVersion protocolVersion )
public InternalServerInfo( String agent, BoltServerAddress address, BoltProtocolVersion protocolVersion )
{
this.agent = agent;
this.address = address.toString();
this.version = version.toString();
this.protocolVersion = protocolVersion.toString();
}

Expand All @@ -52,12 +51,6 @@ public String address()
return address;
}

@Override
public String version()
{
return version;
}

@Override
public String protocolVersion()
{
Expand All @@ -76,18 +69,18 @@ public boolean equals( Object o )
return false;
}
InternalServerInfo that = (InternalServerInfo) o;
return Objects.equals( address, that.address ) && Objects.equals( version, that.version );
return Objects.equals( address, that.address );
}

@Override
public int hashCode()
{
return Objects.hash( address, version );
return Objects.hash( address );
}

@Override
public String toString()
{
return "InternalServerInfo{" + "address='" + address + '\'' + ", version='" + version + '\'' + '}';
return String.format( TO_STRING_FMT, this.getClass().getSimpleName(), address );
}
}
Loading