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

Change transaction apply_batch to take argument by-reference. #1015

Merged
merged 1 commit into from
Mar 13, 2020
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
4 changes: 2 additions & 2 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ impl TransactionalTree {
/// Atomically apply multiple inserts and removals.
pub fn apply_batch(
&self,
batch: Batch,
batch: &Batch,
) -> UnabortableTransactionResult<()> {
for (k, v_opt) in batch.writes {
for (k, v_opt) in &batch.writes {
if let Some(v) = v_opt {
let _old = self.insert(k, v)?;
} else {
Expand Down
23 changes: 23 additions & 0 deletions tests/test_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,29 @@ fn many_tree_transactions() -> TransactionResult<()> {
})
}

#[test]
fn batch_outside_of_transaction() -> TransactionResult<()> {
common::setup_logger();

let config = Config::new().temporary(true).flush_every_ms(None);
let db = config.open().unwrap();

let t1 = db.open_tree(b"1")?;

let mut b1 = Batch::default();
b1.insert(b"k1", b"v1");
b1.insert(b"k2", b"v2");

t1.transaction(|tree| {
tree.apply_batch(&b1)?;
Ok(())
})?;

assert_eq!(t1.get(b"k1")?, Some(b"v1".into()));
assert_eq!(t1.get(b"k2")?, Some(b"v2".into()));
Ok(())
}

#[test]
fn tree_subdir() {
let mut parent_path = std::env::temp_dir();
Expand Down