sstables: random_access_reader: let file_random_access_reader set the input stream

Allow file_random_access_reader constructor to set the
input stream to prepare for futurizing seek() by adding
a protected set() method.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2020-06-29 14:34:45 +03:00
parent 0bb1c0f37d
commit e7fdadd748
2 changed files with 7 additions and 2 deletions

View File

@@ -42,7 +42,7 @@ void random_access_reader::seek(uint64_t pos) {
return fut.then([in = std::move(in)] {});
});
}
_in = std::make_unique < input_stream < char >> (open_at(pos));
set(open_at(pos));
}
future<> random_access_reader::close() {
@@ -53,7 +53,7 @@ future<> random_access_reader::close() {
file_random_access_reader::file_random_access_reader(file f, uint64_t file_size, size_t buffer_size, unsigned read_ahead)
: _file(std::move(f)), _file_size(file_size), _buffer_size(buffer_size), _read_ahead(read_ahead) {
seek(0);
set(open_at(0));
}
input_stream<char> file_random_access_reader::open_at(uint64_t pos) {

View File

@@ -36,6 +36,11 @@ class random_access_reader {
protected:
virtual input_stream<char> open_at(uint64_t pos) = 0;
void set(input_stream<char> in) {
assert(!_in);
_in = std::make_unique<input_stream<char>>(std::move(in));
}
public:
future <temporary_buffer<char>> read_exactly(size_t n);