counters: base counter_id on utils::tagged_uuid
Use the common base class for uuid-based types. tagged_uuid::to_uuid defined here for backward compatibility, but it will be renamed in the next patch to uuid(). Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
@@ -12,10 +12,6 @@
|
||||
|
||||
#include <boost/range/algorithm/sort.hpp>
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const counter_id& id) {
|
||||
return os << id.to_uuid();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, counter_shard_view csv) {
|
||||
return os << "{global_shard id: " << csv.id() << " value: " << csv.value()
|
||||
<< " clock: " << csv.logical_clock() << "}";
|
||||
|
||||
32
counters.hh
32
counters.hh
@@ -18,45 +18,17 @@
|
||||
class mutation;
|
||||
class atomic_cell_or_collection;
|
||||
|
||||
class counter_id {
|
||||
int64_t _least_significant;
|
||||
int64_t _most_significant;
|
||||
class counter_id : public utils::tagged_uuid<counter_id> {
|
||||
public:
|
||||
static_assert(std::is_same<decltype(std::declval<utils::UUID>().get_least_significant_bits()), int64_t>::value
|
||||
&& std::is_same<decltype(std::declval<utils::UUID>().get_most_significant_bits()), int64_t>::value,
|
||||
"utils::UUID is expected to work with two signed 64-bit integers");
|
||||
|
||||
counter_id() = default;
|
||||
explicit counter_id(utils::UUID uuid) noexcept
|
||||
: _least_significant(uuid.get_least_significant_bits())
|
||||
, _most_significant(uuid.get_most_significant_bits())
|
||||
{ }
|
||||
explicit counter_id(utils::UUID uuid) noexcept : utils::tagged_uuid<counter_id>(uuid) {}
|
||||
|
||||
utils::UUID to_uuid() const {
|
||||
return utils::UUID(_most_significant, _least_significant);
|
||||
}
|
||||
|
||||
bool operator<(const counter_id& other) const {
|
||||
return to_uuid() < other.to_uuid();
|
||||
}
|
||||
bool operator>(const counter_id& other) const {
|
||||
return other.to_uuid() < to_uuid();
|
||||
}
|
||||
bool operator==(const counter_id& other) const {
|
||||
return to_uuid() == other.to_uuid();
|
||||
}
|
||||
bool operator!=(const counter_id& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
public:
|
||||
// For tests.
|
||||
static counter_id generate_random() {
|
||||
return counter_id(utils::make_random_uuid());
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const counter_id& id);
|
||||
|
||||
template<mutable_view is_mutable>
|
||||
class basic_counter_shard_view {
|
||||
enum class offset : unsigned {
|
||||
|
||||
@@ -217,6 +217,15 @@ struct tagged_uuid {
|
||||
bool operator<(const tagged_uuid& o) const noexcept {
|
||||
return id < o.id;
|
||||
}
|
||||
bool operator>(const tagged_uuid& o) const noexcept {
|
||||
return id > o.id;
|
||||
}
|
||||
bool operator<=(const tagged_uuid& o) const noexcept {
|
||||
return id <= o.id;
|
||||
}
|
||||
bool operator>=(const tagged_uuid& o) const noexcept {
|
||||
return id >= o.id;
|
||||
}
|
||||
explicit operator bool() const noexcept {
|
||||
// The default constructor sets the id to nil, which is
|
||||
// guaranteed to not match any valid id.
|
||||
@@ -225,6 +234,11 @@ struct tagged_uuid {
|
||||
static tagged_uuid create_random_id() noexcept { return tagged_uuid{utils::make_random_uuid()}; }
|
||||
explicit tagged_uuid(const utils::UUID& uuid) noexcept : id(uuid) {}
|
||||
tagged_uuid() = default;
|
||||
|
||||
// FIXME: rename to uuid()
|
||||
const utils::UUID& to_uuid() const noexcept {
|
||||
return id;
|
||||
}
|
||||
};
|
||||
} // namespace utils
|
||||
|
||||
|
||||
Reference in New Issue
Block a user