21 std::future<std::vector<std::uint8_t>>
prefetch(
22 std::uint64_t partition_id,
23 std::filesystem::path path) {
24 return std::async(std::launch::async,
25 [
this, partition_id, path = std::move(path)]()
mutable {
26 if (
auto* cached = cache_.
get(
static_cast<PartitionId>(partition_id)))
return *cached;
27 advise_prefetch(path);
29 const auto bytes = payload.size();
30 cache_.
put(
static_cast<PartitionId>(partition_id), payload, bytes);
35 std::vector<std::uint8_t>
load(std::uint64_t partition_id,
36 const std::filesystem::path& path) {
37 if (
auto* cached = cache_.
get(
static_cast<PartitionId>(partition_id)))
return *cached;
38 advise_prefetch(path);
40 const auto bytes = payload.size();
41 cache_.
put(
static_cast<PartitionId>(partition_id), payload, bytes);
58 void advise_prefetch(
const std::filesystem::path& path) {
61 else last_prefetch_ = {};
64 PartitionCache<> cache_;
65 FilePrefetchResult last_prefetch_{};
66 IoUringPrefetchResult last_io_uring_{};
const PartitionCacheStats & stats() const noexcept
IoUringPrefetchResult last_io_uring_result() const noexcept
FilePrefetchResult last_prefetch_result() const noexcept
AsyncPartitionLoader(std::size_t resident_bytes)
std::size_t resident_bytes() const noexcept
static constexpr bool native_prefetch_supported() noexcept
static constexpr bool io_uring_prefetch_compiled() noexcept
std::vector< std::uint8_t > load(std::uint64_t partition_id, const std::filesystem::path &path)
std::future< std::vector< std::uint8_t > > prefetch(std::uint64_t partition_id, std::filesystem::path path)
static FilePrefetchResult advise_will_need(const std::filesystem::path &path) noexcept
static constexpr bool supported() noexcept
static constexpr bool compiled() noexcept
static IoUringPrefetchResult prefetch(const std::filesystem::path &path, std::size_t max_bytes=1U<< 20U) noexcept
const PartitionCacheStats & stats() const noexcept
std::size_t resident_bytes() const noexcept
const Payload * get(PartitionId id)
void put(PartitionId id, Payload payload, std::size_t bytes)
static std::vector< std::uint8_t > read_mmap_or_fallback(const std::filesystem::path &path, std::uint64_t expected_partition_id, bool *used_mmap=nullptr)
std::uint32_t PartitionId