Everett
Loading...
Searching...
No Matches
active_engine.h
Go to the documentation of this file.
1
12#pragma once
13
17
18namespace everett {
19 namespace active_detail {
20 template <class P, profile_unit = P::unit> struct family;
21 template <class P> struct family<P, profile_unit::bit> {
23 };
24 template <class P> struct family<P, profile_unit::byte> {
26 };
27 template <class P> inline constexpr bool rebuilding =
28 std::same_as<typed_detail::default_sort_t<P>, unsorted<std::optional<std::string>>>;
29 template <class P> using engine = std::conditional_t<rebuilding<P>,
32 }
33
34 // The registry chooses the physical unit. Bit registries use sort-owned
35 // streamed records; byte registries retain their byte-aligned transport.
36 // Both run the redundant scheduler and charge service at admission. The
37 // single optional-string sort also rebuilds obsolete history as it shrinks.
38 template <class P = storage_policy<>> struct active_engine : active_detail::engine<P> {
40 using world_type = typename base_type::world_type;
41 using metadata_type = typename base_type::metadata_type;
42 using runtime_snapshot = typename base_type::runtime_family::snapshot_type;
43 using base_type::base_type;
44 active_engine() = default;
45 active_engine(active_engine const &) = delete;
47 active_engine(active_engine &&) noexcept(std::is_nothrow_move_constructible_v<base_type>) = default;
48 active_engine & operator=(active_engine &&) noexcept(std::is_nothrow_move_assignable_v<base_type>) = default;
50 return active_engine(base_type::from_snapshot(std::move(value)));
51 }
52 template <class Storage> static active_engine from_snapshot(world_type value, Storage storage)
53 requires requires { base_type::from_snapshot(std::move(value), std::move(storage)); } {
54 return active_engine(base_type::from_snapshot(std::move(value), std::move(storage)));
55 }
56 // A code-stable extension can add a sort in a reserved hole. Its generic
57 // executor reads the old replacement envelope but makes no cleanup-size
58 // promise. Validate the entire old generation before projecting its table
59 // metadata; pending structural merge jobs remain in the runtime frontier.
60 static world_type restore_checkpoint(runtime_snapshot runtime, std::span<std::byte const> bytes,
61 std::string_view schema) {
62 if (schema.empty()) throw std::invalid_argument("active checkpoint requires an expected schema");
63 if constexpr (active_detail::rebuilding<P>)
64 return world_type::restore(std::move(runtime), metadata_type::decode(bytes), schema);
65 else {
66 metadata_type metadata;
67 if (bytes.size() >= 56 && bytes.size() - 56 == schema.size()) {
68 auto previous = replacement_metadata<>::decode(bytes);
69 previous.validate(runtime.admissions());
70 metadata = static_cast<metadata_type const &>(previous);
71 } else if (bytes.size() >= 16 && bytes.size() - 16 == schema.size())
72 metadata = metadata_type::decode(bytes);
73 else throw std::invalid_argument("active checkpoint does not match the expected schema layout");
74 return world_type::restore(std::move(runtime), std::move(metadata), schema);
75 }
76 }
77 private:
78 explicit active_engine(base_type value) : base_type(std::move(value)) {}
79 };
80}
std::conditional_t< rebuilding< P >, replacement_rebuild_engine< P, wrapping_fingerprint_algebra, 256, typename family< P >::type >, typed_engine< P, wrapping_fingerprint_algebra, 256, typename family< P >::type > > engine
Definition active_engine.h:31
constexpr bool rebuilding
Definition active_engine.h:27
Definition active_engine.h:18
profile_unit
Definition registry.h:29
Rebuilds one replacement sort with a frozen scan and charged FIFO replay.
Owns catalog reservations and streamed native and index outputs for one runtime worker.
Persists sort-owned native files behind the redundant runtime's exact checkpoints.
Definition active_engine.h:20
Definition active_engine.h:38
typename base_type::metadata_type metadata_type
Definition active_engine.h:41
active_engine(active_engine &&) noexcept(std::is_nothrow_move_constructible_v< base_type >)=default
static active_engine from_snapshot(world_type value, Storage storage)
Definition active_engine.h:52
static active_engine from_snapshot(world_type value)
Definition active_engine.h:49
static world_type restore_checkpoint(runtime_snapshot runtime, std::span< std::byte const > bytes, std::string_view schema)
Definition active_engine.h:60
active_engine(active_engine const &)=delete
active_detail::engine< P > base_type
Definition active_engine.h:39
typename base_type::runtime_family::snapshot_type runtime_snapshot
Definition active_engine.h:42
typename base_type::world_type world_type
Definition active_engine.h:40
active_engine & operator=(active_engine const &)=delete
active_engine(base_type value)
Definition active_engine.h:78
Definition redundant_runtime.h:918
static replacement_metadata decode(std::span< std::byte const > data)
Definition replacement_rebuild.h:70
Definition replacement_rebuild.h:129
Definition sort_runtime.h:152
Definition typed_world.h:406
Definition registry.h:70