Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit c024b76

Browse files
authored
added namespace destroy param to configure if remote resources should also be destroyed (#657)
1 parent 125e7a1 commit c024b76

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

sqld/src/namespace.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ pub trait MakeNamespace: Sync + Send + 'static {
4646
allow_creation: bool,
4747
) -> crate::Result<Namespace<Self::Database>>;
4848

49-
/// Destroy all resources associated with `namespace`
50-
async fn destroy(&self, namespace: &Bytes) -> crate::Result<()>;
49+
/// Destroy all resources associated with `namespace`.
50+
/// When `prune_all` is false, remove only files from local disk.
51+
/// When `prune_all` is true remove local database files as well as remote backup.
52+
async fn destroy(&self, namespace: &Bytes, prune_all: bool) -> crate::Result<()>;
5153
}
5254

5355
/// Creates new primary `Namespace`
@@ -75,24 +77,26 @@ impl MakeNamespace for PrimaryNamespaceMaker {
7577
Namespace::new_primary(&self.config, name, restore_option, allow_creation).await
7678
}
7779

78-
async fn destroy(&self, namespace: &Bytes) -> crate::Result<()> {
80+
async fn destroy(&self, namespace: &Bytes, prune_all: bool) -> crate::Result<()> {
7981
let ns_path = self
8082
.config
8183
.base_path
8284
.join("dbs")
8385
.join(std::str::from_utf8(namespace).unwrap());
8486

85-
if let Some(ref options) = self.config.bottomless_replication {
86-
let options = make_bottomless_options(options, namespace);
87-
let replicator = bottomless::replicator::Replicator::with_options(
88-
ns_path.join("data").to_str().unwrap(),
89-
options,
90-
)
91-
.await?;
92-
let delete_all = replicator.delete_all(None).await?;
87+
if prune_all {
88+
if let Some(ref options) = self.config.bottomless_replication {
89+
let options = make_bottomless_options(options, namespace);
90+
let replicator = bottomless::replicator::Replicator::with_options(
91+
ns_path.join("data").to_str().unwrap(),
92+
options,
93+
)
94+
.await?;
95+
let delete_all = replicator.delete_all(None).await?;
9396

94-
// perform hard deletion in the background
95-
tokio::spawn(delete_all.commit());
97+
// perform hard deletion in the background
98+
tokio::spawn(delete_all.commit());
99+
}
96100
}
97101

98102
tokio::fs::remove_dir_all(ns_path).await?;
@@ -131,7 +135,7 @@ impl MakeNamespace for ReplicaNamespaceMaker {
131135
Namespace::new_replica(&self.config, name, allow_creation).await
132136
}
133137

134-
async fn destroy(&self, namespace: &Bytes) -> crate::Result<()> {
138+
async fn destroy(&self, namespace: &Bytes, _prune_all: bool) -> crate::Result<()> {
135139
let ns_path = self
136140
.config
137141
.base_path
@@ -163,7 +167,7 @@ impl<M: MakeNamespace> NamespaceStore<M> {
163167
}
164168

165169
// destroy on-disk database
166-
self.make_namespace.destroy(&namespace).await?;
170+
self.make_namespace.destroy(&namespace, true).await?;
167171

168172
tracing::info!(
169173
"destroyed namespace: {}",
@@ -189,7 +193,7 @@ impl<M: MakeNamespace> NamespaceStore<M> {
189193
}
190194

191195
// destroy on-disk database
192-
self.make_namespace.destroy(&namespace).await?;
196+
self.make_namespace.destroy(&namespace, false).await?;
193197
let ns = self
194198
.make_namespace
195199
.create(namespace.clone(), restore_option, true)

0 commit comments

Comments
 (0)