Database

Struct Database 

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

Source

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.

Source

pub fn sync_all(&mut self) -> Result<()>

Sync all writes to disk

This will update both file data and file metadata

Source

pub fn begin_session(&self) -> Result<DatabaseSession<'_, MSG>>

Begin a readonly database session.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn count_messages(&self) -> usize

Return the number of messages in the system. This method returns 0 on error.

Source

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

Source

pub fn load_status(&self) -> LoadingStatus

Get the loading status of this database.

This gives insight into whether recovery occurred, for example.

Trait Implementations§

Source§

impl<T: Message> Debug for Database<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<MSG: Message> Drop for Database<MSG>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

Source§

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more