def test_sync_table_works_with_primary_keys_only_tables(self): # This is "create table": sync_table(PrimaryKeysOnlyModel) # let's make sure settings persisted correctly: assert PrimaryKeysOnlyModel.__compaction__ == LeveledCompactionStrategy # blows up with DoesNotExist if table does not exist table_settings = management.get_table_settings(PrimaryKeysOnlyModel) # let make sure the flag we care about assert LeveledCompactionStrategy in table_settings.options[ 'compaction_strategy_class'] # Now we are "updating" the table: # setting up something to change PrimaryKeysOnlyModel.__compaction__ = SizeTieredCompactionStrategy # primary-keys-only tables do not create entries in system.schema_columns # table. Only non-primary keys are added to that table. # Our code must deal with that eventuality properly (not crash) # on subsequent runs of sync_table (which runs get_fields internally) get_fields(PrimaryKeysOnlyModel) sync_table(PrimaryKeysOnlyModel) table_settings = management.get_table_settings(PrimaryKeysOnlyModel) assert SizeTieredCompactionStrategy in table_settings.options[ 'compaction_strategy_class']
def test_sync_table_works_with_primary_keys_only_tables(self): # This is "create table": sync_table(PrimaryKeysOnlyModel) # let's make sure settings persisted correctly: assert PrimaryKeysOnlyModel.__compaction__ == LeveledCompactionStrategy # blows up with DoesNotExist if table does not exist table_settings = management.get_table_settings(PrimaryKeysOnlyModel) # let make sure the flag we care about assert LeveledCompactionStrategy in table_settings.options['compaction_strategy_class'] # Now we are "updating" the table: # setting up something to change PrimaryKeysOnlyModel.__compaction__ = SizeTieredCompactionStrategy # primary-keys-only tables do not create entries in system.schema_columns # table. Only non-primary keys are added to that table. # Our code must deal with that eventuality properly (not crash) # on subsequent runs of sync_table (which runs get_fields internally) get_fields(PrimaryKeysOnlyModel) sync_table(PrimaryKeysOnlyModel) table_settings = management.get_table_settings(PrimaryKeysOnlyModel) assert SizeTieredCompactionStrategy in table_settings.options['compaction_strategy_class']
def test_all_size_tiered_options(self): class AllSizeTieredOptionsModel(Model): __compaction__ = SizeTieredCompactionStrategy __compaction_bucket_low__ = .3 __compaction_bucket_high__ = 2 __compaction_min_threshold__ = 2 __compaction_max_threshold__ = 64 __compaction_tombstone_compaction_interval__ = 86400 cid = columns.UUID(primary_key=True) name = columns.Text() drop_table(AllSizeTieredOptionsModel) sync_table(AllSizeTieredOptionsModel) settings = get_table_settings(AllSizeTieredOptionsModel) options = json.loads(settings['compaction_strategy_options']) expected = { u'min_threshold': u'2', u'bucket_low': u'0.3', u'tombstone_compaction_interval': u'86400', u'bucket_high': u'2', u'max_threshold': u'64' } self.assertDictEqual(options, expected)
def test_set_table_properties(self): sync_table(ModelWithTableProperties) expected = {'bloom_filter_fp_chance': 0.76328, 'comment': 'TxfguvBdzwROQALmQBOziRMbkqVGFjqcJfVhwGR', 'gc_grace_seconds': 2063, 'read_repair_chance': 0.17985, # For some reason 'dclocal_read_repair_chance' in CQL is called # just 'local_read_repair_chance' in the schema table. # Source: https://issues.apache.org/jira/browse/CASSANDRA-6717 # TODO: due to a bug in the native driver i'm not seeing the local read repair chance show up # 'local_read_repair_chance': 0.50811, } if CASSANDRA_VERSION <= 20: expected['caching'] = CACHING_ALL expected['replicate_on_write'] = False if CASSANDRA_VERSION == 20: expected['populate_io_cache_on_flush'] = True expected['index_interval'] = 98706 if CASSANDRA_VERSION >= 20: expected['default_time_to_live'] = 4756 expected['memtable_flush_period_in_ms'] = 43681 self.assertDictContainsSubset(expected, management.get_table_settings(ModelWithTableProperties).options)
def test_set_table_properties(self): sync_table(ModelWithTableProperties) expected = { 'bloom_filter_fp_chance': 0.76328, 'comment': 'TxfguvBdzwROQALmQBOziRMbkqVGFjqcJfVhwGR', 'gc_grace_seconds': 2063, 'read_repair_chance': 0.17985, # For some reason 'dclocal_read_repair_chance' in CQL is called # just 'local_read_repair_chance' in the schema table. # Source: https://issues.apache.org/jira/browse/CASSANDRA-6717 # TODO: due to a bug in the native driver i'm not seeing the local read repair chance show up # 'local_read_repair_chance': 0.50811, } if CASSANDRA_VERSION <= 20: expected['caching'] = CACHING_ALL expected['replicate_on_write'] = False if CASSANDRA_VERSION == 20: expected['populate_io_cache_on_flush'] = True expected['index_interval'] = 98706 if CASSANDRA_VERSION >= 20: expected['default_time_to_live'] = 4756 expected['memtable_flush_period_in_ms'] = 43681 self.assertDictContainsSubset( expected, management.get_table_settings(ModelWithTableProperties).options)
def test_all_size_tiered_options(self): class AllSizeTieredOptionsModel(Model): __compaction__ = SizeTieredCompactionStrategy __compaction_bucket_low__ = 0.3 __compaction_bucket_high__ = 2 __compaction_min_threshold__ = 2 __compaction_max_threshold__ = 64 __compaction_tombstone_compaction_interval__ = 86400 cid = columns.UUID(primary_key=True) name = columns.Text() drop_table(AllSizeTieredOptionsModel) sync_table(AllSizeTieredOptionsModel) options = get_table_settings(AllSizeTieredOptionsModel).options["compaction_strategy_options"] options = json.loads(options) expected = { u"min_threshold": u"2", u"bucket_low": u"0.3", u"tombstone_compaction_interval": u"86400", u"bucket_high": u"2", u"max_threshold": u"64", } self.assertDictEqual(options, expected)
def test_table_property_update(self): ModelWithTableProperties.__bloom_filter_fp_chance__ = 0.66778 ModelWithTableProperties.__caching__ = CACHING_NONE ModelWithTableProperties.__comment__ = 'xirAkRWZVVvsmzRvXamiEcQkshkUIDINVJZgLYSdnGHweiBrAiJdLJkVohdRy' ModelWithTableProperties.__default_time_to_live__ = 65178 ModelWithTableProperties.__gc_grace_seconds__ = 96362 ModelWithTableProperties.__index_interval__ = 94207 ModelWithTableProperties.__memtable_flush_period_in_ms__ = 60210 ModelWithTableProperties.__populate_io_cache_on_flush__ = False ModelWithTableProperties.__read_repair_chance__ = 0.2989 ModelWithTableProperties.__replicate_on_write__ = True ModelWithTableProperties.__dclocal_read_repair_chance__ = 0.12732 sync_table(ModelWithTableProperties) table_settings = management.get_table_settings(ModelWithTableProperties).options self.assertDictContainsSubset({ 'bloom_filter_fp_chance': 0.66778, 'caching': CACHING_NONE, 'comment': 'xirAkRWZVVvsmzRvXamiEcQkshkUIDINVJZgLYSdnGHweiBrAiJdLJkVohdRy', 'default_time_to_live': 65178, 'gc_grace_seconds': 96362, 'index_interval': 94207, 'memtable_flush_period_in_ms': 60210, 'populate_io_cache_on_flush': False, 'read_repair_chance': 0.2989, 'replicate_on_write': True, # TODO see above comment re: native driver missing local read repair chance # 'local_read_repair_chance': 0.12732, }, table_settings)
def test_all_size_tiered_options(self): class AllSizeTieredOptionsModel(Model): __compaction__ = SizeTieredCompactionStrategy __compaction_bucket_low__ = .3 __compaction_bucket_high__ = 2 __compaction_min_threshold__ = 2 __compaction_max_threshold__ = 64 __compaction_tombstone_compaction_interval__ = 86400 cid = columns.UUID(primary_key=True) name = columns.Text() drop_table(AllSizeTieredOptionsModel) sync_table(AllSizeTieredOptionsModel) options = get_table_settings(AllSizeTieredOptionsModel).options['compaction_strategy_options'] options = json.loads(options) expected = {u'min_threshold': u'2', u'bucket_low': u'0.3', u'tombstone_compaction_interval': u'86400', u'bucket_high': u'2', u'max_threshold': u'64'} self.assertDictEqual(options, expected)
def test_alter_actually_alters(self): tmp = copy.deepcopy(LeveledcompactionTestTable) drop_table(tmp) sync_table(tmp) tmp.__compaction__ = SizeTieredCompactionStrategy tmp.__compaction_sstable_size_in_mb__ = None sync_table(tmp) table_settings = get_table_settings(tmp) self.assertRegexpMatches(table_settings['compaction_strategy_class'], '.*SizeTieredCompactionStrategy$')
def test_all_leveled_options(self): class AllLeveledOptionsModel(Model): __compaction__ = LeveledCompactionStrategy __compaction_sstable_size_in_mb__ = 64 cid = columns.UUID(primary_key=True) name = columns.Text() drop_table(AllLeveledOptionsModel) sync_table(AllLeveledOptionsModel) settings = get_table_settings(AllLeveledOptionsModel) options = json.loads(settings['compaction_strategy_options']) self.assertDictEqual(options, {u'sstable_size_in_mb': u'64'})
def test_table_property_update(self): ModelWithTableProperties.__bloom_filter_fp_chance__ = 0.66778 ModelWithTableProperties.__caching__ = CACHING_NONE ModelWithTableProperties.__comment__ = 'xirAkRWZVVvsmzRvXamiEcQkshkUIDINVJZgLYSdnGHweiBrAiJdLJkVohdRy' ModelWithTableProperties.__gc_grace_seconds__ = 96362 ModelWithTableProperties.__populate_io_cache_on_flush__ = False ModelWithTableProperties.__read_repair_chance__ = 0.2989 ModelWithTableProperties.__replicate_on_write__ = True ModelWithTableProperties.__dclocal_read_repair_chance__ = 0.12732 if CASSANDRA_VERSION >= 20: ModelWithTableProperties.__default_time_to_live__ = 65178 ModelWithTableProperties.__memtable_flush_period_in_ms__ = 60210 ModelWithTableProperties.__index_interval__ = 94207 sync_table(ModelWithTableProperties) table_settings = management.get_table_settings( ModelWithTableProperties).options expected = { 'bloom_filter_fp_chance': 0.66778, 'comment': 'xirAkRWZVVvsmzRvXamiEcQkshkUIDINVJZgLYSdnGHweiBrAiJdLJkVohdRy', 'gc_grace_seconds': 96362, 'read_repair_chance': 0.2989, #'local_read_repair_chance': 0.12732, } if CASSANDRA_VERSION >= 20: expected['memtable_flush_period_in_ms'] = 60210 expected['default_time_to_live'] = 65178 if CASSANDRA_VERSION == 20: expected['index_interval'] = 94207 # these featuers removed in cassandra 2.1 if CASSANDRA_VERSION <= 20: expected['caching'] = CACHING_NONE expected['replicate_on_write'] = True expected['populate_io_cache_on_flush'] = False self.assertDictContainsSubset(expected, table_settings)
def test_table_property_update(self): ModelWithTableProperties.__bloom_filter_fp_chance__ = 0.66778 ModelWithTableProperties.__caching__ = CACHING_NONE ModelWithTableProperties.__comment__ = 'xirAkRWZVVvsmzRvXamiEcQkshkUIDINVJZgLYSdnGHweiBrAiJdLJkVohdRy' ModelWithTableProperties.__gc_grace_seconds__ = 96362 ModelWithTableProperties.__populate_io_cache_on_flush__ = False ModelWithTableProperties.__read_repair_chance__ = 0.2989 ModelWithTableProperties.__replicate_on_write__ = True ModelWithTableProperties.__dclocal_read_repair_chance__ = 0.12732 if CASSANDRA_VERSION >= 20: ModelWithTableProperties.__default_time_to_live__ = 65178 ModelWithTableProperties.__memtable_flush_period_in_ms__ = 60210 ModelWithTableProperties.__index_interval__ = 94207 sync_table(ModelWithTableProperties) table_settings = management.get_table_settings(ModelWithTableProperties).options expected = {'bloom_filter_fp_chance': 0.66778, 'comment': 'xirAkRWZVVvsmzRvXamiEcQkshkUIDINVJZgLYSdnGHweiBrAiJdLJkVohdRy', 'gc_grace_seconds': 96362, 'read_repair_chance': 0.2989, #'local_read_repair_chance': 0.12732, } if CASSANDRA_VERSION >= 20: expected['memtable_flush_period_in_ms'] = 60210 expected['default_time_to_live'] = 65178 if CASSANDRA_VERSION == 20: expected['index_interval'] = 94207 # these featuers removed in cassandra 2.1 if CASSANDRA_VERSION <= 20: expected['caching'] = CACHING_NONE expected['replicate_on_write'] = True expected['populate_io_cache_on_flush'] = False self.assertDictContainsSubset(expected, table_settings)