Skip to content

Commit 8a8b428

Browse files
committed
store: Do not prune deployments that are being copied
Pruning during copying can cause the copy to fail because data it needs disappears during copying.
1 parent 541d169 commit 8a8b428

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

store/postgres/src/copy.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ table! {
9494
}
9595
}
9696

97+
/// Return `true` if the site is the source of a copy operation. The copy
98+
/// operation might be just queued or in progress already
99+
pub fn is_source(conn: &mut PgConnection, site: &Site) -> Result<bool, StoreError> {
100+
use active_copies as ac;
101+
102+
select(diesel::dsl::exists(
103+
ac::table
104+
.filter(ac::src.eq(site.id))
105+
.filter(ac::cancelled_at.is_null()),
106+
))
107+
.get_result::<bool>(conn)
108+
.map_err(StoreError::from)
109+
}
110+
97111
#[derive(Copy, Clone, PartialEq, Eq)]
98112
pub enum Status {
99113
Finished,

store/postgres/src/deployment_store.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use crate::primary::DeploymentId;
5555
use crate::relational::index::{CreateIndex, IndexList, Method};
5656
use crate::relational::{Layout, LayoutCache, SqlName, Table};
5757
use crate::relational_queries::FromEntityData;
58-
use crate::{advisory_lock, catalog, retry};
58+
use crate::{advisory_lock, catalog, copy, retry};
5959
use crate::{connection_pool::ConnectionPool, detail};
6060
use crate::{dynds, primary::Site};
6161

@@ -1234,6 +1234,14 @@ impl DeploymentStore {
12341234
site: Arc<Site>,
12351235
req: PruneRequest,
12361236
) -> Result<(), StoreError> {
1237+
let mut conn = store.get_conn()?;
1238+
if copy::is_source(&mut conn, &site)? {
1239+
debug!(
1240+
logger,
1241+
"Skipping pruning since this deployment is being copied"
1242+
);
1243+
return Ok(());
1244+
}
12371245
let logger2 = logger.cheap_clone();
12381246
retry::forever_async(&logger2, "prune", move || {
12391247
let store = store.cheap_clone();

0 commit comments

Comments
 (0)