Thursday, April 23, 2015

Cassandra - How to Update Keyspace Replication Factor

Depends on where you cretaed your keyspace schema (cqlsh or cassandra-cli), command you will use is different. If you are not sure where did yuo create your keyspace schema, one way to check is:
- Log into cqlsh, do a "desc schema;" you should see the following:
cqlsh > desc schema;

CREATE KEYSPACE tweetskeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};


CREATE TABLE tweetskeyspace.tweets (
    key uuid PRIMARY KEY,
    data text,
    prediction text,
    "timestamp" text
) WITH COMPACT STORAGE
    AND bloom_filter_fp_chance = 0.01
    AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
    AND comment = ''
    AND compaction = {'min_threshold': '4', 'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32'}
    AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    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 = '99.0PERCENTILE';

CREATE INDEX tweets_timestamp_idx ON tweetsentiment.tweets ("timestamp");

- Then log into cassandra-cli, do a "show keyspaces;", if a keyspace or table creted in cqlsh, you should not see any "CREATE" commands. In some version of cassandra-cli you can't even see Column Families.

Calsh is intended to be a command-line too which natively speaks the CQL language, and the CQL language is intended to be the main way to interface with Cassandra going forward.

To update replication in cqlsh:

ALTER KEYSPACE "tweetskeyspace" WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': '3'};

To update replication in cassandra-cli:
update keyspace tweetkeyspace with placement_strategy = 'SimpleStrategy' and strategy_options = {replication_factor : 3};

Then wait for "describe cluster;" to report consistent schema version.

No comments: