Files
scylladb/sstables/version.hh
Piotr Jastrzebski 2bd6ad1e2f sstables: define writable_sstable_versions
and use it instead of all_sstable_versions in tests that check
writting of sstables. Following patches remove LA/KA writer so we
want tests to be ready for that and not break by trying to write LA/KA
sstables.

Signed-off-by: Piotr Jastrzebski <piotr@scylladb.com>
2021-06-25 10:12:00 +02:00

104 lines
3.2 KiB
C++

/*
* Copyright (C) 2017-present ScyllaDB
*/
/*
* This file is part of Scylla.
*
* Scylla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scylla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdexcept>
#include <type_traits>
#include <seastar/core/sstring.hh>
namespace sstables {
enum class sstable_version_types { ka, la, mc, md };
enum class sstable_format_types { big };
constexpr std::array<sstable_version_types, 4> all_sstable_versions = {
sstable_version_types::ka,
sstable_version_types::la,
sstable_version_types::mc,
sstable_version_types::md,
};
constexpr std::array<sstable_version_types, 2> writable_sstable_versions = {
sstable_version_types::mc,
sstable_version_types::md,
};
constexpr sstable_version_types oldest_writable_sstable_format = sstable_version_types::mc;
template <size_t S1, size_t S2>
constexpr bool check_sstable_versions(const std::array<sstable_version_types, S1>& all_sstable_versions,
const std::array<sstable_version_types, S2>& writable_sstable_versions, sstable_version_types oldest_writable_sstable_format) {
for (auto v : writable_sstable_versions) {
if (v < oldest_writable_sstable_format) {
return false;
}
}
size_t expected = 0;
for (auto v : all_sstable_versions) {
if (v >= oldest_writable_sstable_format) {
++expected;
}
}
return expected == S2;
}
static_assert(check_sstable_versions(all_sstable_versions, writable_sstable_versions, oldest_writable_sstable_format));
inline auto get_highest_sstable_version() {
return all_sstable_versions[all_sstable_versions.size() - 1];
}
inline sstable_version_types from_string(const seastar::sstring& format) {
if (format == "ka") {
return sstable_version_types::ka;
}
if (format == "la") {
return sstable_version_types::la;
}
if (format == "mc") {
return sstable_version_types::mc;
}
if (format == "md") {
return sstable_version_types::md;
}
throw std::invalid_argument("Wrong sstable format name: " + format);
}
inline seastar::sstring to_string(sstable_version_types format) {
switch (format) {
case sstable_version_types::ka: return "ka";
case sstable_version_types::la: return "la";
case sstable_version_types::mc: return "mc";
case sstable_version_types::md: return "md";
}
throw std::runtime_error("Wrong sstable format");
}
inline int operator<=>(sstable_version_types a, sstable_version_types b) {
auto to_int = [] (sstable_version_types x) {
return static_cast<std::underlying_type_t<sstable_version_types>>(x);
};
return to_int(a) - to_int(b);
}
}