1
votes

We are using cached PreparedStatement for queries to DataStax Cassandra. But if we need to add new columns to a table, we need to restart our application server to recache the prepared statement.

I came across this bug in cassandra, that explains the solution https://datastax-oss.atlassian.net/browse/JAVA-420

It basically gives a work around to not use "SELECT * FROM table" in the query, but use "SELECT column_names FROM table"

But now we came across the same issue with Delete statements. After adding a new column to a table, the Delete prepared statement does not delete a record.

I don't think we can use the same work around as mentioned in the ticket for Select statement, as * or column_names does not make sense with Deleting a row.

Any help would be appreciated. We basically want to avoid having to restart our application server for any additions to database tables

1

1 Answers

1
votes

We basically want to avoid having to restart our application server for any additions to database tables

Easy solution that require a little bit of coding: use JMX

Let me explain.

In your application code, keep a cache (you can use Guava cache implementation for example) of all prepared statement. The key to access the cache can be, for example, the query string.

Now, expose a JMX method to clear the cache and force the application to re-prepare again the queries.

Every time you update a schema, just call the appropriate method(s) to clean the cache, you don't need to restart your application