mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-05 21:07:43 +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>
61 lines
2.0 KiB
Rust
61 lines
2.0 KiB
Rust
use crate::Error;
|
|
use crate::Log;
|
|
use std::sync::Arc;
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
use tokio::fs::{create_dir_all, File, OpenOptions};
|
|
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter};
|
|
use tokio::sync::RwLock;
|
|
use tracing::instrument;
|
|
|
|
/// `EventStore` is a struct that manages the storage of event logs.
|
|
pub struct EventStore {
|
|
path: String,
|
|
lock: Arc<RwLock<()>>,
|
|
}
|
|
|
|
impl EventStore {
|
|
pub async fn new(path: &str) -> Result<Self, Error> {
|
|
create_dir_all(path).await?;
|
|
Ok(Self {
|
|
path: path.to_string(),
|
|
lock: Arc::new(RwLock::new(())),
|
|
})
|
|
}
|
|
|
|
#[instrument(skip(self))]
|
|
pub async fn save_logs(&self, logs: &[Log]) -> Result<(), Error> {
|
|
let _guard = self.lock.write().await;
|
|
let file_path = format!(
|
|
"{}/events_{}.jsonl",
|
|
self.path,
|
|
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()
|
|
);
|
|
let file = OpenOptions::new().create(true).append(true).open(&file_path).await?;
|
|
let mut writer = BufWriter::new(file);
|
|
for log in logs {
|
|
let line = serde_json::to_string(log)?;
|
|
writer.write_all(line.as_bytes()).await?;
|
|
writer.write_all(b"\n").await?;
|
|
}
|
|
writer.flush().await?;
|
|
tracing::info!("Saved logs to {} end", file_path);
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn load_logs(&self) -> Result<Vec<Log>, Error> {
|
|
let _guard = self.lock.read().await;
|
|
let mut logs = Vec::new();
|
|
let mut entries = tokio::fs::read_dir(&self.path).await?;
|
|
while let Some(entry) = entries.next_entry().await? {
|
|
let file = File::open(entry.path()).await?;
|
|
let reader = BufReader::new(file);
|
|
let mut lines = reader.lines();
|
|
while let Some(line) = lines.next_line().await? {
|
|
let log: Log = serde_json::from_str(&line)?;
|
|
logs.push(log);
|
|
}
|
|
}
|
|
Ok(logs)
|
|
}
|
|
}
|