Struct tocco_s3::state::Db

source ·
pub struct Db { /* private fields */ }
Expand description

SQLite DB state database

Obtain via crate::fs::Archive::state_db().

Implementations§

source§

impl Db

source

pub fn insert_last_seen_times<I, H>(&mut self, hashes: I) -> Result<()>
where I: IntoIterator<Item = H>, H: Borrow<Hash>,

Insert last seen timestamp for given objects.

Unlike Self::update_last_seen_times(), times are only inserted for objects not in the state DB yet. Objects already in the DB are ignored.

source

pub fn update_last_seen_times<I, H>(&mut self, hashes: I) -> Result<()>
where I: IntoIterator<Item = H>, H: Borrow<Hash>,

Update last seen timestamp for given objects.

If an object is missing in state DB, it is inserted.

source

pub fn set_last_seen_time( &mut self, hash: &Hash, ts: DateTime<Local>, ) -> Result<()>

Set last seen time

This is mostly useful for testing. Consider using Self::update_last_seen_times() instead.

source

pub fn last_seen_time(&mut self, hash: &Hash) -> Result<Option<DateTime<Local>>>

Get last seen time

source

pub fn next_objects_older_than<'pager>( &mut self, pager: &'pager mut ObjectsOlderThanPager, ) -> Result<Option<&'pager [Hash]>>

Obtain all objects older than duration

Create an ObjectsOlderThanPager first and then pass it to this function.

Returns the next page (Some(&[Hash])) or None if there is no more matching objects.

use chrono::Duration;
use tocco_s3::state::ObjectsOlderThanPager;
use tocco_s3::Archive;

let archive_path = tempfile::tempdir().unwrap();
let archive_path = archive_path.path().join("archive");
let archive = Archive::init(&archive_path).unwrap();
let mut state_db = archive.state_db().unwrap();
let objects_returned_per_page = 1024;
let older_than = Duration::days(90);
let mut pager = ObjectsOlderThanPager::new(older_than, objects_returned_per_page);
assert!(state_db
    .next_objects_older_than(&mut pager)
    .unwrap()
    .is_none());
source

pub fn delete_objects<I, H>(&mut self, hashes: I) -> Result<()>
where I: IntoIterator<Item = H>, H: Borrow<Hash>,

Delete object matching given hashes.

source

pub fn update_last_db_scan_time(&self) -> Result<()>

Update time when DB was last scanned for live objects.

This time indicates when last a list of all objects was fetched from the DB server and the last_seen times updated.

source

pub fn last_db_scan_time(&self) -> Result<DateTime<Local>>

Get time when DB was last scanned for live objects.

See Self::update_last_db_scan_time

source

pub fn update_last_archive_scan_time(&self) -> Result<()>

Update time when archive was last scanned for live objects.

This time indicates when last a list of all objects in the archive (on disk) was fetched and records created for objects that were missing in the DB.

source

pub fn last_archive_scan_time(&self) -> Result<DateTime<Local>>

Get time when archive was last scanned for live objects.

See Self::update_last_db_scan_time

source

pub fn update_last_s3_backup_time(&self) -> Result<()>

Update time when S3 objects were last backed up to the archive.

This is the last time a backup was created successfully.

source

pub fn last_s3_backup_time(&self) -> Result<DateTime<Local>>

Get time when S3 objects were last backed up to the archive.

See [Self::update_last_s3_time]

source

pub fn vacuum(&self) -> Result<()>

source

pub fn optimize(&self) -> Result<()>

Optimize database

Executed automatically when DB is Dropped as recommended by upstream.

https://www.sqlite.org/pragma.html#pragma_optimize

Trait Implementations§

source§

impl Drop for Db

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Db

§

impl !RefUnwindSafe for Db

§

impl Send for Db

§

impl !Sync for Db

§

impl Unpin for Db

§

impl !UnwindSafe for Db

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T