Skip to content

Upgrade Cassandra Driver to 4.3.1#26

Open
jeff-blaisdell wants to merge 1 commit into
SmartThingsOSS:masterfrom
jeff-blaisdell:upgrade-cass-4_3
Open

Upgrade Cassandra Driver to 4.3.1#26
jeff-blaisdell wants to merge 1 commit into
SmartThingsOSS:masterfrom
jeff-blaisdell:upgrade-cass-4_3

Conversation

@jeff-blaisdell
Copy link
Copy Markdown
Member

@jeff-blaisdell jeff-blaisdell commented Dec 27, 2019

This MR upgrades the Cassandra Migration project to use the latest Cassandra Java driver (4.3.1). It contains many breaking changes from the 3.2.0 version currently in use. As a result of the upgrade the hard dependency on Guava 19.0 has been dropped. The 4.3.1 variant of Cassandra driver shades this to com.datastax.oss.driver.shaded.guava.common

See:
https://github.com/datastax/java-driver/tree/4.x/upgrade_guide

and

https://docs.datastax.com/en/developer/java-driver/4.3/

This bumps version to 0.2.0. Additionally, I made a 0.1.x-master to track previous version.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 27, 2019

Codecov Report

❌ Patch coverage is 82.89474% with 13 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@ef9874d). Learn more about missing BASE report.
⚠️ Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
...ava/smartthings/migration/MigrationParameters.java 50.00% 6 Missing and 1 partial ⚠️
...ava/smartthings/cassandra/CassandraConnection.java 80.00% 2 Missing and 2 partials ⚠️
...in/java/smartthings/migration/MigrationRunner.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master      #26   +/-   ##
=========================================
  Coverage          ?   55.25%           
  Complexity        ?       84           
=========================================
  Files             ?       11           
  Lines             ?      552           
  Branches          ?       46           
=========================================
  Hits              ?      305           
  Misses            ?      221           
  Partials          ?       26           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread build.gradle
testCompile 'org.objenesis:objenesis:2.4'
testRuntime 'io.netty:netty-all:4.1.4.Final'
testRuntime 'ch.qos.logback:logback-classic:1.1.7'
testCompile 'org.cassandraunit:cassandra-unit:4.2.2.0-SNAPSHOT'
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

);

updateLock = session.prepare(
SimpleStatement.newInstance("UPDATE databasechangelock USING TTL :ttl SET lockedby = :owner WHERE id = :lockId IF lockedby = :ifowner")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit obnoxious. All the bind variable - set by name methods appear only to support setting the first occurrence.
See:
https://github.com/datastax/java-driver/blob/4.x/core/src/main/java/com/datastax/oss/driver/api/core/data/SettableByName.java

Best solution I've determined so far is just make each bind name unique.. Couldn't find a method/impl that automagically set them all. If you leave it the same it results in a RuntimeException essentially saying you have unset binds.

ResultSet rs = session.execute(insertLock.bind().setInt("lockId", lockId)
.setInt("ttl", ttl).setString("owner", owner));
ResultSet rs = session.execute(
insertLock.boundStatementBuilder()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched bind to boundStatementBuilder to reduce cost of data copy due to immutable internal implementation.


hints_directory: /tmp/hints

cdc_raw_directory: build/embeddedCassandra/raw
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required to start cassandra-unit's embedded cass after version upgrade.

assert column.keyspace == keyspace
[column.name, row.getString(column.name)]
assert column.keyspace.asCql(true) == keyspace
[column.name.asCql(true), row.getString(column.name)]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

column.keyspace and column.name no longer strings. Later cassandra driver introduces a wrapper type CqlIdentifer.

https://github.com/datastax/java-driver/blob/4.x/core/src/main/java/com/datastax/oss/driver/api/core/CqlIdentifier.java#L118

Cluster.Builder builder = Cluster.builder().addContactPoint(host).withPort(port).withMaxSchemaAgreementWaitSeconds(20).withQueryOptions(queryOptions);
CqlSessionBuilder builder = CqlSession.builder()
.addContactPoint(new InetSocketAddress(host, port))
.withLocalDatacenter(localDatacenter)
Copy link
Copy Markdown
Member Author

@jeff-blaisdell jeff-blaisdell Dec 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cassandra Driver 4.3 will fail to startup when a host / port is specified without also setting the local datacenter field. Added it as a settable parameter w/ a default of "datacenter1" which matches the drivers default value.

This has more details:
https://docs.datastax.com/en/developer/java-driver/4.2/manual/core/load_balancing/

Reading of the docs seems that as we upgrade to the 4.x drivers we should be setting this field in higher environments.. Though I'm a little unsure to what. Could use some feedback here from those closer to Cassandra.

Comment thread version.txt Outdated
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

Successfully merging this pull request may close these issues.

2 participants