diff --git a/include/ircd/m/vm.h b/include/ircd/m/vm.h index 4e1a9b8bd..646e1f0b7 100644 --- a/include/ircd/m/vm.h +++ b/include/ircd/m/vm.h @@ -176,6 +176,7 @@ enum ircd::m::vm::phase FETCH_PREV, ///< Previous events fetch phase. FETCH_STATE, ///< State events fetch phase. PRECOMMIT, ///< Precommit sequence. + PREINDEX, ///< Prefetch indexing & transaction dependencies. AUTH_RELA, ///< Relative authentication phase. COMMIT, ///< Commit sequence. AUTH_PRES, ///< Authentication phase. diff --git a/matrix/homeserver_bootstrap.cc b/matrix/homeserver_bootstrap.cc index c7b697c85..9506dabc1 100644 --- a/matrix/homeserver_bootstrap.cc +++ b/matrix/homeserver_bootstrap.cc @@ -247,6 +247,7 @@ try // Primary interest is to perform the INDEX and WRITE phase which create // a database transaction and commit it respectively. + vmopts.phase.set(vm::phase::PREINDEX, true); vmopts.phase.set(vm::phase::INDEX, true); vmopts.phase.set(vm::phase::WRITE, true); diff --git a/matrix/vm.cc b/matrix/vm.cc index 57e0d3a90..db6ce8ae6 100644 --- a/matrix/vm.cc +++ b/matrix/vm.cc @@ -178,6 +178,7 @@ ircd::m::vm::reflect(const enum phase &code) case phase::FETCH_PREV: return "FETCH_PREV"; case phase::FETCH_STATE: return "FETCH_STATE"; case phase::PRECOMMIT: return "PRECOMMIT"; + case phase::PREINDEX: return "PREINDEX"; case phase::AUTH_RELA: return "AUTH_RELA"; case phase::COMMIT: return "COMMIT"; case phase::AUTH_PRES: return "AUTH_PRES"; diff --git a/matrix/vm_execute.cc b/matrix/vm_execute.cc index 6de3330af..abf368c7b 100644 --- a/matrix/vm_execute.cc +++ b/matrix/vm_execute.cc @@ -869,6 +869,22 @@ ircd::m::vm::execute_pdu(eval &eval, && eval.parent->event_->event_id }; + // Allocate transaction; prefetch dependencies. + if(likely(opts.phase[phase::PREINDEX])) + { + const scope_restore eval_phase + { + eval.phase, phase::PREINDEX + }; + + dbs::write_opts wopts(opts.wopts); + wopts.event_idx = eval.sequence; + const size_t prefetched + { + dbs::prefetch(event, wopts) + }; + } + const scope_restore eval_phase_precommit { eval.phase, phase::PRECOMMIT @@ -1151,6 +1167,7 @@ ircd::m::vm::write_append(eval &eval, } } + assert(eval.txn); const size_t wrote { dbs::write(*eval.txn, event, wopts)