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

Clean up SocketFinder.findSocket(...) handling #663

Merged

Conversation

sehrope
Copy link
Contributor

@sehrope sehrope commented Mar 21, 2018

Cleans up SocketFinder.findSocket(...) a bit and simplifies the logic for the simple case of a single address being resolved.

This changes some of the prior functionality though I wouldn't consider it a breaking change as it's not documented functionality and the new approach seems (to me) to be more correct. Previously if a host resolved to both IPv4 and IPv6 addresses, each set would get half the time out and the IPv4 addresses would be attempted first. This PR changes the logic to handle all IP addresses concurrently using the full timeout.

It also centralizes the logic for handling the case where there's a single address. Regardless of JVM type it now attempts to directly connect to it. This changes the behavior for the IBM JDK as previously it would have attempted the NIO approach followed by a normal socket creation upon success. Again this seems like a better choice as the overall logic is simpler and end result is the same.

This PR was coded atop #662. See there for more details on the parent change.

@codecov-io
Copy link

codecov-io commented Mar 21, 2018

Codecov Report

Merging #663 into dev will decrease coverage by 0.15%.
The diff coverage is 12.5%.

Impacted file tree graph

@@             Coverage Diff              @@
##                dev     #663      +/-   ##
============================================
- Coverage     48.32%   48.16%   -0.16%     
- Complexity     2623     2625       +2     
============================================
  Files           113      113              
  Lines         26626    26609      -17     
  Branches       4480     4472       -8     
============================================
- Hits          12867    12817      -50     
- Misses        11601    11662      +61     
+ Partials       2158     2130      -28
Flag Coverage Δ Complexity Δ
#JDBC42 47.56% <12.5%> (-0.23%) 2571 <0> (-2)
#JDBC43 48.05% <12.5%> (-0.14%) 2623 <0> (+3)
Impacted Files Coverage Δ Complexity Δ
...in/java/com/microsoft/sqlserver/jdbc/IOBuffer.java 53.16% <12.5%> (-1.69%) 0 <0> (ø)
...om/microsoft/sqlserver/jdbc/SimpleInputStream.java 51.11% <0%> (-1.49%) 11% <0%> (-1%)
...om/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java 52.55% <0%> (+0.06%) 240% <0%> (ø) ⬇️
...m/microsoft/sqlserver/jdbc/SQLServerResultSet.java 33.43% <0%> (+0.15%) 248% <0%> (+1%) ⬆️
...n/java/com/microsoft/sqlserver/jdbc/Parameter.java 62.68% <0%> (+0.2%) 63% <0%> (ø) ⬇️
...ncurrentlinkedhashmap/ConcurrentLinkedHashMap.java 38.79% <0%> (+0.64%) 43% <0%> (+1%) ⬆️
...c/main/java/com/microsoft/sqlserver/jdbc/Util.java 61.57% <0%> (+0.65%) 89% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48139e7...f09e0da. Read the comment docs.

@sehrope sehrope force-pushed the socket-address-resolution-cleanup branch from 8bd7d2f to 0f5c355 Compare March 26, 2018 12:27
@ulvii
Copy link
Contributor

ulvii commented Apr 3, 2018

Hi @sehrope ,
Thanks for the contribution. We decided to merge #662 for now, will review and test your changes for one of the upcoming releases.

@ulvii
Copy link
Contributor

ulvii commented May 2, 2018

Hi @sehrope ,

Would you mind resolving the conflicts?

@sehrope sehrope force-pushed the socket-address-resolution-cleanup branch from 0f5c355 to c433c4f Compare May 2, 2018 12:09
@sehrope
Copy link
Contributor Author

sehrope commented May 2, 2018

@ulvii Done.

@peterbae peterbae self-requested a review May 2, 2018 22:37
Refactors socket creation in SocketFinder.findSocket(...) to simplify handling of socket creation.

When the host resolves to a single address the driver now defers to getConnectedSocket(...)
to create the socket without spawning any threads. This happens regardless of whether we're
running on an IBM JDK. Previously the single address case would still use NIO on an IBM JDK.

On non-IBM JDKs the driver now handles both IPv4 and IPv6 addresses concurrently with a single
shared timeout. Previously hosts that resolved to both types of addresses were allowed half the
timeout for socket creation per address type with the resolution performed sequentially.
@sehrope sehrope force-pushed the socket-address-resolution-cleanup branch from c433c4f to 487574e Compare May 3, 2018 14:10
@sehrope
Copy link
Contributor Author

sehrope commented May 3, 2018

One more rebase as dev has been updated since the last one.

@ulvii ulvii self-requested a review May 29, 2018 22:07
@cheenamalhotra cheenamalhotra added this to the 6.5.4 milestone Jun 4, 2018
Copy link
Member

@cheenamalhotra cheenamalhotra left a comment

Choose a reason for hiding this comment

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

I agree with the advantage of having a generic implementation for IBM JDK and OpenJDK - which was differently done before, also using full timeout for all IP addresses instead of splitting half between IPv4 and IPv6 makes it better.

@cheenamalhotra cheenamalhotra merged commit 61b78d7 into microsoft:dev Jun 21, 2018
@sehrope sehrope deleted the socket-address-resolution-cleanup branch June 21, 2018 14:03
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.

5 participants