use super::UndoEntry;
use crate::data::executor::core_loop::CoreLoop;
impl CoreLoop {
pub(in crate::data::executor::handlers) fn rollback_undo_log(
&mut self,
did: u64,
tid: u64,
undo_log: Vec<UndoEntry>,
) -> Result<(), (usize, String)> {
self.rollback_undo_log_inner(did, tid, None, undo_log)
}
pub(in crate::data::executor::handlers) fn rollback_undo_log_at(
&mut self,
did: u64,
tid: u64,
vshard_id: crate::types::VShardId,
undo_log: Vec<UndoEntry>,
) -> Result<(), (usize, String)> {
self.rollback_undo_log_inner(did, tid, Some(vshard_id), undo_log)
}
fn rollback_undo_log_inner(
&mut self,
did: u64,
tid: u64,
vshard_id: Option<crate::types::VShardId>,
undo_log: Vec<UndoEntry>,
) -> Result<(), (usize, String)> {
let total = undo_log.len();
for (rev_idx, entry) in undo_log.into_iter().rev().enumerate() {
let original_idx = total.saturating_sub(1 + rev_idx);
self.apply_undo_entry(did, tid, vshard_id, original_idx, entry)?;
}
Ok(())
}
fn apply_undo_entry(
&mut self,
did: u64,
tid: u64,
vshard_id: Option<crate::types::VShardId>,
entry_index: usize,
entry: UndoEntry,
) -> Result<(), (usize, String)> {
match entry {
UndoEntry::PutDocument { .. } | UndoEntry::DeleteDocument { .. } => {
self.apply_undo_document(did, tid, entry_index, entry)
}
UndoEntry::InsertVector { .. } | UndoEntry::DeleteVector { .. } => {
self.apply_undo_vector(tid, entry_index, entry)
}
UndoEntry::SpatialInsert { .. } | UndoEntry::SpatialDelete { .. } => {
self.apply_undo_spatial(entry_index, entry)
}
UndoEntry::PutEdge { ref src_id, .. } | UndoEntry::DeleteEdge { ref src_id, .. } => {
let account_stats = vshard_id.is_none_or(|vshard_id| {
vshard_id == crate::types::VShardId::from_key(src_id.as_bytes())
});
self.apply_undo_edge_with_stats(did, tid, entry_index, entry, account_stats)
}
UndoEntry::KvPut { .. }
| UndoEntry::KvDelete { .. }
| UndoEntry::KvBatchPut { .. }
| UndoEntry::KvTransfer { .. }
| UndoEntry::KvTransferItem { .. }
| UndoEntry::KvTtl { .. }
| UndoEntry::SortedIndexDdl { .. } => self.apply_undo_kv(did, tid, entry_index, entry),
UndoEntry::ColumnarInsert { .. }
| UndoEntry::ColumnarUpdate { .. }
| UndoEntry::ColumnarDelete { .. } => self.apply_undo_columnar(entry_index, entry),
UndoEntry::TimeseriesIngest { .. } => self.apply_undo_timeseries(entry_index, entry),
UndoEntry::StatsRestore { .. } => self.apply_undo_stats(entry_index, entry),
UndoEntry::MarkNodeDeleted { .. } => self.apply_undo_mark_node(entry_index, entry),
}
}
}