为什么 CQLDataLoader 返回键空间已存在而实际上不存在?

发布于 2025-01-15 07:49:48 字数 1637 浏览 2 评论 0原文

我在创建之前检查了键空间是否存在,但两次检查都返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文