infinispan / infinispan-images

Infinispan is an open source data grid platform and highly scalable NoSQL cloud data store.
https://infinispan.org
Apache License 2.0
31 stars 20 forks source link

How to get JDBC_PING with this image? #228

Open jackie-linz opened 3 months ago

jackie-linz commented 3 months ago

Hi, thanks for the great work in putting together this image.

I'm trying to get the cluster working with JDBC_PING and keeps having trouble with it.

Here's my jgroups stack config:

      <stack name="jdbc-ping" extends="tcp">
         <JDBC_PING connection_driver="org.postgresql.Driver"
            connection_username="user" connection_password="pass"
            connection_url="jdbc:postgresql://dbhost:5432/db"
            stack.combine="REPLACE"
            stack.position="MPING" />

first error is easy to understand - missing postgres driver Caused by: java.lang.IllegalArgumentException: JDBC Driver required for JDBC_PING protocol could not be loaded: 'org.postgresql.Driver'

So I've added SERVER_LIBS="org.postgresql:postgresql:42.6.2" environment variable to the container and I can see that the driver got loaded:

DEBUG (main) [org.infinispan.commons.util.ServiceFinder] Loading service impl: org.postgresql.Driver
INFO  (main) [org.infinispan.SERVER] ISPN080027: Loaded extension 'org.postgresql.Driver'

but then it still errors:

DEBUG (main) [org.jgroups.protocols.JDBC_PING] Registering JDBC Driver named 'org.postgresql.Driver'
ERROR (main) [org.jgroups.protocols.JDBC_PING] JGRP000115: Could not open connection to database java.sql.SQLException: No suitable driver found for jdbc:postgresql://dbhost:5432/db
     at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:706)
     at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:229)
     at org.jgroups.protocols.JDBC_PING.getConnection(JDBC_PING.java:285)
     at org.jgroups.protocols.JDBC_PING.writeToDB(JDBC_PING.java:130)
     at org.jgroups.protocols.JDBC_PING.write(JDBC_PING.java:117)
     at org.jgroups.protocols.FILE_PING.findMembers(FILE_PING.java:150)
     at org.jgroups.protocols.Discovery.callFindMembersInAllDiscoveryProtocols(Discovery.java:389)
     at org.jgroups.protocols.Discovery.findMembers(Discovery.java:238)
     at org.jgroups.protocols.Discovery.down(Discovery.java:420)
     at org.jgroups.protocols.FILE_PING.down(FILE_PING.java:141)
     at org.jgroups.protocols.MERGE3$InfoSender.run(MERGE3.java:424)
     at org.jgroups.util.TimeScheduler3$Task.run(TimeScheduler3.java:332)
     at org.jgroups.util.TimeScheduler3$RecurringTask.run(TimeScheduler3.java:366)
     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
     at java.base/java.lang.Thread.run(Thread.java:840)

Any hint on how I can get this image working with JDBC_PING? 🙏

tristantarrant commented 3 months ago

We believe we solved this with https://issues.redhat.com/browse/JGRP-2756 and therefore with Infinispan 14.0.25.Final and Infinispan 15.0.0.Final What version of the image are you using ?

jackie-linz commented 3 months ago

I was using quay.io/infinispan/server:14.0 and quay.io/infinispan/server:15.0.

I've just tried quay.io/infinispan/server:14.0.25.Final, here's the full stack trace

ERROR (main) [org.jgroups.protocols.JDBC_PING] JGRP000115: Could not open connection to database java.sql.SQLException: No suitable driver found for jdbc:postgresql://dbhost:5432/db
     at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:706)
     at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:229)
     at org.jgroups.protocols.JDBC_PING.getConnection(JDBC_PING.java:285)
     at org.jgroups.protocols.JDBC_PING.attemptSchemaInitialization(JDBC_PING.java:250)
     at org.jgroups.protocols.JDBC_PING.init(JDBC_PING.java:111)
     at org.jgroups.stack.ProtocolStack.initProtocolStack(ProtocolStack.java:802)
     at org.jgroups.stack.ProtocolStack.setup(ProtocolStack.java:442)
     at org.jgroups.JChannel.init(JChannel.java:902)
     at org.jgroups.JChannel.<init>(JChannel.java:124)
     at org.infinispan.remoting.transport.jgroups.EmbeddedJGroupsChannelConfigurator.createChannel(EmbeddedJGroupsChannelConfigurator.java:80)
     at org.infinispan.remoting.transport.jgroups.JGroupsTransport.channelFromConfigurator(JGroupsTransport.java:763)
     at org.infinispan.remoting.transport.jgroups.JGroupsTransport.buildChannel(JGroupsTransport.java:734)
     at org.infinispan.remoting.transport.jgroups.JGroupsTransport.initChannel(JGroupsTransport.java:488)
     at org.infinispan.remoting.transport.jgroups.JGroupsTransport.start(JGroupsTransport.java:472)
     at org.infinispan.remoting.transport.jgroups.CorePackageImpl$2.start(CorePackageImpl.java:63)
     at org.infinispan.remoting.transport.jgroups.CorePackageImpl$2.start(CorePackageImpl.java:49)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.invokeStart(BasicComponentRegistryImpl.java:616)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.doStartWrapper(BasicComponentRegistryImpl.java:607)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:576)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl$ComponentWrapper.running(BasicComponentRegistryImpl.java:807)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.startDependencies(BasicComponentRegistryImpl.java:634)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.doStartWrapper(BasicComponentRegistryImpl.java:598)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:576)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl$ComponentWrapper.running(BasicComponentRegistryImpl.java:807)
     at org.infinispan.factories.GlobalComponentRegistry.preStart(GlobalComponentRegistry.java:284)
     at org.infinispan.factories.AbstractComponentRegistry.start(AbstractComponentRegistry.java:250)
     at org.infinispan.manager.DefaultCacheManager.internalStart(DefaultCacheManager.java:779)
     at org.infinispan.manager.DefaultCacheManager.start(DefaultCacheManager.java:747)
     at org.infinispan.server.SecurityActions.lambda$startCacheManager$1(SecurityActions.java:68)
     at org.infinispan.security.Security.doPrivileged(Security.java:56)
     at org.infinispan.server.SecurityActions.doPrivileged(SecurityActions.java:40)
     at org.infinispan.server.SecurityActions.startCacheManager(SecurityActions.java:71)
     at org.infinispan.server.Server.run(Server.java:425)
     at org.infinispan.server.Bootstrap.runInternal(Bootstrap.java:173)
     at org.infinispan.server.tool.Main.run(Main.java:98)
     at org.infinispan.server.Bootstrap.main(Bootstrap.java:56)
     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.base/java.lang.reflect.Method.invoke(Method.java:568)
     at org.infinispan.server.loader.Loader.run(Loader.java:106)
     at org.infinispan.server.loader.Loader.main(Loader.java:51)

quay.io/infinispan/server:15.0.0.Final produced the same error

ERROR (main) [org.jgroups.protocols.JDBC_PING] JGRP000115: Could not open connection to database java.sql.SQLException: No suitable driver found for jdbc:postgresql://dbhost:5432/db
     at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:708)
     at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)
     at org.jgroups.protocols.JDBC_PING.getConnection(JDBC_PING.java:290)
     at org.jgroups.protocols.JDBC_PING.attemptSchemaInitialization(JDBC_PING.java:255)
     at org.jgroups.protocols.JDBC_PING.init(JDBC_PING.java:112)
     at org.jgroups.stack.ProtocolStack.initProtocolStack(ProtocolStack.java:806)
     at org.jgroups.stack.ProtocolStack.setup(ProtocolStack.java:442)
     at org.jgroups.JChannel.init(JChannel.java:894)
     at org.jgroups.JChannel.<init>(JChannel.java:124)
     at org.infinispan.remoting.transport.jgroups.EmbeddedJGroupsChannelConfigurator.createChannel(EmbeddedJGroupsChannelConfigurator.java:80)
     at org.infinispan.remoting.transport.jgroups.JGroupsTransport.channelFromConfigurator(JGroupsTransport.java:739)
     at org.infinispan.remoting.transport.jgroups.JGroupsTransport.buildChannel(JGroupsTransport.java:710)
     at org.infinispan.remoting.transport.jgroups.JGroupsTransport.initChannel(JGroupsTransport.java:464)
     at org.infinispan.remoting.transport.jgroups.JGroupsTransport.start(JGroupsTransport.java:448)
     at org.infinispan.remoting.transport.jgroups.CorePackageImpl$2.start(CorePackageImpl.java:64)
     at org.infinispan.remoting.transport.jgroups.CorePackageImpl$2.start(CorePackageImpl.java:49)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.invokeStart(BasicComponentRegistryImpl.java:616)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.doStartWrapper(BasicComponentRegistryImpl.java:607)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:576)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl$ComponentWrapper.running(BasicComponentRegistryImpl.java:807)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.startDependencies(BasicComponentRegistryImpl.java:634)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.doStartWrapper(BasicComponentRegistryImpl.java:598)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:576)
     at org.infinispan.factories.impl.BasicComponentRegistryImpl$ComponentWrapper.running(BasicComponentRegistryImpl.java:807)
     at org.infinispan.factories.GlobalComponentRegistry.preStart(GlobalComponentRegistry.java:307)
     at org.infinispan.factories.AbstractComponentRegistry.start(AbstractComponentRegistry.java:241)
     at org.infinispan.manager.DefaultCacheManager.internalStart(DefaultCacheManager.java:779)
     at org.infinispan.manager.DefaultCacheManager.start(DefaultCacheManager.java:747)
     at org.infinispan.server.SecurityActions.lambda$startCacheManager$0(SecurityActions.java:41)
     at org.infinispan.security.Security.doPrivileged(Security.java:62)
     at org.infinispan.server.SecurityActions.startCacheManager(SecurityActions.java:43)
     at org.infinispan.server.Server.run(Server.java:446)
     at org.infinispan.server.Bootstrap.runInternal(Bootstrap.java:184)
     at org.infinispan.server.tool.Main.run(Main.java:98)
     at org.infinispan.server.Bootstrap.main(Bootstrap.java:67)
     at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
     at java.base/java.lang.reflect.Method.invoke(Method.java:580)
     at org.infinispan.server.loader.Loader.run(Loader.java:104)
     at org.infinispan.server.loader.Loader.main(Loader.java:49)
jackie-linz commented 3 months ago

here's a repo with docker compose file that reproduces the issue

https://github.com/jackie-linz/infinispan-jdbc-test

jackie-linz commented 3 months ago

hmm... interestingly, adding SERVER_LIBS_DIR=/opt/infinispan environment variable works, but maybe not how it's intended?

tristantarrant commented 3 months ago

It seems like Java's DriverManager doesn't let classes loaded from another ClassLoader see drivers loaded from a different ClassLoader. I need to reopen JGRP-2756

tristantarrant commented 3 months ago

I have implemented a better fix: https://github.com/infinispan/infinispan/pull/12258