Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage/postgres: Always send keepalives for the replication slot with a tokio::interval #30631

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions src/storage/src/source/postgres/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,12 @@ async fn raw_stream<'a>(
.unwrap();
let feedback_interval = timeout.checked_div(2).unwrap();

// We use this timer to make sure we're always sending a standby update, regardless
// of whether or not the upstream sends us periodic status updates.
let mut feedback_timer = tokio::time::interval(feedback_interval);
// 'Delay' ensures we always tick at least 'feedback_interval'.
feedback_timer.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);

// Postgres will return all transactions that commit *at or after* after the provided LSN,
// following the timely upper semantics.
let lsn = PgLsn::from(resume_lsn.offset);
Expand Down Expand Up @@ -727,6 +733,15 @@ async fn raw_stream<'a>(
Err(err) => Err(err.into()),
_ => Err(TransientError::UnknownReplicationMessage),
},
instant = (&mut feedback_timer).tick() => {
trace!(
"timely-{} ({}) ticked keepalive at {:?}",
config.worker_id,
config.id,
instant,
);
Ok(true)
},
Some(upper) = uppers.next() => match upper.into_option() {
Some(lsn) => {
last_committed_upper = std::cmp::max(last_committed_upper, lsn);
Expand Down Expand Up @@ -764,6 +779,8 @@ async fn raw_stream<'a>(
.standby_status_update(lsn, lsn, lsn, ts, 0)
.await?;
last_feedback = Instant::now();
// Reset our timer so we don't spam the upstream with standby updates.
feedback_timer.reset();
}
}
});
Expand Down