cassandra@cqlsh>CREATE KEYSPACE hireone WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': '2', 'DC2': '1'}
2) Create a table
cassandra@cqlsh:hireone> CREATE TABLE truncateanddrop (hero_of_usa text, hero_of_india text, id int primary key);
3) Describing the table that was created.
cassandra@cqlsh:hireone> DESC TABLE truncateanddrop ;
CREATE TABLE hireone.truncateanddrop (
id int PRIMARY KEY,
hero_of_india text,
hero_of_usa 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': 'org.apache.cassandra.io.compress.LZ4Compressor'}
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';
4) Inserting values into above table.
cassandra@cqlsh:hireone> INSERT INTO truncateanddrop (id, hero_of_india, hero_of_usa ) values (1,'president','prime_minister');
5) View the contents of the table.
cassandra@cqlsh:hireone> select * from truncateanddrop ;
id | hero_of_india | hero_of_usa
----+---------------+----------------
1 | president | prime_minister
(1 rows)
6) Now truncate the table.
cassandra@cqlsh:hireone> TRUNCATE truncateanddrop ;
cassandra@cqlsh:hireone> select * from truncateanddrop ;
id | hero_of_india | hero_of_usa
----+---------------+-------------
(0 rows)
7) By default the cassandra.yaml file will be enable to take snapshot automatically, so you will find the snapshot folder with in the data/your_table directory.
Property in yaml file: auto_snapshot: true
8) cd /var/lib/cassandra/hireone/truncateanddrop-xx/snapshots/table_directory
cp * /var/lib/cassandra/data/hireone/truncateanddrop-xx
***Above step need to be done on every node and on each datacenter.
9) Now we need to do a refresh of the keyspace table
nodetool refresh hireone truncateanddrop
*** Refresh also needs to be done on every node and on each datacenter
10) Now do a select from the table.
cassandra@cqlsh:hireone> select * from truncateanddrop ;
id | hero_of_india | hero_of_usa
----+---------------+----------------
1 | president | prime_minister
(1 rows)
11) If you drop the table also, its the same process.
***
No comments:
Post a Comment