pub struct Database<MSG: Message> { /* private fields */ }Expand description
Main database object.
This object implements the main Noatun database functionality.
Use Database::create_new to create a database.
Use Database::begin_session_mut to start a mutable session to write to the database, using
DatabaseSessionMut::append_single to add a message.
Use Database::begin_session to start a read-only session to gain access to the database
data using DatabaseSession::with_root.
For replication, see crate::communication::DatabaseCommunication.
§Consistency
If thread execution is halted while a mutable Database-operation is running,
the Database will enter a “corrupted” state. Clearing this state requires mutable access,
and this state can thus not be recovered from within any of the methods accepting &self.
Any access to a method using &mut self (and Self::recover in particular) will
execute the recovery procedure and restore the database to working order.
Implementations§
Source§impl<MSG: Message + 'static> Database<MSG>
impl<MSG: Message + 'static> Database<MSG>
Sourcepub fn begin_session_mut(&mut self) -> Result<DatabaseSessionMut<'_, MSG>>
pub fn begin_session_mut(&mut self) -> Result<DatabaseSessionMut<'_, MSG>>
Begin a write transaction
Each transaction has a significant overhead because of the cost of syncing disks.
It is therefore useful to combine as many operations as possible into each transaction.
Sourcepub fn sync_all(&mut self) -> Result<()>
pub fn sync_all(&mut self) -> Result<()>
Sync all writes to disk
This will update both file data and file metadata
Sourcepub fn begin_session(&self) -> Result<DatabaseSession<'_, MSG>>
pub fn begin_session(&self) -> Result<DatabaseSession<'_, MSG>>
Begin a readonly database session.
Sourcepub fn recover(&mut self) -> Result<()>
pub fn recover(&mut self) -> Result<()>
Recover database if in corrupted state. This method is very fast in the case where the database is not corrupted.
Sourcepub fn set_abort_on_panic(&mut self)
pub fn set_abort_on_panic(&mut self)
Set noatun to abort on any panicking message.
The default is to catch panics and log an error.
Aborting can be useful when debugging, as it can sometimes be useful to stop immediately at the first error.
Sourcepub fn noatun_now(&self) -> NoatunTime
pub fn noatun_now(&self) -> NoatunTime
Return this database’s current time.
If time has not been explicitly overridden by calling DatabaseSessionMut::set_mock_time,
this will return current system time.
Sourcepub fn remove_caches(path: impl AsRef<Path>) -> Result<()>
pub fn remove_caches(path: impl AsRef<Path>) -> Result<()>
Remove all cache files, retaining only the actual data files.
This should never be needed, but can possibly serve a purpose if archiving noatun files, since the cache files can always be recreated from the data files.
Sourcepub fn remove_db_files(path: impl AsRef<Path>) -> Result<()>
pub fn remove_db_files(path: impl AsRef<Path>) -> Result<()>
Remove all database files for a database at the given path
Succeeds if the database was removed, or if it didn’t even exist. This is mostly useful to clean up integration tests.
Sourcepub fn create_new(
path: impl AsRef<Path>,
mode: OpenMode,
settings: DatabaseSettings,
) -> Result<Database<MSG>>
pub fn create_new( path: impl AsRef<Path>, mode: OpenMode, settings: DatabaseSettings, ) -> Result<Database<MSG>>
Note: You can set max_file_size to something very large, like 100_000_000_000. The max-size is reserved in the process’ address space, but not actually allocated until needed.
params - Can be anything. Will be provided at initialization time
Sourcepub fn count_messages(&self) -> usize
pub fn count_messages(&self) -> usize
Return the number of messages in the system. This method returns 0 on error.
Sourcepub fn create_in_memory(
max_size: usize,
settings: DatabaseSettings,
) -> Result<Database<MSG>>
pub fn create_in_memory( max_size: usize, settings: DatabaseSettings, ) -> Result<Database<MSG>>
Create a database residing entirely in memory. This is mostly useful for tests
Sourcepub fn load_status(&self) -> LoadingStatus
pub fn load_status(&self) -> LoadingStatus
Get the loading status of this database.
This gives insight into whether recovery occurred, for example.
Trait Implementations§
Auto Trait Implementations§
impl<MSG> Freeze for Database<MSG>
impl<MSG> !RefUnwindSafe for Database<MSG>
impl<MSG> Send for Database<MSG>where
MSG: Send,
impl<MSG> Sync for Database<MSG>where
MSG: Sync,
impl<MSG> Unpin for Database<MSG>where
MSG: Unpin,
impl<MSG> !UnwindSafe for Database<MSG>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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