From d27620e1462597e4c3cbbeb5df524e4528c85cf5 Mon Sep 17 00:00:00 2001 From: Calle Wilund Date: Mon, 17 Jun 2024 13:27:05 +0000 Subject: [PATCH] schema_extensions: Add an option to string method Allow an extension to describe itself as the CQL property string that created it (and is serialized to schema tables) Only paxos extension requires override. --- db/paxos_grace_seconds_extension.hh | 4 ++++ schema/schema.cc | 10 ++++++++++ schema/schema.hh | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/db/paxos_grace_seconds_extension.hh b/db/paxos_grace_seconds_extension.hh index 843d1ddf4d..f46e610458 100644 --- a/db/paxos_grace_seconds_extension.hh +++ b/db/paxos_grace_seconds_extension.hh @@ -55,6 +55,10 @@ public: return ser::serialize_to_buffer(_paxos_gc_sec); } + std::string options_to_string() const override { + return std::to_string(_paxos_gc_sec); + } + static int32_t deserialize(const bytes_view& buffer) { return ser::deserialize_from_buffer(buffer, boost::type()); } diff --git a/schema/schema.cc b/schema/schema.cc index e639020267..ecdbb7cd6b 100644 --- a/schema/schema.cc +++ b/schema/schema.cc @@ -801,6 +801,16 @@ std::ostream& operator<<(std::ostream& os, const schema& s) { return os; } +// default impl assumes options are in a map. +// implementations should override if not +std::string schema_extension::options_to_string() const { + std::ostringstream ss; + ss << '{'; + map_as_cql_param(ss, ser::deserialize_from_buffer(serialize(), boost::type(), 0)); + ss << '}'; + return ss.str(); +} + static std::ostream& column_definition_as_cql_key(std::ostream& os, const column_definition & cd) { os << cd.name_as_cql_string(); os << " " << cd.type->cql3_type_name(); diff --git a/schema/schema.hh b/schema/schema.hh index b93b4ec430..34cc9cf6c7 100644 --- a/schema/schema.hh +++ b/schema/schema.hh @@ -534,6 +534,10 @@ public: virtual bool is_placeholder() const { return false; } + using default_map_type = std::map; + // default impl assumes options are in a map. + // implementations should override if not + virtual std::string options_to_string() const; }; struct schema_static_props {