Struct persy::Config

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

Persy configuration structure.

Lock are taken in order, should never go in deadlock so the default timeout is huge. Current default values:

cache_size = 32M cache_age_limit = 1 Day transaction_lock_timeout = 1 Day concurrent_modification_strategy = LastWin

Implementations§

Examples found in repository?
src/config.rs (line 113)
112
113
114
    fn default() -> Self {
        Self::new()
    }
More examples
Hide additional examples
src/open_options.rs (line 50)
45
46
47
48
49
50
51
52
53
54
    pub fn new() -> OpenOptions {
        OpenOptions {
            truncate: false,
            create: false,
            create_new: false,
            config: Config::new(),
            prepare: None,
            recover: None,
        }
    }
src/persy.rs (line 137)
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    fn init(device: Box<dyn Device>) -> PERes<Box<dyn Device>> {
        // root_page is every time 0
        let root_page = device.create_page_raw(DEFAULT_PAGE_EXP)?;
        let (allocator_page, allocator) = Allocator::init(device, &Config::new())?;
        let address_page = Address::init(&allocator)?;
        let journal_page = Journal::init(&allocator)?;
        {
            let mut root = allocator.disc().load_page_raw(root_page, DEFAULT_PAGE_EXP)?;
            // Version of the disc format
            root.write_u16(0);
            // Position of the start of address structure
            root.write_u64(address_page);
            // Start of the Log data, if shutdown well this will be every time 0
            root.write_u64(journal_page);
            root.write_u64(allocator_page);
            root.write_all(PERSY_TAG_BYTES);
            allocator.flush_page(root)?;
        }
        let res = allocator.disc_sync()?;
        debug_assert!(res);
        Ok(allocator.release())
    }
Examples found in repository?
src/allocator.rs (line 108)
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
    pub fn new(dr: Box<dyn Device>, config: &Config, page: u64) -> PERes<Allocator> {
        let mut root_monitor = RootMonitor::default();
        let mut flush_count = FlushCount::default();
        let mut pg = dr.load_page(page)?;
        let mut freelist = FreeList::read(&mut pg, &mut root_monitor.free_list_holder, &mut flush_count.free_list)?;
        freelist.check_and_clean(&*dr)?;

        let cache_size = config.cache_size();
        let cache_age_limit = config.cache_age_limit();
        Ok(Allocator {
            device: dr,
            free_list: Mutex::new(freelist),
            cache: Mutex::new(Cache::new(cache_size, cache_age_limit)),
            root_monitor: Mutex::new(root_monitor),
            flush_count: Mutex::new(flush_count),
            release_next_sync: Default::default(),
            page,
        })
    }
Examples found in repository?
src/allocator.rs (line 109)
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
    pub fn new(dr: Box<dyn Device>, config: &Config, page: u64) -> PERes<Allocator> {
        let mut root_monitor = RootMonitor::default();
        let mut flush_count = FlushCount::default();
        let mut pg = dr.load_page(page)?;
        let mut freelist = FreeList::read(&mut pg, &mut root_monitor.free_list_holder, &mut flush_count.free_list)?;
        freelist.check_and_clean(&*dr)?;

        let cache_size = config.cache_size();
        let cache_age_limit = config.cache_age_limit();
        Ok(Allocator {
            device: dr,
            free_list: Mutex::new(freelist),
            cache: Mutex::new(Cache::new(cache_size, cache_age_limit)),
            root_monitor: Mutex::new(root_monitor),
            flush_count: Mutex::new(flush_count),
            release_next_sync: Default::default(),
            page,
        })
    }
Examples found in repository?
src/persy.rs (line 253)
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
    pub fn begin_with(&self, mut config: TransactionConfig) -> Result<TransactionImpl, BeginTransactionError> {
        let journal = &self.journal;
        let strategy = if let Some(st) = config.tx_strategy {
            st
        } else {
            self.config.tx_strategy().clone()
        };
        let meta_id = if let Some(id) = replace(&mut config.transaction_id, None) {
            if id.len() > 512 {
                return Err(BeginTransactionError::InvalidTransactionId);
            }
            id
        } else {
            Vec::new()
        };
        let sync_mode = if Some(true) == config.background_sync {
            SyncMode::BackgroundSync
        } else {
            SyncMode::Sync
        };

        let timeout = self.config.transaction_lock_timeout();

        Ok(TransactionImpl::new(journal, &strategy, sync_mode, meta_id, *timeout)?)
    }
Examples found in repository?
src/persy.rs (line 237)
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
    pub fn begin_with(&self, mut config: TransactionConfig) -> Result<TransactionImpl, BeginTransactionError> {
        let journal = &self.journal;
        let strategy = if let Some(st) = config.tx_strategy {
            st
        } else {
            self.config.tx_strategy().clone()
        };
        let meta_id = if let Some(id) = replace(&mut config.transaction_id, None) {
            if id.len() > 512 {
                return Err(BeginTransactionError::InvalidTransactionId);
            }
            id
        } else {
            Vec::new()
        };
        let sync_mode = if Some(true) == config.background_sync {
            SyncMode::BackgroundSync
        } else {
            SyncMode::Sync
        };

        let timeout = self.config.transaction_lock_timeout();

        Ok(TransactionImpl::new(journal, &strategy, sync_mode, meta_id, *timeout)?)
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.