-
Notifications
You must be signed in to change notification settings - Fork 31
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ChuckHend
requested review from
DarrenBaldwin07 and
samay-sharma
as code owners
February 26, 2024 21:29
ChuckHend
commented
Feb 26, 2024
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ChuckHend
changed the title
use same timeout on all calls
use same timeout on all calls, refactor bgw wait latch interaction
Feb 26, 2024
nhudson
approved these changes
Feb 26, 2024
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.