Describing S3 storage for an sstables nowadays has two options -- via sstables registry entry and by using the direct prefix string. The former is used when putting a keyspace on S3. In this case each sstable has the corresponding entry in the system.sstables table. The latter is used by "restore from object storage" code. In that case, sstables don't have entries in the registry, but are accessed by a specific S3 object path. This patch reflects this difference by making s3_options::location be variant of string prefix and table_id owner. The owner needs more explanation, here it is. Today, the system.sstables schema defines partition key to be "string location" and clustering key to be "UUID generation". The partition key is table's datadir string, but it's wrong to use it this way. Next patches will change the partition key to be table's ID (there's table_id type for it), and before doing it storage options must be prepared to carry it onboard. This patch does it, but the table_id alternative of the location is still unused, the rest of the code keeps using the string location to reference a row in the registry table. Next patches will eventually make use of the table_id value. Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
68 lines
1.9 KiB
C++
68 lines
1.9 KiB
C++
/*
|
|
* Copyright (C) 2021-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <filesystem>
|
|
#include <map>
|
|
#include <variant>
|
|
#include <seastar/core/sstring.hh>
|
|
#include "schema/schema_fwd.hh"
|
|
#include "seastarx.hh"
|
|
|
|
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;
|
|
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, 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;
|
|
}
|
|
|
|
} // 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());
|
|
};
|