@@ -69,6 +69,12 @@ impl Default for NamespaceName {
6969 }
7070}
7171
72+ impl AsRef < str > for NamespaceName {
73+ fn as_ref ( & self ) -> & str {
74+ self . as_str ( )
75+ }
76+ }
77+
7278impl NamespaceName {
7379 pub fn from_string ( s : String ) -> crate :: Result < Self > {
7480 Self :: validate ( & s) ?;
@@ -161,7 +167,7 @@ pub trait MakeNamespace: Sync + Send + 'static {
161167 timestamp : Option < NaiveDateTime > ,
162168 ) -> crate :: Result < Namespace < Self :: Database > > ;
163169
164- fn exists ( & self , namespace : & NamespaceName ) -> bool ;
170+ async fn exists ( & self , namespace : & NamespaceName ) -> bool ;
165171}
166172
167173/// Creates new primary `Namespace`
@@ -274,9 +280,32 @@ impl MakeNamespace for PrimaryNamespaceMaker {
274280 Ok ( ns)
275281 }
276282
277- fn exists ( & self , namespace : & NamespaceName ) -> bool {
283+ async fn exists ( & self , namespace : & NamespaceName ) -> bool {
278284 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
280309 }
281310}
282311
@@ -331,7 +360,7 @@ impl MakeNamespace for ReplicaNamespaceMaker {
331360 return Err ( ForkError :: ForkReplica . into ( ) ) ;
332361 }
333362
334- fn exists ( & self , namespace : & NamespaceName ) -> bool {
363+ async fn exists ( & self , namespace : & NamespaceName ) -> bool {
335364 let ns_path = self . config . base_path . join ( "dbs" ) . join ( namespace. as_str ( ) ) ;
336365 ns_path. try_exists ( ) . unwrap_or ( false )
337366 }
@@ -515,7 +544,7 @@ impl<M: MakeNamespace> NamespaceStore<M> {
515544 }
516545
517546 // check that the source namespace exists
518- if !self . inner . make_namespace . exists ( & from) {
547+ if !self . inner . make_namespace . exists ( & from) . await {
519548 return Err ( crate :: error:: Error :: NamespaceDoesntExist ( from. to_string ( ) ) ) ;
520549 }
521550
@@ -581,7 +610,7 @@ impl<M: MakeNamespace> NamespaceStore<M> {
581610 let namespace = namespace. clone ( ) ;
582611 async move {
583612 if namespace != NamespaceName :: default ( )
584- && !self . inner . make_namespace . exists ( & namespace)
613+ && !self . inner . make_namespace . exists ( & namespace) . await
585614 && !self . inner . allow_lazy_creation
586615 {
587616 return Err ( Error :: NamespaceDoesntExist ( namespace. to_string ( ) ) ) ;
@@ -651,7 +680,7 @@ impl<M: MakeNamespace> NamespaceStore<M> {
651680 // otherwise it's an error.
652681 if self . inner . allow_lazy_creation || namespace == NamespaceName :: default ( ) {
653682 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 {
655684 return Err ( Error :: NamespaceAlreadyExist ( namespace. to_string ( ) ) ) ;
656685 }
657686
0 commit comments