risinglight icon indicating copy to clipboard operation
risinglight copied to clipboard

storage: use object to pin and unpin version

Open skyzh opened this issue 2 years ago • 3 comments

https://github.com/risinglightdb/risinglight/blob/7b5bc7a1a258afd64a483990ca95f4c799482791/src/storage/secondary/version_manager.rs#L258-L263

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 avatar Feb 28 '22 15:02 skyzh

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

impl Drop for Version {
 // ...
}

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

skyzh avatar Feb 28 '22 15:02 skyzh

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

Yisaer avatar Mar 04 '22 05:03 Yisaer

Sure, thanks for that!

skyzh avatar Mar 04 '22 05:03 skyzh