-
Notifications
You must be signed in to change notification settings - Fork 38
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
fix: Retry writing lease when error code 429 (too many requests). #2773
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ use protogen::gen::metastore::storage; | |
use protogen::metastore::types::storage::{LeaseInformation, LeaseState}; | ||
use tokio::sync::{mpsc, oneshot}; | ||
use tokio::task::JoinHandle; | ||
use tracing::{debug_span, error, Instrument}; | ||
use tracing::{debug, debug_span, error, Instrument}; | ||
use uuid::Uuid; | ||
|
||
use crate::storage::{Result, SingletonStorageObject, StorageError, StorageObject}; | ||
|
@@ -339,11 +339,16 @@ impl LeaseRenewer { | |
Ok(lease) | ||
} | ||
|
||
async fn write_lease(&self, lease: LeaseInformation) -> Result<()> { | ||
async fn try_write_lease(&self, lease: LeaseInformation) -> Result<()> { | ||
// Write to storage. | ||
let proto: storage::LeaseInformation = lease.into(); | ||
let mut bs = BytesMut::new(); | ||
proto.encode(&mut bs)?; | ||
|
||
// TODO: Generate a new temp path everytime? This will definitely avoid | ||
// the rate limitation over over-writing the same object here and might | ||
// just be enough to delay the "renaming" process so we don't exceed | ||
// the limit there as well. | ||
self.store.put(&self.tmp_path, bs.freeze()).await?; | ||
|
||
// Rename... | ||
|
@@ -360,6 +365,42 @@ impl LeaseRenewer { | |
|
||
Ok(()) | ||
} | ||
|
||
async fn write_lease(&self, lease: LeaseInformation) -> Result<()> { | ||
let mut final_err = None; | ||
|
||
for num_try in 0..3 { | ||
if let Err(err) = self.try_write_lease(lease.clone()).await { | ||
final_err = Some(err.to_string()); | ||
|
||
if let StorageError::ObjectStore(err) = &err { | ||
if let ObjectStoreError::Generic { store, source } = err { | ||
let source = source.to_string(); | ||
// Error code 429 is not handled by object_store's retry | ||
// configuration. We should maybe upstream to catch this | ||
// and retry properly. | ||
if store == &"GCS" && source.contains("429") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I worry about the fragility of this little block, (in terms of the matching/destructuring of the error as well as the constants/string parsing of the error. |
||
debug!(%err, %num_try, "retrying writing the lease"); | ||
// Sleep for some time (half the time of when the | ||
// request wouldn't throttle) before trying to write | ||
// the lease. | ||
// | ||
// See: https://cloud.google.com/storage/docs/objects#immutability | ||
tokio::time::sleep(Duration::from_millis(500)).await; | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
return Err(err); | ||
} else { | ||
return Ok(()); | ||
} | ||
} | ||
|
||
// Return the original error if failed after retries. | ||
Err(StorageError::LeaseWriteError(final_err.unwrap())) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
|
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
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.
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.
@scsmithr how do you feel about this?
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.
I think that'd be reasonable, we can just generate a temp path every time. For some reason, I had read the original error message thinking that we were errorring on writing to the actual lease, and not the temp. But if it's just the temp, then this seems good.
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.
I merged this PR before reading this. Will open another to add this as well.