为什么 CQLDataLoader 返回键空间已存在而实际上不存在?
我在创建之前检查了键空间是否存在,但两次检查都返回 null。但是,当我执行键空间创建 cql 文件时,它总是返回键空间已存在。我正在使用 org.cassandra:cassandra:cassandra-unit-spring:3.1.3.2 包。不知道如何解决这个问题。我有另一种方法“EmbeddedCassandraServerHelper.cleanEmbeddedCassandra()”,它似乎会删除键空间,因为在检查库键空间时它也会返回 null。所以在这一点上,我假设这是我的逻辑错误,但我无法弄清楚。
public static void setupEmbeddedCassandra(String cqlFile, String keyspaceName)
throws IOException, TTransportException, InterruptedException {
synchronized (lock) {
if (finalKeyspace == null) {
System.out.println(CLASS_NAME + " Setting up local embedded cassandra environment");
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
int embeddedCassandraPort = EmbeddedCassandraServerHelper.getNativeTransportPort();
System.setProperty("embeddedCassandraPort", String.valueOf(embeddedCassandraPort));
cluster =
(new Cluster.Builder())
.addContactPoints(new String[] {"localhost"})
.withPort(embeddedCassandraPort)
.build();
session = cluster.connect();
cluster.getConfiguration();
System.out.println(cluster.getMetadata().getKeyspace("library"));
CQLDataLoader dataLoader = new CQLDataLoader(session);
System.out.println(cluster.getMetadata().getKeyspace("library"));
dataLoader.load(new ClassPathCQLDataSet(cqlFile, true, keyspaceName));
System.out.println(
CLASS_NAME
+ " Embedded Server started on port "
+ EmbeddedCassandraServerHelper.getNativeTransportPort());
}
finalKeyspace = keyspaceName;
}
}
I checked to see if the keyspace exists before creation, but both checks returns null. However, when I execute the keyspace creation cql file, it always returns that the keyspace already exists. I'm using org.cassandra:cassandra:cassandra-unit-spring:3.1.3.2 package. Not sure how to fix this issue. I have another method, '''EmbeddedCassandraServerHelper.cleanEmbeddedCassandra()''', that seemingly drops the keyspace since it also returns null when checking for library keyspace. So at this point, I'm assuming its a logic error on my part but I can't figure it out.
public static void setupEmbeddedCassandra(String cqlFile, String keyspaceName)
throws IOException, TTransportException, InterruptedException {
synchronized (lock) {
if (finalKeyspace == null) {
System.out.println(CLASS_NAME + " Setting up local embedded cassandra environment");
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
int embeddedCassandraPort = EmbeddedCassandraServerHelper.getNativeTransportPort();
System.setProperty("embeddedCassandraPort", String.valueOf(embeddedCassandraPort));
cluster =
(new Cluster.Builder())
.addContactPoints(new String[] {"localhost"})
.withPort(embeddedCassandraPort)
.build();
session = cluster.connect();
cluster.getConfiguration();
System.out.println(cluster.getMetadata().getKeyspace("library"));
CQLDataLoader dataLoader = new CQLDataLoader(session);
System.out.println(cluster.getMetadata().getKeyspace("library"));
dataLoader.load(new ClassPathCQLDataSet(cqlFile, true, keyspaceName));
System.out.println(
CLASS_NAME
+ " Embedded Server started on port "
+ EmbeddedCassandraServerHelper.getNativeTransportPort());
}
finalKeyspace = keyspaceName;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论