From c496d60716ed2580e963ccee7b473a153dc4ed92 Mon Sep 17 00:00:00 2001 From: Nadav Har'El Date: Sun, 21 Jan 2024 16:38:58 +0200 Subject: [PATCH] alternator: use tablets by default, if available Before this patch, Alternator tables did not use tablets even if this feature was available - tablets had to be manually enabled per table by using a tag. But recently we changed CQL to enable tablets by default on all keyspaces (when the experimental "tablets" option is turned on), so this patch does the same for Alternator tables: 1. When the "tablets" experimental feature is on, new Alternator tables will use tablets instead of vnodes. They will use the default choice of initial_tablets. 2. The same tag that in the past could be used to enable tablets on a specific table, now can be used to disable tablets or change the default initial_tablets for a specific table at creation time. Fixes #16355 Signed-off-by: Nadav Har'El --- alternator/executor.cc | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/alternator/executor.cc b/alternator/executor.cc index a7812c7a48..b7d61607fa 100644 --- a/alternator/executor.cc +++ b/alternator/executor.cc @@ -8,6 +8,7 @@ #include #include "alternator/executor.hh" +#include "db/config.hh" #include "log.hh" #include "schema/schema_builder.hh" #include "exceptions/exceptions.hh" @@ -4513,20 +4514,34 @@ static lw_shared_ptr create_keyspace_metadata(std::string_vie keyspace_name, rf, endpoint_count); } auto opts = get_network_topology_options(sp, gossiper, rf); - std::optional initial_tablets; - // Tablets are not yet enabled by default on Alternator tables, because of - // missing support for CDC (see issue #16313). Until then, allow - // requesting tablets at table-creation time by supplying following tag, - // with an integer value. This is useful for testing Tablet support in - // Alternator even before it is ready for prime time. + // If the "tablets" experimental feature is available, we enable tablets + // by default on all Alternator tables. However, some Alternator features + // are not yet available with tablets (Streams #16313 and TTL #16567) so + // we allow disabling tablets at table-creation by supplying the following + // tags with any non-numeric value (e.g., empty string or the word "none"). + // Supplying it with an integer value allows overriding the default choice + // of initial_tablets (setting the value to 0 asks for the default choice). // If we make this tag a permanent feature, it will get a "system:" prefix - // until then we give it the "experimental:" prefix to not commit to it. static constexpr auto INITIAL_TABLETS_TAG_KEY = "experimental:initial_tablets"; - if (tags_map.contains(INITIAL_TABLETS_TAG_KEY)) { - initial_tablets = std::stol(tags_map.at(INITIAL_TABLETS_TAG_KEY)); + std::optional initial_tablets; + if (sp.get_db().local().get_config().check_experimental(db::experimental_features_t::feature::TABLETS)) { + auto it = tags_map.find(INITIAL_TABLETS_TAG_KEY); + if (it == tags_map.end()) { + // No tag - ask to choose a reasonable default number of tablets + initial_tablets = 0; + } else { + // Tag set. If it's a valid number, use it. If not - e.g., it's + // empty or a word like "none", disable tablets by setting + // initial_tablets to a disengaged optional. + try { + initial_tablets = std::stol(tags_map.at(INITIAL_TABLETS_TAG_KEY)); + } catch(...) { + initial_tablets = std::nullopt; + } + } } - return keyspace_metadata::new_keyspace(keyspace_name, "org.apache.cassandra.locator.NetworkTopologyStrategy", std::move(opts), initial_tablets); }