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

periodic checkpoint: Don't checkpoint at startup #1883

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

haaawk
Copy link
Contributor

@haaawk haaawk commented Dec 16, 2024

Currently there's no way to disable checkpoint but one can emulate it by enabling periodic checkpoint with really long interval between checkpoints.

Unfortunately, current implementation runs checkpoint first before waiting for the interval to pass.

This change makes the periodic checkpoint to first wait and only after that checkpoint.

Currently there's no way to disable checkpoint but one can
emulate it by enabling periodic checkpoint with really long
interval between checkpoints.

Unfortunately, current implementation runs checkpoint first
before waiting for the interval to pass.

This change makes the periodic checkpoint to first wait
and only after that checkpoint.

Signed-off-by: Piotr Jastrzebski <[email protected]>
@@ -368,6 +368,8 @@ where
tracing::info!("setting checkpoint interval to {:?}", period);
let mut interval = interval(period);
interval.set_missed_tick_behavior(MissedTickBehavior::Delay);
// Make sure that we don't checkpoint immediately after startup
interval.tick().await;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand the patch, unfortunately. If you set interval to be really long, why is it checkpointing immediately?

The loop looks as follows:

        if let Some(retry) = retry.take() {
            if retry.is_zero() {
                tracing::warn!("database was not set in WAL journal mode");
                return Ok(());
            }
            sleep(retry).await;
        } else {
            interval.tick().await;
        }

When you call run_periodic_checkpoint() you should always end up calling interval.tick().await, which should be identical to what your patch is doing. (Except that in your patch you wait two times the interval.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never, mind Tokio's documentation explains this -- arguably confusing -- behavior:

The first tick completes immediately.

https://docs.rs/tokio/latest/tokio/time/fn.interval.html

Copy link
Member

@avinassh avinassh Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should document this in the code too with the same link

@penberg penberg added this pull request to the merge queue Dec 16, 2024
Merged via the queue into main with commit 21861a6 Dec 16, 2024
19 checks passed
@penberg penberg deleted the fix_interval_checkpoint branch December 16, 2024 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants