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

Impossible to connect to Liquibase Cassandra #43

Closed
VincentBrule opened this issue Nov 20, 2023 · 5 comments
Closed

Impossible to connect to Liquibase Cassandra #43

VincentBrule opened this issue Nov 20, 2023 · 5 comments

Comments

@VincentBrule
Copy link

VincentBrule commented Nov 20, 2023

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
Copy link
Collaborator

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).

@maximevw maximevw added the to investigate Investigation needed label Nov 20, 2023
@VincentBrule
Copy link
Author

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
Copy link
Collaborator

maximevw commented Nov 20, 2023

@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: liquibase/liquibase-cassandra#242 (comment)

@maximevw maximevw removed the to investigate Investigation needed label Nov 21, 2023
@VincentBrule
Copy link
Author

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

@maximevw
Copy link
Collaborator

You are welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants