Struct pagecache::Log
[−]
[src]
pub struct Log { /* fields omitted */ }
A sequential store which allows users to create reservations placed at known log offsets, used for writing persistent data structures that need to know where to find persisted bits in the future.
Working with Log
let conf = pagecache::ConfigBuilder::new() .temporary(true) .segment_mode(pagecache::SegmentMode::Linear) .build(); let log = pagecache::Log::start_raw_log(conf).unwrap(); let (first_lsn, _first_offset) = log.write(b"1".to_vec()).unwrap(); log.write(b"22".to_vec()).unwrap(); log.write(b"333".to_vec()).unwrap(); // stick an abort in the middle, which should not be returned let res = log.reserve(b"never_gonna_hit_disk".to_vec()).unwrap(); res.abort().unwrap(); log.write(b"4444".to_vec()); let (last_lsn, _last_offset) = log.write(b"55555".to_vec()).unwrap(); log.make_stable(last_lsn).unwrap(); let mut iter = log.iter_from(first_lsn); assert_eq!(iter.next().unwrap().2, b"1".to_vec()); assert_eq!(iter.next().unwrap().2, b"22".to_vec()); assert_eq!(iter.next().unwrap().2, b"333".to_vec()); assert_eq!(iter.next().unwrap().2, b"4444".to_vec()); assert_eq!(iter.next().unwrap().2, b"55555".to_vec()); assert_eq!(iter.next(), None);
Methods
impl Log
[src]
pub fn start<R>(config: Config, snapshot: Snapshot<R>) -> CacheResult<Log, ()>
[src]
Start the log, open or create the configured file, and optionally start the periodic buffer flush thread.
pub fn start_raw_log(config: Config) -> CacheResult<Log, ()>
[src]
Starts a log for use without a materializer.
pub fn flush(&self) -> CacheResult<(), ()>
[src]
Flushes any pending IO buffers to disk to ensure durability.
pub fn reserve(&self, buf: Vec<u8>) -> CacheResult<Reservation, ()>
[src]
Reserve space in the log for a pending linearized operation.
pub fn write(&self, buf: Vec<u8>) -> CacheResult<(Lsn, LogID), ()>
[src]
Write a buffer into the log. Returns the log sequence number and the file offset of the write.
pub fn iter_from(&self, lsn: Lsn) -> LogIter
[src]
Return an iterator over the log, starting with a specified offset.
pub fn read(&self, lsn: Lsn, lid: LogID) -> CacheResult<LogRead, ()>
[src]
read a buffer from the disk
pub fn stable_offset(&self) -> Lsn
[src]
returns the current stable offset written to disk
pub fn make_stable(&self, lsn: Lsn) -> CacheResult<(), ()>
[src]
blocks until the specified log sequence number has been made stable on disk