实时架构更改时的Cassandra异常

时间:2014-04-23 05:17:01

标签: cassandra

对于我们的项目,我们需要实时架构更改。为此,我们创建了测试。它在cassandra中添加和删除表。 I'm using 10 threads with datastax driver. But I am getting this Exception in some threads

  

线程“Thread-7”中的异常   com.datastax.driver.core.exceptions.NoHostAvailableException:全部   尝试查询失败的主机(尝试:localhost / 127.0.0.1   (com.datastax.driver.core.exceptions.DriverException:超时期间   读))

卡珊德拉还活着。我仍然可以执行查询throw cqlsh。 线程确实没有失败。线程可以添加表,然后突然记录此异常并再次添加表。异常可以在一个线程中出现多次。 每个线程都有自己的会话。

期待 cassandra.yaml

concurrent_writes and reads = 32

增加MAX_HEAP_SIZE and HEAP_NEWSIZE in cassandra-env.sh doesn't help me

Cassandra版本2.0.7

有人可以建议如何处理吗?

public class AddTableThread extends Thread {

    private Cluster cluster;
    private Session session;

    private final String KEYSPACE = "cas";
    private final String HOST = "localhost";
    private final int PORT = 9042;

    private boolean isRunning = true;

    // counter for the added tables
    private int i = 0;

    // Number of the tables that thread has to add
    private int fin = -2;

    public AddTableThread() {
        connect();
    }

    public AddTableThread setTablesCount(int f) {
        this.fin = f;
        System.out.println(this.getName() + " : must add " + fin + " tables");
        return this;
    }

    @Override
    public void run() {

        System.out.println(this.getName() + " : starting thread \n");

        while (isRunning) {
            String name = createName();
            try {

                session.execute(createTableQuery(name));

                System.out.println(this.getName() + " : table is created "
                        + name);
                i++;
            } catch (com.datastax.driver.core.exceptions.NoHostAvailableException e) {
                System.out
                        .println("\n\n" + this.getName() + "!!!!FAILED!!!!!!");
                System.out.println(this.getName() + " : added " + i + " tables");
                System.out.println(this.getName() + " : table " + name
                        + " wasn't added");
            }

            try {
                Thread.sleep((new Random().nextInt(5000)));

            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if (i == fin) {
                isRunning = false;
            }
        }
        close();
        log();
    }

    // creates query that creates table in keyspace with name tableName
    private String createTableQuery(String tableName) {
        return "CREATE TABLE cas." + tableName
                + "(id timeuuid PRIMARY KEY, text varchar, value int);";
    }

    public void finish() {
        isRunning = false;

    }

    private void log() {
        System.out.println("\n" + this.getName() + " : finish");
        System.out.println(this.getName() + " : added " + i + " tables");
        System.out.println("_____________________\n");
    }

    // generates unique table name
    private String createName() {
        return "cf_" + UUIDGen.getTimeUUID().toString().replace("-", "_");
    }

    private void connect() {
        SocketOptions so = new SocketOptions();
        so.setConnectTimeoutMillis(20000);
        so.setReadTimeoutMillis(20000);

        cluster = Cluster.builder().withSocketOptions(so).addContactPoint(HOST)
                .withPort(PORT).build();
        session = cluster.connect(KEYSPACE);
    }

    private void close() {
        session.close();
        cluster.close();
    }

}

1 个答案:

答案 0 :(得分:1)

创造需要时间。所以试着增加:

  

read_request_timeout_in_ms:5000

  

request_timeout_in_ms:10000

尝试取消注释

  

rpc_max_threads:2048

试验这些参数。