pub struct Db { /* private fields */ }
Expand description
SQLite DB state database
Obtain via crate::fs::Archive::state_db()
.
Implementations§
source§impl Db
impl Db
sourcepub fn insert_last_seen_times<I, H>(&mut self, hashes: I) -> Result<()>
pub fn insert_last_seen_times<I, H>(&mut self, hashes: I) -> Result<()>
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.
sourcepub fn update_last_seen_times<I, H>(&mut self, hashes: I) -> Result<()>
pub fn update_last_seen_times<I, H>(&mut self, hashes: I) -> Result<()>
Update last seen timestamp for given objects.
If an object is missing in state DB, it is inserted.
sourcepub fn set_last_seen_time(
&mut self,
hash: &Hash,
ts: DateTime<Local>,
) -> Result<()>
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.
sourcepub fn last_seen_time(&mut self, hash: &Hash) -> Result<Option<DateTime<Local>>>
pub fn last_seen_time(&mut self, hash: &Hash) -> Result<Option<DateTime<Local>>>
Get last seen time
sourcepub fn next_objects_older_than<'pager>(
&mut self,
pager: &'pager mut ObjectsOlderThanPager,
) -> Result<Option<&'pager [Hash]>>
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());
sourcepub fn delete_objects<I, H>(&mut self, hashes: I) -> Result<()>
pub fn delete_objects<I, H>(&mut self, hashes: I) -> Result<()>
Delete object matching given hashes.
sourcepub fn update_last_db_scan_time(&self) -> Result<()>
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.
sourcepub fn last_db_scan_time(&self) -> Result<DateTime<Local>>
pub fn last_db_scan_time(&self) -> Result<DateTime<Local>>
Get time when DB was last scanned for live objects.
sourcepub fn update_last_archive_scan_time(&self) -> Result<()>
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.
sourcepub fn last_archive_scan_time(&self) -> Result<DateTime<Local>>
pub fn last_archive_scan_time(&self) -> Result<DateTime<Local>>
Get time when archive was last scanned for live objects.
sourcepub fn update_last_s3_backup_time(&self) -> Result<()>
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.
sourcepub fn last_s3_backup_time(&self) -> Result<DateTime<Local>>
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
]
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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