Struct persy::Snapshot

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

Read snapshot at a specific point in time.

All the changes from transactions committed at the specific point in time were the snapshot was create are readable from this snapshot, all subsequent transactions are ignored.

Copy of the data old data is kept on the disc, with indexing access from in memory structures, on drop of the Snapshot, if there are no older snapshot all the data old by this snapshot not existing anymore in the final state will be cleaned up.

Implementations§

source§

impl Snapshot

source

pub fn read( &self, segment: impl ToSegmentId, id: &PersyId ) -> Result<Option<Vec<u8>>, PE<ReadError>>

Read the record content at the point of time the snapshot was taken ignoring all following committed transactions

§Example
let mut tx = persy.begin()?;
let data = vec![1;20];
let id = tx.insert("seg", &data)?;
tx.prepare()?.commit()?;
let snapshot = persy.snapshot()?;
let read = snapshot.read("seg", &id)?.expect("record exists");
assert_eq!(data,read);
source

pub fn scan( &self, segment: impl ToSegmentId ) -> Result<SnapshotSegmentIter, PE<SegmentError>>

Scan for records existing at the moment of snapshot creation, ignoring all the following committed transactions.

§Example
let mut tx = persy.begin()?;
let data = vec![1;20];
let id = tx.insert("seg", &data)?;
tx.prepare()?.commit()?;
let snapshot = persy.snapshot()?;
let mut count = 0;
for (id,content) in snapshot.scan("seg")? {
    println!("record size:{}",content.len());
    count+=1;
}
assert_eq!(count,1);
source

pub fn get<K, V>( &self, index_name: &str, k: &K ) -> Result<ValueIter<V>, PE<IndexOpsError>>
where K: IndexType, V: IndexType,

Get a value or a group of values from a key at the point the snapshot was taken ignoring all following committed transactions.

§Example
tx.put::<u8,u8>("my_new_index",10,10)?;
tx.prepare()?.commit()?;
let snapshot = persy.snapshot()?;
let values = snapshot.get::<u8,u8>("my_new_index",&10)?;
for value in values {
 //...
}
source

pub fn one<K, V>( &self, index_name: &str, k: &K ) -> Result<Option<V>, PE<IndexOpsError>>
where K: IndexType, V: IndexType,

Get a value or None from a key at the point the snapshot was taken ignoring all following committed transactions.

§Example
tx.put::<u8,u8>("my_new_index",10,10)?;
tx.prepare()?.commit()?;
let snapshot = persy.snapshot()?;
if let Some(value) = snapshot.one::<u8,u8>("my_new_index",&10)?{
 //...
}
source

pub fn range<K, V, R>( &self, index_name: &str, range: R ) -> Result<IndexIter<K, V>, PE<IndexOpsError>>
where K: IndexType, V: IndexType, R: RangeBounds<K>,

Browse a range of keys and values from an index at the pointing that the snapshot was created ignoring all the following committed transactions.

§Example
let mut tx = persy.begin()?;
tx.put::<u8,u8>("my_new_index",10,10)?;
tx.prepare()?.commit()?;
let snapshot = persy.snapshot()?;
let iter:IndexIter<u8,u8> = snapshot.range("my_new_index",10..12)?;
for (k,values) in iter  {
    for value in values {
        //...
    }
}
source

pub fn list_segments( &self ) -> Result<Vec<(String, SegmentId)>, PE<GenericError>>

List all the existing segments, at the pointing that the snapshot was created ignoring all the following committed transactions.

§Example
let mut tx = persy.begin()?;
tx.create_segment("seg")?;
tx.prepare()?.commit()?;
let snapshot = persy.snapshot()?;
let segments = snapshot.list_segments()?;
let names = segments.into_iter().map(|(name,_id)|name).collect::<Vec<String>>();
assert!(names.contains(&"seg".to_string()));
source

pub fn list_indexes(&self) -> Result<Vec<(String, IndexInfo)>, PE<GenericError>>

List all the existing indexes, at the pointing that the snapshot was created ignoring all the following committed transactions.

§Example
let mut tx = persy.begin()?;
tx.create_index::<u8, u8>("idx", ValueMode::Replace)?;
tx.prepare()?.commit()?;
let snapshot = persy.snapshot()?;
let indexes = snapshot.list_indexes()?;
let names = indexes.into_iter().map(|(name,_id)|name).collect::<Vec<String>>();
assert!(names.contains(&"idx".to_string()));

Trait Implementations§

source§

impl Clone for Snapshot

source§

fn clone(&self) -> Snapshot

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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.

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V