Sunday, December 06, 2015

Cassandra - "Cannot achieve consistency level ONE" Exception

Cassandra version: 3.0.0

Today I am playing around with Cassandra 3.0.0, after I create a keyspace "mykeyspace", a column family "Hotel", and try to insert some value, I got the following error:

Traceback (most recent call last):
  File "/usr/bin/", line 1216, in perform_simple_statement
    result = future.result()
  File "/usr/share/cassandra/lib/", line 3118, in result
    raise self._final_exception

Unavailable: code=1000 [Unavailable exception] message="Cannot achieve consistency level ONE" info={'required_replicas': 1, 'alive_replicas': 0, 'consistency': 'ONE'}

My keyspace description looks like this:
CREATE KEYSPACE mykeyspace WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': '1'}  AND durable_writes = true;

and my "Hotel" column family looks like:
CREATE TABLE mykeyspace.hotel (
    key text PRIMARY KEY,
    address text,
    city text,
    name text,
    phone text,
    state text,
    zip_code text
) WITH 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', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': ''}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

Replication factor is '1', and why it complains about "Cannot achieve consistency level ONE"? I only have one node, but that should not be the cause. After some research, I found out that my "dc" and "rack" were defined to "dc1" and "rac1". In my keyspace descrition, I actually ised 'DC1'. So I stop the Cassandra process, did a clean bootstrap, updated the "dc" definition to 'DC1', restarted Cassandra process. This time after create "mykeyspace" and "Hotel" column family, I can insert write and read without any issue!

cqlsh:mykeyspace> INSERT INTO Hotel (key, name, phone, address, city, state, zip_code)
              ... VALUES('AZC_043', 'Cambria Suites Hayden', '480-444-4444', '400 N. Hayden Rd.', 'Scottsdale', 'AZ', '85255');
cqlsh:mykeyspace> select * from Hotel;

 key     | address           | city       | name                  | phone        | state | zip_code


 AZC_043 | 400 N. Hayden Rd. | Scottsdale | Cambria Suites Hayden | 480-444-4444 |    AZ |    85255

No comments: