Allow commit with custom timestamp (#105)

This commit is contained in:
Zixuan Chen 2023-08-05 12:43:29 +08:00 committed by GitHub
parent b22bd98f6b
commit a661b776c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,7 +12,7 @@ use rle::{HasLength, RleVec};
use smallvec::smallvec;
use crate::{
change::{get_sys_timestamp, Change, Lamport},
change::{get_sys_timestamp, Change, Lamport, Timestamp},
container::{
idx::ContainerIdx, list::list_op::InnerListOp, text::text_content::SliceRanges,
IntoContainerId,
@ -51,6 +51,7 @@ pub struct Transaction {
pub(super) arena: SharedArena,
finished: bool,
on_commit: Option<OnCommitFn>,
timestamp: Option<Timestamp>,
}
#[derive(Debug, Clone, EnumAsInner)]
@ -97,6 +98,7 @@ impl Transaction {
local_ops: RleVec::new(),
finished: false,
on_commit: None,
timestamp: None,
}
}
@ -108,6 +110,10 @@ impl Transaction {
self._commit()
}
pub fn set_timestamp(&mut self, time: Timestamp) {
self.timestamp = Some(time);
}
pub fn set_on_commit(&mut self, f: OnCommitFn) {
self.on_commit = Some(f);
}
@ -147,7 +153,9 @@ impl Transaction {
ops,
deps,
id: ID::new(self.peer, self.start_counter),
timestamp: oplog.latest_timestamp.max(get_sys_timestamp()),
timestamp: oplog
.latest_timestamp
.max(self.timestamp.unwrap_or_else(get_sys_timestamp)),
};
let diff = if state.is_recording() {