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

Conversation

xinifinity
Copy link
Contributor
@xinifinity xinifinity commented Apr 13, 2023

Closes #37

This PR breaks the mutex lock on DBInner to separate ones on latest batch and revisions. So that users can get a revision while a batch is active. It also allows users to read their writes for a uncommitted batch.

A follow up PR will associate revisions with root hashes to ensure a revision has static meaning.

);

// 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.

@xinifinity xinifinity force-pushed the locking branch 2 times, most recently from 6b437ef to 52d0775 Compare April 13, 2023 17:32
Copy link
Collaborator
@rkuris rkuris left a comment

Choose a reason for hiding this comment

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

Minor suggestions, otherwise looks good

let old_value = merkle
.remove(key, header.kv_root)
.map_err(DBError::Merkle)?;
drop(rev);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be needed; rev can go out of scope and get cleaned up after the construction of the return value.

Copy link
Contributor Author
@xinifinity xinifinity Apr 13, 2023

Choose a reason for hiding this comment

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

If I remove it, there's error showing borrow of 'self.m' occurs here on L887

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting. I wonder if you instead don't even have rev, something like:

let (header, merkle, _)= self.m.write().latest.borrow_split();

@xinifinity xinifinity force-pushed the locking branch 2 times, most recently from 9a1864b to cf0b3bf Compare April 13, 2023 19:16
@xinifinity xinifinity merged commit c204756 into main Apr 14, 2023
@hexfusion hexfusion deleted the locking branch April 14, 2023 03:58
@xinifinity xinifinity self-assigned this Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resolve the locking issue to be able to get revisions while a batch is active
3 participants
0