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

storage: use object to pin and unpin version #537

Closed
skyzh opened this issue Feb 28, 2022 · 3 comments · Fixed by #685
Closed

storage: use object to pin and unpin version #537

skyzh opened this issue Feb 28, 2022 · 3 comments · Fixed by #685
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@skyzh
Copy link
Member

skyzh commented Feb 28, 2022

pub fn pin(&self) -> (u64, Arc<Snapshot>) {
let mut inner = self.inner.lock();
let epoch = inner.epoch;
*inner.ref_cnt.entry(epoch).or_default() += 1;
(epoch, inner.status.get(&epoch).unwrap().clone())
}

Currently, users will need to manually call pin and unpin. If there are futures cancelled or somehow, it is possible that we fail to unpin by ourselves.

We should implement a struct called Version, and implement Drop for it. pin will return a Arc<Version> instead of some strange things. When a Version gets dropped (which means that all reference of Arc<Version> is now dropped), we can call unpin in Drop.

@skyzh skyzh added enhancement New feature or request good first issue Good for newcomers labels Feb 28, 2022
@skyzh
Copy link
Member Author

skyzh commented Feb 28, 2022

pub struct Version(u64, Arc<Snapshot>);

impl Drop for Version {
 // ...
}

pub fn pin(&self) -> Arc<Version> { /* .. */ }

@Yisaer
Copy link

Yisaer commented Mar 4, 2022

I'm not familiar with rust, May I try this issue? :)

@skyzh
Copy link
Member Author

skyzh commented Mar 4, 2022

Sure, thanks for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
2 participants