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§
source§impl Config
impl Config
sourcepub fn new() -> Config
pub fn new() -> Config
Examples found in repository?
More examples
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())
}
sourcepub fn cache_size(&self) -> u64
pub fn cache_size(&self) -> u64
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,
})
}
sourcepub fn cache_age_limit(&self) -> Duration
pub fn cache_age_limit(&self) -> Duration
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,
})
}
sourcepub fn transaction_lock_timeout(&self) -> &Duration
pub fn transaction_lock_timeout(&self) -> &Duration
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)?)
}
pub fn change_cache_size(&mut self, cache_size: u64)
pub fn change_cache_age_limit(&mut self, cache_age_limit: Duration)
pub fn change_transaction_lock_timeout(
&mut self,
transaction_lock_timeout: Duration
)
sourcepub fn tx_strategy(&self) -> &TxStrategy
pub fn tx_strategy(&self) -> &TxStrategy
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)?)
}