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

chore: refactor ProxyServer to use channels instead of sockets #184

Open
wants to merge 38 commits into
base: postgresql-dialect
Choose a base branch
from

Conversation

olavloite
Copy link
Collaborator

@olavloite olavloite commented Jun 14, 2022

Refactors the ProxyServer to use the SocketChannel interfaces instead of Sockets. This makes the sockets replaceable for the new Unix domain socket implementation in Java16, which again means that we can conditionally load that when we know that we have Java16 or higher as the target language.

Also adds a Maven profile for building a .jar that can be used for a native image. This profile loads a Socket factory that uses the default Java Unix domain sockets implementation instead of a third-party dependency that requires a native library.

Refactors the ProxyServer to use the SocketChannel interfaces instead of
Sockets. This makes the sockets replaceable for the new Unix domain
socket implementation in Java16, which again means that we can
conditionally load that when we know that we have Java16 or higher as
the target language.
@codecov
Copy link

codecov bot commented Jun 14, 2022

Codecov Report

Merging #184 (b389979) into postgresql-dialect (808217e) will decrease coverage by 0.02%.
The diff coverage is 81.15%.

@@                   Coverage Diff                    @@
##             postgresql-dialect     #184      +/-   ##
========================================================
- Coverage                 84.09%   84.07%   -0.03%     
- Complexity                 1614     1622       +8     
========================================================
  Files                       114      115       +1     
  Lines                      5470     5525      +55     
  Branches                    733      738       +5     
========================================================
+ Hits                       4600     4645      +45     
- Misses                      644      651       +7     
- Partials                    226      229       +3     
Flag Coverage Δ
all_tests 84.07% <81.15%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...om/google/cloud/spanner/pgadapter/ProxyServer.java 78.52% <75.67%> (-2.43%) ⬇️
...ud/spanner/pgadapter/Java8ServerSocketFactory.java 86.66% <86.66%> (ø)
...gle/cloud/spanner/pgadapter/ConnectionHandler.java 74.46% <88.23%> (+0.19%) ⬆️
...r/pgadapter/statements/SessionStatementParser.java 72.89% <0.00%> (-0.89%) ⬇️
...ud/spanner/pgadapter/statements/CopyStatement.java 80.00% <0.00%> (-0.63%) ⬇️
...ud/spanner/pgadapter/metadata/OptionsMetadata.java 77.34% <0.00%> (-0.31%) ⬇️
...loud/spanner/pgadapter/statements/DdlExecutor.java 86.36% <0.00%> (-0.22%) ⬇️
.../cloud/spanner/pgadapter/utils/MutationWriter.java 93.02% <0.00%> (-0.04%) ⬇️
... and 8 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@olavloite olavloite marked this pull request as ready for review June 16, 2022 17:54
GOOGLE_CLOUD_PROJECT: "span-cloud-testing"
GOOGLE_CLOUD_INSTANCE: "pgadapter-testing"
GOOGLE_CLOUD_DATABASE: "testdb_integration"
GOOGLE_CLOUD_ENDPOINT: "spanner.googleapis.com"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it fine to to put these in public repo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The endpoint is public information. It's for example also included in the generated client for each programming language.
The project, instance and database names are also included in many other repositories.

@@ -80,7 +83,9 @@ public class ConnectionHandler extends Thread {
private static final String CHANNEL_PROVIDER_PROPERTY = "CHANNEL_PROVIDER";

private final ProxyServer server;
private final Socket socket;
private final ByteChannel socketChannel;
private final InetSocketAddress remoteAddress;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add a comment that this is nullable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, added a @Nullable annotation and a comment.

super("ConnectionHandler-" + CONNECTION_HANDLER_ID_GENERATOR.incrementAndGet());
this.server = server;
this.socket = socket;
this.socketChannel = byteChannel;
if (byteChannel instanceof SocketChannel
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are the cases when byteChannel is not of SocketChannel type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added a comment to explain. SocketChannel is only used by TCP connections. Unix domain sockets use other implementations.

@olavloite
Copy link
Collaborator Author

There's a good chance that this will not be needed, as the Unix domain socket factory that we are currently using has added support for GraalVM, which was the initial reason to add this.

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.

2 participants