Struct spacetimedb::db::message_log::MessageLog
source · pub struct MessageLog {
pub open_segment_max_offset: u64,
/* private fields */
}Fields§
§open_segment_max_offset: u64Implementations§
source§impl MessageLog
impl MessageLog
pub fn open(path: impl AsRef<Path>) -> Result<Self, OpenError>
pub fn options() -> OpenOptions
pub fn append(&mut self, message: impl AsRef<[u8]>) -> Result<()>
pub fn flush(&mut self) -> Result<()>
pub fn sync_all(&mut self) -> Result<()>
pub fn size(&self) -> u64
pub fn max_segment_size(&self) -> u64
sourcepub fn total_segments(&self) -> usize
pub fn total_segments(&self) -> usize
Total number of segments currently comprising the log.
Equivalent to self.segments().count(), but more efficient.
pub fn get_root(&self) -> PathBuf
sourcepub fn segments(&self) -> Segments ⓘ
pub fn segments(&self) -> Segments ⓘ
Obtains an iterator over all segments in the log, in the order they were created.
The iterator represents a snapshot of the log at the time this method is called. That is, segments created after the method returns will not appear in the iteration. The last segment yielded by the iterator may be incomplete (i.e. still be appended to).
See also: MessageLog::segments_from
sourcepub fn segments_from(&self, offset: u64) -> Segments ⓘ
pub fn segments_from(&self, offset: u64) -> Segments ⓘ
Obtains an iterator over all segments containing messages equal to or
newer than offset.
offset counts all messages (not: bytes) in the log, starting from
zero.
Note that the first segment yielded by the iterator may contain messages with an offset smaller than the argument, as segments do not currently support slicing.
If offset is larger than the offset of any message already written to
the log, an empty iterator is returned.
The iterator represents a snapshot of the log at the time this method is called. That is, segments created after the method returns will not appear in the iteration. The last segment yielded by the iterator may be incomplete (i.e. still be appended to).
sourcepub fn reset_to(&mut self, offset: u64) -> Result<()>
pub fn reset_to(&mut self, offset: u64) -> Result<()>
Truncate the log to message offset offset.
This method destructively modifies the on-disk log!
After reset_to returns successfully, the message offset will be the
last message in the log. That is:
reset_to(0)will leave exactly zero messages in the logreset_to(1)will leave exactly one message in the logreset_to(n)will leavemin(n, open_segment_max_offset)messages in the log
Segments with an offset range greater than offset will be removed.
Note that this may interfere with readers which operate on a snapshot
of the internal state of MessageLog (i.e. the Segments iterator).
Setting the new offset (i.e. self.open_segment_max_offset) is
not atomic, because MessageLog operates on multiple segment
files internally.
For example, the given offset may require some number of segment files
at the end of the log to be deleted. Deleting a file could fail, in
which case this method returns an error. The new offset in this case
will be the max offset of the segment which could not be deleted, but
potentially be greater than offset.
However, file operations (unlink, ftruncate) are guaranteed to be
atomic, to the extent required by POSIX.