ing-bank / cassandra-jdbc-wrapper

A JDBC wrapper of Java Driver for Apache Cassandra®, which offers a simple JDBC compliant API to work with CQL3.
Apache License 2.0
74 stars 25 forks source link

Impossible to connect to Liquibase Cassandra #43

Closed VincentBrule closed 12 months ago

VincentBrule commented 12 months ago

Hello,

I tried to use the latest version of this driver (4.10.2) with the latest version of liquibase-core and liquibase-cassandra (4.25.0). I use SBT (1.9.7) and Java 11.

I haven't managed to replace the old datastax driver with the new one.

Previously, settings were made as follows:

val database = DatabaseFactory.getInstance.findCorrectDatabaseImplementation(
   new JdbcConnection(
      new Driver().connect(
          s"jdbc:cassandra://localhost:${cqlPort.toString}/$keyspace;DefaultKeyspace=$keyspace",
          new Properties()
     )
  )
)

new Liquibase(
  changeLog.getAbsolutePath,
  new FileSystemResourceAccessor(new File("/")),
  database
)

After swapping with the ING driver, I updated the above code like this (https://docs.liquibase.com/workflows/liquibase-community/using-liquibase-java-api.html):

val connection: Connection = DriverManager.getConnection(
        s"jdbc:cassandra://localhost:${cqlPort.toString}/$keyspace?compliancemode=Liquibase&localdatacenter=dc1&requesttimeout=10000"
 )

new Liquibase(
  changeLog.getAbsolutePath,
  new FileSystemResourceAccessor(new File("/")),
  DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection))
)

And I'm getting the error:

java.lang.ClassCastException: class liquibase.database.jvm.JdbcConnection cannot be cast to class com.ing.data.cassandra.jdbc.CassandraConnection (liquibase.database.jvm.JdbcConnection and com.ing.data.cassandra.jdbc.CassandraConnection are in unnamed module of loader sbt.internal.LayeredClassLoader @20850fc2)

Let me know if you need more details. Thanks in advance

maximevw commented 12 months ago

Hello @VincentBrule,

There is no obvious reason to get a ClassCastException in the provided piece of code. So, could you please provide the full stack trace leading to this exception to know where it is exactly thrown?

Then, I'll try to investigate further. But, you should maybe open an issue either in liquibase-cassandra or liquibase project since CassandraConnection is a standard implementation of java.sql.Connection interface and possibly the problem occurs somewhere in Liquibase code (indeed, it's not possible to cast CassandraConnection into liquibase.database.jvm.JdbcConnection and vice versa; and I don't think a such operation could happen in this driver's code... but to check).

VincentBrule commented 12 months ago

Hello @maximevw ,

Thank you for this quick response. I will create an issue on the liquibase-cassandra project 👍

The full stack trace is:

at liquibase.ext.cassandra.database.CassandraDatabase.getKeyspace(CassandraDatabase.java:114)
    at liquibase.ext.cassandra.database.CassandraDatabase.getDefaultCatalogName(CassandraDatabase.java:136)
    at liquibase.changelog.ChangeLogParameters.<init>(ChangeLogParameters.java:74)
    at liquibase.Liquibase.<init>(Liquibase.java:96)
    at vincent.cassandra.LiquibaseUtils$.initializeLiquibase(LiquibaseUtils.scala:102)
    at vincent.cassandra.LiquibaseUtils$.$anonfun$runner$2(LiquibaseUtils.scala:84)
    at vincent.cassandra.LiquibaseUtils$.$anonfun$runner$2$adapted(LiquibaseUtils.scala:83)
    at vincent.cassandra.LiquibaseUtils$.withDatabaseAndChangelog(LiquibaseUtils.scala:123)
    at vincent.cassandra.LiquibaseUtils$.$anonfun$runner$1(LiquibaseUtils.scala:83)
    at liquibase.Scope.lambda$child$0(Scope.java:184)
    at liquibase.Scope.child(Scope.java:193)
    at liquibase.Scope.child(Scope.java:183)
    at liquibase.Scope.child(Scope.java:162)
    at vincent.cassandra.LiquibaseUtils$.runUpdateLiquibase(LiquibaseUtils.scala:70)
    at vincent.cassandra.CassandraSpec.beforeAll(CassandraSpec.scala:86)
    at vincent.cassandra.CassandraSpec.beforeAll$(CassandraSpec.scala:70)
    at vincent.cassandra.LiquibaseUtilsSpecContext1.beforeAll(LiquibaseUtilsSpec.scala:19)
    at org.scalatest.BeforeAndAfterAll.liftedTree1$1(BeforeAndAfterAll.scala:212)
    at org.scalatest.BeforeAndAfterAll.run(BeforeAndAfterAll.scala:210)
    at org.scalatest.BeforeAndAfterAll.run$(BeforeAndAfterAll.scala:208)
    at vincent.cassandra.LiquibaseUtilsSpecContext1.run(LiquibaseUtilsSpec.scala:19)
    at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:321)
    at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:517)
    at sbt.TestRunner.runTest$1(TestFramework.scala:153)
    at sbt.TestRunner.run(TestFramework.scala:168)
    at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.$anonfun$apply$1(TestFramework.scala:336)
    at sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework.scala:296)
    at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:336)
    at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:336)
    at sbt.TestFunction.apply(TestFramework.scala:348)
    at sbt.Tests$.$anonfun$toTask$1(Tests.scala:436)
    at sbt.std.Transform$$anon$3.$anonfun$apply$2(Transform.scala:47)
    at sbt.std.Transform$$anon$4.work(Transform.scala:69)
    at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
    at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
    at sbt.Execute.work(Execute.scala:292)
    at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
    at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
maximevw commented 12 months ago

@VincentBrule,

I commented your issue on liquibase-cassandra. I was able to reproduce the behaviour on a quick project using this Liquibase extension and I found they wrongly cast the connection whey retrieving the keyspace. So, I guess it is a blocking issue for everyone trying to use the version 4.25.0!

The workaround you can try, if it's really blocking for you and you cannot wait a fix from the Liquibase team, is to fork the liquibase-cassandra project locally and re-build a custom version including the small change I specified here: https://github.com/liquibase/liquibase-cassandra/issues/242#issuecomment-1819557841

VincentBrule commented 12 months ago

OK, let's continue the discussion in the other project. Thank you very much for your help!

maximevw commented 12 months ago

You are welcome :)