[
https://issues.apache.org/jira/browse/PHOENIX-2032?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14580146#comment-14580146
]
Gabriel Reid commented on PHOENIX-2032:
---------------------------------------
My experience with stuff like this (ServiceLoader API) is that it typically
leads to weird and difficult-to-debug issues like this :-)
I just took a look, and what I can see is that the
{{META-INF/services/java.sql.Driver}} file contains the following:
{code}
org.apache.phoenix.queryserver.client.Driver
org.apache.calcite.avatica.remote.Driver
org.apache.phoenix.jdbc.PhoenixDriver
{code}
so the PhoenixDriver will be loaded/attempted last.
What I also noticed when running psql through a debugger is that in
{{java.sql.DriverManager#loadInitialDrivers}} (around line 509 in my JDK) is
the following handling while using the ServiceLoader API to load drivers on the
classpath:
{code}
try{
while(driversIterator.hasNext()) {
driversIterator.next();
}
} catch(Throwable t) {
// Do nothing
}
return null;
{code}
What I see happening is that there is an attempt made to load
{{org.apache.phoenix.queryserver.client.Driver}} via {{Class.forName}} in the
call to {{driversIterator.next()}} in that loop, and that throws and exception
(probably a ClassNotFoundException, because I don't think that driver is
packaged in the jar in question). That breaks out of the loop completely, so
{{org.apache.phoenix.jdbc.PhoenixDriver}} never gets loaded via the
ServiceLoader API.
I'm guessing the best fix for this (apart from probably fixing that catch-call
clause in DriverManager) is to fix the assembly building for that assembly to
only contain a reference to {{org.apache.phoenix.jdbc.PhoenixDriver}} in
{{META-INF/services/java.sql.Driver}}. I guess the other option (actually
probably better) is to ensure that the thin driver is fully included in the jar
file being used by psql.
> psql.py is broken after PHOENIX-2013
> ------------------------------------
>
> Key: PHOENIX-2032
> URL: https://issues.apache.org/jira/browse/PHOENIX-2032
> Project: Phoenix
> Issue Type: Bug
> Affects Versions: 5.0.0, 4.5.0, 4.4.1
> Reporter: Sergio Peleato
> Assignee: Nick Dimiduk
> Priority: Blocker
> Attachments: PHOENIX-2032.00.patch
>
>
> psql is no longer able to load the phoenix driver after PHOENIX-2013.
> {noformat}
> $ ./bin/psql.py localhost examples/WEB_STAT.sql
>
>
> java.sql.SQLException: No suitable driver found for jdbc:phoenix:localhost
> at java.sql.DriverManager.getConnection(DriverManager.java:596)
> at java.sql.DriverManager.getConnection(DriverManager.java:187)
> at
> org.apache.phoenix.util.PhoenixRuntime.main(PhoenixRuntime.java:183)
> {noformat}
> Hat-tip to [[email protected]] for tracking down the breaking change.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)