@@ -12,7 +12,6 @@ use spin_factors::{
1212 ConfigureAppContext , Factor , FactorInstanceBuilder , InitContext , PrepareContext , RuntimeFactors ,
1313} ;
1414use spin_locked_app:: MetadataKey ;
15- use util:: DefaultManagerGetter ;
1615
1716/// Metadata key for key-value stores.
1817pub const KEY_VALUE_STORES_KEY : MetadataKey < Vec < String > > = MetadataKey :: new ( "key_value_stores" ) ;
@@ -21,19 +20,15 @@ pub use runtime_config::RuntimeConfig;
2120pub use util:: { CachingStoreManager , DelegatingStoreManager } ;
2221
2322/// A factor that provides key-value storage.
23+ #[ derive( Default ) ]
2424pub struct KeyValueFactor {
25- default_label_resolver : Arc < dyn DefaultLabelResolver > ,
25+ _priv : ( ) ,
2626}
2727
2828impl KeyValueFactor {
2929 /// Create a new KeyValueFactor.
30- ///
31- /// The `default_label_resolver` is used to resolve store managers for labels that
32- /// are not defined in the runtime configuration.
33- pub fn new ( default_label_resolver : impl DefaultLabelResolver + ' static ) -> Self {
34- Self {
35- default_label_resolver : Arc :: new ( default_label_resolver) ,
36- }
30+ pub fn new ( ) -> Self {
31+ Self { _priv : ( ) }
3732 }
3833}
3934
@@ -53,13 +48,10 @@ impl Factor for KeyValueFactor {
5348 mut ctx : ConfigureAppContext < T , Self > ,
5449 ) -> anyhow:: Result < Self :: AppState > {
5550 let store_managers = ctx. take_runtime_config ( ) . unwrap_or_default ( ) ;
56- let default_label_resolver = self . default_label_resolver . clone ( ) ;
57- let default_fn: DefaultManagerGetter =
58- Arc :: new ( move |label| default_label_resolver. default ( label) ) ;
5951
60- let delegating_manager = DelegatingStoreManager :: new ( store_managers, default_fn ) ;
52+ let delegating_manager = DelegatingStoreManager :: new ( store_managers) ;
6153 let caching_manager = CachingStoreManager :: new ( delegating_manager) ;
62- let store_manager_manager = Arc :: new ( caching_manager) ;
54+ let store_manager = Arc :: new ( caching_manager) ;
6355
6456 // Build component -> allowed stores map
6557 let mut component_allowed_stores = HashMap :: new ( ) ;
@@ -73,8 +65,7 @@ impl Factor for KeyValueFactor {
7365 for label in & key_value_stores {
7466 // TODO: port nicer errors from KeyValueComponent (via error type?)
7567 ensure ! (
76- store_manager_manager. is_defined( label)
77- || self . default_label_resolver. default ( label) . is_some( ) ,
68+ store_manager. is_defined( label) ,
7869 "unknown key_value_stores label {label:?} for component {component_id:?}"
7970 ) ;
8071 }
@@ -83,7 +74,7 @@ impl Factor for KeyValueFactor {
8374 }
8475
8576 Ok ( AppState {
86- store_manager : store_manager_manager ,
77+ store_manager,
8778 component_allowed_stores,
8879 } )
8980 }
@@ -159,22 +150,10 @@ impl FactorInstanceBuilder for InstanceBuilder {
159150 store_manager,
160151 allowed_stores,
161152 } = self ;
162- let mut dispatch = KeyValueDispatch :: new_with_capacity ( u32:: MAX ) ;
163- dispatch. init ( allowed_stores, store_manager) ;
164- Ok ( dispatch)
165- }
166- }
167-
168- /// Resolves a label to a default [`StoreManager`].
169- pub trait DefaultLabelResolver : Send + Sync {
170- /// If there is no runtime configuration for a given store label, return a default store manager.
171- ///
172- /// If `Option::None` is returned, the store is not allowed.
173- fn default ( & self , label : & str ) -> Option < Arc < dyn StoreManager > > ;
174- }
175-
176- impl < T : DefaultLabelResolver > DefaultLabelResolver for Arc < T > {
177- fn default ( & self , label : & str ) -> Option < Arc < dyn StoreManager > > {
178- self . as_ref ( ) . default ( label)
153+ Ok ( KeyValueDispatch :: new_with_capacity (
154+ allowed_stores,
155+ store_manager,
156+ u32:: MAX ,
157+ ) )
179158 }
180159}
0 commit comments