You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 aWeak<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
'sWeak
counterpart. Internally it would hold multipleWeak<Whatever>
(page cache, flusher, whatever) and would onlyupgrade
successfully to aDb
if it is able to upgrade all of its internalWeak
s.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.The text was updated successfully, but these errors were encountered: