没有足够的可读字节 - 需要4,最大值为0

时间:2016-07-03 19:04:47

标签: java hadoop cassandra database nosql

连接到Cassandra数据库并创建密钥空间时,我收到以下错误。

  

线程中的异常" main" > com.datastax.driver.core.exceptions.NoHostAvailableException:
  所有主机尝试查询失败(尝试:/127.0.0.1:9042
  (com.datastax.driver.core.ConnectionException:[/ 127.0.0.1:9042]传输初始化期间出现意外错误
  (com.datastax.driver.core.TransportException:[/ 127.0.0.1:9042]触发了意外异常(java.lang.IndexOutOfBoundsException:没有足够的可读字节 - 需要4,最大值为0))))

这是我的代码:

package com.hadoop.reloaded.cassandra;

import com.datastax.driver.core.*;

public class CassandraOne {

    public static void main(String[] args){

        Cluster cluster1 = Cluster.builder().withPort(9042).addContactPoint("127.0.0.1").build();
        Session session = cluster1.connect();
        String query = "CREATE KEYSPACE test WITH replication "
                + "= {'class':'SimpleStrategy', 'replication_factor':1}; ";
        session.execute(query);
        session.execute("USE test");

    }
}

当我运行它时抛出此异常:

Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException:
All host(s) tried for query failed (tried: /127.0.0.1:9042 (
    com.datastax.driver.core.ConnectionException: [/127.0.0.1:9042] 
        Unexpected error during transport initialization (
            com.datastax.driver.core.TransportException: [/127.0.0.1:9042]
                Unexpected exception triggered (java.lang.IndexOutOfBoundsException: Not enough readable bytes - Need 4, maximum is 0))))

    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:196)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1104)
    at com.datastax.driver.core.Cluster.init(Cluster.java:121)
    at com.datastax.driver.core.Cluster.connect(Cluster.java:198)
    at com.hadoop.reloaded.cassandra.CassandraOne.main(CassandraOne.java:13)
    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:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

3 个答案:

答案 0 :(得分:1)

My guess is you are using a version of the Datastax Java Driver that is too old. Check to see if you are running version 3.0.0 or later as this is required to connect to a Cassandra 3.X cluster.

答案 1 :(得分:1)

将驱动程序升级到cassandra-driver-core-3.0.3.jar后,我遇到了同样的问题 和netty这张照片。问题已经解决 enter image description here

答案 2 :(得分:0)

也许是编码问题?

this link

上的更多文章