@@ -85,23 +85,36 @@ impl<B: BackingStore> Storage<B> {
8585 }
8686 }
8787
88- pub async fn init ( & self ) -> Result < ( ) , StorageError > {
89- let mut locked_config = self . config . lock ( ) . await ;
90- let mut backing_store = self . backing_store . borrow_mut ( ) ;
91- if let Ok ( mut config) = backing_store. load ( ) . await {
92- let seq = config. sequence ( ) ;
88+ pub async fn load ( & self ) -> Result < ProvisionedConfiguration , StorageError > {
89+ let config = {
90+ let mut backing_store = self . backing_store . borrow_mut ( ) ;
91+ backing_store. load ( ) . await ?
92+ } ;
93+ Ok ( config)
94+ }
9395
94- let mut extra = seq % 100 ;
95- if extra == 100 {
96- extra = 0 ;
96+ pub async fn init ( & self ) -> Result < ( ) , StorageError > {
97+ let config = self . load ( ) . await ;
98+ match config {
99+ Ok ( mut config) => {
100+ let seq = config. sequence ( ) ;
101+
102+ let mut extra = seq % 100 ;
103+ if extra == 100 {
104+ extra = 0 ;
105+ }
106+ let seq = ( seq - extra) + 100 ;
107+
108+ * config. sequence_mut ( ) = seq;
109+ let mut backing_store = self . backing_store . borrow_mut ( ) ;
110+ backing_store. store ( & config) . await ?;
111+ let mut locked_config = self . config . lock ( ) . await ;
112+ locked_config. replace ( Configuration :: Provisioned ( config) ) ;
113+ }
114+ Err ( _) => {
115+ let mut locked_config = self . config . lock ( ) . await ;
116+ locked_config. replace ( Configuration :: Unprovisioned ( self . default_config . clone ( ) ) ) ;
97117 }
98- let seq = ( seq - extra) + 100 ;
99-
100- * config. sequence_mut ( ) = seq;
101- backing_store. store ( & config) . await ?;
102- locked_config. replace ( Configuration :: Provisioned ( config) ) ;
103- } else {
104- locked_config. replace ( Configuration :: Unprovisioned ( self . default_config . clone ( ) ) ) ;
105118 }
106119 Ok ( ( ) )
107120 }
@@ -194,4 +207,8 @@ impl<B: BackingStore> Storage<B> {
194207 pub ( crate ) fn set_composition ( & self , composition : Composition ) {
195208 self . composition . borrow_mut ( ) . replace ( composition) ;
196209 }
210+
211+ pub fn default_config ( & self ) -> UnprovisionedConfiguration {
212+ self . default_config
213+ }
197214}
0 commit comments