mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-07 13:53:12 +00:00
01d5383ce3
* add tracing instrument * fix rebalance/decom * modify Telemetry filter order * feat: improve address binding and port handling mechanism (#366) * feat: improve address binding and port handling mechanism 1. Add support for ":port" format to enable dual-stack binding (IPv4/IPv6) 2. Implement automatic port allocation when port 0 is specified 3. Optimize server startup process with unified address resolution 4. Enhance error handling and logging for address resolution 5. Improve graceful shutdown with signal listening 6. Clean up commented code in console.rs Files: - ecstore/src/utils/net.rs - rustfs/src/console.rs - rustfs/src/main.rs Branch: feature/server-and-console-port * improve code for console * improve code * improve code for console and net.rs * Update rustfs/src/main.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update rustfs/src/utils/mod.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * upgrade config file * modify * fix readme Signed-off-by: junxiang Mu <1948535941@qq.com> * improve readme.md * improve code for readme.md add chinese readme.md * Implement Storage Service Event Notification System Added event notification capability to the storage module, enabling the storage service to publish object operation events. Key changes include: 1. Created `event_notifier` module providing core functionality: - `create_metadata()` - Creates event metadata objects with default configuration ID - `send_event()` - Asynchronously sends event notifications with error handling 2. Integrated the `rustfs_event_notifier` library: - Supports object creation, deletion, and access events - Provides event metadata building and management - Includes proper error propagation These changes enable the system to trigger notifications when storage operations occur, facilitating auditing, monitoring, and integration with other systems. * fix --------- Signed-off-by: junxiang Mu <1948535941@qq.com> Co-authored-by: weisd <im@weisd.in> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: junxiang Mu <1948535941@qq.com>
103 lines
4.2 KiB
Rust
103 lines
4.2 KiB
Rust
use crate::ChannelAdapter;
|
|
use crate::Error;
|
|
use crate::EventStore;
|
|
use crate::{Event, Log};
|
|
use std::sync::Arc;
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
use tokio::sync::mpsc;
|
|
use tokio::time::Duration;
|
|
use tokio_util::sync::CancellationToken;
|
|
use tracing::instrument;
|
|
|
|
/// Handles incoming events from the producer.
|
|
///
|
|
/// This function is responsible for receiving events from the producer and sending them to the appropriate adapters.
|
|
/// It also handles the shutdown process and saves any pending logs to the event store.
|
|
#[instrument(skip_all)]
|
|
pub async fn event_bus(
|
|
mut rx: mpsc::Receiver<Event>,
|
|
adapters: Vec<Arc<dyn ChannelAdapter>>,
|
|
store: Arc<EventStore>,
|
|
shutdown: CancellationToken,
|
|
shutdown_complete: Option<tokio::sync::oneshot::Sender<()>>,
|
|
) -> Result<(), Error> {
|
|
let mut current_log = Log {
|
|
event_name: crate::event::Name::Everything,
|
|
key: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs().to_string(),
|
|
records: Vec::new(),
|
|
};
|
|
|
|
let mut unprocessed_events = Vec::new();
|
|
loop {
|
|
tokio::select! {
|
|
Some(event) = rx.recv() => {
|
|
current_log.records.push(event.clone());
|
|
let mut send_tasks = Vec::new();
|
|
for adapter in &adapters {
|
|
if event.channels.contains(&adapter.name()) {
|
|
let adapter = adapter.clone();
|
|
let event = event.clone();
|
|
send_tasks.push(tokio::spawn(async move {
|
|
if let Err(e) = adapter.send(&event).await {
|
|
tracing::error!("Failed to send event to {}: {}", adapter.name(), e);
|
|
Err(e)
|
|
} else {
|
|
Ok(())
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
for task in send_tasks {
|
|
if task.await?.is_err() {
|
|
// If sending fails, add the event to the unprocessed list
|
|
let failed_event = event.clone();
|
|
unprocessed_events.push(failed_event);
|
|
}
|
|
}
|
|
|
|
// Clear the current log because we only care about unprocessed events
|
|
current_log.records.clear();
|
|
}
|
|
_ = shutdown.cancelled() => {
|
|
tracing::info!("Shutting down event bus, saving pending logs...");
|
|
// Check if there are still unprocessed messages in the channel
|
|
while let Ok(Some(event)) = tokio::time::timeout(
|
|
Duration::from_millis(100),
|
|
rx.recv()
|
|
).await {
|
|
unprocessed_events.push(event);
|
|
}
|
|
|
|
// save only if there are unprocessed events
|
|
if !unprocessed_events.is_empty() {
|
|
tracing::info!("Save {} unhandled events", unprocessed_events.len());
|
|
// create and save logging
|
|
let shutdown_log = Log {
|
|
event_name: crate::event::Name::Everything,
|
|
key: format!("shutdown_{}", SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()),
|
|
records: unprocessed_events,
|
|
};
|
|
|
|
store.save_logs(&[shutdown_log]).await?;
|
|
} else {
|
|
tracing::info!("no unhandled events need to be saved");
|
|
}
|
|
tracing::debug!("shutdown_complete is Some: {}", shutdown_complete.is_some());
|
|
|
|
if let Some(complete_sender) = shutdown_complete {
|
|
// send a completion signal
|
|
let result = complete_sender.send(());
|
|
match result {
|
|
Ok(_) => tracing::info!("Event bus shutdown signal sent"),
|
|
Err(e) => tracing::error!("Failed to send event bus shutdown signal: {:?}", e),
|
|
}
|
|
tracing::info!("Shutting down event bus");
|
|
}
|
|
tracing::info!("Event bus shutdown complete");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|