Skip to content

Commit f093799

Browse files
committed
store: Asyncify advisory_lock::Scope::try_lock
1 parent 408f0ed commit f093799

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

store/postgres/src/advisory_lock.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ struct Scope {
3131
impl Scope {
3232
/// Try to lock the deployment in this scope with the given id. Return
3333
/// `true` if we got the lock, and `false` if it is already locked.
34-
fn try_lock(&self, conn: &mut PgConnection, id: DeploymentId) -> Result<bool, StoreError> {
34+
async fn try_lock(
35+
&self,
36+
conn: &mut PgConnection,
37+
id: DeploymentId,
38+
) -> Result<bool, StoreError> {
3539
#[derive(QueryableByName)]
3640
struct Locked {
3741
#[diesel(sql_type = Bool)]
@@ -111,11 +115,11 @@ pub(crate) fn unlock_copying(conn: &mut PgConnection, dst: &Site) -> Result<(),
111115
/// simultaneously. Return `true` if we got the lock, and `false` if we did
112116
/// not. You don't want to use this directly. Instead, use
113117
/// `deployment::with_lock`
114-
pub(crate) fn lock_deployment_session(
118+
pub(crate) async fn lock_deployment_session(
115119
conn: &mut PgConnection,
116120
site: &Site,
117121
) -> Result<bool, StoreError> {
118-
WRITE.try_lock(conn, site.id)
122+
WRITE.try_lock(conn, site.id).await
119123
}
120124

121125
/// Release the lock acquired with `lock_deployment_session`.
@@ -128,8 +132,11 @@ pub(crate) fn unlock_deployment_session(
128132

129133
/// Try to take the lock used to prevent two prune operations from running at the
130134
/// same time. Return `true` if we got the lock, and `false` otherwise.
131-
pub(crate) fn try_lock_pruning(conn: &mut PgConnection, site: &Site) -> Result<bool, StoreError> {
132-
PRUNE.try_lock(conn, site.id)
135+
pub(crate) async fn try_lock_pruning(
136+
conn: &mut PgConnection,
137+
site: &Site,
138+
) -> Result<bool, StoreError> {
139+
PRUNE.try_lock(conn, site.id).await
133140
}
134141

135142
pub(crate) fn unlock_pruning(conn: &mut PgConnection, site: &Site) -> Result<(), StoreError> {

store/postgres/src/deployment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ where
13921392
F: AsyncFnOnce(&mut PgConnection) -> Result<R, StoreError>,
13931393
{
13941394
let mut backoff = ExponentialBackoff::new(Duration::from_millis(100), Duration::from_secs(15));
1395-
while !advisory_lock::lock_deployment_session(conn, site)? {
1395+
while !advisory_lock::lock_deployment_session(conn, site).await? {
13961396
backoff.sleep();
13971397
}
13981398
let res = f(conn).await;

store/postgres/src/deployment_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ impl DeploymentStore {
894894
// We lock pruning for this deployment to make sure that if the
895895
// deployment is reassigned to another node, that node won't
896896
// kick off a pruning run while this node might still be pruning
897-
if advisory_lock::try_lock_pruning(conn, &site)? {
897+
if advisory_lock::try_lock_pruning(conn, &site).await? {
898898
let res = do_prune(store, conn, site.cheap_clone(), cancel, req, reporter).await;
899899
advisory_lock::unlock_pruning(conn, &site)?;
900900
res

0 commit comments

Comments
 (0)