Closed ckunki closed 11 months ago
In my impression the factory is also used for caching and reusing a connection with the intention to improve performance by not creating a new connection every time. From that closing the connection in case of an exception should rather be ensured on a higher level, e.g. in JDBCAdapter.pushdown().
Alignment with @kaklakariada:
JDBCAdapter
in VSJDBC implements interface VirtualSchemaAdapter
requiring 6 methods ConnectionFactory
) and close it if an exception occurs as reusing a connection between multiple calls to one of these methods is not possible anyway.AutoCloseable
to enable try-with-resourcesRemoteConnectionFactory
and interface ConnectionFactory
need to be enhanced.Couple of issues in connection management have found:
AutoClosable
interface, so they will be closed on try-with-resource block. But we're not using this pattern anywhere, so connections will be closed only on garbage collection (because we're not closing them explicitly as well)RemoteConnectionFactory
was created inside the function: https://github.com/exasol/virtual-schema-common-jdbc/blob/main/src/main/java/com/exasol/adapter/jdbc/JDBCAdapter.java#L161, which is not how factories should be created. Because of that, connections are automatically closed after every operation (query or schema refresh) and being reestablished again. It also might lead to connection leak in some cases (if reference is kept after exception, for example)But before fixing all this, hive-virtual-schema has to be updated to the latest libraries version
Optimizing connection establishment doesn't have much sense, as we're restarting whole java process on every request (at least jar file is being reloaded from bucketfs)
Ticket mentioned as "IntRef" reported that when user cancels an SQL query in Exasol database the resulting Hive query in VSHIVE does not get canceled.
The current ticket therefore requests to inspect and if possible to improve the connection handling in VSCJDBC. See also ticket https://github.com/exasol/hive-virtual-schema/issues/39 for improved connection handling in VSHIVE.
If possible then VSCJDBC should ensure that especially in the case of an exception VSCJDBC closes all connections.
Acceptance criteria
See for example ImportIntoTemporaryTableQueryRewriter.java#L75