Cassandra system_schema 键空间在创建表时不是用户可修改的

Posted

技术标签:

【中文标题】Cassandra system_schema 键空间在创建表时不是用户可修改的【英文标题】:Cassandra system_schema keyspace is not user-modifiable when creating table 【发布时间】:2017-04-11 03:06:42 【问题描述】:

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

ERROR UNAUTHORIZED: system_schema keyspace is not user-modifiable.

产生这个问题的查询是:

如果不存在则创建表 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 状态表明所有节点都已连接,但某些节点无法访问并且存在架构分歧。在我解决了这些问题后,一切都很好。

【问题讨论】:

创建第 23 个表的 cql 看起来如何?您不应该手动更改 system_schemas,cassandra 会为您维护这些。 【参考方案1】:

这是 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)");
    

【讨论】:

这不会改变任何东西。我在每个 CREATE TABLE 查询之前添加了 USE 键空间,它仍然在发生,尽管它现在正在发生在其他一些表中。 连接时使用提供键空间名称,如 cluster.connect("keyspace_name") 我正在使用它。请检查我刚刚添加的用于连接键空间的代码。我已经检查过了,它总是连接到键空间,但问题仍然存在。但是,经过一些更改后,我得到了 uncofigured table ... 错误

以上是关于Cassandra system_schema 键空间在创建表时不是用户可修改的的主要内容,如果未能解决你的问题,请参考以下文章

如果键空间不存在,Cassandra 连接到集群

Cassandra 数据建模分区键

Cassandra 表有多少个分区键?

Cassandra 分区键可以跨一个键空间中的多个表吗?

Cassandra 分区键部分丢失

cassandra 2.0.11 - 分区键的列数