fix: resolve event target deletion issue (#1219)

This commit is contained in:
yxrxy
2025-12-21 12:43:48 +08:00
committed by GitHub
parent 20ea591049
commit 3bd96bcf10
2 changed files with 41 additions and 15 deletions
+19 -2
View File
@@ -212,6 +212,11 @@ impl NotificationSystem {
return Ok(()); return Ok(());
} }
// Save the modified configuration to storage
rustfs_ecstore::config::com::save_server_config(store, &new_config)
.await
.map_err(|e| NotificationError::SaveConfig(e.to_string()))?;
info!("Configuration updated. Reloading system..."); info!("Configuration updated. Reloading system...");
self.reload_config(new_config).await self.reload_config(new_config).await
} }
@@ -294,7 +299,8 @@ impl NotificationSystem {
/// If the target configuration does not exist, it returns Ok(()) without making any changes. /// If the target configuration does not exist, it returns Ok(()) without making any changes.
pub async fn remove_target_config(&self, target_type: &str, target_name: &str) -> Result<(), NotificationError> { pub async fn remove_target_config(&self, target_type: &str, target_name: &str) -> Result<(), NotificationError> {
info!("Removing config for target {} of type {}", target_name, target_type); info!("Removing config for target {} of type {}", target_name, target_type);
self.update_config_and_reload(|config| { let config_result = self
.update_config_and_reload(|config| {
let mut changed = false; let mut changed = false;
if let Some(targets) = config.0.get_mut(&target_type.to_lowercase()) { if let Some(targets) = config.0.get_mut(&target_type.to_lowercase()) {
if targets.remove(&target_name.to_lowercase()).is_some() { if targets.remove(&target_name.to_lowercase()).is_some() {
@@ -310,7 +316,18 @@ impl NotificationSystem {
debug!("Config after remove: {:?}", config); debug!("Config after remove: {:?}", config);
changed changed
}) })
.await .await;
if config_result.is_ok() {
let target_id = TargetID::new(target_name.to_string(), target_type.to_string());
// Remove from target list
let target_list = self.notifier.target_list();
let mut target_list_guard = target_list.write().await;
let _ = target_list_guard.remove_target_only(&target_id).await;
}
config_result
} }
/// Enhanced event stream startup function, including monitoring and concurrency control /// Enhanced event stream startup function, including monitoring and concurrency control
+9
View File
@@ -195,6 +195,10 @@ impl EventNotifier {
) -> Result<(), NotificationError> { ) -> Result<(), NotificationError> {
// Currently active, simpler logic // Currently active, simpler logic
let mut target_list_guard = self.target_list.write().await; //Gets a write lock for the TargetList let mut target_list_guard = self.target_list.write().await; //Gets a write lock for the TargetList
// Clear existing targets first - rebuild from scratch to ensure consistency with new configuration
target_list_guard.clear();
for target_boxed in targets_to_init { for target_boxed in targets_to_init {
// Traverse the incoming Box<dyn Target > // Traverse the incoming Box<dyn Target >
debug!("init bucket target: {}", target_boxed.name()); debug!("init bucket target: {}", target_boxed.name());
@@ -240,6 +244,11 @@ impl TargetList {
Ok(()) Ok(())
} }
/// Clears all targets from the list
pub fn clear(&mut self) {
self.targets.clear();
}
/// Removes a target by ID. Note: This does not stop its associated event stream. /// Removes a target by ID. Note: This does not stop its associated event stream.
/// Stream cancellation should be handled by EventNotifier. /// Stream cancellation should be handled by EventNotifier.
pub async fn remove_target_only(&mut self, id: &TargetID) -> Option<Arc<dyn Target<Event> + Send + Sync>> { pub async fn remove_target_only(&mut self, id: &TargetID) -> Option<Arc<dyn Target<Event> + Send + Sync>> {