From e621e20afcb4472c4940a2cffc6b02df601877bc Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 5 Feb 2023 12:26:30 -0800 Subject: [PATCH] ircd::m::vm: Split vm::sequence into unit. --- matrix/Makefile.am | 1 + matrix/vm.cc | 79 ------------------------------------------- matrix/vm_seq.cc | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 79 deletions(-) create mode 100644 matrix/vm_seq.cc diff --git a/matrix/Makefile.am b/matrix/Makefile.am index b6fcb942e..7725c2955 100644 --- a/matrix/Makefile.am +++ b/matrix/Makefile.am @@ -179,6 +179,7 @@ libircd_matrix_la_SOURCES += push.cc libircd_matrix_la_SOURCES += filter.cc libircd_matrix_la_SOURCES += txn.cc libircd_matrix_la_SOURCES += vm.cc +libircd_matrix_la_SOURCES += vm_seq.cc libircd_matrix_la_SOURCES += vm_eval.cc libircd_matrix_la_SOURCES += vm_inject.cc libircd_matrix_la_SOURCES += vm_execute.cc diff --git a/matrix/vm.cc b/matrix/vm.cc index c7d77c3b1..cc43cc841 100644 --- a/matrix/vm.cc +++ b/matrix/vm.cc @@ -179,82 +179,3 @@ ircd::m::vm::reflect(const enum fault &code) return "??????"; } - -// -// sequence -// - -decltype(ircd::m::vm::sequence::dock) -ircd::m::vm::sequence::dock; - -decltype(ircd::m::vm::sequence::retired) -ircd::m::vm::sequence::retired; - -decltype(ircd::m::vm::sequence::committed) -ircd::m::vm::sequence::committed; - -decltype(ircd::m::vm::sequence::uncommitted) -ircd::m::vm::sequence::uncommitted; - -uint64_t -ircd::m::vm::sequence::min() -{ - const auto *const e - { - eval::seqmin() - }; - - return e? get(*e) : 0; -} - -uint64_t -ircd::m::vm::sequence::max() -{ - const auto *const e - { - eval::seqmax() - }; - - return e? get(*e) : 0; -} - -uint64_t -ircd::m::vm::sequence::get(id::event::buf &event_id) -{ - static constexpr auto column_idx - { - json::indexof() - }; - - auto &column - { - dbs::event_column.at(column_idx) - }; - - const auto it - { - column.rbegin() - }; - - if(!it) - { - // If this iterator is invalid the events db should - // be completely fresh. - assert(db::sequence(*dbs::events) == 0); - return 0; - } - - const auto &ret - { - byte_view(it->first) - }; - - event_id = it->second; - return ret; -} - -const uint64_t & -ircd::m::vm::sequence::get(const eval &eval) -{ - return eval.sequence; -} diff --git a/matrix/vm_seq.cc b/matrix/vm_seq.cc new file mode 100644 index 000000000..0775d6116 --- /dev/null +++ b/matrix/vm_seq.cc @@ -0,0 +1,84 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2023 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. The +// full license for this software is available in the LICENSE file. + +decltype(ircd::m::vm::sequence::dock) +ircd::m::vm::sequence::dock; + +decltype(ircd::m::vm::sequence::retired) +ircd::m::vm::sequence::retired; + +decltype(ircd::m::vm::sequence::committed) +ircd::m::vm::sequence::committed; + +decltype(ircd::m::vm::sequence::uncommitted) +ircd::m::vm::sequence::uncommitted; + +uint64_t +ircd::m::vm::sequence::min() +{ + const auto *const e + { + eval::seqmin() + }; + + return e? get(*e) : 0; +} + +uint64_t +ircd::m::vm::sequence::max() +{ + const auto *const e + { + eval::seqmax() + }; + + return e? get(*e) : 0; +} + +uint64_t +ircd::m::vm::sequence::get(id::event::buf &event_id) +{ + static constexpr auto column_idx + { + json::indexof() + }; + + auto &column + { + dbs::event_column.at(column_idx) + }; + + const auto it + { + column.rbegin() + }; + + if(!it) + { + // If this iterator is invalid the events db should + // be completely fresh. + assert(db::sequence(*dbs::events) == 0); + return 0; + } + + const auto &ret + { + byte_view(it->first) + }; + + event_id = it->second; + return ret; +} + +const uint64_t & +ircd::m::vm::sequence::get(const eval &eval) +{ + return eval.sequence; +}