创建表

时间:2016-11-27 07:09:08

标签: java cassandra datastax

我有java应用程序通过执行查询初始化应用程序中使用的所有cassandra表。它在本地运行良好,并与Apache Cassandra 3.3的远程测试服务器。但是,当我在具有3个节点的Cassandra 3.3集群的生产中运行它时,它会创建前22个表并始终在一个特定的表上停止并显示错误

ERROR UNAUTHORIZED: system_schema keyspace is not user-modifiable.

产生此问题的查询是:

  

CREATE TABLE IF NOT NOT EXISTS userrecom_newusers(userid bigint,timestamp   bigint,PRIMARY KEY(userid))

它使用密钥空间“prosolo_logs_moocs”,因此它与system_schema没有任何关系。

创建这些表的Java代码是:

this.createSchemaIfNotExists(this.getSession(), this.dbName,
                this.dbConfig.replicationFactor);
        Metadata metadata = this.getCluster().getMetadata();
        metadata.getKeyspace(keyspacename).getTables();
        this.getSession().execute("USE "+keyspacename);
        for (String ddl : this.ddls) {
            try {
                this.getSession().execute(ddl);
            } catch (Exception ex) {
                logger.error("Error during the creation of table:"
                        + keyspacename + " for DDL:" + ddl);
                ex.printStackTrace();
            }
        }

完整的跟踪日志是:

    TRACE   [2016-11-27 06:55:31,313] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:71)       [1154641956] CREATE TABLE IF NOT EXISTS userrecom_newusers(userid bigint, timestamp bigint,  PRIMARY KEY (userid))
TRACE   [2016-11-27 06:55:31,313] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:71)       [1154641956] CREATE TABLE IF NOT EXISTS userrecom_newusers(userid bigint, timestamp bigint,  PRIMARY KEY (userid))
TRACE   [2016-11-27 06:55:31,313] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:272)      [1154641956-1] Starting
TRACE   [2016-11-27 06:55:31,313] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:272)      [1154641956-1] Starting
TRACE   [2016-11-27 06:55:31,313] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:280)      [1154641956-1] Querying node /10.0.0.184:9042
TRACE   [2016-11-27 06:55:31,313] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:280)      [1154641956-1] Querying node /10.0.0.184:9042
TRACE   [2016-11-27 06:55:31,313] [localhost-startStop-1] driver.core.Connection (Connection.java:519)      Connection[/10.0.0.184:9042-2, inFlight=1, closed=false], stream 1088, writing request QUERY CREATE TABLE IF NOT EXISTS userrecom_newusers(userid bigint, timestamp bigint,  PRIMARY KEY (userid))([cl=LOCAL_ONE, positionalVals=[], namedVals={}, skip=false, psize=5000, state=null, serialCl=SERIAL])
TRACE   [2016-11-27 06:55:31,313] [localhost-startStop-1] driver.core.Connection (Connection.java:519)      Connection[/10.0.0.184:9042-2, inFlight=1, closed=false], stream 1088, writing request QUERY CREATE TABLE IF NOT EXISTS userrecom_newusers(userid bigint, timestamp bigint,  PRIMARY KEY (userid))([cl=LOCAL_ONE, positionalVals=[], namedVals={}, skip=false, psize=5000, state=null, serialCl=SERIAL])
TRACE   [2016-11-27 06:55:31,313] [cluster3-nio-worker-3] driver.core.Connection (Connection.java:567)      Connection[/10.0.0.184:9042-2, inFlight=1, closed=false], stream 1088, request sent successfully
TRACE   [2016-11-27 06:55:31,313] [cluster3-nio-worker-3] driver.core.Connection (Connection.java:567)      Connection[/10.0.0.184:9042-2, inFlight=1, closed=false], stream 1088, request sent successfully
TRACE   [2016-11-27 06:55:31,315] [cluster3-nio-worker-3] driver.core.Connection (Connection.java:979)      Connection[/10.0.0.184:9042-2, inFlight=1, closed=false], stream 1088, received: ERROR UNAUTHORIZED: system_schema keyspace is not user-modifiable.
TRACE   [2016-11-27 06:55:31,315] [cluster3-nio-worker-3] driver.core.Connection (Connection.java:979)      Connection[/10.0.0.184:9042-2, inFlight=1, closed=false], stream 1088, received: ERROR UNAUTHORIZED: system_schema keyspace is not user-modifiable.
TRACE   [2016-11-27 06:55:31,316] [cluster3-nio-worker-3] driver.core.RequestHandler (RequestHandler.java:166)      [1154641956-1] Setting final result
TRACE   [2016-11-27 06:55:31,316] [cluster3-nio-worker-3] driver.core.RequestHandler (RequestHandler.java:166)      [1154641956-1] Setting final result
ERROR   [2016-11-27 06:55:31,316] [localhost-startStop-1] cassandra.impl.SimpleCassandraClientImpl (CassandraDDLManagerImpl.java:274)       Error during the creation of table:prosolo_logs_mooc for DDL:CREATE TABLE IF NOT EXISTS userrecom_newusers(userid bigint, timestamp bigint,  PRIMARY KEY (userid))
com.datastax.driver.core.exceptions.UnauthorizedException: system_schema keyspace is not user-modifiable.
    at com.datastax.driver.core.exceptions.UnauthorizedException.copy(UnauthorizedException.java:59)
    at com.datastax.driver.core.exceptions.UnauthorizedException.copy(UnauthorizedException.java:25)
    at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:37)
    at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:245)
    at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:63)
    at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:39)
    at org.prosolo.bigdata.dal.cassandra.impl.CassandraDDLManagerImpl.checkIfTablesExistsAndCreate(CassandraDDLManagerImpl.java:272)
    at org.prosolo.bigdata.dal.cassandra.impl.CassandraDDLManagerImpl.<init>(CassandraDDLManagerImpl.java:39)
    at org.prosolo.bigdata.dal.cassandra.impl.CassandraDDLManagerImpl.<init>(CassandraDDLManagerImpl.java:23)
    at org.prosolo.bigdata.dal.cassandra.impl.CassandraDDLManagerImpl$CassandraDDLManagerImplHolder.<clinit>(CassandraDDLManagerImpl.java:44)
    at org.prosolo.bigdata.dal.cassandra.impl.CassandraDDLManagerImpl.getInstance(CassandraDDLManagerImpl.java:47)
    at org.prosolo.bigdata.app.ContextLoader.contextInitialized(ContextLoader.java:40)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:940)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1816)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.datastax.driver.core.exceptions.UnauthorizedException: system_schema keyspace is not user-modifiable.
    at com.datastax.driver.core.Responses$Error.asException(Responses.java:134)
    at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:179)
    at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:184)
    at com.datastax.driver.core.RequestHandler.access$2500(RequestHandler.java:43)
    at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:798)
    at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:617)
    at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1005)
    at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:928)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:276)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:263)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
    at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:831)
    at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:346)
    at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:254)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
    ... 1 more

此查询从Datastax DevCenter执行得很好。我正在使用datastax cassandra驱动程序3.0.0。

知道可能是什么问题吗?

更新:

这是我用来连接群集的代码:

public void connect(String node, int dbPort, String keyspace, int replicationFactor) {
    System.out.println("CONNECTING CASSANDRA:"+node+" keyspace:"+keyspace);
    if (this.session != null) {
        return;
    }
    if (this.cluster != null) {
        return;
    }
    /*cluster = Cluster.builder().addContactPoint(node).build();*/
    this.cluster = Cluster.builder()
            .withPoolingOptions( getPoolingOptions())
            .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
            .withReconnectionPolicy(new ConstantReconnectionPolicy(100L))
            .withPort(dbPort)
            .addContactPoint(node).build();
    Metadata metadata = cluster.getMetadata();
    System.out.printf("Connected to cluster: %s\n",
            metadata.getClusterName());
    for ( Host host : metadata.getAllHosts() ) {
        System.out.printf("Datacenter: %s; Host: %s; Rack: %s\n",
                host.getDatacenter(), host.getAddress(), host.getRack());
    }
    if (keyspace != null) {
        try {
            this.session = this.cluster.connect(keyspace);
        } catch (InvalidQueryException iqu) {
            logger.error(iqu);
            this.session = this.cluster.connect();
            this.createSchemaIfNotExists(this.session, keyspace,
                    replicationFactor);
        }
    } else {
        this.session = this.cluster.connect();
    }
    this.session.execute("USE "+keyspace);
}

在我做了几次更改之后,我现在得到了一个例外

Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table logevents

整个错误日志是:

    TRACE   [2016-11-27 20:09:08,775] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:72)       [1994318425] USE prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,775] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:72)       [1994318425] USE prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,775] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:262)      [1994318425-1] Starting
TRACE   [2016-11-27 20:09:08,775] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:262)      [1994318425-1] Starting
TRACE   [2016-11-27 20:09:08,775] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:270)      [1994318425-1] Querying node /10.0.0.182:9042
TRACE   [2016-11-27 20:09:08,775] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:270)      [1994318425-1] Querying node /10.0.0.182:9042
TRACE   [2016-11-27 20:09:08,775] [localhost-startStop-1] driver.core.Connection (Connection.java:472)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false] Setting keyspace prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,775] [localhost-startStop-1] driver.core.Connection (Connection.java:472)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false] Setting keyspace prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,776] [localhost-startStop-1] driver.core.Connection (Connection.java:532)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 384, writing request QUERY USE "prosolo_logs_mooc"([cl=ONE, positionalVals=[], namedVals={}, skip=false, psize=-1, state=null, serialCl=SERIAL])
TRACE   [2016-11-27 20:09:08,776] [localhost-startStop-1] driver.core.Connection (Connection.java:532)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 384, writing request QUERY USE "prosolo_logs_mooc"([cl=ONE, positionalVals=[], namedVals={}, skip=false, psize=-1, state=null, serialCl=SERIAL])
TRACE   [2016-11-27 20:09:08,776] [cluster3-nio-worker-1] driver.core.Connection (Connection.java:580)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 384, request sent successfully
TRACE   [2016-11-27 20:09:08,776] [cluster3-nio-worker-1] driver.core.Connection (Connection.java:580)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 384, request sent successfully
TRACE   [2016-11-27 20:09:08,776] [cluster3-nio-worker-1] driver.core.Connection (Connection.java:986)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 384, received: RESULT set keyspace prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,776] [cluster3-nio-worker-1] driver.core.Connection (Connection.java:986)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 384, received: RESULT set keyspace prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,777] [localhost-startStop-1] driver.core.Connection (Connection.java:532)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 448, writing request QUERY USE prosolo_logs_mooc([cl=LOCAL_ONE, positionalVals=[], namedVals={}, skip=false, psize=5000, state=null, serialCl=SERIAL])
TRACE   [2016-11-27 20:09:08,777] [localhost-startStop-1] driver.core.Connection (Connection.java:532)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 448, writing request QUERY USE prosolo_logs_mooc([cl=LOCAL_ONE, positionalVals=[], namedVals={}, skip=false, psize=5000, state=null, serialCl=SERIAL])
TRACE   [2016-11-27 20:09:08,777] [cluster3-nio-worker-1] driver.core.Connection (Connection.java:580)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 448, request sent successfully
TRACE   [2016-11-27 20:09:08,777] [cluster3-nio-worker-1] driver.core.Connection (Connection.java:580)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 448, request sent successfully
TRACE   [2016-11-27 20:09:08,777] [cluster3-nio-worker-1] driver.core.Connection (Connection.java:986)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 448, received: RESULT set keyspace prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,777] [cluster3-nio-worker-1] driver.core.Connection (Connection.java:986)      Connection[/10.0.0.182:9042-1, inFlight=1, closed=false], stream 448, received: RESULT set keyspace prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,778] [cluster3-nio-worker-1] driver.core.RequestHandler (RequestHandler.java:156)      [1994318425-1] Setting final result
TRACE   [2016-11-27 20:09:08,778] [cluster3-nio-worker-1] driver.core.RequestHandler (RequestHandler.java:156)      [1994318425-1] Setting final result
TRACE   [2016-11-27 20:09:08,778] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:72)       [1035879214] CREATE INDEX IF NOT EXISTS eventtype_id ON logevents (eventtype);
TRACE   [2016-11-27 20:09:08,778] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:72)       [1035879214] CREATE INDEX IF NOT EXISTS eventtype_id ON logevents (eventtype);
TRACE   [2016-11-27 20:09:08,778] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:262)      [1035879214-1] Starting
TRACE   [2016-11-27 20:09:08,778] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:262)      [1035879214-1] Starting
TRACE   [2016-11-27 20:09:08,778] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:270)      [1035879214-1] Querying node /10.0.0.183:9042
TRACE   [2016-11-27 20:09:08,778] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:270)      [1035879214-1] Querying node /10.0.0.183:9042
TRACE   [2016-11-27 20:09:08,778] [localhost-startStop-1] driver.core.Connection (Connection.java:472)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false] Setting keyspace prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,778] [localhost-startStop-1] driver.core.Connection (Connection.java:472)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false] Setting keyspace prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,778] [localhost-startStop-1] driver.core.Connection (Connection.java:532)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 384, writing request QUERY USE "prosolo_logs_mooc"([cl=ONE, positionalVals=[], namedVals={}, skip=false, psize=-1, state=null, serialCl=SERIAL])
TRACE   [2016-11-27 20:09:08,778] [localhost-startStop-1] driver.core.Connection (Connection.java:532)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 384, writing request QUERY USE "prosolo_logs_mooc"([cl=ONE, positionalVals=[], namedVals={}, skip=false, psize=-1, state=null, serialCl=SERIAL])
TRACE   [2016-11-27 20:09:08,779] [cluster3-nio-worker-2] driver.core.Connection (Connection.java:580)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 384, request sent successfully
TRACE   [2016-11-27 20:09:08,779] [cluster3-nio-worker-2] driver.core.Connection (Connection.java:580)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 384, request sent successfully
TRACE   [2016-11-27 20:09:08,779] [cluster3-nio-worker-2] driver.core.Connection (Connection.java:986)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 384, received: RESULT set keyspace prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,779] [cluster3-nio-worker-2] driver.core.Connection (Connection.java:986)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 384, received: RESULT set keyspace prosolo_logs_mooc
TRACE   [2016-11-27 20:09:08,780] [localhost-startStop-1] driver.core.Connection (Connection.java:532)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 448, writing request QUERY CREATE INDEX IF NOT EXISTS eventtype_id ON logevents (eventtype);([cl=LOCAL_ONE, positionalVals=[], namedVals={}, skip=false, psize=5000, state=null, serialCl=SERIAL])
TRACE   [2016-11-27 20:09:08,780] [localhost-startStop-1] driver.core.Connection (Connection.java:532)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 448, writing request QUERY CREATE INDEX IF NOT EXISTS eventtype_id ON logevents (eventtype);([cl=LOCAL_ONE, positionalVals=[], namedVals={}, skip=false, psize=5000, state=null, serialCl=SERIAL])
TRACE   [2016-11-27 20:09:08,780] [cluster3-nio-worker-2] driver.core.Connection (Connection.java:580)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 448, request sent successfully
TRACE   [2016-11-27 20:09:08,780] [cluster3-nio-worker-2] driver.core.Connection (Connection.java:580)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 448, request sent successfully
TRACE   [2016-11-27 20:09:08,781] [cluster3-nio-worker-2] driver.core.Connection (Connection.java:986)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 448, received: ERROR INVALID: unconfigured table logevents
TRACE   [2016-11-27 20:09:08,781] [cluster3-nio-worker-2] driver.core.Connection (Connection.java:986)      Connection[/10.0.0.183:9042-1, inFlight=1, closed=false], stream 448, received: ERROR INVALID: unconfigured table logevents
TRACE   [2016-11-27 20:09:08,781] [cluster3-nio-worker-2] driver.core.RequestHandler (RequestHandler.java:156)      [1035879214-1] Setting final result
TRACE   [2016-11-27 20:09:08,781] [cluster3-nio-worker-2] driver.core.RequestHandler (RequestHandler.java:156)      [1035879214-1] Setting final result
ERROR   [2016-11-27 20:09:08,782] [localhost-startStop-1] cassandra.impl.SimpleCassandraClientImpl (CassandraDDLManagerImpl.java:274)       Error during the creation of table:prosolo_logs_mooc for DDL:CREATE INDEX IF NOT EXISTS eventtype_id ON logevents (eventtype);
com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table logevents
    at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:50)
    at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:37)
    at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:245)
    at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:64)
    at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:39)
    at org.prosolo.bigdata.dal.cassandra.impl.CassandraDDLManagerImpl.checkIfTablesExistsAndCreate(CassandraDDLManagerImpl.java:272)
    at org.prosolo.bigdata.dal.cassandra.impl.CassandraDDLManagerImpl.<init>(CassandraDDLManagerImpl.java:39)
    at org.prosolo.bigdata.dal.cassandra.impl.CassandraDDLManagerImpl.<init>(CassandraDDLManagerImpl.java:23)
    at org.prosolo.bigdata.dal.cassandra.impl.CassandraDDLManagerImpl$CassandraDDLManagerImplHolder.<clinit>(CassandraDDLManagerImpl.java:44)
    at org.prosolo.bigdata.dal.cassandra.impl.CassandraDDLManagerImpl.getInstance(CassandraDDLManagerImpl.java:47)
    at org.prosolo.bigdata.app.ContextLoader.contextInitialized(ContextLoader.java:40)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:940)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1816)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table logevents
    at com.datastax.driver.core.Responses$Error.asException(Responses.java:136)
    at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:179)
    at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:174)
    at com.datastax.driver.core.RequestHandler.access$2600(RequestHandler.java:43)
    at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:793)
    at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:627)
    at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1012)
    at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:935)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:328)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:321)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:328)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:321)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:328)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:321)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:328)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:321)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1280)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:328)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:890)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:564)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:505)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:419)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:391)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
    ... 1 more
TRACE   [2016-11-27 20:09:08,783] [localhost-startStop-1] driver.core.RequestHandler (RequestHandler.java:72)       [1037500672] USE prosolo_logs_mooc

更新2:

似乎我遇到的所有问题都与未正确配置的群集有关。即使nodetool状态指示所有节点都已连接,但某些节点无法访问,并且存在架构不一致。在我解决了这些问题之后,一切都很好。

1 个答案:

答案 0 :(得分:0)

以下是Java中的工作代码:

public static void main(String[] args) {
    try (Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withCredentials("username", "password").build(); Session session = cluster.connect("test")) {
        createTableIfNotExist(cluster, session, "test");
    }
}

private static void createTableIfNotExist(Cluster cluster, Session session, String keyspace) {
    Metadata metadata = cluster.getMetadata();
    TableMetadata tableMetadata = metadata.getKeyspace(keyspace).getTable("exp");
    if (tableMetadata == null) {
        session.execute("USE " + keyspace);
        session.execute("CREATE TABLE exp(a int primary key, b int)");
    }
}