sled icon indicating copy to clipboard operation
sled copied to clipboard

An method should be added to determine whether the `Tree` exists

Open rv64m opened this issue 3 years ago • 2 comments

Use Case:

In my scenario, the data of different tenants is stored in different Trees, so that Tree as a tenant. When I create a Tree for a new tenant, I want to know if it has been created before. so I use something like the following to implementation a similar function

let volume_id_bytes = EncodeVolumeId(volume_id)?;
if let Some(_) = self
    .db
    .tree_names()
    .iter()
    .find(|name| **name == IVec::from(volume_id_bytes.as_slice()))
{
    return Err(Error::VolumeAlreadyExists(volume_id))
}

But I probably have hundreds of millions of volume ids, so I think there might be a problem with that.

I think we should add a method like this, e.g.

if db.existis_tree("tree") {
    return Err(...)
}
// do something...

Proposed Change:

I see that currently sled only has method for open_tree to use, I want to add an method like exists_tree.

rv64m avatar Oct 09 '22 03:10 rv64m

cc @spacejam

rv64m avatar Oct 11 '22 10:10 rv64m

Db::contains_tree (doesn't seem to be on crates.io yet)

wackbyte avatar Nov 03 '22 15:11 wackbyte