@@ -27,10 +27,10 @@ use crate::collection_resolver_cached::{
27
27
} ;
28
28
use crate :: collection_resolver_memd:: { CollectionResolverMemd , CollectionResolverMemdOptions } ;
29
29
use crate :: compressionmanager:: { CompressionManager , StdCompressor } ;
30
- use crate :: configparser:: ConfigParser ;
31
- use crate :: configwatcher:: {
32
- ConfigWatcher , ConfigWatcherMemd , ConfigWatcherMemdConfig , ConfigWatcherMemdOptions ,
30
+ use crate :: configmanager:: {
31
+ ConfigManager , ConfigManagerMemd , ConfigManagerMemdConfig , ConfigManagerMemdOptions ,
33
32
} ;
33
+ use crate :: configparser:: ConfigParser ;
34
34
use crate :: crudcomponent:: CrudComponent ;
35
35
use crate :: errmapcomponent:: ErrMapComponent ;
36
36
use crate :: error:: { Error , ErrorKind , Result } ;
@@ -72,7 +72,6 @@ struct AgentState {
72
72
num_pool_connections : usize ,
73
73
// http_transport:
74
74
last_clients : HashMap < String , KvClientConfig > ,
75
- latest_config : ParsedConfig ,
76
75
network_type : String ,
77
76
78
77
client_name : String ,
@@ -84,7 +83,7 @@ type AgentCollectionResolver = CollectionResolverCached<CollectionResolverMemd<A
84
83
pub ( crate ) struct AgentInner {
85
84
state : Arc < Mutex < AgentState > > ,
86
85
87
- cfg_watcher : Arc < dyn ConfigWatcher > ,
86
+ config_manager : Arc < dyn ConfigManager > ,
88
87
conn_mgr : Arc < AgentClientManager > ,
89
88
vb_router : Arc < StdVbucketRouter > ,
90
89
collections : Arc < AgentCollectionResolver > ,
@@ -111,11 +110,11 @@ pub(crate) struct AgentInner {
111
110
pub struct Agent {
112
111
pub ( crate ) inner : Arc < AgentInner > ,
113
112
114
- config_watcher_shutdown_tx : Sender < ( ) > ,
113
+ config_manager_shutdown_tx : Sender < ( ) > ,
115
114
}
116
115
117
116
struct AgentComponentConfigs {
118
- pub config_watcher_memd_config : ConfigWatcherMemdConfig ,
117
+ pub config_manager_memd_config : ConfigManagerMemdConfig ,
119
118
pub kv_client_manager_client_configs : HashMap < String , KvClientConfig > ,
120
119
pub vbucket_routing_info : VbucketRoutingInfo ,
121
120
pub query_config : QueryComponentConfig ,
@@ -129,18 +128,13 @@ impl AgentInner {
129
128
pub async fn apply_config ( & self , config : ParsedConfig ) {
130
129
let mut state = self . state . lock ( ) . await ;
131
130
132
- if !Self :: can_update_config ( & config, & state. latest_config ) {
133
- return ;
134
- }
135
-
136
131
info ! ( "Applying updated config" ) ;
137
- state. latest_config = config;
138
132
139
- self . update_state ( & mut state) . await ;
133
+ self . update_state ( config , & mut state) . await ;
140
134
}
141
135
142
- async fn update_state ( & self , state : & mut AgentState ) {
143
- let agent_component_configs = Self :: gen_agent_component_configs ( state) ;
136
+ async fn update_state ( & self , config : ParsedConfig , state : & mut AgentState ) {
137
+ let agent_component_configs = Self :: gen_agent_component_configs ( & config , state) ;
144
138
145
139
// In order to avoid race conditions between operations selecting the
146
140
// endpoint they need to send the request to, and fetching an actual
@@ -178,8 +172,8 @@ impl AgentInner {
178
172
. update_vbucket_info ( agent_component_configs. vbucket_routing_info ) ;
179
173
180
174
if let Err ( e) = self
181
- . cfg_watcher
182
- . reconfigure ( agent_component_configs. config_watcher_memd_config )
175
+ . config_manager
176
+ . reconfigure ( agent_component_configs. config_manager_memd_config )
183
177
{
184
178
error ! ( "Failed to reconfigure memd config watcher component; {}" , e) ;
185
179
}
@@ -213,27 +207,11 @@ impl AgentInner {
213
207
self . mgmt . reconfigure ( agent_component_configs. mgmt_config ) ;
214
208
}
215
209
216
- fn can_update_config ( new_config : & ParsedConfig , old_config : & ParsedConfig ) -> bool {
217
- if new_config. bucket != old_config. bucket {
218
- debug ! ( "Switching config due to changed bucket type (bucket takeover)" ) ;
219
- return true ;
220
- } else if let Some ( cmp) = new_config. partial_cmp ( old_config) {
221
- if cmp == Ordering :: Less {
222
- debug ! ( "Skipping config due to new config being an older revision" )
223
- } else if cmp == Ordering :: Equal {
224
- debug ! ( "Skipping config due to matching revisions" )
225
- } else {
226
- return true ;
227
- }
228
- }
229
-
230
- false
231
- }
232
-
233
- fn gen_agent_component_configs ( state : & mut AgentState ) -> AgentComponentConfigs {
234
- let network_info = state
235
- . latest_config
236
- . addresses_group_for_network_type ( & state. network_type ) ;
210
+ fn gen_agent_component_configs (
211
+ config : & ParsedConfig ,
212
+ state : & mut AgentState ,
213
+ ) -> AgentComponentConfigs {
214
+ let network_info = config. addresses_group_for_network_type ( & state. network_type ) ;
237
215
238
216
let mut kv_data_node_ids = Vec :: new ( ) ;
239
217
let mut kv_data_hosts: HashMap < String , String > = HashMap :: new ( ) ;
@@ -311,7 +289,7 @@ impl AgentInner {
311
289
clients. insert ( node_id, config) ;
312
290
}
313
291
314
- let vbucket_routing_info = if let Some ( info) = & state . latest_config . bucket {
292
+ let vbucket_routing_info = if let Some ( info) = & config . bucket {
315
293
VbucketRoutingInfo {
316
294
// TODO: Clone
317
295
vbucket_info : info. vbucket_map . clone ( ) ,
@@ -327,7 +305,7 @@ impl AgentInner {
327
305
} ;
328
306
329
307
AgentComponentConfigs {
330
- config_watcher_memd_config : ConfigWatcherMemdConfig {
308
+ config_manager_memd_config : ConfigManagerMemdConfig {
331
309
endpoints : kv_data_node_ids,
332
310
} ,
333
311
kv_client_manager_client_configs : clients,
@@ -339,8 +317,7 @@ impl AgentInner {
339
317
search_config : SearchComponentConfig {
340
318
endpoints : search_endpoints,
341
319
authenticator : state. authenticator . clone ( ) ,
342
- vector_search_enabled : state
343
- . latest_config
320
+ vector_search_enabled : config
344
321
. features
345
322
. contains ( & ParsedConfigFeature :: FtsVectorSearch ) ,
346
323
} ,
@@ -358,11 +335,8 @@ impl AgentInner {
358
335
}
359
336
}
360
337
361
- // TODO: This really shouldn't be async
362
- pub async fn bucket_features ( & self ) -> Result < Vec < BucketFeature > > {
363
- let guard = self . state . lock ( ) . await ;
364
-
365
- if let Some ( bucket) = & guard. latest_config . bucket {
338
+ pub fn bucket_features ( & self ) -> Result < Vec < BucketFeature > > {
339
+ if let Some ( bucket) = self . config_manager . bucket ( ) {
366
340
let mut features = vec ! [ ] ;
367
341
368
342
for feature in & bucket. features {
@@ -442,7 +416,6 @@ impl Agent {
442
416
authenticator : Arc :: new ( opts. authenticator ) ,
443
417
num_pool_connections : 1 ,
444
418
last_clients : Default :: default ( ) ,
445
- latest_config : ParsedConfig :: default ( ) ,
446
419
network_type : "" . to_string ( ) ,
447
420
client_name : client_name. clone ( ) ,
448
421
tls_config : opts. tls_config ,
@@ -471,12 +444,11 @@ impl Agent {
471
444
)
472
445
. await ?;
473
446
474
- state. latest_config = first_config;
475
-
476
- let network_type = NetworkTypeHeuristic :: identify ( & state. latest_config ) ;
447
+ let network_type = NetworkTypeHeuristic :: identify ( & first_config) ;
477
448
state. network_type = network_type;
478
449
479
- let agent_component_configs = AgentInner :: gen_agent_component_configs ( & mut state) ;
450
+ let agent_component_configs =
451
+ AgentInner :: gen_agent_component_configs ( & first_config, & mut state) ;
480
452
481
453
let err_map_component_conn_mgr = err_map_component. clone ( ) ;
482
454
@@ -501,11 +473,12 @@ impl Agent {
501
473
. await ?,
502
474
) ;
503
475
504
- let cfg_watcher = Arc :: new ( ConfigWatcherMemd :: new (
505
- agent_component_configs. config_watcher_memd_config ,
506
- ConfigWatcherMemdOptions {
476
+ let cfg_watcher = Arc :: new ( ConfigManagerMemd :: new (
477
+ agent_component_configs. config_manager_memd_config ,
478
+ ConfigManagerMemdOptions {
507
479
polling_period : opts. config_poller_config . poll_interval ,
508
480
kv_client_manager : conn_mgr. clone ( ) ,
481
+ first_config,
509
482
} ,
510
483
) ) ;
511
484
let vb_router = Arc :: new ( StdVbucketRouter :: new (
@@ -575,7 +548,7 @@ impl Agent {
575
548
576
549
let inner = Arc :: new ( AgentInner {
577
550
state : Arc :: new ( Mutex :: new ( state) ) ,
578
- cfg_watcher : cfg_watcher. clone ( ) ,
551
+ config_manager : cfg_watcher. clone ( ) ,
579
552
conn_mgr,
580
553
vb_router,
581
554
crud,
@@ -596,20 +569,20 @@ impl Agent {
596
569
597
570
let agent = Agent {
598
571
inner,
599
- config_watcher_shutdown_tx : shutdown_tx,
572
+ config_manager_shutdown_tx : shutdown_tx,
600
573
} ;
601
574
602
- agent. start_config_watcher ( cfg_watcher, shutdown_rx) ;
575
+ agent. start_config_manager ( cfg_watcher, shutdown_rx) ;
603
576
604
577
Ok ( agent)
605
578
}
606
579
607
- fn start_config_watcher (
580
+ fn start_config_manager (
608
581
& self ,
609
- config_watcher : Arc < impl ConfigWatcher > ,
582
+ config_manager : Arc < impl ConfigManager > ,
610
583
shutdown_rx : Receiver < ( ) > ,
611
584
) {
612
- let mut watch_rx = config_watcher . watch ( shutdown_rx) ;
585
+ let mut watch_rx = config_manager . watch ( shutdown_rx) ;
613
586
614
587
let inner = self . inner . clone ( ) ;
615
588
tokio:: spawn ( async move {
@@ -668,7 +641,12 @@ impl Agent {
668
641
Err ( _e) => continue ,
669
642
} ;
670
643
671
- let raw_config = match client. get_cluster_config ( GetClusterConfigRequest { } ) . await {
644
+ let raw_config = match client
645
+ . get_cluster_config ( GetClusterConfigRequest {
646
+ known_version : None ,
647
+ } )
648
+ . await
649
+ {
672
650
Ok ( resp) => resp. config ,
673
651
Err ( _e) => continue ,
674
652
} ;
@@ -821,7 +799,7 @@ impl Agent {
821
799
}
822
800
823
801
pub async fn close ( & mut self ) {
824
- self . config_watcher_shutdown_tx . send ( ( ) ) . unwrap_or_default ( ) ;
802
+ self . config_manager_shutdown_tx . send ( ( ) ) . unwrap_or_default ( ) ;
825
803
826
804
self . inner . conn_mgr . close ( ) . await . unwrap_or_default ( ) ;
827
805
}
@@ -837,7 +815,7 @@ struct FirstHttpConfig {
837
815
838
816
// impl Drop for Agent {
839
817
// fn drop(&mut self) {
840
- // self.config_watcher_shutdown_tx .send(()).unwrap_or_default();
818
+ // self.config_manager_shutdown_tx .send(()).unwrap_or_default();
841
819
//
842
820
// block_on(async { self.inner.conn_mgr.close().await }).unwrap_or_default();
843
821
// }
0 commit comments