Skip to content

Commit

Permalink
Fix full_access_guard in start_snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
petuhovskiy committed Jun 20, 2024
1 parent d04eb92 commit 52646b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions safekeeper/src/pull_timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl FullAccessTimeline {
ar: &mut tokio_tar::Builder<W>,
) -> Result<SnapshotContext> {
let mut shared_state = self.write_shared_state().await;
let wal_seg_size = shared_state.get_wal_seg_size();

let cf_path = self.get_timeline_dir().join(CONTROL_FILE_NAME);
let mut cf = File::open(cf_path).await?;
Expand All @@ -181,11 +182,11 @@ impl FullAccessTimeline {
// elected message
bail!("snapshot is called on uninitialized timeline");
}
let from_segno = from_lsn.segment_number(shared_state.get_wal_seg_size());
let from_segno = from_lsn.segment_number(wal_seg_size);
let term = shared_state.sk.get_term();
let last_log_term = shared_state.sk.get_last_log_term();
let flush_lsn = shared_state.sk.flush_lsn();
let upto_segno = flush_lsn.segment_number(shared_state.get_wal_seg_size());
let upto_segno = flush_lsn.segment_number(wal_seg_size);
// have some limit on max number of segments as a sanity check
const MAX_ALLOWED_SEGS: u64 = 1000;
let num_segs = upto_segno - from_segno + 1;
Expand All @@ -206,14 +207,17 @@ impl FullAccessTimeline {
}
shared_state.wal_removal_on_hold = true;

// Drop shared_state to release the lock, before calling full_access_guard().
drop(shared_state);

let tli_copy = self.full_access_guard().await?;
let bctx = SnapshotContext {
from_segno,
upto_segno,
term,
last_log_term,
flush_lsn,
wal_seg_size: shared_state.get_wal_seg_size(),
wal_seg_size,
tli: tli_copy,
};

Expand Down
1 change: 1 addition & 0 deletions safekeeper/src/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ impl Timeline {
/// while someone is holding FullAccessTimeline guard.
///
/// NB: don't use this function from timeline_manager, it will deadlock.
/// Don't use this function while holding shared_state lock.
pub async fn full_access_guard(self: &Arc<Self>) -> Result<FullAccessTimeline> {
if self.is_cancelled() {
bail!(TimelineError::Cancelled(self.ttid));
Expand Down

0 comments on commit 52646b0

Please sign in to comment.