-
Notifications
You must be signed in to change notification settings - Fork 53
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
make Manager consumable #21
Conversation
The idea was to not make the constructor public precisely to prevent any consumer from bypassing the single-instance restriction. If you’re brave enough to do that, just create stores directly rather than using |
@@ -0,0 +1,32 @@ | |||
extern crate rkv; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 272c689.
src/manager.rs
Outdated
@@ -40,7 +40,7 @@ pub struct Manager { | |||
} | |||
|
|||
impl Manager { | |||
fn new() -> Manager { | |||
pub fn new() -> Manager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t mind allowing Manager
to be created for tests, but in that case please do so via a #[cfg(test)]
pub(crate)
method called new_for_test
or something.
Right, makes sense. However, in that case, how does one use Manager today? Perhaps I'm missing something, but there doesn't currently appear to be that single instance of Manager that consumers can access. |
There isn’t, and some kind of thread-safe singleton must be implemented. If you can make it eager/on module load, that’s fine; it doesn’t really need to be very lazy. |
Making it eager fails on "calls in statics are limited to struct and enum constructors," and while we could replace Manager::new() with a direct call to the struct constructor, we'd still need to call RwLock::new() to make it threadsafe. (In the past, we would've been able to use StaticRwLock, but that was deprecated in favor of lazy_static in rust-lang/rust#27717.) So 273ff58 uses lazy_static to add a thread-safe static singleton and makes |
@fluffyemily and @ncalexan: per our conversation earlier today about expanding the reviewer corps for rkv, perhaps y'all can look at this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tree is all over the place, with reversions and a merge from master
. Land just one commit with no merge, please.
Otherwise, this looks fine, but I have a slight preference for exposing Manager::singleton()
or Manager::instance()
rather than the all-caps very-special lazy static to consumers. Lazy static instances have strange types, or at least they did.
In the diff from master
, I noticed some tests were removed from src/env.rs
. Explain why?
I have mixed feelings about this, as I sometimes appreciate the "messy" history of a feature's development when digging at code archaeological sites. But, ok, I'll "squash and merge" this pull request.
They still do, as the macro generates a type that dereferences to the specified type of the static (which appears to be of type manager::MANAGER). It isn't clear to me how likely it is for consumers to be confused by this type. Nevertheless, I agree that In 6293a29, I've made MANAGER private and added a (An alternative would be for Manager to implement RwLock, such that consumers can call
I didn't intend to do this, nor do I see it in this pull request, nor local diffs. Are you perhaps diffing locally against a local master branch that is behind upstream? |
Erm, or did you mean to both squash all commits on this branch and also land it without a merge commit, fast-forwarding master to the squashed commit? |
Squash so there's one commit; the false starts are rarely valuable. Rebase that onto master. Merge vs. fast-forward is your choice; I personally prefer merge with the r= on the merge commit, but GH makes that onerous. |
I'll agree to disagree. 😉
Indeed, and it's quite useful to employ one of the flows that GitHub optimizes. In this case, it looks like "squash and merge" is the closest to what you prefer, so I'll do that. |
@rnewman
Manager::new
would have to be pub in order for a consumer to use it to create a Manager instance that manages database handles for them. But perhaps you have a different plan for how consumers should use Manager?I suppose it somewhat begs the question to enable consumers to instantiate them directly, since a consumer can then evade the constraint that Manager imposes by instantiating it multiple times. One alternative would be to create a Manager singleton via a lazy static, i.e. something like:
Then keep
Manager::new()
private to force consumers to get or create Rkv instances via the singleton.