@@ -69,6 +69,12 @@ impl Default for NamespaceName {
69
69
}
70
70
}
71
71
72
+ impl AsRef < str > for NamespaceName {
73
+ fn as_ref ( & self ) -> & str {
74
+ self . as_str ( )
75
+ }
76
+ }
77
+
72
78
impl NamespaceName {
73
79
pub fn from_string ( s : String ) -> crate :: Result < Self > {
74
80
Self :: validate ( & s) ?;
@@ -161,7 +167,7 @@ pub trait MakeNamespace: Sync + Send + 'static {
161
167
timestamp : Option < NaiveDateTime > ,
162
168
) -> crate :: Result < Namespace < Self :: Database > > ;
163
169
164
- fn exists ( & self , namespace : & NamespaceName ) -> bool ;
170
+ async fn exists ( & self , namespace : & NamespaceName ) -> bool ;
165
171
}
166
172
167
173
/// Creates new primary `Namespace`
@@ -274,9 +280,32 @@ impl MakeNamespace for PrimaryNamespaceMaker {
274
280
Ok ( ns)
275
281
}
276
282
277
- fn exists ( & self , namespace : & NamespaceName ) -> bool {
283
+ async fn exists ( & self , namespace : & NamespaceName ) -> bool {
278
284
let ns_path = self . config . base_path . join ( "dbs" ) . join ( namespace. as_str ( ) ) ;
279
- ns_path. try_exists ( ) . unwrap_or ( false )
285
+ if let Ok ( true ) = ns_path. try_exists ( ) {
286
+ return true ;
287
+ }
288
+
289
+ if let Some ( replication_options) = self . config . bottomless_replication . as_ref ( ) {
290
+ tracing:: info!( "Bottomless: {:?}" , replication_options) ;
291
+ match bottomless:: replicator:: Replicator :: has_backup_of ( namespace, replication_options)
292
+ . await
293
+ {
294
+ Ok ( true ) => {
295
+ tracing:: debug!( "Bottomless: Backup found" ) ;
296
+ return true ;
297
+ }
298
+ Ok ( false ) => {
299
+ tracing:: debug!( "Bottomless: No backup found" ) ;
300
+ }
301
+ Err ( err) => {
302
+ tracing:: debug!( "Bottomless: Error checking backup: {}" , err) ;
303
+ }
304
+ }
305
+ } else {
306
+ tracing:: debug!( "Bottomless: No backup configured" ) ;
307
+ }
308
+ false
280
309
}
281
310
}
282
311
@@ -331,7 +360,7 @@ impl MakeNamespace for ReplicaNamespaceMaker {
331
360
return Err ( ForkError :: ForkReplica . into ( ) ) ;
332
361
}
333
362
334
- fn exists ( & self , namespace : & NamespaceName ) -> bool {
363
+ async fn exists ( & self , namespace : & NamespaceName ) -> bool {
335
364
let ns_path = self . config . base_path . join ( "dbs" ) . join ( namespace. as_str ( ) ) ;
336
365
ns_path. try_exists ( ) . unwrap_or ( false )
337
366
}
@@ -515,7 +544,7 @@ impl<M: MakeNamespace> NamespaceStore<M> {
515
544
}
516
545
517
546
// check that the source namespace exists
518
- if !self . inner . make_namespace . exists ( & from) {
547
+ if !self . inner . make_namespace . exists ( & from) . await {
519
548
return Err ( crate :: error:: Error :: NamespaceDoesntExist ( from. to_string ( ) ) ) ;
520
549
}
521
550
@@ -581,7 +610,7 @@ impl<M: MakeNamespace> NamespaceStore<M> {
581
610
let namespace = namespace. clone ( ) ;
582
611
async move {
583
612
if namespace != NamespaceName :: default ( )
584
- && !self . inner . make_namespace . exists ( & namespace)
613
+ && !self . inner . make_namespace . exists ( & namespace) . await
585
614
&& !self . inner . allow_lazy_creation
586
615
{
587
616
return Err ( Error :: NamespaceDoesntExist ( namespace. to_string ( ) ) ) ;
@@ -651,7 +680,7 @@ impl<M: MakeNamespace> NamespaceStore<M> {
651
680
// otherwise it's an error.
652
681
if self . inner . allow_lazy_creation || namespace == NamespaceName :: default ( ) {
653
682
tracing:: trace!( "auto-creating the namespace" ) ;
654
- } else if self . inner . make_namespace . exists ( & namespace) {
683
+ } else if self . inner . make_namespace . exists ( & namespace) . await {
655
684
return Err ( Error :: NamespaceAlreadyExist ( namespace. to_string ( ) ) ) ;
656
685
}
657
686
0 commit comments