Cassandra java.lang.IllegalArgumentException:getMetaData时的文本

时间:2016-03-07 22:09:16

标签: java cassandra cassandra-cli cassandra-2.1

我在收集元数据时遇到了cassandra异常。 例外:

Exception in thread "main" java.lang.IllegalArgumentException: text
at com.datastax.driver.core.ColumnMetadata$Raw$Kind.fromStringV3(ColumnMetadata.java:160)
at com.datastax.driver.core.ColumnMetadata$Raw.fromRow(ColumnMetadata.java:188)
at com.datastax.driver.core.SchemaParser.groupByKeyspaceAndCf(SchemaParser.java:442)
at com.datastax.driver.core.SchemaParser$2.refresh(SchemaParser.java:255)
at com.datastax.driver.core.ControlConnection.refreshSchema(ControlConnection.java:323)
at com.datastax.driver.core.ControlConnection.tryConnect(ControlConnection.java:264)
at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:187)
at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:75)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1269)
at com.datastax.driver.core.Cluster.getMetadata(Cluster.java:338)
at com.pentaquin.core.database.driver.CassandraDriver.connect(CassandraDriver.java:70)
at com.pentaquin.core.database.driver.CassandraDriver.createFromConfig(CassandraDriver.java:136)
at com.pentaquin.login.server.LoginServerMain.main(LoginServerMain.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

CassandraDriver第70行中的代码:

this.metadata = this.cluster.getMetadata();

CassandraDriver方法代码:

/*
    * Cassandra Configuration
    */
    Cluster.Builder builder = Cluster.builder();

    Logger.getRootLogger().info(configuration.listServerContactPoints().size() + " cassandra contact points registered.");

    //add all server contact points
    for (ServerContactPoint serverContactPoint : configuration.listServerContactPoints()) {
        String ip = serverContactPoint.getIp();
        int port = serverContactPoint.getPort();

        //add cassandra contact point
        builder.addContactPoint(ip).withPort(port);
    }

    //use credentials
    if (!configuration.getUser().equals("") && !configuration.getPassword().equals("")) {
        builder.withCredentials(configuration.getUser(), configuration.getPassword());
    }

    if (configuration.listServerContactPoints().size() > 1) {
        DCAwareRoundRobinPolicy dcAwareRoundRobinPolicy = DCAwareRoundRobinPolicy.builder().allowRemoteDCsForLocalConsistencyLevel()/*.withLocalDc(configuration.getLocalDatacenter())*/.build();

        //TODO: add load balancing support here

        //because client connects to many servers, client can use load balancing
        /*builder.withLoadBalancingPolicy(
                new TokenAwarePolicy(dcAwareRoundRobinPolicy));*/
    }

    Logger.getRootLogger().info("connect to cassandra database.");

    //connect to cluster
    this.cluster = builder.build();

    this.metadata = cluster.getMetadata();
    Logger.getRootLogger().debug("Cassandra Cluster Name: " + this.metadata.getClusterName());

    /**
    * connect to cassandra database
     *
     * @link http://www.tutorialspoint.com/cassandra/cassandra_data_model.htm
    */
    this.keyspace = configuration.getDatabase();
    this.session = this.cluster.connect();

    if (!this.keyspace.equals("")) {
        //keyspace support
        try {
            this.session.execute("USE " + this.keyspace);
        } catch (InvalidQueryException e) {
            //create keyspace first
            this.session.execute("CREATE KEYSPACE " + this.keyspace + " WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3};");

            this.session.execute("USE " + this.keyspace);
        }
    }

为什么抛出异常? 这是什么意思? 谢谢!

编辑:添加代码 该方法负责连接到cassandra集群并设置密钥空间。 因此,有一个解析为对象配置的配置文件。

2 个答案:

答案 0 :(得分:1)

从行号看起来您使用的是驱动程序3.0.0-alpha2或更早版本。当时Cassandra是3.0.0-beta1,之后元数据格式发生了一些变化。

尝试将驱动程序升级到3.0.0,它可以正确处理所有Cassandra版本。

答案 1 :(得分:0)

检查Java驱动程序版本和Cassandra版本,它们应该对齐