简体   繁体   English

删除表不起作用-com.datastax.driver.core

[英]drop table not working - com.datastax.driver.core

Drop table using the datastax driver for Cassandra doesn't look to be working. 使用Cassandra的datastax驱动程序删除表似乎不起作用。 create table works but drop table does not and does not throw an exception. 创建表有效,但删除表无效,并且不会引发异常。 1) Am I doing the drop correctly? 1)我是否正确放置了滴水? 2) Anyone else seen this behavior? 2)有人看到过这种行为吗?

In the output you can see the table gets created and apparently dropped as it is not in the second table listing in the first run. 在输出中,您可以看到该表已创建,并且显然已删除,因为该表不在第一次运行的第二个表中。 However, when I reconnect (second run) the table is there resulting in an exception. 但是,当我重新连接(第二次运行)时,表在那里导致异常。

import java.util.Collection;
import com.datastax.driver.core.*;

public class Fail {
    SimpleStatement createTableCQL = new SimpleStatement("create table test_table(testfield varchar primary key)");
    SimpleStatement dropTableCQL = new SimpleStatement("drop table test_table");
    Session session = null;
    Cluster cluster = null;

    public Fail()
    {
        System.out.println("First Run");
        this.run();
        System.out.println("Second Run");
        this.run();
    }

    private void run()
    {
        try
        {
            cluster = Cluster.builder().addContactPoints("10.48.8.43 10.48.8.47 10.48.8.53")
                  .withCredentials("394016","394016")
                  .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.ALL))
                  .build();
            session = cluster.connect("gid394016");
        }
        catch(Exception e)
        {
            System.err.println(e.toString());
            System.exit(1);
        }

        //create the table
        System.out.println("createTableCQL");
        this.session.execute(createTableCQL);

        //list tables in the keyspace
        System.out.println("Table list:");
        Collection<TableMetadata> results1 = cluster.getMetadata().getKeyspace("gid394016").getTables();
        for (TableMetadata tm : results1)
        {
            System.out.println(tm.toString());
        }

        //drop the table
        System.out.println("dropTableCQL");
        this.session.execute(dropTableCQL);

        //list tables in the keyspace
        System.out.println("Table list:");
        Collection<TableMetadata> results2 = cluster.getMetadata().getKeyspace("gid394016").getTables();
        for (TableMetadata tm : results2)
        {
            System.out.println(tm.toString());
        }

        session.close();
        cluster.close();    
    }

    public static void main(String[] args) {
        new Fail(); 
    }

}

Console output: 控制台输出:

First Run
[main] INFO com.datastax.driver.core.NettyUtil - Did not find Netty's native epoll transport in the classpath, defaulting to NIO.
[main] INFO com.datastax.driver.core.policies.DCAwareRoundRobinPolicy - Using data-center name 'Cassandra' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)
[main] INFO com.datastax.driver.core.Cluster - New Cassandra host /10.48.8.51:9042 added
[main] INFO com.datastax.driver.core.Cluster - New Cassandra host /10.48.8.47:9042 added
[main] INFO com.datastax.driver.core.Cluster - New Cassandra host /10.48.8.53:9042 added
[main] INFO com.datastax.driver.core.Cluster - New Cassandra host /10.48.8.49:9042 added
[main] INFO com.datastax.driver.core.Cluster - New Cassandra host 10.48.8.43 10.48.8.47 10.48.8.53/10.48.8.43:9042 added
createTableCQL
Table list:
CREATE TABLE gid394016.test_table (testfield text, PRIMARY KEY (testfield)) WITH read_repair_chance = 0.0 AND dclocal_read_repair_chance = 0.1 AND gc_grace_seconds = 864000 AND bloom_filter_fp_chance = 0.01 AND caching = { 'keys' : 'ALL', 'rows_per_partition' : 'NONE' } AND comment = '' AND compaction = { 'class' : 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy' } AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.LZ4Compressor' } AND default_time_to_live = 0 AND speculative_retry = '99.0PERCENTILE' AND min_index_interval = 128 AND max_index_interval = 2048;
dropTableCQL
Table list:
Second Run
[main] INFO com.datastax.driver.core.policies.DCAwareRoundRobinPolicy - Using data-center name 'Cassandra' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)
[main] INFO com.datastax.driver.core.Cluster - New Cassandra host /10.48.8.51:9042 added
[main] INFO com.datastax.driver.core.Cluster - New Cassandra host /10.48.8.47:9042 added
[main] INFO com.datastax.driver.core.Cluster - New Cassandra host /10.48.8.53:9042 added
[main] INFO com.datastax.driver.core.Cluster - New Cassandra host /10.48.8.49:9042 added
[main] INFO com.datastax.driver.core.Cluster - New Cassandra host 10.48.8.43 10.48.8.47 10.48.8.53/10.48.8.43:9042 added
createTableCQL
Exception in thread "main" com.datastax.driver.core.exceptions.AlreadyExistsException: Table gid394016.test_table already exists
    at com.datastax.driver.core.exceptions.AlreadyExistsException.copy(AlreadyExistsException.java:111)
    at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:37)
    at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:217)
    at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:54)
    at com.bdcauto.cassandrachecks.Fail.run(Fail.java:38)
    at com.bdcauto.cassandrachecks.Fail.<init>(Fail.java:17)
    at com.bdcauto.cassandrachecks.Fail.main(Fail.java:65)
Caused by: com.datastax.driver.core.exceptions.AlreadyExistsException: Table gid394016.test_table already exists
    at com.datastax.driver.core.exceptions.AlreadyExistsException.copy(AlreadyExistsException.java:130)
    at com.datastax.driver.core.Responses$Error.asException(Responses.java:118)
    at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:151)
    at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:175)
    at com.datastax.driver.core.RequestHandler.access$2500(RequestHandler.java:44)
    at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:801)
    at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:617)
    at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1014)
    at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:937)
    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.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.datastax.driver.core.exceptions.AlreadyExistsException: Table gid394016.test_table already exists
    at com.datastax.driver.core.Responses$Error$1.decode(Responses.java:69)
    at com.datastax.driver.core.Responses$Error$1.decode(Responses.java:37)
    at com.datastax.driver.core.Message$ProtocolDecoder.decode(Message.java:230)
    at com.datastax.driver.core.Message$ProtocolDecoder.decode(Message.java:221)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89)
    ... 14 more

You are running this code with the table present in the database and that's why you are getting the "already exists" error. 您正在使用数据库中存在的表来运行此代码,这就是为什么您会收到“已经存在”错误的原因。 Please connect to the database using cqlsh and check that yourself. 请使用cqlsh连接到数据库并检查一下自己。

Create, alter and drop table statements are being propagated throughout the cluster asynchronously. 创建,更改和删除表语句将在整个群集中异步传播。 Even though you are receiving a response from the coordinator you still need to wait for schema agreement . 即使收到协调员的答复,您仍然需要等待架构协议

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 package com.datastax.driver.core 不存在 - package com.datastax.driver.core does not exist com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表用户” - com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table user" com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表schema_keyspaces - com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table schema_keyspaces com.datastax.driver.core.exceptions.InvalidQueryException: 未配置表 peers_v2 - com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table peers_v2 卡桑德拉数据库。 com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表人 - Cassandra DB. com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table person 使用Datastax Java驱动程序的com.datastax.driver.core.exceptions.InvalidQueryException - com.datastax.driver.core.exceptions.InvalidQueryException using Datastax Java driver 我应该为“ com.datastax.driver.core.exceptions.ReadTimeoutException”做什么? - what should I do for “com.datastax.driver.core.exceptions.ReadTimeoutException”? 线程“ main”中的异常com.datastax.driver.core.exceptions.InvalidQueryException:PRIMARY KEY中引用的未知定义 - Exception in thread “main” com.datastax.driver.core.exceptions.InvalidQueryException: Unknown definition referenced in PRIMARY KEY Cassandra-com.datastax.driver.core.exceptions.DriverException:尝试获取可用连接时超时 - Cassandra - com.datastax.driver.core.exceptions.DriverException: Timeout while trying to acquire available connection 引起原因:com.datastax.driver.core.exceptions.SyntaxError:行0:-1输入不匹配&#39; <EOF> &#39;期待&#39;)&#39; - Caused by: com.datastax.driver.core.exceptions.SyntaxError: line 0:-1 mismatched input '<EOF>' expecting ')'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM