db: commitlog: add min_position()
Add a helper function which returns the minimum replay position across all existing or future commitlog segments. Only positions greater or equal to it can be replayed on the next reboot. We will use this helper in a future patch to garbage collect some cleanup metadata which refers to replay positions.
This commit is contained in:
@@ -321,6 +321,8 @@ public:
|
||||
requires std::derived_from<T, db::commitlog::entry_writer> && std::same_as<R, decltype(std::declval<T>().result())>
|
||||
future<R> allocate_when_possible(T writer, db::timeout_clock::time_point timeout);
|
||||
|
||||
replay_position min_position();
|
||||
|
||||
template<typename T>
|
||||
struct byte_flow {
|
||||
T bytes_written = 0;
|
||||
@@ -1410,6 +1412,14 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
db::replay_position db::commitlog::segment_manager::min_position() {
|
||||
if (_segments.empty()) {
|
||||
return {_ids, 0};
|
||||
} else {
|
||||
return {_segments.front()->_desc.id, 0};
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename R>
|
||||
requires std::derived_from<T, db::commitlog::entry_writer> && std::same_as<R, decltype(std::declval<T>().result())>
|
||||
future<R> db::commitlog::segment_manager::allocate_when_possible(T writer, db::timeout_clock::time_point timeout) {
|
||||
@@ -3253,6 +3263,10 @@ gc_clock::time_point db::commitlog::min_gc_time(const cf_id_type& id) const {
|
||||
return _segment_manager->min_gc_time(id);
|
||||
}
|
||||
|
||||
db::replay_position db::commitlog::min_position() const {
|
||||
return _segment_manager->min_position();
|
||||
}
|
||||
|
||||
future<std::vector<sstring>> db::commitlog::get_segments_to_replay() const {
|
||||
return _segment_manager->get_segments_to_replay();
|
||||
}
|
||||
|
||||
@@ -369,6 +369,11 @@ public:
|
||||
|
||||
gc_clock::time_point min_gc_time(const cf_id_type&) const;
|
||||
|
||||
// Return the lowest possible replay position across all existing or future commitlog segments.
|
||||
// In other words, only positions greater or equal to min_position() can
|
||||
// be replayed on the next reboot.
|
||||
replay_position min_position() const;
|
||||
|
||||
typedef std::function<future<>(buffer_and_replay_position)> commit_load_reader_func;
|
||||
|
||||
class segment_error : public std::exception {};
|
||||
|
||||
Reference in New Issue
Block a user