Interface CqlMigrator


  • public interface CqlMigrator
    Interface for managing application schema changes in a synchronized fashion. The implementation classes are expected to implement some locking mechanism so that there are no concurrent schema modifications when multiple threads attempt to make the schema changes on the same cassandra keyspace.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void clean​(com.datastax.driver.core.Session session, java.lang.String keyspace)
      Drops keyspace if it exists
      void clean​(java.lang.String[] hosts, int port, java.lang.String username, java.lang.String password, java.lang.String keyspace)
      Drops keyspace if it exists
      void migrate​(com.datastax.driver.core.Session session, java.lang.String keyspace, java.util.Collection<java.nio.file.Path> directories)
      If all nodes are up and a lock can be acquired this runs migration starting with bootstrap.cql and then the rest in alphabetical order.
      void migrate​(java.lang.String[] hosts, int port, java.lang.String username, java.lang.String password, java.lang.String keyspace, java.util.Collection<java.nio.file.Path> directories)
      If all nodes are up and a lock can be acquired this runs migration starting with bootstrap.cql and then the rest in alphabetical order.
    • Method Detail

      • migrate

        void migrate​(java.lang.String[] hosts,
                     int port,
                     java.lang.String username,
                     java.lang.String password,
                     java.lang.String keyspace,
                     java.util.Collection<java.nio.file.Path> directories)
        If all nodes are up and a lock can be acquired this runs migration starting with bootstrap.cql and then the rest in alphabetical order. If the migration fails for any reason, the lock will not be released and manual intervention is required to cleanup and fix the issue.
        Parameters:
        hosts - Comma separated list of cassandra hosts
        port - Native transport port for the above cassandra nodes
        username - Username for Cassandra's internal authentication using PasswordAuthenticator (if using AllowAllAuthenticator, can be set to any value)
        password - Password for Cassandra's internal authentication using PasswordAuthenticator (if using AllowAllAuthenticator, can be set to any value)
        keyspace - Keyspace name for which the schema migration needs to be applied
        directories - Comma separated list of directory paths containing the cql statements for the schema change
        Throws:
        ClusterUnhealthyException - if any nodes are down or the schema is not in agreement before running migration
        CannotAcquireLockException - if any of the queries to acquire lock fail or CassandraLockConfig.CassandraLockConfigBuilder.withTimeout(Duration) is reached before lock can be acquired.
        CannotReleaseLockException - if any of the queries to release lock fail
        java.lang.IllegalArgumentException - if any file types other than .cql are found
        java.lang.IllegalStateException - if cql file has changed after migration has been run
        com.datastax.driver.core.exceptions.DriverException - if any of the migration queries fails
      • migrate

        void migrate​(com.datastax.driver.core.Session session,
                     java.lang.String keyspace,
                     java.util.Collection<java.nio.file.Path> directories)
        If all nodes are up and a lock can be acquired this runs migration starting with bootstrap.cql and then the rest in alphabetical order. If the migration fails for any reason, the lock will not be released and manual intervention is required to cleanup and fix the issue.
        Parameters:
        session - Session to a cassandra cluster
        keyspace - Keyspace name for which the schema migration needs to be applied
        directories - Comma separated list of directory paths containing the cql statements for the schema change
        Throws:
        ClusterUnhealthyException - if any nodes are down or the schema is not in agreement before running migration
        CannotAcquireLockException - if any of the queries to acquire lock fail or CassandraLockConfig.CassandraLockConfigBuilder.withTimeout(Duration) is reached before lock can be acquired.
        CannotReleaseLockException - if any of the queries to release lock fail
        java.lang.IllegalArgumentException - if any file types other than .cql are found
        java.lang.IllegalStateException - if cql file has changed after migration has been run
        com.datastax.driver.core.exceptions.DriverException - if any of the migration queries fails
      • clean

        void clean​(java.lang.String[] hosts,
                   int port,
                   java.lang.String username,
                   java.lang.String password,
                   java.lang.String keyspace)
        Drops keyspace if it exists
        Parameters:
        hosts - Comma separated list of cassandra hosts
        port - Native transport port for the above cassandra nodes
        username - Username for Cassandra's internal authentication using PasswordAuthenticator (if using AllowAllAuthenticator, can be set to any value)
        password - Password for Cassandra's internal authentication using PasswordAuthenticator (if using AllowAllAuthenticator, can be set to any value)
        keyspace - Keyspace name for which the schema migration needs to be applied
        Throws:
        com.datastax.driver.core.exceptions.DriverException - if query fails
      • clean

        void clean​(com.datastax.driver.core.Session session,
                   java.lang.String keyspace)
        Drops keyspace if it exists
        Parameters:
        session - Session to a cassandra cluster
        keyspace - Keyspace name for which the schema migration needs to be applied
        Throws:
        com.datastax.driver.core.exceptions.DriverException - if query fails