ckb_store/
snapshot.rs

1use crate::cache::StoreCache;
2use crate::store::ChainStore;
3use ckb_db::{
4    DBPinnableSlice, RocksDBSnapshot,
5    iter::{DBIter, DBIterator, IteratorMode},
6};
7use ckb_db_schema::Col;
8use ckb_freezer::Freezer;
9use std::sync::Arc;
10
11/// A snapshot of the chain store.
12pub struct StoreSnapshot {
13    pub(crate) inner: RocksDBSnapshot,
14    pub(crate) freezer: Option<Freezer>,
15    pub(crate) cache: Arc<StoreCache>,
16}
17
18impl ChainStore for StoreSnapshot {
19    fn cache(&self) -> Option<&StoreCache> {
20        Some(&self.cache)
21    }
22
23    fn freezer(&self) -> Option<&Freezer> {
24        self.freezer.as_ref()
25    }
26
27    fn get(&self, col: Col, key: &[u8]) -> Option<DBPinnableSlice> {
28        self.inner
29            .get_pinned(col, key)
30            .expect("db operation should be ok")
31    }
32
33    fn get_iter(&self, col: Col, mode: IteratorMode) -> DBIter {
34        self.inner
35            .iter(col, mode)
36            .expect("db operation should be ok")
37    }
38}