mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-21 03:46:37 +00:00
@@ -37,7 +37,7 @@ async fn receive_webhook(Json(payload): Json<Value>) -> StatusCode {
|
|||||||
println!("current time:{:04}-{:02}-{:02} {:02}:{:02}:{:02}", year, month, day, hour, minute, second);
|
println!("current time:{:04}-{:02}-{:02} {:02}:{:02}:{:02}", year, month, day, hour, minute, second);
|
||||||
println!(
|
println!(
|
||||||
"received a webhook request time:{} content:\n {}",
|
"received a webhook request time:{} content:\n {}",
|
||||||
seconds.to_string(),
|
seconds,
|
||||||
serde_json::to_string_pretty(&payload).unwrap()
|
serde_json::to_string_pretty(&payload).unwrap()
|
||||||
);
|
);
|
||||||
StatusCode::OK
|
StatusCode::OK
|
||||||
@@ -66,10 +66,10 @@ fn convert_seconds_to_date(seconds: u64) -> (u32, u32, u32, u32, u32, u32) {
|
|||||||
|
|
||||||
// calculate month
|
// calculate month
|
||||||
let days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
let days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
||||||
for m in 0..12 {
|
for m in &days_in_month {
|
||||||
if total_seconds >= days_in_month[m] * seconds_per_day {
|
if total_seconds >= m * seconds_per_day {
|
||||||
month += 1;
|
month += 1;
|
||||||
total_seconds -= days_in_month[m] * seconds_per_day;
|
total_seconds -= m * seconds_per_day;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ mod tests {
|
|||||||
let config = NotifierConfig::default();
|
let config = NotifierConfig::default();
|
||||||
let _ = initialize(config.clone()).await; // first initialization
|
let _ = initialize(config.clone()).await; // first initialization
|
||||||
let result = initialize(config).await; // second initialization
|
let result = initialize(config).await; // second initialization
|
||||||
assert!(!result.is_ok(), "Initialization should succeed");
|
assert!(result.is_err(), "Initialization should succeed");
|
||||||
assert!(result.is_err(), "Re-initialization should fail");
|
assert!(result.is_err(), "Re-initialization should fail");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let result = initialize(config).await;
|
let result = initialize(config).await;
|
||||||
assert!(!result.is_err(), "Initialization with invalid config should fail");
|
assert!(result.is_ok(), "Initialization with invalid config should fail");
|
||||||
assert!(is_initialized(), "System should not be marked as initialized after failure");
|
assert!(is_initialized(), "System should not be marked as initialized after failure");
|
||||||
assert!(is_ready(), "System should not be marked as ready after failure");
|
assert!(is_ready(), "System should not be marked as ready after failure");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ pub fn init_telemetry(config: &OtelConfig) -> OtelGuard {
|
|||||||
let tracer = tracer_provider.tracer(Cow::Borrowed(service_name).to_string());
|
let tracer = tracer_provider.tracer(Cow::Borrowed(service_name).to_string());
|
||||||
|
|
||||||
// Configure registry to avoid repeated calls to filter methods
|
// Configure registry to avoid repeated calls to filter methods
|
||||||
let _registry = tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(filter)
|
.with(filter)
|
||||||
.with(ErrorLayer::default())
|
.with(ErrorLayer::default())
|
||||||
.with(if config.local_logging_enabled.unwrap_or(false) {
|
.with(if config.local_logging_enabled.unwrap_or(false) {
|
||||||
|
|||||||
+10
-19
@@ -53,7 +53,7 @@ impl Erasure {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip(self, reader, writers))]
|
#[tracing::instrument(level = "info", skip(self, reader, writers))]
|
||||||
pub async fn encode<S>(
|
pub async fn encode<S>(
|
||||||
self: Arc<Self>,
|
self: Arc<Self>,
|
||||||
mut reader: S,
|
mut reader: S,
|
||||||
@@ -65,23 +65,16 @@ impl Erasure {
|
|||||||
where
|
where
|
||||||
S: AsyncRead + Etag + Unpin + Send + 'static,
|
S: AsyncRead + Etag + Unpin + Send + 'static,
|
||||||
{
|
{
|
||||||
// pin_mut!(body);
|
let (tx, mut rx) = mpsc::channel(5);
|
||||||
// let mut reader = tokio_util::io::StreamReader::new(
|
|
||||||
// body.map(|f| f.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))),
|
|
||||||
// );
|
|
||||||
|
|
||||||
let (tx, mut rx) = mpsc::channel(3);
|
|
||||||
let self_clone = self.clone();
|
|
||||||
let task = tokio::spawn(async move {
|
let task = tokio::spawn(async move {
|
||||||
let mut total: usize = 0;
|
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
let mut total: usize = 0;
|
||||||
loop {
|
loop {
|
||||||
let mut blocks = <SmallVec<[Bytes; 16]>>::new();
|
|
||||||
if total_size > 0 {
|
if total_size > 0 {
|
||||||
let new_len = {
|
let new_len = {
|
||||||
let remain = total_size - total;
|
let remain = total_size - total;
|
||||||
if remain > self_clone.block_size {
|
if remain > self.block_size {
|
||||||
self_clone.block_size
|
self.block_size
|
||||||
} else {
|
} else {
|
||||||
remain
|
remain
|
||||||
}
|
}
|
||||||
@@ -104,11 +97,10 @@ impl Erasure {
|
|||||||
};
|
};
|
||||||
total += buf.len();
|
total += buf.len();
|
||||||
}
|
}
|
||||||
self_clone.clone().encode_data(&buf, &mut blocks)?;
|
let blocks = Arc::new(Box::pin(self.clone().encode_data(&buf)?));
|
||||||
let _ = tx.send(blocks).await;
|
let _ = tx.send(blocks).await;
|
||||||
}
|
}
|
||||||
// let etag = reader.etag().await;
|
let etag = reader.etag().await;
|
||||||
let etag = String::new();
|
|
||||||
Ok((total, etag))
|
Ok((total, etag))
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -368,7 +360,7 @@ impl Erasure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(data_len=data.len()))]
|
#[tracing::instrument(level = "info", skip_all, fields(data_len=data.len()))]
|
||||||
pub fn encode_data(self: Arc<Self>, data: &[u8], shards: &mut SmallVec<[Bytes; 16]>) -> Result<()> {
|
pub fn encode_data(self: Arc<Self>, data: &[u8]) -> Result<Vec<Bytes>> {
|
||||||
let (shard_size, total_size) = self.need_size(data.len());
|
let (shard_size, total_size) = self.need_size(data.len());
|
||||||
|
|
||||||
// 生成一个新的 所需的所有分片数据长度
|
// 生成一个新的 所需的所有分片数据长度
|
||||||
@@ -390,14 +382,13 @@ impl Erasure {
|
|||||||
|
|
||||||
// 零拷贝分片,所有 shard 引用 data_buffer
|
// 零拷贝分片,所有 shard 引用 data_buffer
|
||||||
let mut data_buffer = data_buffer.freeze();
|
let mut data_buffer = data_buffer.freeze();
|
||||||
shards.clear();
|
let mut shards = Vec::with_capacity(self.total_shard_count());
|
||||||
shards.reserve(self.total_shard_count());
|
|
||||||
for _ in 0..self.total_shard_count() {
|
for _ in 0..self.total_shard_count() {
|
||||||
let shard = data_buffer.split_to(shard_size);
|
let shard = data_buffer.split_to(shard_size);
|
||||||
shards.push(shard);
|
shards.push(shard);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(shards)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode_data(&self, shards: &mut [Option<Vec<u8>>]) -> Result<()> {
|
pub fn decode_data(&self, shards: &mut [Option<Vec<u8>>]) -> Result<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user