Files
scylladb/sstables/sstable_set.hh
Botond Dénes 94fc550e68 sstable_set::incremental_selector: select() now returns a selection
A seletion contains - in addition to the list of sstables - a next_token
which is a hint as to what is the next best token to call select() with.
This should be the smallest token such that at the next call to
select() the least number of new sstables will be returned, without
skipping any.
2017-08-09 16:27:33 +03:00

81 lines
2.9 KiB
C++

/*
* Copyright (C) 2016 ScyllaDB
*/
/*
* This file is part of Scylla.
*
* Scylla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scylla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "sstables.hh"
#include "query-request.hh" // for partition_range; FIXME: move it out of there
#include <seastar/core/shared_ptr.hh>
#include <vector>
namespace sstables {
class sstable_set_impl;
class incremental_selector_impl;
class sstable_set {
std::unique_ptr<sstable_set_impl> _impl;
// used to support column_family::get_sstable(), which wants to return an sstable_list
// that has a reference somewhere
lw_shared_ptr<sstable_list> _all;
public:
~sstable_set();
sstable_set(std::unique_ptr<sstable_set_impl> impl, lw_shared_ptr<sstable_list> all);
sstable_set(const sstable_set&);
sstable_set(sstable_set&&) noexcept;
sstable_set& operator=(const sstable_set&);
sstable_set& operator=(sstable_set&&) noexcept;
std::vector<shared_sstable> select(const dht::partition_range& range) const;
lw_shared_ptr<sstable_list> all() const { return _all; }
void insert(shared_sstable sst);
void erase(shared_sstable sst);
// Used to incrementally select sstables from sstable set using tokens.
// sstable set must be alive and cannot be modified while incremental
// selector is used.
class incremental_selector {
std::unique_ptr<incremental_selector_impl> _impl;
mutable stdx::optional<dht::token_range> _current_token_range;
mutable std::vector<shared_sstable> _current_sstables;
mutable dht::token _current_next_token;
public:
~incremental_selector();
incremental_selector(std::unique_ptr<incremental_selector_impl> impl);
incremental_selector(incremental_selector&&) noexcept;
struct selection {
const std::vector<shared_sstable>& sstables;
dht::token next_token;
};
// Return the sstables that intersect with t and the best next
// token (inclusive) to call select() with so that the least
// amount of sstables will be returned (without skipping any).
// NOTE: selection.sstables is a reference to an internal cache
// and can be invalidated by another call to select().
// If you need it long-term copy it!
selection select(const dht::token& t) const;
};
incremental_selector make_incremental_selector() const;
};
}