From 8910d37994df42f2cc285652353382c797413096 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 31 Jan 2024 16:40:12 +0300 Subject: [PATCH] keyspace_metadata: Include tablets property in DESCRIBE When tablets are enabled and a keyspace being described has them explicitly disabled or non-automatic initial value of zero, include this into the returned describe statement too Signed-off-by: Pavel Emelyanov --- data_dictionary/data_dictionary.cc | 13 +++++++++++-- data_dictionary/keyspace_metadata.hh | 2 +- test/cql-pytest/test_tablets.py | 9 +++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/data_dictionary/data_dictionary.cc b/data_dictionary/data_dictionary.cc index 509695eac5..25be48693e 100644 --- a/data_dictionary/data_dictionary.cc +++ b/data_dictionary/data_dictionary.cc @@ -20,6 +20,7 @@ #include #include #include +#include "replica/database.hh" namespace data_dictionary { @@ -345,7 +346,7 @@ no_such_column_family::no_such_column_family(std::string_view ks_name, const tab { } -std::ostream& keyspace_metadata::describe(std::ostream& os) const { +std::ostream& keyspace_metadata::describe(replica::database& db, std::ostream& os, bool with_internals) const { os << "CREATE KEYSPACE " << cql3::util::maybe_quote(_name) << " WITH replication = {'class': " << cql3::util::single_quote(_strategy_name); for (const auto& opt: _strategy_options) { @@ -357,7 +358,15 @@ std::ostream& keyspace_metadata::describe(std::ostream& os) const { os << ", " << cql3::util::single_quote(e.first) << ": " << cql3::util::single_quote(e.second); } } - os << "} AND durable_writes = " << std::boolalpha << _durable_writes << std::noboolalpha << ";"; + os << "} AND durable_writes = " << std::boolalpha << _durable_writes << std::noboolalpha; + if (db.features().tablets) { + if (!_initial_tablets.has_value()) { + os << " AND tablets = {'enabled': false}"; + } else if (_initial_tablets.value() > 0) { + os << " AND tablets = {'initial': " << _initial_tablets.value() << "}"; + } + } + os << ";"; return os; } diff --git a/data_dictionary/keyspace_metadata.hh b/data_dictionary/keyspace_metadata.hh index d9e9bec605..c788cb14d9 100644 --- a/data_dictionary/keyspace_metadata.hh +++ b/data_dictionary/keyspace_metadata.hh @@ -95,7 +95,7 @@ public: virtual sstring keypace_name() const override { return name(); } virtual sstring element_name() const override { return name(); } virtual sstring element_type() const override { return "keyspace"; } - virtual std::ostream& describe(std::ostream& os) const override; + virtual std::ostream& describe(replica::database& db, std::ostream& os, bool with_internals) const override; }; } diff --git a/test/cql-pytest/test_tablets.py b/test/cql-pytest/test_tablets.py index 7787cd40b0..f3e54990fa 100644 --- a/test/cql-pytest/test_tablets.py +++ b/test/cql-pytest/test_tablets.py @@ -98,3 +98,12 @@ def test_alter_changes_initial_tablets(cql, skip_without_tablets): cql.execute(f"ALTER KEYSPACE {keyspace} WITH replication = {{'class': 'NetworkTopologyStrategy', 'replication_factor': 1}} AND 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 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' } " \ + "AND TABLETS = { 'initial' : 1 }" + with new_test_keyspace(cql, ksdef) as keyspace: + desc = cql.execute(f"DESCRIBE KEYSPACE {keyspace}") + assert "and tablets = {'initial': 1}" in desc.one().create_statement.lower()