pub struct MultiLog { /* private fields */ }Expand description
A MultiLog contains multiple [Log]s with a centric metadata file.
Metadata is “frozen” and changes to the metadata on the filesystem are not
visible to Logs until MultiLog::lock gets called. The only way to write
the centric metadata back to the filesystem is MultiLog::write_meta.
Note: MultiLog::sync calls the above functions and is another way to
exchange data with the filesystem.
[Log]s will be accessible via indexing. For example, multilog[0]
accesses the first [Log]. [Log]s can also be moved out of this
struct by MultiLog::detach_logs.
MultiLog makes sure the data consistency on disk but not always
in memory. In case MultiLog::write_meta is not called or is not
successful, but [Log::sync] was called. The data in [Log] might
be rewritten by other processes, breaking the [Log]!
Implementations§
Source§impl MultiLog
impl MultiLog
Sourcepub fn lock(&mut self) -> Result<LockGuard>
pub fn lock(&mut self) -> Result<LockGuard>
Lock the MultiLog directory for writing.
After taking the lock, metadata will be reloaded so [Log]s can see the
latest metadata on disk and do sync() accordingly.
Once everything is done, use MultiLog::write_meta to persistent the
changed metadata.
Sourcepub fn write_meta(&mut self, lock: &LockGuard) -> Result<()>
pub fn write_meta(&mut self, lock: &LockGuard) -> Result<()>
Write meta to disk so they become visible to other processes.
A lock must be provided to prove that there is no race condition.
The lock is usually obtained via lock().
Sourcepub fn version(&self) -> (u64, u64)
pub fn version(&self) -> (u64, u64)
Return the version in (epoch, length) form.
Version gets updated on write_meta.
The version is maintained exclusively by indexedlog and cannot be
changed directly via public APIs. Appending data bumps length.
Rewriting data changes epoch.
See also crate::log::Log::version.