Files
scylladb/range_tombstone.cc
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.9 KiB
C++

/*
* Copyright (C) 2016-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include "range_tombstone.hh"
#include "mutation_fragment.hh"
#include "mutation_fragment_v2.hh"
#include <boost/range/algorithm/upper_bound.hpp>
std::ostream& operator<<(std::ostream& out, const range_tombstone& rt) {
if (rt) {
return out << "{range_tombstone: start=" << rt.start_bound() << ", end=" << rt.end_bound() << ", " << rt.tomb << "}";
} else {
return out << "{range_tombstone: none}";
}
}
std::ostream& operator<<(std::ostream& out, const range_tombstone_change& rt) {
return out << "{range_tombstone_change: pos=" << rt.position() << ", " << rt.tombstone() << "}";
}
std::optional<range_tombstone> range_tombstone::apply(const schema& s, range_tombstone&& src)
{
bound_view::compare cmp(s);
if (tomb == src.tomb) {
if (cmp(end_bound(), src.end_bound())) {
end = std::move(src.end);
end_kind = src.end_kind;
}
return { };
}
if (tomb < src.tomb) {
std::swap(*this, src);
}
if (cmp(end_bound(), src.end_bound())) {
return range_tombstone(end, invert_kind(end_kind), std::move(src.end), src.end_kind, src.tomb);
}
return { };
}
position_in_partition_view range_tombstone::position() const {
return position_in_partition_view(position_in_partition_view::range_tombstone_tag_t(), start_bound());
}
position_in_partition_view range_tombstone::end_position() const {
return position_in_partition_view(position_in_partition_view::range_tombstone_tag_t(), end_bound());
}
void range_tombstone_accumulator::update_current_tombstone() {
_current_tombstone = boost::accumulate(_range_tombstones, _partition_tombstone, [] (tombstone t, const range_tombstone& rt) {
t.apply(rt.tomb);
return t;
});
}
void range_tombstone_accumulator::drop_unneeded_tombstones(const clustering_key_prefix& ck, int w) {
auto cmp = [&] (const range_tombstone& rt, const clustering_key_prefix& ck, int w) {
auto bv = rt.end_bound();
return _cmp(bv.prefix(), weight(bv.kind()), ck, w);
};
bool dropped = false;
while (!_range_tombstones.empty() && cmp(*_range_tombstones.begin(), ck, w)) {
dropped = true;
_range_tombstones.pop_front();
}
if (dropped) {
update_current_tombstone();
}
}
void range_tombstone_accumulator::apply(range_tombstone rt) {
drop_unneeded_tombstones(rt.start, weight(rt.start_kind));
_current_tombstone.apply(rt.tomb);
auto cmp = [&] (const range_tombstone& rt1, const range_tombstone& rt2) {
return _cmp(rt1.end_bound(), rt2.end_bound());
};
_range_tombstones.insert(boost::upper_bound(_range_tombstones, rt, cmp), std::move(rt));
}
void range_tombstone_accumulator::clear() {
_range_tombstones.clear();
_partition_tombstone = { };
_current_tombstone = { };
}