Skip to content

Commit

Permalink
tombstone: use comparison operator instead of ad-hoc compare() functi…
Browse files Browse the repository at this point in the history
…on and with_relational_operators

The comparison operator (<=>) default implementation happens to exactly
match tombstone::compare(), so use the compiler-generated defaults. Also
default operator== and operator!= (these are not brought in by operator<=>).
These become slightly faster as they perform just an equality comparison,
not three-way compare.

shadowable_tombstone and row_tombstone depend on tombstone::compare(),
so convert them too in a similar way.

with_relational_operations.hh becomes unused, so delete it.

Tests: unit (dev)
Message-Id: <20200602055626.2874801-1-avi@scylladb.com>
  • Loading branch information
avikivity authored and nyh committed Jun 2, 2020
1 parent 160e2b0 commit 6f394e8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 90 deletions.
22 changes: 15 additions & 7 deletions mutation_partition.hh
Expand Up @@ -45,7 +45,6 @@
#include "range_tombstone_list.hh"
#include "clustering_key_filter.hh"
#include "intrusive_set_external_comparator.hh"
#include "utils/with_relational_operators.hh"
#include "utils/preempt.hh"
#include "utils/managed_ref.hh"

Expand Down Expand Up @@ -762,7 +761,7 @@ struct appending_hash<row_marker> {

class clustering_row;

class shadowable_tombstone : public with_relational_operators<shadowable_tombstone> {
class shadowable_tombstone {
tombstone _tomb;
public:

Expand All @@ -774,10 +773,13 @@ public:
: _tomb(std::move(tomb)) {
}

int compare(const shadowable_tombstone& t) const {
return _tomb.compare(t._tomb);
std::strong_ordering operator<=>(const shadowable_tombstone& t) const {
return _tomb <=> t._tomb;
}

bool operator==(const shadowable_tombstone&) const = default;
bool operator!=(const shadowable_tombstone&) const = default;

explicit operator bool() const {
return bool(_tomb);
}
Expand Down Expand Up @@ -845,7 +847,7 @@ The rules for row_tombstones are as follows:
- The shadowable tombstone can be erased or compacted away by a newer
row marker.
*/
class row_tombstone : public with_relational_operators<row_tombstone> {
class row_tombstone {
tombstone _regular;
shadowable_tombstone _shadowable; // _shadowable is always >= _regular
public:
Expand All @@ -860,8 +862,14 @@ public:

row_tombstone() = default;

int compare(const row_tombstone& t) const {
return _shadowable.compare(t._shadowable);
std::strong_ordering operator<=>(const row_tombstone& t) const {
return _shadowable <=> t._shadowable;
}
bool operator==(const row_tombstone& t) const {
return _shadowable == t._shadowable;
}
bool operator!=(const row_tombstone& t) const {
return _shadowable != t._shadowable;
}

explicit operator bool() const {
Expand Down
2 changes: 1 addition & 1 deletion range_tombstone_list.cc
Expand Up @@ -114,7 +114,7 @@ void range_tombstone_list::insert_from(const schema& s,
return;
}

auto c = tomb.compare(it->tomb);
auto c = tomb <=> it->tomb;
if (c == 0) {
// same timestamp, overlapping or adjacent, so merge.
if (less(it->start_bound(), start_bound)) {
Expand Down
2 changes: 1 addition & 1 deletion sstables/mp_row_consumer.hh
Expand Up @@ -903,7 +903,7 @@ class mp_row_consumer_m : public consumer_m {
format("Closing range tombstone that wasn't opened: clustering {}, kind {}, tombstone {}",
ck, k, t));
}
if (_opened_range_tombstone->tomb.compare(t) != 0) {
if (_opened_range_tombstone->tomb != t) {
throw sstables::malformed_sstable_exception(
format("Range tombstone with ck {} and two different tombstones at ends: {}, {}",
ck, _opened_range_tombstone->tomb, t));
Expand Down
2 changes: 1 addition & 1 deletion test/lib/flat_mutation_reader_assertions.hh
Expand Up @@ -41,7 +41,7 @@ private:
static bool are_tombstones_mergeable(const schema& s, const range_tombstone& a, const range_tombstone& b) {
const auto range_a = position_range(position_in_partition(a.position()), position_in_partition(a.end_position()));
const auto tri_cmp = position_in_partition::tri_compare(s);
return a.tomb.compare(b.tomb) == 0 && (range_a.overlaps(s, b.position(), b.end_position()) ||
return (a.tomb <=> b.tomb) == 0 && (range_a.overlaps(s, b.position(), b.end_position()) ||
tri_cmp(a.end_position(), b.position()) == 0 ||
tri_cmp(b.end_position(), a.position()) == 0);
}
Expand Down
20 changes: 5 additions & 15 deletions tombstone.hh
Expand Up @@ -22,17 +22,17 @@
#pragma once

#include <functional>
#include <compare>

#include "timestamp.hh"
#include "gc_clock.hh"
#include "hashing.hh"
#include "utils/with_relational_operators.hh"

/**
* Represents deletion operation. Can be commuted with other tombstones via apply() method.
* Can be empty.
*/
struct tombstone final : public with_relational_operators<tombstone> {
struct tombstone final {
api::timestamp_type timestamp;
gc_clock::time_point deletion_time;

Expand All @@ -45,19 +45,9 @@ struct tombstone final : public with_relational_operators<tombstone> {
: tombstone(api::missing_timestamp, {})
{ }

int compare(const tombstone& t) const {
if (timestamp < t.timestamp) {
return -1;
} else if (timestamp > t.timestamp) {
return 1;
} else if (deletion_time < t.deletion_time) {
return -1;
} else if (deletion_time > t.deletion_time) {
return 1;
} else {
return 0;
}
}
std::strong_ordering operator<=>(const tombstone& t) const = default;
bool operator==(const tombstone&) const = default;
bool operator!=(const tombstone&) const = default;

explicit operator bool() const {
return timestamp != api::missing_timestamp;
Expand Down
65 changes: 0 additions & 65 deletions utils/with_relational_operators.hh

This file was deleted.

0 comments on commit 6f394e8

Please sign in to comment.