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 <xemul@scylladb.com>
This commit is contained in:
Pavel Emelyanov
2024-01-31 16:40:12 +03:00
parent bd3ed168ab
commit 8910d37994
3 changed files with 21 additions and 3 deletions

View File

@@ -20,6 +20,7 @@
#include <boost/range/adaptor/filtered.hpp>
#include <boost/algorithm/string/join.hpp>
#include <array>
#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;
}

View File

@@ -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;
};
}

View File

@@ -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()