Files
scylladb/data_dictionary/storage_options.hh
Tomasz Grabiec 66755db062 locator, cql3: Support rack lists in replication options
Allows per-DC replication factor to be either a string, holding a
numerical value, or a list of strings, holding a list of rack names.

The rack list is not respected yet by the tablet allocator, this is
achieved in subsequent commit.

This changes the format of options stored in the flattened map
in system_schema.keyspaces#replication. Values which are rack lists,
are converted into multiple entries, with the list index appended to
the key with ':' as the separator:

For example, this extended map:

   {
      'dc1': '3',
      'dc2': ['rack1', 'rack2']
   }

is stored as a flattened map:

  {
    'dc1': '3',
    'dc2:0': 'rack1',
    'dc2:1': 'rack2'
  }

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@scylladb.com>
2025-10-02 19:42:39 +02:00

86 lines
2.5 KiB
C++

/*
* Copyright (C) 2021-present ScyllaDB
*/
/*
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
*/
#pragma once
#include <filesystem>
#include <map>
#include <variant>
#include <seastar/core/sstring.hh>
#include "schema/schema_fwd.hh"
#include "utils/s3/utils/manip_s3.hh"
#include "seastarx.hh"
namespace seastar {
class abort_source;
}
namespace data_dictionary {
struct storage_options {
struct local {
std::filesystem::path dir;
static constexpr std::string_view name = "LOCAL";
static local from_map(const std::map<sstring, sstring>&);
std::map<sstring, sstring> to_map() const;
bool operator==(const local&) const = default;
};
struct s3 {
sstring bucket;
sstring endpoint;
std::variant<sstring, table_id> location;
seastar::abort_source* abort_source = nullptr;
static constexpr std::string_view name = "S3";
static s3 from_map(const std::map<sstring, sstring>&);
std::map<sstring, sstring> to_map() const;
bool operator==(const s3&) const = default;
};
using value_type = std::variant<local, s3>;
value_type value = local{};
storage_options() = default;
bool is_local_type() const noexcept;
std::string_view type_string() const;
std::map<sstring, sstring> to_map() const;
bool can_update_to(const storage_options& new_options);
static value_type from_map(std::string_view type, const std::map<sstring, sstring>& values);
storage_options append_to_s3_prefix(const sstring& s) const;
};
inline storage_options make_local_options(std::filesystem::path dir) {
storage_options so;
so.value = data_dictionary::storage_options::local { .dir = std::move(dir) };
return so;
}
inline storage_options make_s3_options(const std::string& endpoint, const std::string& fqn) {
std::string bucket;
std::string object;
s3::s3fqn_to_parts(fqn, bucket, object);
object = std::filesystem::path(object).parent_path().string(); // remove the filename and trailing separator from the path
storage_options so;
so.value = storage_options::s3{.bucket = std::move(bucket), .endpoint = endpoint, .location = std::move(object)};
return so;
}
} // namespace data_dictionary
template <>
struct fmt::formatter<data_dictionary::storage_options> {
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
auto format(const data_dictionary::storage_options&, fmt::format_context& ctx) const -> decltype(ctx.out());
};