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

timeout and wait_latch refactor #63

Merged
merged 2 commits into from
Feb 26, 2024
Merged

timeout and wait_latch refactor #63

merged 2 commits into from
Feb 26, 2024

Conversation

ChuckHend
Copy link
Member

No description provided.

@ChuckHend ChuckHend marked this pull request as ready for review February 26, 2024 21:29
Comment on lines +47 to +70
let mut ext_ready: bool = false;
let mut wait_duration: Duration = Duration::from_secs(6);
while BackgroundWorker::wait_latch(Some(wait_duration)) {
if !ext_ready {
warning!("pg-vectorize: waiting for CREATE EXTENSION vectorize CASCADE;");
runtime.block_on(async {
ext_ready = ready(&conn).await;
});
// return to wait_latch if extension is not ready
continue;
}

let _worker_ran: Result<()> = runtime.block_on(async {
// continue to poll without pauses
let start = Instant::now();
let duration = Duration::from_secs(6);
// return control to wait_latch() after `duration` has elapsed
while start.elapsed() < duration {
match run_worker(queue.clone(), &conn, VECTORIZE_QUEUE).await {
// sleep for 2 seconds when no messages in the queue
Ok(None) => tokio::time::sleep(Duration::from_secs(2)).await,
// sleep for 6 seconds when there is an error reading messages
Err(_) => tokio::time::sleep(Duration::from_secs(6)).await,
// continue to poll where there was a message consumed
Ok(Some(_)) => continue,
}
}
Ok(())
wait_duration = runtime.block_on(async {
let wait_dur = match run_worker(queue.clone(), &conn, VECTORIZE_QUEUE).await {
// no messages in queue, so wait 2 seconds
Ok(None) => 2000,
// wait 10 seconds between polls when there is a failure
Err(_) => 10000,
// when there was a successfully processed message from queue,
// only wait 10ms before checking for more messages
// this allows postgres to kill or restart the bgw in between messages
Ok(Some(_)) => 10,
};
Duration::from_millis(wait_dur)
Copy link
Member Author

Choose a reason for hiding this comment

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

@ChuckHend ChuckHend changed the title use same timeout on all calls use same timeout on all calls, refactor bgw wait latch interaction Feb 26, 2024
@ChuckHend ChuckHend merged commit 08e2d96 into main Feb 26, 2024
6 checks passed
@ChuckHend ChuckHend deleted the patch/timeouts branch February 26, 2024 21:45
@ChuckHend ChuckHend changed the title use same timeout on all calls, refactor bgw wait latch interaction timeout and wait_latch refactor Feb 26, 2024
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.

2 participants