assert() is traditionally disabled in release builds, but not in
scylladb. This hasn't caused problems so far, but the latest abseil
release includes a commit [1] that causes a 1000 insn/op regression when
NDEBUG is not defined.
Clearly, we must move towards a build system where NDEBUG is defined in
release builds. But we can't just define it blindly without vetting
all the assert() calls, as some were written with the expectation that
they are enabled in release mode.
To solve the conundrum, change all assert() calls to a new SCYLLA_ASSERT()
macro in utils/assert.hh. This macro is always defined and is not conditional
on NDEBUG, so we can later (after vetting Seastar) enable NDEBUG in release
mode.
[1] 66ef711d68
Closes scylladb/scylladb#20006
59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
/*
|
|
* Copyright (C) 2018-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "utils/assert.hh"
|
|
#include <memory>
|
|
#include <seastar/core/file.hh>
|
|
#include <seastar/core/fstream.hh>
|
|
#include <seastar/core/future.hh>
|
|
#include <seastar/core/gate.hh>
|
|
#include <seastar/core/iostream.hh>
|
|
#include <seastar/core/temporary_buffer.hh>
|
|
#include "seastarx.hh"
|
|
|
|
namespace sstables {
|
|
|
|
class random_access_reader {
|
|
std::unique_ptr <input_stream<char>> _in;
|
|
protected:
|
|
virtual input_stream<char> open_at(uint64_t pos) = 0;
|
|
|
|
void set(input_stream<char> in) {
|
|
SCYLLA_ASSERT(!_in);
|
|
_in = std::make_unique<input_stream<char>>(std::move(in));
|
|
}
|
|
|
|
public:
|
|
future <temporary_buffer<char>> read_exactly(size_t n) noexcept;
|
|
|
|
future<> seek(uint64_t pos) noexcept;
|
|
|
|
bool eof() const noexcept { return _in->eof(); }
|
|
|
|
virtual future<> close() noexcept;
|
|
|
|
virtual ~random_access_reader() {}
|
|
};
|
|
|
|
class file_random_access_reader : public random_access_reader {
|
|
file _file;
|
|
uint64_t _file_size;
|
|
size_t _buffer_size;
|
|
unsigned _read_ahead;
|
|
public:
|
|
virtual input_stream<char> open_at(uint64_t pos) override;
|
|
|
|
explicit file_random_access_reader(file f, uint64_t file_size, size_t buffer_size = 8192, unsigned read_ahead = 4);
|
|
|
|
virtual future<> close() noexcept override;
|
|
};
|
|
|
|
}
|