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

fix: don't ignore add_user errors #640

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
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
32 changes: 16 additions & 16 deletions autopush-common/src/db/dual/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ impl DbClient for DualClientImpl {
debug_assert!(user.version.is_none());
user.version = Some(Uuid::new_v4());
if let Err(e) = self.primary.add_user(&user).await {
if matches!(e, DbError::Conditional) {
// User is being migrated underneath us.
// Try fetching the record from primary again,
// and back off if still not there.
let user = self.primary.get_user(uaid).await?;
// Possibly a higher number of these occur than
// expected, so sanity check that a user now
// exists
self.metrics
.incr_with_tags("database.already_migrated")
.with_tag("exists", &user.is_some().to_string())
.send();
if user.is_none() {
return Err(DbError::Backoff("Move in progress".to_owned()));
};
return Ok(user);
if !matches!(e, DbError::Conditional) {
return Err(e);
}
// User is being migrated underneath us. Try
// fetching the record from primary again, and back
// off if still not there.
let user = self.primary.get_user(uaid).await?;
// Possibly a higher number of these occur than
// expected, so sanity check that a user now exists
self.metrics
.incr_with_tags("database.already_migrated")
.with_tag("exists", &user.is_some().to_string())
.send();
if user.is_none() {
return Err(DbError::Backoff("Move in progress".to_owned()));
};
return Ok(user);
};
self.metrics.incr_with_tags("database.migrate").send();
let channels = self.secondary.get_channels(uaid).await?;
Expand Down