Everett
Loading...
Searching...
No Matches
file_index_builder.h
Go to the documentation of this file.
1
13#pragma once
14
17
18#include <cstdint>
19#include <filesystem>
20#include <memory>
21#include <optional>
22#include <stdexcept>
23#include <utility>
24
25namespace everett {
26 namespace profile_detail {
27 template <class P, class Ops> struct file_index_output {
28 using policy_type = P;
29 file_index_output(std::filesystem::path root, object_id id, object_attempt_id attempt,
30 object_id native_id, std::optional<blob_identity> target_id)
31 : native_id_(checked(std::move(native_id))), target_id_(checked(std::move(target_id))),
32 output_(std::move(root), std::move(id), std::move(attempt)) {}
33 file_index_output(std::filesystem::path root, object_id id, object_attempt_id attempt,
34 object_id native_id, std::optional<blob_identity> target_id, Ops & ops)
35 : native_id_(checked(std::move(native_id))), target_id_(checked(std::move(target_id))),
36 output_(std::move(root), std::move(id), std::move(attempt), 0, ops) {}
37 std::uint64_t size() const noexcept { return output_.size(); }
38 bool finished() const noexcept { return output_.finished(); }
39 bool failed() const noexcept { return output_.failed(); }
40 object_write_paths const & paths() const & noexcept { return output_.paths(); }
41 object_write_paths const & paths() const && = delete;
42 void append_known(bit_view key, std::uint64_t common_bits) {
43 auto retained = common_bits >> P::unit_shift;
44 auto first = retained << P::unit_shift;
45 output_.append(retained, key.subview(first, key.size() - first), {});
46 }
49 metadata.false_borrows, metadata.cut_lcps, metadata.virtual_count};
50 return output_.finish(sections);
51 }
52 private:
54 if (id.hex().size() != 32)
55 error_detail::raise<std::invalid_argument>("file index requires valid dependency identities");
56 return id;
57 }
58 static std::optional<blob_identity> checked(std::optional<blob_identity> target) {
59 if (target && (target->native.hex().size() != 32 || target->index.hex().size() != 32))
60 error_detail::raise<std::invalid_argument>("file index requires valid target identities");
61 return target;
62 }
64 std::optional<blob_identity> target_id_;
66 };
67 template <class P, class Ops> struct file_index_output_ref {
68 using policy_type = P;
70 std::uint64_t size() const noexcept { return output->size(); }
71 bool finished() const noexcept { return output->finished(); }
72 bool failed() const noexcept { return output->failed(); }
73 void append_known(bit_view key, std::uint64_t common_bits) { output->append_known(key, common_bits); }
74 object_seal_receipt finish(index_metadata<P> const & metadata) { return output->finish(metadata); }
75 };
76 }
77
78 // The ordinary index builder with a bounded borrowed-FC file sink. Native
79 // storage is pinned, not copied. The caller supplies trusted samples and
80 // exact native/target identities, retaining those dependencies through sealing
81 // and publication. Counts do not authenticate sample contents or identities.
82 // Each step budgets occurrences; key bytes and final navigation construction
83 // remain additional work. Only finish seals a complete IX02 object: there is
84 // no durable partial-output checkpoint or resumed-job API. An external Ops
85 // object supplied by reference must outlive the builder.
86 template <class P, class Native = profile_array<P>, class Ops = posix_object_ops>
88 using policy_type = P;
89 using source_pointer = std::shared_ptr<Native const>;
93 file_index_builder(std::filesystem::path root, object_id id, object_attempt_id attempt,
94 source_pointer native, object_id native_id, std::optional<blob_identity> target_id = std::nullopt)
95 : output_(std::move(root), std::move(id), std::move(attempt), std::move(native_id), std::move(target_id)),
96 builder_({&output_}, std::move(native)) {}
97 file_index_builder(std::filesystem::path root, object_id id, object_attempt_id attempt,
98 source_pointer native, object_id native_id, std::optional<blob_identity> target_id, Ops & ops)
99 : output_(std::move(root), std::move(id), std::move(attempt), std::move(native_id), std::move(target_id), ops),
100 builder_({&output_}, std::move(native)) {}
105 bool needs_input() const noexcept { return builder_.needs_input(); }
106 bool has_output() const noexcept { return builder_.has_output(); }
107 bool done() const noexcept { return builder_.done(); }
108 bool failed() const noexcept { return builder_.failed(); }
109 bool finished() const noexcept { return builder_.finished(); }
110 std::uint64_t size() const noexcept { return builder_.size(); }
111 std::uint64_t received_samples() const noexcept { return builder_.received_samples(); }
112 void push(bit_view key, std::uint64_t target_ordinal) { builder_.push(key, target_ordinal); }
113 void push(coded_sample_type const & sample) { builder_.push(sample); }
115 std::uint64_t step(std::uint64_t budget_entries) { return builder_.step(budget_entries); }
118 object_seal_receipt finish(std::uint64_t target_count) { return builder_.finish_index(target_count); }
119 object_write_paths const & paths() const & noexcept { return output_.paths(); }
120 object_write_paths const & paths() const && = delete;
121 private:
122 profile_detail::file_index_output<P, Ops> output_;
124 };
125}
Declares Everett's incremental fractional-index builder.
Definition active_engine.h:18
Streams native and borrowed profile sections with bounded payload buffering.
Definition profile.h:56
Definition file_index_builder.h:87
object_write_paths const & paths() const &&=delete
std::uint64_t step(std::uint64_t budget_entries)
Definition file_index_builder.h:115
void push(coded_sample_type const &sample)
Definition file_index_builder.h:113
bool done() const noexcept
Definition file_index_builder.h:107
object_write_paths const & paths() const &noexcept
Definition file_index_builder.h:119
std::uint64_t received_samples() const noexcept
Definition file_index_builder.h:111
bool finished() const noexcept
Definition file_index_builder.h:109
std::shared_ptr< Native const > source_pointer
Definition file_index_builder.h:89
builder_type builder_
Definition file_index_builder.h:123
file_index_builder & operator=(file_index_builder &&)=delete
bool needs_input() const noexcept
Definition file_index_builder.h:105
std::uint64_t size() const noexcept
Definition file_index_builder.h:110
void close_input()
Definition file_index_builder.h:114
profile_detail::file_index_output< P, Ops > output_
Definition file_index_builder.h:122
void push(bit_view key, std::uint64_t target_ordinal)
Definition file_index_builder.h:112
file_index_builder & operator=(file_index_builder const &)=delete
bool has_output() const noexcept
Definition file_index_builder.h:106
coded_sample_type take_coded_output()
Definition file_index_builder.h:117
file_index_builder(std::filesystem::path root, object_id id, object_attempt_id attempt, source_pointer native, object_id native_id, std::optional< blob_identity > target_id=std::nullopt)
Definition file_index_builder.h:93
object_seal_receipt finish(std::uint64_t target_count)
Definition file_index_builder.h:118
file_index_builder(std::filesystem::path root, object_id id, object_attempt_id attempt, source_pointer native, object_id native_id, std::optional< blob_identity > target_id, Ops &ops)
Definition file_index_builder.h:97
sample_type take_output()
Definition file_index_builder.h:116
bool failed() const noexcept
Definition file_index_builder.h:108
file_index_builder(file_index_builder const &)=delete
P policy_type
Definition file_index_builder.h:88
file_index_builder(file_index_builder &&)=delete
Definition index_builder.h:47
void push(bit_view key, std::uint64_t target_ordinal)
Definition index_builder.h:91
std::uint64_t size() const noexcept
Definition index_builder.h:88
bool needs_input() const noexcept
Definition index_builder.h:79
std::uint64_t step(std::uint64_t budget_entries)
Definition index_builder.h:115
auto finish_index(std::uint64_t target_count) -> decltype(std::declval< Output & >().finish(std::declval< profile_detail::index_metadata< P > >()))
Definition index_builder.h:212
sample_type take_output()
Definition index_builder.h:167
bool finished() const noexcept
Definition index_builder.h:86
bool failed() const noexcept
Definition index_builder.h:87
bool done() const noexcept
Definition index_builder.h:83
void close_input()
Definition index_builder.h:109
bool has_output() const noexcept
Definition index_builder.h:82
coded_sample_type take_coded_output()
Definition index_builder.h:178
std::uint64_t received_samples() const noexcept
Definition index_builder.h:89
Definition object_writer.h:39
Definition object_path.h:38
Definition object_writer.h:88
Definition object_writer.h:53
Definition sampling.h:46
Definition file_index_builder.h:67
bool finished() const noexcept
Definition file_index_builder.h:71
P policy_type
Definition file_index_builder.h:68
std::uint64_t size() const noexcept
Definition file_index_builder.h:70
bool failed() const noexcept
Definition file_index_builder.h:72
object_seal_receipt finish(index_metadata< P > const &metadata)
Definition file_index_builder.h:74
void append_known(bit_view key, std::uint64_t common_bits)
Definition file_index_builder.h:73
file_index_output< P, Ops > * output
Definition file_index_builder.h:69
Definition file_index_builder.h:27
P policy_type
Definition file_index_builder.h:28
object_write_paths const & paths() const &noexcept
Definition file_index_builder.h:40
object_write_paths const & paths() const &&=delete
file_index_output(std::filesystem::path root, object_id id, object_attempt_id attempt, object_id native_id, std::optional< blob_identity > target_id, Ops &ops)
Definition file_index_builder.h:33
profile_file_output< P, stream_role::borrowed, Ops > output_
Definition file_index_builder.h:65
static std::optional< blob_identity > checked(std::optional< blob_identity > target)
Definition file_index_builder.h:58
object_id native_id_
Definition file_index_builder.h:63
void append_known(bit_view key, std::uint64_t common_bits)
Definition file_index_builder.h:42
file_index_output(std::filesystem::path root, object_id id, object_attempt_id attempt, object_id native_id, std::optional< blob_identity > target_id)
Definition file_index_builder.h:29
std::optional< blob_identity > target_id_
Definition file_index_builder.h:64
object_seal_receipt finish(index_metadata< P > const &metadata)
Definition file_index_builder.h:47
bool failed() const noexcept
Definition file_index_builder.h:39
std::uint64_t size() const noexcept
Definition file_index_builder.h:37
static object_id checked(object_id id)
Definition file_index_builder.h:53
bool finished() const noexcept
Definition file_index_builder.h:38
Definition profile_file_output.h:31
Definition profile_index.h:28
std::vector< std::uint64_t > cut_lcps
Definition profile_index.h:31
rank_groups< P::group_size > interleave
Definition profile_index.h:29
std::vector< std::byte > false_borrows
Definition profile_index.h:30
std::uint64_t virtual_count
Definition profile_index.h:32
Definition profile_file_output.h:44
bool finished() const noexcept
Definition profile_file_output.h:71
object_write_paths const & paths() const &noexcept
Definition profile_file_output.h:73
std::uint64_t size() const noexcept
Definition profile_file_output.h:69
object_seal_receipt finish()
Definition profile_file_output.h:131
bool failed() const noexcept
Definition profile_file_output.h:70
void append(std::uint64_t retained, bit_view literal, bit_view value)
Definition profile_file_output.h:80
Definition sampling.h:29