31 template <
class P,
class Selector = registry_selector<
typename P::registry_type>,
class Ids = random_
object_
ids,
32 class CatalogOps = sqlite_catalog_ops,
class FileOps = posix_
object_ops>
33 struct sort_runtime_context : std::enable_shared_from_this<sort_runtime_context<P, Selector, Ids, CatalogOps, FileOps>> {
38 std::shared_ptr<sort_runtime_context>
owner_;
39 explicit context_pin(std::shared_ptr<sort_runtime_context> owner) :
owner_(std::move(owner)) {}
55 std::optional<catalog_native_merge>
recipe_;
57 std::optional<catalog_native_merge> recipe)
59 std::move(older), std::move(newer), std::move(compose)),
recipe_(std::move(recipe)) {}
61 static std::shared_ptr<sort_runtime_context>
open(std::filesystem::path
const &
root, Ids ids = {},
62 catalog_options options = {}, CatalogOps catalog_ops = {}, FileOps file_ops = {},
63 runtime_output_options outputs = {}, std::string
schema = {}) {
65 if (catalog.schema_version() != 4)
throw std::invalid_argument(
"streamed runtime requires a named catalog");
66 return std::shared_ptr<sort_runtime_context>(
new sort_runtime_context(std::move(catalog), std::move(ids), std::move(file_ops), outputs, std::move(schema)));
78 if (!
schema_.empty() &&
schema_ != schema)
throw std::invalid_argument(
"runtime merge schema differs from typed snapshot");
86 std::filesystem::path
const &
root() const && = delete;
90 auto owner = this->shared_from_this();
97 sort_runtime_detail::write_sorted_native<P, Selector>(writer, records);
98 auto completed = writer.finish();
100 auto receipt = std::get<1>(std::move(completed));
104 }
catch (...) {
failed_ =
true;
throw; }
109 auto recipe = merge_recipe<Compose>(older, newer);
110 return std::unique_ptr<merge_type<Compose>>(
new merge_type<Compose>(this->shared_from_this(),
111 std::move(older), std::move(newer), std::move(compose), std::move(recipe)));
112 }
catch (...) {
failed_ =
true;
throw; }
117 auto recipe = merge_recipe<Compose>(older, newer);
118 if (!recipe)
return {};
120 if (!receipt)
return {};
123 }
catch (...) {
failed_ =
true;
throw; }
128 if (merge.owner_.get() !=
this)
throw std::invalid_argument(
"merge belongs to another runtime context");
129 auto completed = merge.finish();
131 auto receipt = std::get<1>(std::move(completed));
138 }
catch (...) {
failed_ =
true;
throw; }
142 using mapped_type =
typename family::storage_type::mapped_pair_type;
144 std::shared_ptr<sort_runtime_context>
owner_;
148 std::shared_ptr<pair_binding<mapped_type>
const>
main_;
151 auto & owner = *
owner_; owner.require_active();
160 auto pin = owner.ids_().hex();
auto operation = owner.ids_().hex();
161 owner.catalog_.reserve(operation, attempt, pin, std::span<blob_identity const>(inputs.data(),
main_ ? 1 : 0), reservation);
163 main_ ? std::optional<blob_identity>(
main_->identity) : std::nullopt,
165 return std::make_unique<destination_type>(owner.root(), std::move(output), std::move(attempt),
166 std::move(dependencies), owner.file_ops_, owner.spool_ops_);
167 }
catch (...) { owner.failed_ =
true;
throw; }
177 }
catch (...) {
failed_ =
true;
throw; }
183 using mapped_type =
typename family::storage_type::mapped_pair_type;
184 if (index.
factory().owner_.get() !=
this)
throw std::invalid_argument(
"index belongs to another runtime context");
185 auto output = index.
finish();
186 if (
auto built = std::get_if<std::shared_ptr<typename Node::built_type const>>(&output))
187 return Node::from_built(std::move(*built));
188 auto receipt = std::get<object_seal_receipt>(std::move(output));
192 auto const & factory = index.
factory();
193 auto const & n = factory.native_;
auto const & m = factory.main_;
auto const & s = factory.secondary_;
196 auto mapped = mapped_type::bind(identity, n->mapped, std::move(
mapped_index), m ? m->mapped :
nullptr,
197 s ? s->mapped :
nullptr, s ? std::optional<object_id>(s->receipt.object) : std::nullopt);
198 auto binding = std::make_shared<pair_binding<mapped_type>
const>(
pair_seal{
identity_, identity, std::move(receipt)}, std::move(mapped));
199 auto result = Node::from_sealed_parts(std::move(binding),
root(), std::move(
native), std::move(
main), std::move(
secondary));
201 }
catch (...) {
failed_ =
true;
throw; }
218 template <
class Compose> std::optional<catalog_native_merge>
merge_recipe(
220 if (!older || !newer)
throw std::invalid_argument(
"null native merge input");
224 using composer = std::remove_cvref_t<decltype(native_merge_detail::composer(std::declval<Compose &>()))>;
228 if constexpr ((std::is_same_v<composer, replace_native_value> || std::is_same_v<composer, conservative>) &&
230 std::is_same_v<typename P::registry_type, string_registry> &&
232 if (
schema_.empty())
return {};
246 auto owner =
ids_().hex();
auto operation =
ids_().hex();
251 return std::make_unique<object_stream<P, FileOps>>(
root(), std::move(output), std::move(attempt),
253 }
catch (...) {
failed_ =
true;
throw; }
258 template <
class P,
class Selector = registry_selector<
typename P::registry_type>,
class Ids = random_
object_
ids,
259 class CatalogOps = sqlite_catalog_ops,
class FileOps = posix_
object_ops>
268 if (!
context_)
throw std::invalid_argument(
"null sort runtime context");
271 catalog_options options = {}, CatalogOps catalog_ops = {}, FileOps file_ops = {},
272 runtime_output_options outputs = {}) {
303 template <
class P =
string_policy,
class Selector = registry_selector<
typename P::registry_type>,
class Ids = random_
object_
ids,
304 class CatalogOps = sqlite_catalog_ops,
class FileOps = posix_
object_ops>
Keeps small encoded indexes in memory and spills the same IX03 stream lazily.
constexpr char schema[]
Definition sqlite_catalog.h:282
Definition active_engine.h:18
@ conservative_tombstones
Shares an allowance for encoded outputs retained in memory.
Seals new runtime owners once and stops at acknowledged shared dependencies.
Seals runtime frontiers and restores named sessions through immutable mappings.
Retains small native merge outputs and spills larger encoded streams once.
Merges sort-owned native records directly into a streamed immutable file.
Runs typed updates through sort-owned native files and the shared redundant scheduler.
Definition sqlite_catalog.h:50
Definition sqlite_catalog.h:39
Definition cola_adaptive_index.h:149
native_pointer native_owner() const noexcept
Definition cola_adaptive_index.h:165
main_pointer main_target() const noexcept
Definition cola_adaptive_index.h:166
auto finish()
Definition cola_adaptive_index.h:169
Factory const & factory() const noexcept
Definition cola_adaptive_index.h:170
native_pointer secondary_target() const noexcept
Definition cola_adaptive_index.h:167
Definition cola_adaptive_index.h:20
Definition cola_file_index.h:33
Definition sections.h:486
Definition object_writer.h:39
Definition object_path.h:38
Definition output_budget.h:26
std::size_t limit() const noexcept
Definition output_budget.h:69
std::size_t used() const noexcept
Definition output_budget.h:70
Definition runtime_seal.h:24
Definition cola_file_index.h:20
Definition sort_profile.h:20
Definition sort_runtime_context.h:23
std::size_t object_bytes
Definition sort_runtime_context.h:25
std::size_t retained_bytes
Definition sort_runtime_context.h:24
Definition runtime_graph_sealer.h:22
std::shared_ptr< pair_binding_type const > ensure_pair(pair_type const &pair)
Definition runtime_graph_sealer.h:147
std::shared_ptr< native_binding_type const > ensure_native(native_pointer const &native)
Definition runtime_graph_sealer.h:136
Definition sort_runtime_context.h:260
sort_file_runtime_storage(std::shared_ptr< context_type > context)
Definition sort_runtime_context.h:267
auto make_merge(native_pointer older, native_pointer newer, Compose compose)
Definition sort_runtime_context.h:289
typename context_type::template index_type< Node > index_type
Definition sort_runtime_context.h:293
std::shared_ptr< context_type > context_
Definition sort_runtime_context.h:299
void require_context() const
Definition sort_runtime_context.h:300
void check_schema(std::string_view schema) const
Definition sort_runtime_context.h:279
static sort_file_runtime_storage open(std::filesystem::path const &root, Ids ids={}, catalog_options options={}, CatalogOps catalog_ops={}, FileOps file_ops={}, runtime_output_options outputs={})
Definition sort_runtime_context.h:270
typename context_type::native_type native_type
Definition sort_runtime_context.h:263
native_pointer finish_merge(Merge &merge)
Definition sort_runtime_context.h:292
typename context_type::native_pointer native_pointer
Definition sort_runtime_context.h:264
std::shared_ptr< context_type > context() const noexcept
Definition sort_runtime_context.h:283
static sort_file_runtime_storage open_for_schema(std::filesystem::path const &root, std::string_view schema, catalog_options options={})
Definition sort_runtime_context.h:275
auto make_index(native_pointer native, typename Node::pair_type main={}, native_pointer secondary={})
Definition sort_runtime_context.h:294
native_pointer sorted_native(std::span< profile_record const > records)
Definition sort_runtime_context.h:285
sort_file_runtime_storage()=default
typename context_type::template merge_type< Compose > merge_type
Definition sort_runtime_context.h:265
auto finish_index(index_type< Node > &index)
Definition sort_runtime_context.h:297
void poison() noexcept
Definition sort_runtime_context.h:288
native_pointer reuse_merge(native_pointer const &older, native_pointer const &newer)
Definition sort_runtime_context.h:280
native_pointer empty() const
Definition sort_runtime_context.h:284
Definition sort_profile_adaptive.h:137
Definition sort_profile_adaptive.h:83
Definition sort_runtime_context.h:37
context_pin(std::shared_ptr< sort_runtime_context > owner)
Definition sort_runtime_context.h:39
std::shared_ptr< sort_runtime_context > owner_
Definition sort_runtime_context.h:38
Definition sort_runtime_context.h:140
native_pointer native
Definition sort_runtime_context.h:145
std::shared_ptr< native_binding< typename mapped_type::native_type > const > native_
Definition sort_runtime_context.h:147
native_pointer secondary
Definition sort_runtime_context.h:145
std::shared_ptr< sort_runtime_context > owner_
Definition sort_runtime_context.h:144
std::shared_ptr< pair_binding< mapped_type > const > main_
Definition sort_runtime_context.h:148
std::unique_ptr< destination_type > operator()()
Definition sort_runtime_context.h:150
typename family::storage_type::mapped_pair_type mapped_type
Definition sort_runtime_context.h:142
Node::pair_type main
Definition sort_runtime_context.h:146
std::shared_ptr< native_binding< typename mapped_type::native_type > const > secondary_
Definition sort_runtime_context.h:147
void poison() noexcept
Definition sort_runtime_context.h:149
Definition sort_runtime_context.h:51
merge_type(std::shared_ptr< sort_runtime_context > owner, native_pointer older, native_pointer newer, Compose compose, std::optional< catalog_native_merge > recipe)
Definition sort_runtime_context.h:56
std::optional< catalog_native_merge > recipe_
Definition sort_runtime_context.h:55
Definition sort_runtime_context.h:41
auto operator()()
Definition sort_runtime_context.h:43
sort_runtime_context * owner
Definition sort_runtime_context.h:42
void poison() noexcept
Definition sort_runtime_context.h:44
Definition sort_runtime_context.h:33
native_pointer finish_merge(Merge &merge)
Definition sort_runtime_context.h:125
object_id identity_
Definition sort_runtime_context.h:211
bool failed_
Definition sort_runtime_context.h:214
static std::shared_ptr< sort_runtime_context > open(std::filesystem::path const &root, Ids ids={}, catalog_options options={}, CatalogOps catalog_ops={}, FileOps file_ops={}, runtime_output_options outputs={}, std::string schema={})
Definition sort_runtime_context.h:61
catalog_type catalog_
Definition sort_runtime_context.h:204
auto make_index(native_pointer native, typename Node::pair_type main, native_pointer secondary)
Definition sort_runtime_context.h:171
std::filesystem::path const & root() const &noexcept
Definition sort_runtime_context.h:85
sort_runtime_context & operator=(sort_runtime_context const &)=delete
std::size_t output_limit() const noexcept
Definition sort_runtime_context.h:81
Ids ids_
Definition sort_runtime_context.h:205
native_pointer sorted_native(std::span< profile_record const > records)
Definition sort_runtime_context.h:88
void check_schema(std::string_view schema) const
Definition sort_runtime_context.h:77
std::uint64_t reused_outputs_
Definition sort_runtime_context.h:212
object_id const & catalog_identity() const &noexcept
Definition sort_runtime_context.h:83
std::uint64_t reused_outputs() const noexcept
Definition sort_runtime_context.h:76
std::uint64_t sealed_indexes_
Definition sort_runtime_context.h:212
std::optional< catalog_native_merge > merge_recipe(native_pointer const &older, native_pointer const &newer) const
Definition sort_runtime_context.h:218
output_budget budget_
Definition sort_runtime_context.h:209
sort_runtime_context(catalog_type catalog, Ids ids, FileOps file_ops, runtime_output_options outputs, std::string schema)
Definition sort_runtime_context.h:215
auto make_merge(native_pointer older, native_pointer newer, Compose compose)
Definition sort_runtime_context.h:106
sort_runtime_context(sort_runtime_context &&)=delete
posix_index_spool_ops spool_ops_
Definition sort_runtime_context.h:207
std::uint64_t sealed_indexes() const noexcept
Definition sort_runtime_context.h:75
std::filesystem::path const & root() const &&=delete
void poison() noexcept
Definition sort_runtime_context.h:73
sort_runtime_native< P, Selector > native_type
Definition sort_runtime_context.h:47
std::unique_ptr< object_stream< P, FileOps > > start_native_stream()
Definition sort_runtime_context.h:242
runtime_output_options outputs_
Definition sort_runtime_context.h:208
native_pointer empty() const noexcept
Definition sort_runtime_context.h:82
native_pointer empty_
Definition sort_runtime_context.h:210
FileOps file_ops_
Definition sort_runtime_context.h:206
Node::pair_type finish_index(index_type< Node > &index)
Definition sort_runtime_context.h:179
bool failed() const noexcept
Definition sort_runtime_context.h:72
native_pointer reuse_merge(native_pointer const &older, native_pointer const &newer)
Definition sort_runtime_context.h:114
sort_runtime_context & operator=(sort_runtime_context &&)=delete
std::shared_ptr< native_type const > native_pointer
Definition sort_runtime_context.h:48
object_id const & catalog_identity() const &&=delete
sort_runtime_context(sort_runtime_context const &)=delete
std::string schema_
Definition sort_runtime_context.h:213
std::size_t retained_output_bytes() const noexcept
Definition sort_runtime_context.h:80
void require_active() const
Definition sort_runtime_context.h:255
std::uint64_t sealed_outputs() const noexcept
Definition sort_runtime_context.h:74
std::uint64_t sealed_outputs_
Definition sort_runtime_context.h:212
Definition sort_runtime.h:152
Definition sort_runtime.h:42
static pointer from_sealed(std::filesystem::path const &root, object_id catalog, object_seal_receipt receipt)
Definition sort_runtime.h:70
static pointer from_owned(array_type value)
Definition sort_runtime.h:48
Definition sort_runtime.h:121
static auto empty()
Definition sort_runtime.h:139
Definition sqlite_catalog.h:351
void record_native_merge(std::string_view op, catalog_native_merge const &key, object_seal_receipt const &receipt, std::string_view owner)
Definition sqlite_catalog.h:568
bool private_construction() const noexcept
Definition sqlite_catalog.h:392
static sqlite_catalog open(std::filesystem::path const &root, catalog_options options={}, Ops ops={})
Definition sqlite_catalog.h:379
std::filesystem::path const & root() const &noexcept
Definition sqlite_catalog.h:396
std::optional< object_seal_receipt > acquire_native_merge(std::string_view op, catalog_native_merge const &key, std::string_view owner)
Definition sqlite_catalog.h:603
void record_sealed(std::string_view op, object_seal_receipt const &receipt)
Definition sqlite_catalog.h:552
bool poisoned() const noexcept
Definition sqlite_catalog.h:391
void reserve(std::string_view op, object_attempt_id const &attempt, std::string_view owner, std::span< blob_identity const > inputs, std::span< catalog_object_reservation const > outputs)
Definition sqlite_catalog.h:518
Definition typed_world.h:171