Trait spacetimedb_table::blob_store::BlobStore
source · pub trait BlobStore: Sync {
// Required methods
fn clone_blob(&mut self, hash: &BlobHash) -> Result<(), NoSuchBlobError>;
fn insert_blob(&mut self, bytes: &[u8]) -> BlobHash;
fn insert_with_uses(
&mut self,
hash: &BlobHash,
uses: usize,
bytes: Box<[u8]>,
);
fn retrieve_blob(&self, hash: &BlobHash) -> Result<&[u8], NoSuchBlobError>;
fn free_blob(&mut self, hash: &BlobHash) -> Result<(), NoSuchBlobError>;
fn iter_blobs(&self) -> BlobsIter<'_>;
}
Expand description
The interface that tables use to talk to the blob store engine for large var-len objects.
These blob objects are referred to by their BlobHash
,
which is currently defined through BLAKE3 on the bytes of the blob object.
Required Methods§
sourcefn clone_blob(&mut self, hash: &BlobHash) -> Result<(), NoSuchBlobError>
fn clone_blob(&mut self, hash: &BlobHash) -> Result<(), NoSuchBlobError>
Mark the hash
as used.
This is a more efficient way of doing:
let bytes = self.retrieve_blob(&hash);
let _ = self.insert_blob(&bytes);
sourcefn insert_blob(&mut self, bytes: &[u8]) -> BlobHash
fn insert_blob(&mut self, bytes: &[u8]) -> BlobHash
Insert bytes
into the blob store.
Returns the content address of bytes
a BlobHash
which can be used in [retrieve_blob
] to fetch it.
sourcefn insert_with_uses(&mut self, hash: &BlobHash, uses: usize, bytes: Box<[u8]>)
fn insert_with_uses(&mut self, hash: &BlobHash, uses: usize, bytes: Box<[u8]>)
Insert hash
referring to bytes
and mark its refcount as uses
.
Used when restoring from a snapshot.
sourcefn retrieve_blob(&self, hash: &BlobHash) -> Result<&[u8], NoSuchBlobError>
fn retrieve_blob(&self, hash: &BlobHash) -> Result<&[u8], NoSuchBlobError>
Returns the bytes stored at the content address hash
.
sourcefn free_blob(&mut self, hash: &BlobHash) -> Result<(), NoSuchBlobError>
fn free_blob(&mut self, hash: &BlobHash) -> Result<(), NoSuchBlobError>
Marks the hash
as unused.
Depending on the strategy employed by the blob store, this might not actually free the data, but rather just decrement a reference count.
sourcefn iter_blobs(&self) -> BlobsIter<'_>
fn iter_blobs(&self) -> BlobsIter<'_>
Iterate over all blobs present in the blob store.
Each element is a tuple (hash, uses, data)
,
where hash
is a blob’s content-addressed BlobHash
,
uses
is the number of references to that blob,
and data
is the data itself.
Used when capturing a snapshot.