@@ -46,8 +46,10 @@ pub trait MakeNamespace: Sync + Send + 'static {
46
46
allow_creation : bool ,
47
47
) -> crate :: Result < Namespace < Self :: Database > > ;
48
48
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 < ( ) > ;
51
53
}
52
54
53
55
/// Creates new primary `Namespace`
@@ -75,24 +77,26 @@ impl MakeNamespace for PrimaryNamespaceMaker {
75
77
Namespace :: new_primary ( & self . config , name, restore_option, allow_creation) . await
76
78
}
77
79
78
- async fn destroy ( & self , namespace : & Bytes ) -> crate :: Result < ( ) > {
80
+ async fn destroy ( & self , namespace : & Bytes , prune_all : bool ) -> crate :: Result < ( ) > {
79
81
let ns_path = self
80
82
. config
81
83
. base_path
82
84
. join ( "dbs" )
83
85
. join ( std:: str:: from_utf8 ( namespace) . unwrap ( ) ) ;
84
86
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 ?;
93
96
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
+ }
96
100
}
97
101
98
102
tokio:: fs:: remove_dir_all ( ns_path) . await ?;
@@ -131,7 +135,7 @@ impl MakeNamespace for ReplicaNamespaceMaker {
131
135
Namespace :: new_replica ( & self . config , name, allow_creation) . await
132
136
}
133
137
134
- async fn destroy ( & self , namespace : & Bytes ) -> crate :: Result < ( ) > {
138
+ async fn destroy ( & self , namespace : & Bytes , _prune_all : bool ) -> crate :: Result < ( ) > {
135
139
let ns_path = self
136
140
. config
137
141
. base_path
@@ -163,7 +167,7 @@ impl<M: MakeNamespace> NamespaceStore<M> {
163
167
}
164
168
165
169
// destroy on-disk database
166
- self . make_namespace . destroy ( & namespace) . await ?;
170
+ self . make_namespace . destroy ( & namespace, true ) . await ?;
167
171
168
172
tracing:: info!(
169
173
"destroyed namespace: {}" ,
@@ -189,7 +193,7 @@ impl<M: MakeNamespace> NamespaceStore<M> {
189
193
}
190
194
191
195
// destroy on-disk database
192
- self . make_namespace . destroy ( & namespace) . await ?;
196
+ self . make_namespace . destroy ( & namespace, false ) . await ?;
193
197
let ns = self
194
198
. make_namespace
195
199
. create ( namespace. clone ( ) , restore_option, true )
0 commit comments