cassandra 会在同时执行的两个并行创建密钥空间命令上失败吗

will cassandra fail on two parallel create keyspace commands executed simultanously

我们的经验是,如果我们推出 DDL cql 脚本,这将同时改变现有的 table,很有可能会破坏密钥空间,以至于我们需要重新创建它。

我们现在已经序列化了这个过程,包括那个键空间的创建。现在有一个激烈的讨论,如果 cassandra 明确支持并行创建不同的键空间。

我想,这没问题,但由于集群很大,我们想听听其他意见,所以我在这里问:

我们可以安全地假设,并行创建不同的键空间在 cassandra 中是安全的吗?

在当前版本的 Cassandra 中这是不可能的 - 您需要等待 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);
        }
    }
}

新版本的 Cassandra 将在这方面进行改进,例如通过 CASSANDRA-13426 (committed into 4.0), and CASSANDRA-10699(尚未完成)