mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-09 14:49:25 +00:00
Feature up/ilm (#305)
* fix * fix * fix * fix delete-marker expiration. add api_restore. * fix * time retry object upload * lock file * make fmt * fix * restore object * fix * fix * serde-rs-xml -> quick-xml * fix * checksum * fix * fix * fix * fix * fix * fix * fix
This commit is contained in:
+97
-41
@@ -12,44 +12,39 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::time::Duration;
|
||||
use futures::Stream;
|
||||
use hyper::http;
|
||||
use std::{
|
||||
pin::Pin,
|
||||
sync::LazyLock,
|
||||
task::{Context, Poll},
|
||||
time::Duration,
|
||||
};
|
||||
use tokio::time::interval;
|
||||
|
||||
pub const MAX_RETRY: i64 = 10;
|
||||
pub const MAX_JITTER: f64 = 1.0;
|
||||
pub const NO_JITTER: f64 = 0.0;
|
||||
|
||||
/*
|
||||
struct Delay {
|
||||
when: Instant,
|
||||
}
|
||||
pub const DEFAULT_RETRY_UNIT: Duration = Duration::from_millis(200);
|
||||
pub const DEFAULT_RETRY_CAP: Duration = Duration::from_secs(1);
|
||||
|
||||
impl Future for Delay {
|
||||
type Output = &'static str;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>)
|
||||
-> Poll<&'static str>
|
||||
{
|
||||
if Instant::now() >= self.when {
|
||||
println!("Hello world");
|
||||
Poll::Ready("done")
|
||||
} else {
|
||||
// Ignore this line for now.
|
||||
cx.waker().wake_by_ref();
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct RetryTimer {
|
||||
rem: usize,
|
||||
delay: Delay,
|
||||
pub struct RetryTimer {
|
||||
base_sleep: Duration,
|
||||
max_sleep: Duration,
|
||||
jitter: f64,
|
||||
random: u64,
|
||||
rem: i64,
|
||||
}
|
||||
|
||||
impl RetryTimer {
|
||||
fn new() -> Self {
|
||||
pub fn new(max_retry: i64, base_sleep: Duration, max_sleep: Duration, jitter: f64, random: u64) -> Self {
|
||||
Self {
|
||||
rem: 3,
|
||||
delay: Delay { when: Instant::now() }
|
||||
base_sleep,
|
||||
max_sleep,
|
||||
jitter,
|
||||
random,
|
||||
rem: max_retry,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,26 +52,87 @@ impl RetryTimer {
|
||||
impl Stream for RetryTimer {
|
||||
type Item = ();
|
||||
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>)
|
||||
-> Poll<Option<()>>
|
||||
{
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<()>> {
|
||||
let jitter = self.jitter.clamp(NO_JITTER, MAX_JITTER);
|
||||
|
||||
let attempt = MAX_RETRY - self.rem;
|
||||
let mut sleep = self.base_sleep * (1 << attempt);
|
||||
if sleep > self.max_sleep {
|
||||
sleep = self.max_sleep;
|
||||
}
|
||||
if (jitter - NO_JITTER).abs() > 1e-9 {
|
||||
sleep -= sleep * self.random as u32 * jitter as u32;
|
||||
}
|
||||
|
||||
if self.rem == 0 {
|
||||
// No more delays
|
||||
return Poll::Ready(None);
|
||||
}
|
||||
|
||||
match Pin::new(&mut self.delay).poll(cx) {
|
||||
Poll::Ready(_) => {
|
||||
let when = self.delay.when + Duration::from_millis(10);
|
||||
self.delay = Delay { when };
|
||||
self.rem -= 1;
|
||||
Poll::Ready(Some(()))
|
||||
}
|
||||
self.rem -= 1;
|
||||
let mut t = interval(sleep);
|
||||
match t.poll_tick(cx) {
|
||||
Poll::Ready(_) => Poll::Ready(Some(())),
|
||||
Poll::Pending => Poll::Pending,
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
pub fn new_retry_timer(_max_retry: i32, _base_sleep: Duration, _max_sleep: Duration, _jitter: f64) -> Vec<i32> {
|
||||
static RETRYABLE_S3CODES: LazyLock<Vec<String>> = LazyLock::new(|| {
|
||||
vec![
|
||||
"RequestError".to_string(),
|
||||
"RequestTimeout".to_string(),
|
||||
"Throttling".to_string(),
|
||||
"ThrottlingException".to_string(),
|
||||
"RequestLimitExceeded".to_string(),
|
||||
"RequestThrottled".to_string(),
|
||||
"InternalError".to_string(),
|
||||
"ExpiredToken".to_string(),
|
||||
"ExpiredTokenException".to_string(),
|
||||
"SlowDown".to_string(),
|
||||
]
|
||||
});
|
||||
|
||||
static RETRYABLE_HTTP_STATUSCODES: LazyLock<Vec<http::StatusCode>> = LazyLock::new(|| {
|
||||
vec![
|
||||
http::StatusCode::REQUEST_TIMEOUT,
|
||||
http::StatusCode::TOO_MANY_REQUESTS,
|
||||
//499,
|
||||
http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
http::StatusCode::BAD_GATEWAY,
|
||||
http::StatusCode::SERVICE_UNAVAILABLE,
|
||||
http::StatusCode::GATEWAY_TIMEOUT,
|
||||
//520,
|
||||
]
|
||||
});
|
||||
|
||||
pub fn is_s3code_retryable(s3code: &str) -> bool {
|
||||
RETRYABLE_S3CODES.contains(&s3code.to_string())
|
||||
}
|
||||
|
||||
pub fn is_http_status_retryable(http_statuscode: &http::StatusCode) -> bool {
|
||||
RETRYABLE_HTTP_STATUSCODES.contains(http_statuscode)
|
||||
}
|
||||
|
||||
pub fn is_request_error_retryable(_err: std::io::Error) -> bool {
|
||||
/*if err == Err::Canceled || err == Err::DeadlineExceeded {
|
||||
return err() == nil;
|
||||
}
|
||||
let uerr = err.(*url.Error);
|
||||
if uerr.is_ok() {
|
||||
let e = uerr.unwrap();
|
||||
return match e.type {
|
||||
x509.UnknownAuthorityError => {
|
||||
false
|
||||
}
|
||||
_ => true,
|
||||
};
|
||||
return match e.error() {
|
||||
"http: server gave HTTP response to HTTPS client" => {
|
||||
false
|
||||
}
|
||||
_ => rue,
|
||||
};
|
||||
}
|
||||
true*/
|
||||
todo!();
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ impl UserAgent {
|
||||
Some(version) => version,
|
||||
None => "Windows NT Unknown".to_string(),
|
||||
};
|
||||
format!("Windows NT {}", version)
|
||||
format!("Windows NT {version}")
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
|
||||
Reference in New Issue
Block a user