Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
petuhovskiy committed Jun 24, 2024
1 parent 4761233 commit 0950055
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions safekeeper/src/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'a> Drop for WriteGuardSharedState<'a> {

pub enum StateSK {
Loaded(SafeKeeper<control_file::FileStorage, wal_storage::PhysicalStorage>),
Offloaded(TimelineState<control_file::FileStorage>),
Offloaded(Box<TimelineState<control_file::FileStorage>>),
Empty,
}

Expand Down Expand Up @@ -271,7 +271,7 @@ impl StateSK {
fn take_state(self) -> TimelineState<control_file::FileStorage> {
match self {
StateSK::Loaded(sk) => sk.state,
StateSK::Offloaded(state) => state,
StateSK::Offloaded(state) => *state,
StateSK::Empty => unreachable!(),
}
}
Expand Down Expand Up @@ -345,7 +345,9 @@ impl SharedState {
conf.my_id,
)?)
}
EvictionState::Offloaded(_) => StateSK::Offloaded(TimelineState::new(control_store)),
EvictionState::Offloaded(_) => {
StateSK::Offloaded(Box::new(TimelineState::new(control_store)))
}
};

Ok(Self {
Expand Down Expand Up @@ -1031,7 +1033,7 @@ impl ManagerTimeline {
// now we can switch shared.sk to Offloaded, shouldn't fail
let prev_sk = std::mem::replace(&mut shared.sk, StateSK::Empty);
let cfile_state = prev_sk.take_state();
shared.sk = StateSK::Offloaded(cfile_state);
shared.sk = StateSK::Offloaded(Box::new(cfile_state));

Ok(())
}
Expand Down
5 changes: 5 additions & 0 deletions safekeeper/src/timeline_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@ impl AtomicStatus {
}

pub fn load(&self, order: std::sync::atomic::Ordering) -> Status {
// Safety: This line of code uses `std::mem::transmute` to reinterpret the loaded value as `Status`.
// It is safe to use `transmute` in this context because `Status` is a repr(usize) enum,
// which means it has the same memory layout as usize.
// However, it is important to ensure that the loaded value is a valid variant of `Status`,
// otherwise, the behavior will be undefined.
unsafe { std::mem::transmute(self.inner.load(order)) }
}

Expand Down

0 comments on commit 0950055

Please sign in to comment.