Search code examples
cassandraddlcqldatastax-java-driver

will cassandra fail on two parallel create keyspace commands executed simultanously


We have experienced, that if we rollout DDL cql scripts, that will alter an existing table in parallel, that there is a substantial chance to corrupt the keyspace to the point that we needed to recreate it.

We have now serialized this process, including the creation of that keyspace. Now there is a flaming discussion, if cassandra explicitely supports the creation of different keyspaces in parallel.

I suppose, that this is ok, but since the cluster is large, we would like to have a second opinion, so I am asking here:

Can we safely assume, that parallel creation of different keyspaces is safe in cassandra?


Solution

  • In current versions of the Cassandra it's not possible - you need to wait for schema agreement after each DDL statement, including creation of other keyspaces. Usually drivers are waiting for some time (default 10 seconds) to get confirmation that all nodes in cluster have the same schema version. Depending on the driver, you can explicitly check for schema agreement - either in the result set returned after execution of statement, or via cluster metadata. For example, in Java it could look as following:

    Metadata metadata = cluster.getMetadata();
    for (int i = 0; i < commands.length; i++) {
        System.out.println("Executing '" + commands[i] + "'");
        ResultSet rs = session.execute(commands[i]);
        if (!rs.getExecutionInfo().isSchemaInAgreement()) {
            while (!metadata.checkSchemaAgreement()) {
                 System.out.println("Schema isn't in agreement, sleep 1 second...");
                 Thread.sleep(1000);
            }
        }
    }
    

    New versions of Cassandra will have improvements in this area, for example, via CASSANDRA-13426 (committed into 4.0), and CASSANDRA-10699 (not yet done)