mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
sstables: random_access_reader: make methods noexcept
handle all exceptions in read_exactly, seek, and close and specify them as noexcept. Also, specify eof() as noexcept as it trivially is. Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
@@ -29,8 +29,12 @@ namespace sstables {
|
||||
|
||||
extern logging::logger sstlog;
|
||||
|
||||
future <temporary_buffer<char>> random_access_reader::read_exactly(size_t n) {
|
||||
future <temporary_buffer<char>> random_access_reader::read_exactly(size_t n) noexcept {
|
||||
try {
|
||||
return _in->read_exactly(n);
|
||||
} catch (...) {
|
||||
return current_exception_as_future<temporary_buffer<char>>();
|
||||
}
|
||||
}
|
||||
|
||||
static future<> close_if_needed(std::unique_ptr<input_stream<char>> in) {
|
||||
@@ -40,17 +44,18 @@ static future<> close_if_needed(std::unique_ptr<input_stream<char>> in) {
|
||||
return in->close().finally([in = std::move(in)] {});
|
||||
}
|
||||
|
||||
future<> random_access_reader::seek(uint64_t pos) {
|
||||
// FIXME: temporary bad indentation.
|
||||
// A following patch will enclose the body of this function
|
||||
// in a try/catch block.
|
||||
future<> random_access_reader::seek(uint64_t pos) noexcept {
|
||||
try {
|
||||
auto tmp = std::make_unique<input_stream<char>>(open_at(pos));
|
||||
std::swap(tmp, _in);
|
||||
return close_if_needed(std::move(tmp));
|
||||
} catch (...) {
|
||||
return current_exception_as_future();
|
||||
}
|
||||
}
|
||||
|
||||
future<> random_access_reader::close() {
|
||||
return close_if_needed(std::move(_in));
|
||||
future<> random_access_reader::close() noexcept {
|
||||
return futurize_invoke(close_if_needed, std::move(_in));
|
||||
}
|
||||
|
||||
file_random_access_reader::file_random_access_reader(file f, uint64_t file_size, size_t buffer_size, unsigned read_ahead)
|
||||
@@ -67,7 +72,7 @@ input_stream<char> file_random_access_reader::open_at(uint64_t pos) {
|
||||
return make_file_input_stream(_file, pos, len, std::move(options));
|
||||
}
|
||||
|
||||
future<> file_random_access_reader::close() {
|
||||
future<> file_random_access_reader::close() noexcept {
|
||||
return random_access_reader::close().finally([this] {
|
||||
return _file.close().handle_exception([save = _file](auto ep) {
|
||||
sstlog.warn("sstable close failed: {}", ep);
|
||||
|
||||
@@ -41,13 +41,13 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
future <temporary_buffer<char>> read_exactly(size_t n);
|
||||
future <temporary_buffer<char>> read_exactly(size_t n) noexcept;
|
||||
|
||||
future<> seek(uint64_t pos);
|
||||
future<> seek(uint64_t pos) noexcept;
|
||||
|
||||
bool eof() const { return _in->eof(); }
|
||||
bool eof() const noexcept { return _in->eof(); }
|
||||
|
||||
virtual future<> close();
|
||||
virtual future<> close() noexcept;
|
||||
|
||||
virtual ~random_access_reader() {}
|
||||
};
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
|
||||
explicit file_random_access_reader(file f, uint64_t file_size, size_t buffer_size = 8192, unsigned read_ahead = 4);
|
||||
|
||||
virtual future<> close() override;
|
||||
virtual future<> close() noexcept override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user