diff --git a/cql3/statements/ks_prop_defs.cc b/cql3/statements/ks_prop_defs.cc index 32ce97117b..861cd81223 100644 --- a/cql3/statements/ks_prop_defs.cc +++ b/cql3/statements/ks_prop_defs.cc @@ -24,7 +24,6 @@ static std::map prepare_options( const sstring& strategy_class, const locator::token_metadata& tm, std::map options, - std::optional& initial_tablets, const std::map& old_options = {}) { options.erase(ks_prop_defs::REPLICATION_STRATEGY_CLASS_KEY); @@ -162,7 +161,7 @@ std::optional ks_prop_defs::get_replication_strategy_class() const { lw_shared_ptr ks_prop_defs::as_ks_metadata(sstring ks_name, const locator::token_metadata& tm, const gms::feature_service& feat) { auto sc = get_replication_strategy_class().value(); std::optional initial_tablets = get_initial_tablets(sc, feat.tablets); - auto options = prepare_options(sc, tm, get_replication_options(), initial_tablets); + auto options = prepare_options(sc, tm, get_replication_options()); return data_dictionary::keyspace_metadata::new_keyspace(ks_name, sc, std::move(options), initial_tablets, get_boolean(KW_DURABLE_WRITES, true), get_storage_options()); } @@ -171,13 +170,14 @@ lw_shared_ptr ks_prop_defs::as_ks_metadata_u std::map options; const auto& old_options = old->strategy_options(); auto sc = get_replication_strategy_class(); - std::optional initial_tablets; if (sc) { - initial_tablets = get_initial_tablets(*sc, old->initial_tablets().has_value()); - options = prepare_options(*sc, tm, get_replication_options(), initial_tablets, old_options); + options = prepare_options(*sc, tm, get_replication_options(), old_options); } else { sc = old->strategy_name(); options = old_options; + } + std::optional initial_tablets = get_initial_tablets(*sc, old->initial_tablets().has_value()); + if (!initial_tablets) { initial_tablets = old->initial_tablets(); } diff --git a/test/cql-pytest/test_tablets.py b/test/cql-pytest/test_tablets.py index 5ee80f68e4..96cb23c89a 100644 --- a/test/cql-pytest/test_tablets.py +++ b/test/cql-pytest/test_tablets.py @@ -100,6 +100,20 @@ def test_alter_changes_initial_tablets(cql, skip_without_tablets): assert res.initial_tablets == 2 +def test_alter_changes_initial_tablets_short(cql, skip_without_tablets): + ksdef = "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND tablets = {'initial': 1};" + with new_test_keyspace(cql, ksdef) as keyspace: + orig_rep = cql.execute(f"SELECT replication FROM system_schema.keyspaces WHERE keyspace_name = '{keyspace}'").one() + + cql.execute(f"ALTER KEYSPACE {keyspace} WITH tablets = {{'initial': 2}};") + res = cql.execute(f"SELECT * FROM system_schema.scylla_keyspaces WHERE keyspace_name = '{keyspace}'").one() + assert res.initial_tablets == 2 + + # Test that replication parameters didn't change + rep = cql.execute(f"SELECT replication FROM system_schema.keyspaces WHERE keyspace_name = '{keyspace}'").one() + assert rep.replication == orig_rep.replication + + # Test that initial number of tablets is preserved in describe def test_describe_initial_tablets(cql, skip_without_tablets): ksdef = "WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'replication_factor' : '1' } " \