Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SAFETY.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ durability model
* return None if last_lsn_in_batch >= self.max_lsn
* batch requirement set to last reservation base + inline len - 1
* reserve bumps
* TODO: Change this
* bump_atomic_lsn(&self.iobufs.max_reserved_lsn, reservation_lsn + inline_buf_len as Lsn - 1);

lock-free linearizability model
Expand Down
2 changes: 1 addition & 1 deletion src/pagecache/iobuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ impl IoBufs {
let max_header_stable_lsn = self.max_header_stable_lsn.clone();
guard.defer(move || {
trace!("bumping atomic header lsn to {}", stored_max_stable_lsn);
bump_atomic_lsn(&max_header_stable_lsn, stored_max_stable_lsn)
AtomicLsn::fetch_max(&max_header_stable_lsn, stored_max_stable_lsn, SeqCst)
});

guard.flush();
Expand Down
5 changes: 3 additions & 2 deletions src/pagecache/logger.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;

use super::{
arr_to_lsn, arr_to_u32, assert_usize, bump_atomic_lsn, decompress, header,
arr_to_lsn, arr_to_u32, assert_usize, decompress, header,
iobuf, lsn_to_arr, pread_exact, pread_exact_or_eof, roll_iobuf, u32_to_arr,
Arc, BasedBuf, DiskPtr, HeapId, IoBuf, IoBufs, LogKind, LogOffset, Lsn,
MessageKind, Reservation, Serialize, Snapshot, BATCH_MANIFEST_PID,
Expand Down Expand Up @@ -364,9 +364,10 @@ impl Log {
reservation_lid,
);

bump_atomic_lsn(
AtomicLsn::fetch_max(
&self.iobufs.max_reserved_lsn,
reservation_lsn + inline_buf_len as Lsn - 1,
SeqCst
);

let (heap_reservation, heap_id) = if over_heap_threshold {
Expand Down
18 changes: 1 addition & 17 deletions src/pagecache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,6 @@ where
usize::try_from(from).expect("lost data cast while converting to usize")
}

// TODO remove this when atomic fetch_max stabilizes in #48655
fn bump_atomic_lsn(atomic_lsn: &AtomicLsn, to: Lsn) {
let mut current = atomic_lsn.load(Acquire);
loop {
if current >= to {
return;
}
let last = atomic_lsn.compare_and_swap(current, to, SeqCst);
if last == current {
// we succeeded.
return;
}
current = last;
}
}

use std::convert::{TryFrom, TryInto};

#[inline]
Expand Down Expand Up @@ -992,7 +976,7 @@ impl PageCache {
snapshot::write_snapshot(&self.config, &snapshot)?;

// NB: this must only happen after writing the snapshot to disk
bump_atomic_lsn(&self.snapshot_min_lsn, stable_lsn_before);
AtomicLsn::fetch_max(&self.snapshot_min_lsn, stable_lsn_before, SeqCst);

// explicitly drop this to make it clear that it needs to
// be held for the duration of the snapshot operation.
Expand Down