pub fn shrink(
      &self,
      target_bytes: usize,
      shrink_behavior: ShrinkBehavior,
    ) -> Result<usize, String> {
      let mut used_bytes: usize = 0;
      let mut fingerprints_by_expired_ago = BinaryHeap::new();

      self.aged_fingerprints(
        EntryType::File,
        &mut used_bytes,
        &mut fingerprints_by_expired_ago,
      )?;
      self.aged_fingerprints(
        EntryType::Directory,
        &mut used_bytes,
        &mut fingerprints_by_expired_ago,
      )?;
      while used_bytes > target_bytes {
        let aged_fingerprint = fingerprints_by_expired_ago
          .pop()
          .expect("lmdb corruption detected, sum of size of blobs exceeded stored blobs");
        if aged_fingerprint.expired_seconds_ago == 0 {
          // Ran out of expired blobs - everything remaining is leased and cannot be collected.
          return Ok(used_bytes);
        }
        let lmdbs = match aged_fingerprint.entry_type {
          EntryType::File => self.inner.file_dbs.clone(),
          EntryType::Directory => self.inner.directory_dbs.clone(),
        };
        let (env, database, lease_database) = lmdbs.clone()?.get(&aged_fingerprint.fingerprint);
        {
          env
            .begin_rw_txn()
            .and_then(|mut txn| {
              txn.del(database, &aged_fingerprint.fingerprint.as_ref(), None)?;

              txn
                .del(lease_database, &aged_fingerprint.fingerprint.as_ref(), None)
                .or_else(|err| match err {
                  NotFound => Ok(()),
                  err => Err(err),
                })?;
              used_bytes -= aged_fingerprint.size_bytes;
              txn.commit()
            })
            .map_err(|err| format!("Error garbage collecting: {}", err))?;
        }
      }

      if shrink_behavior == ShrinkBehavior::Compact {
        self.inner.file_dbs.clone()?.compact()?;
      }

      Ok(used_bytes)
    }
///
/// Attempts to shrink the stored files to be no bigger than target_bytes
/// (excluding lmdb overhead).
///
/// Returns the size it was shrunk to, which may be larger than target_bytes.
///
/// Ignores directories. TODO: Shrink directories.
///
/// TODO: Use LMDB database statistics when lmdb-rs exposes them.
///
Attempts to shrink the stored files to be no bigger than target_bytes
(excluding lmdb overhead).

Returns the size it was shrunk to, which may be larger than target_bytes.

Ignores directories. TODO: Shrink directories.

Use LMDB database statistics when lmdb-rs exposes them.
Attempts to shrink the stored files to be no bigger than target_bytes ( excluding lmdb overhead ) . Returns the size it was shrunk to which may be larger than target_bytes . Ignores directories . TODO : Shrink directories . Use LMDB database statistics when lmdb - rs exposes them .
pub fn shrink(
      &self,
      target_bytes: usize,
      shrink_behavior: ShrinkBehavior,
    ) -> Result<usize, String> {
      let mut used_bytes: usize = 0;
      let mut fingerprints_by_expired_ago = BinaryHeap::new();
      self.aged_fingerprints(
        EntryType::File,
        &mut used_bytes,
        &mut fingerprints_by_expired_ago,
      )?;
      self.aged_fingerprints(
        EntryType::Directory,
        &mut used_bytes,
        &mut fingerprints_by_expired_ago,
      )?;
      while used_bytes > target_bytes {
        let aged_fingerprint = fingerprints_by_expired_ago
          .pop()
          .expect("lmdb corruption detected, sum of size of blobs exceeded stored blobs");
        if aged_fingerprint.expired_seconds_ago == 0 {
          // Ran out of expired blobs - everything remaining is leased and cannot be collected.
          return Ok(used_bytes);
        }
        let lmdbs = match aged_fingerprint.entry_type {
          EntryType::File => self.inner.file_dbs.clone(),
          EntryType::Directory => self.inner.directory_dbs.clone(),
        };
        let (env, database, lease_database) = lmdbs.clone()?.get(&aged_fingerprint.fingerprint);
        {
          env
            .begin_rw_txn()
            .and_then(|mut txn| {
              txn.del(database, &aged_fingerprint.fingerprint.as_ref(), None)?;
              txn
                .del(lease_database, &aged_fingerprint.fingerprint.as_ref(), None)
                .or_else(|err| match err {
                  NotFound => Ok(()),
                  err => Err(err),
                })?;
              used_bytes -= aged_fingerprint.size_bytes;
              txn.commit()
            })
            .map_err(|err| format!("Error garbage collecting: {}", err))?;
        }
      }
      if shrink_behavior == ShrinkBehavior::Compact {
        self.inner.file_dbs.clone()?.compact()?;
      }
      Ok(used_bytes)
    }
pub fn shrink ( & self , target_bytes : usize , shrink_behavior : ShrinkBehavior , ) -> Result < usize , String > { let mut used_bytes : usize = 0 ; let mut fingerprints_by_expired_ago = BinaryHeap :: new ( ) ; self . aged_fingerprints ( EntryType :: File , & mut used_bytes , & mut fingerprints_by_expired_ago , ) ? ; self . aged_fingerprints ( EntryType :: Directory , & mut used_bytes , & mut fingerprints_by_expired_ago , ) ? ; while used_bytes > target_bytes { let aged_fingerprint = fingerprints_by_expired_ago . pop ( ) . expect ( " " ) ; if aged_fingerprint . expired_seconds_ago == 0 { // Ran out of expired blobs - everything remaining is leased and cannot be collected. return Ok ( used_bytes ) ; } let lmdbs = match aged_fingerprint . entry_type { EntryType :: File => self . inner . file_dbs . clone ( ) , EntryType :: Directory => self . inner . directory_dbs . clone ( ) , } ; let ( env , database , lease_database ) = lmdbs . clone ( ) ? . get ( & aged_fingerprint . fingerprint ) ; { env . begin_rw_txn ( ) . and_then ( | mut txn | { txn . del ( database , & aged_fingerprint . fingerprint . as_ref ( ) , None ) ? ; txn . del ( lease_database , & aged_fingerprint . fingerprint . as_ref ( ) , None ) . or_else ( | err | match err { NotFound => Ok ( ( ) ) , err => Err ( err ) , } ) ? ; used_bytes -= aged_fingerprint . size_bytes ; txn . commit ( ) } ) . map_err ( | err | format ! ( " " err ) ) ? ; } } if shrink_behavior == ShrinkBehavior :: Compact { self . inner . file_dbs . clone ( ) ? . compact ( ) ? ; } Ok ( used_bytes ) }
Attempts to shrink the stored files to be no bigger than target_bytes
(excluding lmdb overhead).
Attempts to shrink the stored files to be no bigger than target_bytes ( excluding lmdb overhead ) .
&self
target_bytes
usize
shrink_behavior
ShrinkBehavior
&self
target_bytes
usize
shrink_behavior
ShrinkBehavior