Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -144,18 +144,22 @@ impl BackendEdge for PostgresBackend {
|
|||||||
|
|
||||||
let res = match res {
|
let res = match res {
|
||||||
Ok(res) => res,
|
Ok(res) => res,
|
||||||
Err(e) => match &e {
|
Err(e) => {
|
||||||
sqlx::Error::Database(database_error) => {
|
self.revision.store(0, Ordering::Relaxed);
|
||||||
if database_error.is_unique_violation() {
|
|
||||||
anyhow::bail!("update conflict: another leader holds lock")
|
match &e {
|
||||||
} else {
|
sqlx::Error::Database(database_error) => {
|
||||||
|
if database_error.is_unique_violation() {
|
||||||
|
anyhow::bail!("update conflict: another leader holds lock")
|
||||||
|
} else {
|
||||||
|
anyhow::bail!(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
anyhow::bail!(e);
|
anyhow::bail!(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
}
|
||||||
anyhow::bail!(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
@@ -170,6 +174,8 @@ impl BackendEdge for PostgresBackend {
|
|||||||
// Only update our local revision if the update succeeded with our expected value
|
// Only update our local revision if the update succeeded with our expected value
|
||||||
self.revision.store(rec.revision as u64, Ordering::Relaxed);
|
self.revision.store(rec.revision as u64, Ordering::Relaxed);
|
||||||
} else {
|
} else {
|
||||||
|
self.revision.store(0, Ordering::Relaxed);
|
||||||
|
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"update conflict: expected value={}, revision={}, got value={}, revision={}",
|
"update conflict: expected value={}, revision={}, got value={}, revision={}",
|
||||||
val.0.to_string(),
|
val.0.to_string(),
|
||||||
@@ -207,6 +213,8 @@ impl BackendEdge for PostgresBackend {
|
|||||||
.await
|
.await
|
||||||
.context("failed to release lock, it will expire naturally")?;
|
.context("failed to release lock, it will expire naturally")?;
|
||||||
|
|
||||||
|
self.revision.store(0, Ordering::Relaxed);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user