Files
scylladb/sstables/version.hh
Avi Kivity fcb8d040e8 treewide: use Software Package Data Exchange (SPDX) license identifiers
Instead of lengthy blurbs, switch to single-line, machine-readable
standardized (https://spdx.dev) license identifiers. The Linux kernel
switched long ago, so there is strong precedent.

Three cases are handled: AGPL-only, Apache-only, and dual licensed.
For the latter case, I chose (AGPL-3.0-or-later and Apache-2.0),
reasoning that our changes are extensive enough to apply our license.

The changes we applied mechanically with a script, except to
licenses/README.md.

Closes #9937
2022-01-18 12:15:18 +01:00

91 lines
2.6 KiB
C++

/*
* Copyright (C) 2017-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#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);
}
}