Files
Library/include/Void/Storage/AsyncAdapter.hpp
T

73 lines
2.1 KiB
C++

#pragma once
#include <Void/Async/Detail/Types.hpp>
#include <Void/Async/Executor.hpp>
#include <Void/Async/Operation.hpp>
#include <Void/Async/Task.hpp>
#include <Void/Storage/Engine.hpp>
#include <Void/Storage/Types.hpp>
#include <Void/Time/Clock.hpp>
#include <cstddef>
#include <cstdint>
#include <expected>
#include <memory>
namespace Void::Storage
{
struct AsyncAdapterOptions {
std::size_t max_pending_batches{64};
std::size_t max_pending_bytes{64ULL * 1024ULL * 1024ULL};
const Void::Time::MonotonicClock* clock{nullptr};
};
struct AsyncAdapterStats {
std::size_t queued_writes{0};
std::size_t pending_bytes{0};
std::uint64_t completed_writes{0};
std::uint64_t rejected_writes{0};
std::uint64_t unknown_outcomes{0};
std::uint64_t cancelled_before_append{0};
};
/// Bounded blocking async adapter over Storage::Engine following C-03
/// domain-result classification (never steals a persisted commit outcome with
/// a synthetic timeout/cancel once WAL append begins; single delivery only).
class AsyncStorageAdapter
{
public:
explicit AsyncStorageAdapter(
Engine& engine,
AsyncAdapterOptions options = {},
Void::Async::Executor* completion_executor = nullptr);
~AsyncStorageAdapter();
AsyncStorageAdapter(const AsyncStorageAdapter&) = delete;
AsyncStorageAdapter& operator=(const AsyncStorageAdapter&) = delete;
AsyncStorageAdapter(AsyncStorageAdapter&&) = delete;
AsyncStorageAdapter& operator=(AsyncStorageAdapter&&) = delete;
[[nodiscard]] Void::Coro::Task<std::expected<CommitReceipt, WriteFailure>>
write_async(
Batch batch,
Durability durability,
Void::Async::OperationOptions op = {});
[[nodiscard]] Void::Coro::Task<Result<OwnedValue>>
get_async(
ByteView key,
Void::Async::OperationOptions op = {});
[[nodiscard]] Void::Coro::Task<Result<void>>
checkpoint_async(Void::Async::OperationOptions op = {});
[[nodiscard]] AsyncAdapterStats stats() const noexcept;
void close_and_join();
private:
struct Impl;
std::shared_ptr<Impl> m_impl{};
};
} // namespace Void::Storage