Struct ipfs_sqlite_block_store::BlockStore[][src]

pub struct BlockStore { /* fields omitted */ }

Implementations

impl BlockStore[src]

pub fn memory(config: Config) -> Result<Self>[src]

Create an in memory block store with the given config

pub fn open(path: impl AsRef<Path>, config: Config) -> Result<Self>[src]

Create a persistent block store with the given config

pub fn open_test(path: impl AsRef<Path>, config: Config) -> Result<Self>[src]

Open the file at the given path for testing.

This will create a writeable in-memory database that is initialized with the content of the file at the given path.

pub fn flush(&self) -> Result<()>[src]

pub fn integrity_check(&self) -> Result<()>[src]

pub fn temp_pin(&self) -> TempPin[src]

Get a temporary alias for safely adding blocks to the store

pub fn alias(
    &mut self,
    name: impl AsRef<[u8]>,
    link: Option<&Cid>
) -> Result<()>
[src]

Add a permanent named alias/pin for a root

pub fn resolve(&self, name: impl AsRef<[u8]>) -> Result<Option<Cid>>[src]

Resolves an alias to a cid.

pub fn alias_many(
    &mut self,
    aliases: impl IntoIterator<Item = (impl AsRef<[u8]>, Option<Cid>)>
) -> Result<()>
[src]

Add multiple permanent named aliases

pub fn assign_temp_pin(
    &mut self,
    pin: &TempPin,
    links: impl IntoIterator<Item = Cid>
) -> Result<()>
[src]

pub fn reverse_alias(&self, cid: &Cid) -> Result<Option<Vec<Vec<u8>>>>[src]

Returns the aliases referencing a block.

pub fn has_cid(&self, cid: &Cid) -> Result<bool>[src]

Checks if the store knows about the cid. Note that this does not necessarily mean that the store has the data for the cid.

pub fn has_block(&mut self, cid: &Cid) -> Result<bool>[src]

Checks if the store has the data for a cid

pub fn has_blocks<I, O>(&self, cids: I) -> Result<O> where
    I: IntoIterator<Item = Cid>,
    O: FromIterator<(Cid, bool)>, 
[src]

Look up multiple blocks in one read transaction

pub fn get_store_stats(&self) -> Result<StoreStats>[src]

Get the stats for the store.

The stats are kept up to date, so this is fast.

pub fn get_known_cids<C: FromIterator<Cid>>(&mut self) -> Result<C>[src]

Get all cids that the store knows about

pub fn get_block_cids<C: FromIterator<Cid>>(&self) -> Result<C>[src]

Get all cids for which the store has blocks

pub fn get_descendants<C: FromIterator<Cid>>(&self, cid: &Cid) -> Result<C>[src]

Get descendants of a cid

pub fn get_missing_blocks<C: FromIterator<Cid>>(&self, cid: &Cid) -> Result<C>[src]

Given a root of a dag, gives all cids which we do not have data for.

pub fn aliases<C: FromIterator<(Vec<u8>, Cid)>>(&self) -> Result<C>[src]

list all aliases

pub fn vacuum(&self) -> Result<()>[src]

pub fn gc(&mut self) -> Result<()>[src]

do a full garbage collection

for a large block store, this can take several seconds to minutes. If that is not acceptable, consider using incremental gc.

pub fn incremental_gc(
    &mut self,
    min_blocks: usize,
    max_duration: Duration
) -> Result<bool>
[src]

Perform an incremental garbage collection.

Will collect unpinned blocks until either the size targets are met again, or at minimum min_blocks blocks are collected. Then it will continue connecting blocks until max_duration is elapsed.

Note that this might significantly exceed max_duration for various reasons. Also note that when doing incremental gc, the actual blocks are not yet deleted. So a call to this method should usually be followed by a call to incremental_delete_orphaned.

  • min_blocks the minium number of blocks to collect in any case
  • max_duration the maximum duration that should be spent on gc

Returns true if either size targets are met or there are no unpinned blocks left.

pub fn incremental_delete_orphaned(
    &mut self,
    min_blocks: usize,
    max_duration: Duration
) -> Result<bool>
[src]

Incrementally delete orphaned blocks

Orphaned blocks are blocks for which we have deleted the metadata in incremental_gc.

Will delete orphaned blocks until either all orphaned blocks are deleted, or at minimum min_blocks blocks are deleted. Then it will continue deleting blocks until max_duration is elapsed.

Note that this might significantly exceed max_duration for various reasons.

  • min_blocks the minium number of blocks to delete in any case
  • max_duration the maximum duration that should be spent on gc

Returns true if all orphaned blocks are deleted

pub fn put_blocks<B: Block>(
    &mut self,
    blocks: impl IntoIterator<Item = B>,
    pin: Option<&TempPin>
) -> Result<()>
[src]

Add a number of blocks to the store

It is up to the caller to extract links from blocks. Also, the store does not know anything about content-addressing and will not validate that the cid of a block is the actual hash of the content.

  • blocks the blocks to add. Even we already have these blocks, the alias will be set. However, it will not be checked that the links or data are the same as last time the block was added. That is responsibility of the caller.
  • alias an optional temporary alias. This can be used to incrementally add blocks without having to worry about them being garbage collected before they can be pinned with a permanent alias.

pub fn put_block(
    &mut self,
    block: &impl Block,
    alias: Option<&TempPin>
) -> Result<()>
[src]

Add a single block

this is just a convenience method that calls put_blocks internally.

  • cid the cid This should be a hash of the data, with some format specifier.
  • data a blob
  • links links extracted from the data
  • alias an optional temporary alias

pub fn get_blocks<I>(
    &self,
    cids: I
) -> Result<impl Iterator<Item = (Cid, Option<Vec<u8>>)>> where
    I: IntoIterator<Item = Cid>, 
[src]

Get multiple blocks in a single read transaction

pub fn get_block(&self, cid: &Cid) -> Result<Option<Vec<u8>>>[src]

Get data for a block

Will return None if we don't have the data

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> References<RawCodec> for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.