From f4792a15b429bd3df0ada3f269f968f26a7edaf6 Mon Sep 17 00:00:00 2001 From: mck Date: Thu, 11 May 2017 10:22:08 +1000 Subject: [PATCH] Cassandra performance: Replace sequence ids with time-based UUIDs ref: - https://github.com/thelastpickle/cassandra-reaper/pull/99 - https://github.com/thelastpickle/cassandra-reaper/issues/94 --- .../db/cassandra/001_Initialize_db.cql | 70 +++++++++++-------- .../db/cassandra/002_table_properties.cql | 41 ----------- 2 files changed, 42 insertions(+), 69 deletions(-) delete mode 100644 src/main/resources/db/cassandra/002_table_properties.cql diff --git a/src/main/resources/db/cassandra/001_Initialize_db.cql b/src/main/resources/db/cassandra/001_Initialize_db.cql index d1ff566d5..0830ffdd1 100644 --- a/src/main/resources/db/cassandra/001_Initialize_db.cql +++ b/src/main/resources/db/cassandra/001_Initialize_db.cql @@ -9,23 +9,27 @@ CREATE TABLE IF NOT EXISTS cluster ( name text PRIMARY KEY, partitioner text, seed_hosts set -); +) + WITH compaction = {'class': 'LeveledCompactionStrategy'} + AND caching = {'rows_per_partition': 'ALL'}; -- Repair unit is basically a keyspace with a set of column families. -- Cassandra supports repairing multiple column families in one go. CREATE TABLE IF NOT EXISTS repair_unit ( - id bigint PRIMARY KEY, + id timeuuid PRIMARY KEY, cluster_name text, keyspace_name text, column_families set, incremental_repair boolean -); +) + WITH compaction = {'class': 'LeveledCompactionStrategy'} + AND caching = {'rows_per_partition': 10}; CREATE TABLE IF NOT EXISTS repair_run ( - id bigint PRIMARY KEY, + id timeuuid PRIMARY KEY, cluster_name text, - repair_unit_id bigint, + repair_unit_id timeuuid, cause text, owner text, state text, @@ -37,24 +41,30 @@ CREATE TABLE IF NOT EXISTS repair_run ( last_event text , segment_count int , repair_parallelism text -); +) + WITH compaction = {'class': 'LeveledCompactionStrategy'} + AND caching = {'rows_per_partition': 10}; CREATE TABLE IF NOT EXISTS repair_run_by_cluster( cluster_name text, - id bigint, + id timeuuid, PRIMARY KEY(cluster_name, id) -); +) + WITH compaction = {'class': 'LeveledCompactionStrategy'} + AND caching = {'rows_per_partition': 10}; CREATE TABLE IF NOT EXISTS repair_run_by_unit( - repair_unit_id bigint, - id bigint, + repair_unit_id timeuuid, + id timeuuid, PRIMARY KEY(repair_unit_id, id) -); +) + WITH compaction = {'class': 'LeveledCompactionStrategy'} + AND caching = {'rows_per_partition': 10}; CREATE TABLE IF NOT EXISTS repair_segment ( - id bigint PRIMARY KEY, - repair_unit_id bigint, - run_id bigint, + id timeuuid PRIMARY KEY, + repair_unit_id timeuuid, + run_id timeuuid, start_token varint, end_token varint, state int , @@ -62,39 +72,43 @@ CREATE TABLE IF NOT EXISTS repair_segment ( start_time timestamp, end_time timestamp, fail_count INT -); +) + WITH compaction = {'class': 'LeveledCompactionStrategy'} + AND caching = {'rows_per_partition': 10}; CREATE TABLE IF NOT EXISTS repair_segment_by_run_id ( - run_id bigint, - segment_id bigint, + run_id timeuuid, + segment_id timeuuid, PRIMARY KEY(run_id, segment_id) -); +) + WITH compaction = {'class': 'LeveledCompactionStrategy'} + AND caching = {'rows_per_partition': 10}; CREATE TABLE IF NOT EXISTS repair_schedule ( - id bigint PRIMARY KEY, - repair_unit_id bigint, + id timeuuid PRIMARY KEY, + repair_unit_id timeuuid, state text , days_between int , next_activation timestamp, - run_history set, + run_history set, segment_count int , repair_parallelism text , intensity double , creation_time timestamp, owner text , pause_time timestamp -); +) + WITH compaction = {'class': 'LeveledCompactionStrategy'} + AND caching = {'rows_per_partition': 10}; CREATE TABLE IF NOT EXISTS repair_schedule_by_cluster_and_keyspace( cluster_name text, keyspace_name text, - repair_schedule_id bigint, + repair_schedule_id timeuuid, PRIMARY KEY((cluster_name, keyspace_name), repair_schedule_id) -); +) + WITH compaction = {'class': 'LeveledCompactionStrategy'} + AND caching = {'rows_per_partition': 10}; -CREATE TABLE IF NOT EXISTS repair_id( - id_type text PRIMARY KEY, - id bigint -); diff --git a/src/main/resources/db/cassandra/002_table_properties.cql b/src/main/resources/db/cassandra/002_table_properties.cql deleted file mode 100644 index ef9240217..000000000 --- a/src/main/resources/db/cassandra/002_table_properties.cql +++ /dev/null @@ -1,41 +0,0 @@ - --- Optimal table properties - -ALTER TABLE cluster - WITH compaction = {'class': 'LeveledCompactionStrategy'} - AND caching = {'rows_per_partition': 'ALL'}; - -ALTER TABLE repair_unit - WITH compaction = {'class': 'LeveledCompactionStrategy'} - AND caching = {'rows_per_partition': 10}; - -ALTER TABLE repair_run - WITH compaction = {'class': 'LeveledCompactionStrategy'} - AND caching = {'rows_per_partition': 10}; - -ALTER TABLE repair_run_by_cluster - WITH compaction = {'class': 'LeveledCompactionStrategy'} - AND caching = {'rows_per_partition': 10}; - -ALTER TABLE repair_run_by_unit - WITH compaction = {'class': 'LeveledCompactionStrategy'} - AND caching = {'rows_per_partition': 10}; - -ALTER TABLE repair_segment - WITH compaction = {'class': 'LeveledCompactionStrategy'}; - -ALTER TABLE repair_segment_by_run_id - WITH compaction = {'class': 'LeveledCompactionStrategy'} - AND caching = {'rows_per_partition': 10}; - -ALTER TABLE repair_schedule - WITH compaction = {'class': 'LeveledCompactionStrategy'} - AND caching = {'rows_per_partition': 10}; - -ALTER TABLE repair_schedule_by_cluster_and_keyspace - WITH compaction = {'class': 'LeveledCompactionStrategy'} - AND caching = {'rows_per_partition': 10}; - -ALTER TABLE repair_id - WITH compaction = {'class': 'LeveledCompactionStrategy'} - AND caching = {'rows_per_partition': 10};