8000 [locking] Get a revision while a batch is active by xinifinity · Pull Request #17 · ava-labs/firewood · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[locking] Get a revision while a batch is active #17

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

Merged
merged 2 commits into from
Apr 14, 2023
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
24 changes: 24 additions & 0 deletions firewood/examples/rev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,34 @@ fn main() {
"{}",
hex::encode(*db.get_revision(1, None).unwrap().kv_root_hash().unwrap())
);
let root_hash = *db.get_revision(1, None).unwrap().kv_root_hash().unwrap();
println!(
"{}",
hex::encode(*db.get_revision(2, None).unwrap().kv_root_hash().unwrap())
);
let write = db.new_writebatch().kv_insert("k", vec![b'v']).unwrap();

// Get a revision while a batch is active.
println!(
"{}",
hex::encode(*db.get_revision(1, None).unwrap().kv_root_hash().unwrap())
);
assert_eq!(
root_hash,
*db.get_revision(1, None).unwrap().kv_root_hash().unwrap()
);

// Read the uncommitted value while the batch is still active.
let val = db.kv_get("k").unwrap();
Copy link
Contributor
@hexfusion hexfusion Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My expectation here would be that kv_get would return no value as the key has not been committed. db.kv_get() should return against the latest revision. In this case its returning against an uncommitted batch which makes me think a mutation has taken place on disk.

ref.

firewood/firewood/src/db.rs

Lines 710 to 717 in 8d46653

/// Get a value in the kv store associated with a particular key.
pub fn kv_get<K: AsRef<[u8]>>(&self, key: K) -> Result<Vec<u8>, DBError> {
self.inner
.lock()
.latest
.kv_get(key)
.ok_or(DBError::KeyNotFound)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, for the current user who open the batch and want to read the uncommitted changes. It is desired the user can read it. But the other concurrent user shouldn't read it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this will be further complicated by the API changes. I think we should proceed with improving the concurrency of this now though; this seems to be heading the right way for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, talked to @hexfusion offline, with this change, there is still something needs to be improved that DB should not has APIs that would expose the staging changes. And user should directly interact with a DBRev to write/read their uncommitted changes. I will have a follow up PR for it. But agree would want to merge this as incremental changes.

assert_eq!("v".as_bytes().to_vec(), val);

write.commit();
println!(
"{}",
hex::encode(*db.get_revision(1, None).unwrap().kv_root_hash().unwrap())
);
let val = db.kv_get("k").unwrap();
assert_eq!("v".as_bytes().to_vec(), val);
}
{
let db = DB::new("rev_db", &cfg.truncate(false).build()).unwrap();
Expand Down
Loading
0