Skip to content

Commit

Permalink
Feat: autocommit transaction (#127)
Browse files Browse the repository at this point in the history
* feat: auto commit

* fix: make recursive single thread event work again
  • Loading branch information
zxch3n authored Oct 30, 2023
1 parent 734b832 commit 8293347
Show file tree
Hide file tree
Showing 18 changed files with 769 additions and 554 deletions.
2 changes: 2 additions & 0 deletions crates/loro-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub enum LoroError {
TreeError(#[from] LoroTreeError),
#[error("Invalid argument ({0})")]
ArgErr(Box<str>),
#[error("Auto commit has not started. The doc is readonly when detached. You should ensure autocommit is on and the doc and the state is attached.")]
AutoCommitNotStarted,
// #[error("the data for key `{0}` is not available")]
// Redaction(String),
// #[error("invalid header (expected {expected:?}, found {found:?})")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ impl RichtextState {
"pos: {}, len: {}, self.len(): {}",
pos,
len,
self.to_string()
&self.to_string()
);
// PERF: may use cache to speed up
self.cursor_cache.invalidate();
Expand Down
25 changes: 16 additions & 9 deletions crates/loro-internal/src/fuzz/recursive_refactored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,23 @@ trait Actionable {

impl Actor {
fn add_new_container(&mut self, idx: ContainerIdx, type_: ContainerType) {
let txn = self.loro.get_global_txn();
match type_ {
ContainerType::Text => self
.text_containers
.push(TextHandler::new(idx, Arc::downgrade(self.loro.app_state()))),
ContainerType::Map => self
.map_containers
.push(MapHandler::new(idx, Arc::downgrade(self.loro.app_state()))),
ContainerType::List => self
.list_containers
.push(ListHandler::new(idx, Arc::downgrade(self.loro.app_state()))),
ContainerType::Text => self.text_containers.push(TextHandler::new(
txn,
idx,
Arc::downgrade(self.loro.app_state()),
)),
ContainerType::Map => self.map_containers.push(MapHandler::new(
txn,
idx,
Arc::downgrade(self.loro.app_state()),
)),
ContainerType::List => self.list_containers.push(ListHandler::new(
txn,
idx,
Arc::downgrade(self.loro.app_state()),
)),
ContainerType::Tree => {
// TODO Tree
}
Expand Down
36 changes: 6 additions & 30 deletions crates/loro-internal/src/fuzz/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ use crate::{
ContainerType, LoroValue,
};
use crate::{
container::idx::ContainerIdx, delta::TreeDiffItem, handler::TreeHandler, loro::LoroDoc,
state::Forest, value::ToJson, version::Frontiers, ApplyDiff, ListHandler, MapHandler,
TextHandler,
delta::TreeDiffItem, handler::TreeHandler, loro::LoroDoc, state::Forest, value::ToJson,
version::Frontiers, ApplyDiff, ListHandler, MapHandler, TextHandler,
};

#[derive(Arbitrary, EnumAsInner, Clone, PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -227,26 +226,6 @@ trait Actionable {
fn preprocess(&mut self, action: &mut Action);
}

impl Actor {
#[allow(unused)]
fn add_new_container(&mut self, idx: ContainerIdx, type_: ContainerType) {
match type_ {
ContainerType::Text => self
.text_containers
.push(TextHandler::new(idx, Arc::downgrade(self.loro.app_state()))),
ContainerType::Map => self
.map_containers
.push(MapHandler::new(idx, Arc::downgrade(self.loro.app_state()))),
ContainerType::List => self
.list_containers
.push(ListHandler::new(idx, Arc::downgrade(self.loro.app_state()))),
ContainerType::Tree => self
.tree_containers
.push(TreeHandler::new(idx, Arc::downgrade(self.loro.app_state()))),
}
}
}

impl Actionable for Vec<Actor> {
fn preprocess(&mut self, action: &mut Action) {
let max_users = self.len() as u8;
Expand Down Expand Up @@ -552,13 +531,10 @@ impl Actionable for Vec<Actor> {
let key = parent_peer.to_string();
let value = *parent_counter;
let meta = container
.get_meta(
&mut txn,
TreeID {
peer: *target_peer,
counter: *target_counter,
},
)
.get_meta(TreeID {
peer: *target_peer,
counter: *target_counter,
})
.unwrap();
meta.insert(&mut txn, &key, value.into()).unwrap();
}
Expand Down
Loading

0 comments on commit 8293347

Please sign in to comment.