Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should not use snapshot importing when it's inside a batch importing #436

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/strong-walls-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"loro-wasm": patch
"loro-crdt": patch
---

Fix batch importing with snapshot
7 changes: 6 additions & 1 deletion crates/loro-internal/src/loro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ impl LoroDoc {
/// Is the document empty? (no ops)
#[inline(always)]
pub fn can_reset_with_snapshot(&self) -> bool {
self.oplog.lock().unwrap().is_empty() && self.state.lock().unwrap().is_empty()
let oplog = self.oplog.lock().unwrap();
if oplog.batch_importing {
return false;
}

oplog.is_empty() && self.state.lock().unwrap().is_empty()
}

/// Whether [OpLog] and [DocState] are detached.
Expand Down
2 changes: 1 addition & 1 deletion crates/loro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl LoroDoc {
/// Import a batch of updates/snapshot.
///
/// The data can be in arbitrary order. The import result will be the same.
pub fn import_batch(&mut self, bytes: &[Vec<u8>]) -> LoroResult<()> {
pub fn import_batch(&self, bytes: &[Vec<u8>]) -> LoroResult<()> {
self.doc.import_batch(bytes)
}

Expand Down
14 changes: 14 additions & 0 deletions crates/loro/tests/issue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use loro::LoroDoc;

#[ctor::ctor]
fn init() {
dev_utils::setup_test_log();
}

#[test]
fn issue_0() {
let bytes = include_bytes!("./issue_0.bin");
let doc = LoroDoc::new();
doc.import_batch(&[bytes.into()]).unwrap();
doc.export_snapshot();
}
Binary file added crates/loro/tests/issue_0.bin
Binary file not shown.
Loading