alter_keyspace_statement: Include tablets information in system.topology

Altering a keyspace (that has tablets enabled) without changing
tablets attributes, i.e. no `AND tablets = {...}` results in incorrect
"Update Keyspace..." log message being printed. The printed log
contains "tablets={"enabled":false}".

Refs https://github.com/scylladb/scylladb/issues/22261

Closes scylladb/scylladb#22324
This commit is contained in:
Łukasz Paszkowski
2025-01-15 16:09:28 +01:00
committed by Botond Dénes
parent 6ae3076b4e
commit 9ec1a457d6
2 changed files with 13 additions and 8 deletions

View File

@@ -146,7 +146,6 @@ void add_prefixed_key(const sstring& prefix, const std::map<sstring, sstring>& i
};
std::map<sstring, sstring> get_current_options_flattened(const shared_ptr<cql3::statements::ks_prop_defs>& ks,
bool include_tablet_options,
const gms::feature_service& feat) {
std::map<sstring, sstring> all_options;
@@ -154,7 +153,7 @@ std::map<sstring, sstring> get_current_options_flattened(const shared_ptr<cql3::
add_prefixed_key(ks->KW_STORAGE, ks->get_storage_options().to_map(), all_options);
// if no tablet options are specified in ATLER KS statement,
// we want to preserve the old ones and hence cannot overwrite them with defaults
if (include_tablet_options) {
if (ks->has_property(ks->KW_TABLETS)) {
auto initial_tablets = ks->get_initial_tablets(std::nullopt);
add_prefixed_key(ks->KW_TABLETS,
{{"enabled", initial_tablets ? "true" : "false"},
@@ -168,13 +167,13 @@ std::map<sstring, sstring> get_current_options_flattened(const shared_ptr<cql3::
return all_options;
}
std::map<sstring, sstring> get_old_options_flattened(const data_dictionary::keyspace& ks, bool include_tablet_options) {
std::map<sstring, sstring> get_old_options_flattened(const data_dictionary::keyspace& ks) {
std::map<sstring, sstring> all_options;
using namespace cql3::statements;
add_prefixed_key(ks_prop_defs::KW_REPLICATION, ks.get_replication_strategy().get_config_options(), all_options);
add_prefixed_key(ks_prop_defs::KW_STORAGE, ks.metadata()->get_storage_options().to_map(), all_options);
if (include_tablet_options) {
if (ks.metadata()->initial_tablets()) {
add_prefixed_key(ks_prop_defs::KW_TABLETS,
{{"enabled", ks.metadata()->initial_tablets() ? "true" : "false"},
{"initial", std::to_string(ks.metadata()->initial_tablets().value_or(0))}},
@@ -200,9 +199,8 @@ cql3::statements::alter_keyspace_statement::prepare_schema_mutations(query_proce
auto ks_md_update = _attrs->as_ks_metadata_update(ks_md, tm, feat);
std::vector<mutation> muts;
std::vector<sstring> warnings;
bool include_tablet_options = _attrs->get_map(_attrs->KW_TABLETS).has_value();
auto old_ks_options = get_old_options_flattened(ks, include_tablet_options);
auto ks_options = get_current_options_flattened(_attrs, include_tablet_options, feat);
auto old_ks_options = get_old_options_flattened(ks);
auto ks_options = get_current_options_flattened(_attrs, feat);
ks_options.merge(old_ks_options);
auto ts = mc.write_timestamp();

View File

@@ -32,7 +32,7 @@ import re
from cassandra import InvalidRequest
from .util import new_test_table, local_process_id
from .util import new_test_keyspace, new_test_table, local_process_id
from .test_batch import generate_big_batch
# A fixture to find the Scylla log file, returning the log file's path.
@@ -118,6 +118,13 @@ def test_log_table_operations(cql, test_keyspace, logfile):
wait_for_log(logfile, f'Dropping {table}')
def test_log_alter_keyspace_operation(cql, this_dc, logfile):
ksdef = f"WITH replication = {{'class': 'NetworkTopologyStrategy', '{this_dc}': 1}} AND tablets = {{'initial': 1}};"
with new_test_keyspace(cql, ksdef) as keyspace:
cql.execute(f"ALTER KEYSPACE {keyspace} WITH replication = {{'class': 'NetworkTopologyStrategy', '{this_dc}': 2}}")
wait_for_log(logfile, r'Update Keyspace.*name=%s.*tablets={\"initial\":\d+' % keyspace)
@pytest.fixture(scope="module")
def table_batch(cql, test_keyspace):
with new_test_table(cql, test_keyspace, "k int primary key, t text") as table: