DataStax Help Center

"AlreadyExistsException" seen when creating tables with the Java driver

Summary

When creating tables with the java driver an "AlreadyExistsException" is seen sometimes

Symptoms

The user's program could be creating multiple tables normally when this occurs and can happen seemingly randomly

Cause

The symptoms are expected, they occur as follows

  1. Driver sends the message into the cluster to create the table
  2. The table is created
  3. The driver doesn't receive a response within the configured timeout
  4. The driver retries on another node
  5. Error occurs because the table already exists

Solution

The best action here is to catch the error and continue. In essence the error is a good indicator at least in the sense of you know the table you want to be there is actually there.

Example

try {
//create table code here
} catch (AlreadyExistsException ae) {
System.out.println(ae.getMessage());
}

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

  • Avatar
    José Martínez Poblete

    I love it! :)

  • Avatar
    Olivier Michallat

    Another way to mitigate the issue is to use CREATE TABLE IF NOT EXISTS, if the Cassandra version allows it.

Powered by Zendesk