Everett
Loading...
Searching...
No Matches
runtime_checkpoint.h
Go to the documentation of this file.
1
12#pragma once
13
16
17namespace everett {
19 std::vector<cola_runtime_interval> intervals;
20 std::vector<std::byte> semantic;
21 };
22
23 namespace runtime_store_detail {
24 inline constexpr std::array<std::byte, 8> magic{
25 std::byte{'E'}, std::byte{'V'}, std::byte{'R'}, std::byte{'T'},
26 std::byte{'R'}, std::byte{'T'}, std::byte{0}, std::byte{1}};
27
28 template <class P> std::vector<std::byte> checkpoint(cola_runtime_snapshot<P> const & source,
29 std::span<std::byte const> semantic) {
30 std::vector<std::byte> out(magic.begin(), magic.end());
31 catalog_detail::number(out, source.runs().size());
32 for (auto const & run : source.runs()) {
33 catalog_detail::number(out, run.first); catalog_detail::number(out, run.last);
34 }
35 catalog_detail::binary(out, semantic);
36 return out;
37 }
38 inline runtime_checkpoint checkpoint(std::span<std::byte const> encoded) {
39 if (encoded.size() < magic.size() || !std::equal(magic.begin(), magic.end(), encoded.begin()))
40 throw std::invalid_argument("unsupported Everett runtime checkpoint");
41 catalog_detail::outcome_reader input{encoded.subspan(magic.size())};
42 auto count = input.number();
43 if (count > 65 || count > input.data.size() / 16)
44 throw std::invalid_argument("invalid Everett runtime interval count");
45 runtime_checkpoint result;
46 result.intervals.reserve(static_cast<std::size_t>(count));
47 for (std::uint64_t i = 0; i != count; ++i) {
48 auto first = input.number(), last = input.number();
49 result.intervals.push_back({first, last});
50 }
51 auto size = input.number();
52 if (size != input.data.size()) throw std::invalid_argument("invalid Everett runtime semantic extent");
53 result.semantic.assign(input.data.begin(), input.data.end());
54 return result;
55 }
56 }
57
58 template <class Snapshot> struct decoded_runtime_checkpoint {
59 Snapshot snapshot;
60 std::vector<std::byte> semantic;
61 };
62 template <class Family> struct runtime_storage_codec;
63 template <class P> struct runtime_storage_codec<binary_runtime_family<P>> {
65 template <class Pair, class Native> static void collect(snapshot_type const & source, Pair pair, Native) {
66 pair(source.query_root().head());
67 }
68 template <class Pair, class Native> static std::vector<std::byte> encode(snapshot_type const & source,
69 std::span<std::byte const> semantic, Pair, Native) { return runtime_store_detail::checkpoint(source, semantic); }
70 template <class Resolver> static decoded_runtime_checkpoint<snapshot_type> decode(
71 std::span<std::byte const> data, blob_identity const & head, Resolver & resolver) {
72 auto value = runtime_store_detail::checkpoint(data);
73 return {snapshot_type::restore(resolver.pair(head), value.intervals), std::move(value.semantic)};
74 }
75 };
76}
Executes charged encoded COLA carries behind immutable queryable snapshots.
void number(bytes &out, std::uint64_t value)
Definition sqlite_catalog.h:109
void binary(bytes &out, std::span< std::byte const > value)
Definition sqlite_catalog.h:127
std::vector< std::byte > checkpoint(cola_runtime_snapshot< P > const &source, std::span< std::byte const > semantic)
Definition runtime_checkpoint.h:28
constexpr std::array< std::byte, 8 > magic
Definition runtime_checkpoint.h:24
Definition active_engine.h:18
Stores retained roots, timeline generations and exact file graphs in optional SQLite metadata.
Definition cola_runtime.h:519
Definition sections.h:34
Definition sqlite_catalog.h:152
std::uint64_t number()
Definition sqlite_catalog.h:155
pair_type head() const noexcept
Definition cola_query.h:63
Definition cola_runtime.h:140
std::span< run_type const > runs() const &noexcept
Definition cola_runtime.h:151
query_type const & query_root() const &noexcept
Definition cola_runtime.h:153
Definition runtime_checkpoint.h:58
Snapshot snapshot
Definition runtime_checkpoint.h:59
std::vector< std::byte > semantic
Definition runtime_checkpoint.h:60
Definition runtime_checkpoint.h:18
std::vector< cola_runtime_interval > intervals
Definition runtime_checkpoint.h:19
std::vector< std::byte > semantic
Definition runtime_checkpoint.h:20
static std::vector< std::byte > encode(snapshot_type const &source, std::span< std::byte const > semantic, Pair, Native)
Definition runtime_checkpoint.h:68
static decoded_runtime_checkpoint< snapshot_type > decode(std::span< std::byte const > data, blob_identity const &head, Resolver &resolver)
Definition runtime_checkpoint.h:70
static void collect(snapshot_type const &source, Pair pair, Native)
Definition runtime_checkpoint.h:65
Definition runtime_checkpoint.h:62