use super::super::super::{EmbeddedSqlCall, EmbeddedSqlFileFacts};
use super::super::types::PendingRelativeSpan;
pub(super) fn transaction_calls(
facts: &mut EmbeddedSqlFileFacts,
) -> impl Iterator<Item = &mut EmbeddedSqlCall> {
facts
.calls
.iter_mut()
.chain(
facts
.pending_imported
.iter_mut()
.map(|pending| &mut pending.template),
)
.chain(
facts
.imported_lock_helpers
.iter_mut()
.map(|invocation| &mut invocation.call),
)
}
pub(super) fn retain_helper_invocations(facts: &mut EmbeddedSqlFileFacts, kept: &[bool]) {
facts.imported_lock_helpers.retain(|invocation| {
invocation.relative_owners.is_empty()
|| super::kept_owner(kept, &invocation.relative_owners)
});
}
pub(super) fn clear_unproven_transactions<'a>(
calls: impl Iterator<Item = &'a mut EmbeddedSqlCall>,
spans: &[PendingRelativeSpan],
kept: &[bool],
) {
let rejected: crate::fx::FxHashSet<_> = spans
.iter()
.filter(|span| !super::kept_owner(kept, &span.owners))
.map(|span| span.start)
.collect();
if rejected.is_empty() {
return;
}
for call in calls {
if call.transaction_id.is_some_and(|id| rejected.contains(&id)) {
call.forget_transaction();
}
}
}
pub(super) fn mark_proven_helper_definitions(
facts: &mut EmbeddedSqlFileFacts,
promoted: &mut [(super::PendingRelativeCall, (u32, u32))],
) {
let definitions: crate::fx::FxHashSet<_> = promoted
.iter()
.filter_map(|(pending, _)| pending.call.local_lock_helper_offset)
.collect();
if definitions.is_empty() {
return;
}
let confirmed = facts.calls.iter_mut().zip(&facts.call_spans);
let pending = promoted
.iter_mut()
.map(|(pending, span)| (&mut pending.call, &*span));
for (call, (start, _)) in confirmed.chain(pending) {
call.helper_definition |= definitions.contains(start);
}
}
#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
mod tests {
use super::*;
#[test]
fn promoted_invocation_marks_promoted_definition() {
let mut facts = EmbeddedSqlFileFacts::default();
let mut promoted = [
(
super::super::PendingRelativeCall {
seq: 0,
owners: vec![0],
call: EmbeddedSqlCall::default(),
},
(10, 20),
),
(
super::super::PendingRelativeCall {
seq: 1,
owners: vec![0],
call: EmbeddedSqlCall {
local_lock_helper_offset: Some(10),
..EmbeddedSqlCall::default()
},
},
(30, 40),
),
];
mark_proven_helper_definitions(&mut facts, &mut promoted);
assert!(promoted[0].0.call.helper_definition);
assert!(!promoted[1].0.call.helper_definition);
}
}