com.datastax.driver.core.exceptions.AlreadyExistsException: Table gid394016.test_table already exists

DataStax JIRA | Rob Mitchell | 7 months ago
  1. 0

    drop table not working - com.datastax.driver.core

    Stack Overflow | 7 months ago | Rob Mitchell
    com.datastax.driver.core.exceptions.AlreadyExistsException: Table gid394016.test_table already exists
  2. 0

    I hope this is the right place to report this. Drop table using the datastax driver for Cassandra doesn't look to be working. create table works but drop table does not and does not throw an exception. 1) Am I doing the drop correctly? 2) Anyone else seen this behavior? 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. {code} 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(); } } {code} Console output: {code} 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 {code}

    DataStax JIRA | 7 months ago | Rob Mitchell
    com.datastax.driver.core.exceptions.AlreadyExistsException: Table gid394016.test_table already exists
  3. 0

    I hope this is the right place to report this. Drop table using the datastax driver for Cassandra doesn't look to be working. create table works but drop table does not and does not throw an exception. 1) Am I doing the drop correctly? 2) Anyone else seen this behavior? 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. {code} 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(); } } {code} Console output: {code} 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 {code}

    DataStax JIRA | 7 months ago | Rob Mitchell
    com.datastax.driver.core.exceptions.AlreadyExistsException: Table gid394016.test_table already exists
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Unable to generate executable war file using "mvnw -Pprod package", getting following stacktrace

    GitHub | 1 month ago | KalavaraSiri
    com.datastax.driver.core.exceptions.AlreadyExistsException: Keyspace cassandra_unit_keyspace already exists

Root Cause Analysis

  1. com.datastax.driver.core.exceptions.AlreadyExistsException

    Table gid394016.test_table already exists

    at com.datastax.driver.core.Responses$Error$1.decode()
  2. DataStax Java Driver for Apache Cassandra - Core
    Message$ProtocolDecoder.decode
    1. com.datastax.driver.core.Responses$Error$1.decode(Responses.java:69)
    2. com.datastax.driver.core.Responses$Error$1.decode(Responses.java:37)
    3. com.datastax.driver.core.Message$ProtocolDecoder.decode(Message.java:230)
    4. com.datastax.driver.core.Message$ProtocolDecoder.decode(Message.java:221)
    4 frames
  3. Netty
    SingleThreadEventExecutor$2.run
    1. io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89)
    2. io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    3. io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    4. io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:276)
    5. io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:263)
    6. io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    7. io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    8. io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
    9. io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    10. io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    11. io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    12. io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    13. io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    14. io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
    14 frames
  4. Java RT
    Thread.run
    1. java.lang.Thread.run(Thread.java:745)
    1 frame