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

[Java] JDBC Flight SQL driver not connect to individual endpoints specified by GetFlightInfo #40336

Closed
xinyiZzz opened this issue Mar 4, 2024 · 3 comments

Comments

@xinyiZzz
Copy link

xinyiZzz commented Mar 4, 2024

Describe the bug, including details regarding any error messages, version, and platform.

FlightEndpoint returned by GetFlightInfoPreparedStatement is another flight server, but JDBC Flight SQL driver still fetch results from main flight server connection.

version: 15.0.0 release and 15.0.0 nightlies 2024.2.20

#38785, In fact I found this problem in arrow 14.0.1, It was solved using 15.0.0 nightlies at that time, but today I tried again and found problem occurred again.

#38521 This PR seems to actually solve this problem.

Component(s)

FlightRPC

@lidavidm
Copy link
Member

lidavidm commented Mar 4, 2024

Hmm, there were definitely other changes but looking at the core it should definitely be using all locations:

try {
for (FlightEndpoint endpoint : flightInfo.getEndpoints()) {
if (endpoint.getLocations().isEmpty()) {
// Create a stream using the current client only and do not close the client at the end.
endpoints.add(new CloseableEndpointStreamPair(
sqlClient.getStream(endpoint.getTicket(), getOptions()), null));
} else {
// Clone the builder and then set the new endpoint on it.
// GH-38574: Currently a new FlightClient will be made for each partition that returns a non-empty Location
// then disposed of. It may be better to cache clients because a server may report the same Locations.
// It would also be good to identify when the reported location is the same as the original connection's
// Location and skip creating a FlightClient in that scenario.
List<Exception> exceptions = new ArrayList<>();
CloseableEndpointStreamPair stream = null;
for (Location location : endpoint.getLocations()) {
final URI endpointUri = location.getUri();
final Builder builderForEndpoint = new Builder(ArrowFlightSqlClientHandler.this.builder)
.withHost(endpointUri.getHost())
.withPort(endpointUri.getPort())
.withEncryption(endpointUri.getScheme().equals(LocationSchemes.GRPC_TLS));
ArrowFlightSqlClientHandler endpointHandler = null;
try {
endpointHandler = builderForEndpoint.build();
stream = new CloseableEndpointStreamPair(
endpointHandler.sqlClient.getStream(endpoint.getTicket(),
endpointHandler.getOptions()), endpointHandler.sqlClient);
// Make sure we actually get data from the server
stream.getStream().getSchema();
} catch (Exception ex) {
if (endpointHandler != null) {
AutoCloseables.close(endpointHandler);
}
exceptions.add(ex);
continue;
}
break;
}
if (stream != null) {
endpoints.add(stream);
} else if (exceptions.isEmpty()) {
// This should never happen...
throw new IllegalStateException("Could not connect to endpoint and no errors occurred");
} else {
Exception ex = exceptions.remove(0);
while (!exceptions.isEmpty()) {
ex.addSuppressed(exceptions.remove(exceptions.size() - 1));
}
throw ex;
}
}
}
} catch (Exception outerException) {
try {
AutoCloseables.close(endpoints);
} catch (Exception innerEx) {
outerException.addSuppressed(innerEx);
}
if (outerException instanceof SQLException) {
throw (SQLException) outerException;
}
throw new SQLException(outerException);
}
return endpoints;
}

@xinyiZzz
Copy link
Author

xinyiZzz commented Mar 5, 2024

Hmm, there were definitely other changes but looking at the core it should definitely be using all locations:

Thanks for your reply, i will debug this part of the code

@xinyiZzz
Copy link
Author

xinyiZzz commented Apr 2, 2024

I upgrade to arrow 15.0.2 and redeploy environment, no problem anymore. not sure it’s related to version or environment.

close issue, thanks for reply.

@xinyiZzz xinyiZzz closed this as completed Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants