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

Weak Db handle #1504

Open
jeffparsons opened this issue Apr 13, 2024 · 0 comments
Open

Weak Db handle #1504

jeffparsons opened this issue Apr 13, 2024 · 0 comments
Labels

Comments

@jeffparsons
Copy link

My understanding is that various types like Tree hold references to internal Sled structures, so a database will remain "open" until all instances of such types are dropped, and it's not safe/possible to open the database again while it is already open. If this is incorrect, then the rest of this won't make any sense. 😅

Use Case:

I have a use case where code that wants to use a Sled database doesn't know if it has already been opened by someone else in the same process. So I added a central registry of open databases and hand out Arc<Db>s, only opening the database if it has not already been opened by someone else.

I'd like to be able to have databases close when nobody is using them anymore, but the Arc<Db> I store in my registry will keep it open forever. And I don't have enough information to know when I can drop it and then assume the database is closed even if I use a Weak<Db>, because there are other things that can keep the database open outside of my own bookkeeping.

Proposed Change:

Sled could expose a weak database handle, conceptually equivalent to Arc's Weak counterpart. Internally it would hold multiple Weak<Whatever> (page cache, flusher, whatever) and would only upgrade successfully to a Db if it is able to upgrade all of its internal Weaks.

Alternative Approaches:

Sled could store an internal global map of open databases and use it to do the equivalent of this internally. I.e. no extra types in the public API, and instead open would just magically succeed if somebody else in the same process already opened it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant