Skip to content

Conversation

@zhenlineo
Copy link
Contributor

No description provided.

technige and others added 2 commits May 16, 2017 12:14
…tocol.

Background:
A connection holds a socketClient. A socketClient has a protocol which specifies what protocol version the driver should work on.
When a connection is created in a pool, the connection will first be `started` (where the socketClient will negotiate protocol version with the server) and then `initialized` (where the server version will be sent back).

Problem description:
The problem that we need to solve here is that for 3.2+ servers, the protocol the driver is working on should allow bytes, while for server version lower than 3.2.0, the protocol should disallow bytes to be sent to prevent from crashing server connection in a bad way. While the server version is only known after the protocol is created, so after the server version arrived the protocol need either be updated (this commit) or the protocol need to be informed (previous impl).

Solution:
This commit changed the behaviour in connection to update protocol regarding bytes support right after server version is received. By doing in this way we avoid some two-direction reference between connection and protocol.
@zhenlineo zhenlineo requested a review from lutovich May 16, 2017 13:42
@zhenlineo zhenlineo mentioned this pull request May 16, 2017
@zhenlineo zhenlineo requested a review from technige May 16, 2017 13:48
Copy link
Contributor

@lutovich lutovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhenlineo review round completed. Changes generally look good. I think we should use consistent naming - "byte array" instead of "bytes". There is also a bit of code duplication.

PR should go in 1.4 when we create such branch.

}
catch ( IOException e )
{
close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to close here?
I think connection will be properly close by the session if it throws from here.


ChunkedOutput output = new ChunkedOutput( channel );
BufferingChunkedInput input = new BufferingChunkedInput( channel );
public static SocketProtocol create( ByteChannel channel, boolean byteArraySupportEnabled )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this method be named createWithoutByteArraySupport or simply withoutByteArraySupport? We could then get rid of second boolean parameter.


this.writer = new PackStreamMessageFormatV1.Writer( output, output.messageBoundaryHook() );
this.reader = new PackStreamMessageFormatV1.Reader( input, input.messageBoundaryHook() );
public SocketProtocolV1( ByteChannel channel, boolean byteArraySupportEnabled )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor can be private

}
}

public static ServerVersion version( Session session )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to inline this method in ParametersIT because it is only used there


import java.util.Arrays;

public class BytesValue extends ValueAdapter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe also implement asList() and asList(Function<Value,T>) methods?

return new ListValue( values );
}

private static Value bytesValue( byte[] input )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method is not used

}

private void ensure( int size ) throws IOException
private void ensure(int size ) throws IOException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a typo :)

throw new Unexpected( "Expected a double, but got: " + toHexString( markerByte ));
}

public byte[] unpackBytes() throws IOException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method different from #unpackRawBytes()?
Looks like only error message has changed. Can we remove #unpackRawBytes()?

Copy link
Contributor

@lutovich lutovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhenlineo changes look good. PR can be merged after changing base branch to 1.4

@zhenlineo zhenlineo changed the base branch from 1.3 to 1.4 May 23, 2017 09:35
@zhenlineo zhenlineo merged commit 1886bfa into neo4j:1.4 May 24, 2017
@zhenlineo zhenlineo deleted the 1.3-byte-arrays branch May 24, 2017 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants