refactor: replace chrono with jiff for time handling (#1582)

Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
heihutu
2026-01-22 17:24:56 +08:00
committed by GitHub
parent 6631407416
commit db253c01a9
20 changed files with 307 additions and 117 deletions
+1
View File
@@ -99,6 +99,7 @@ rustls-pemfile = { workspace = true }
# Time and Date
chrono = { workspace = true }
jiff = { workspace = true }
time = { workspace = true, features = ["parsing", "formatting", "serde"] }
# Utilities and Tools
+1 -1
View File
@@ -555,7 +555,7 @@ async fn health_check(method: Method) -> Response {
let body_json = json!({
"status": health_status,
"service": "rustfs-console",
"timestamp": chrono::Utc::now().to_rfc3339(),
"timestamp": jiff::Zoned::now().to_string(),
"version": env!("CARGO_PKG_VERSION"),
"details": details,
"uptime": std::time::SystemTime::now()
+1 -1
View File
@@ -132,7 +132,7 @@ impl Operation for HealthCheckHandler {
let health_info = json!({
"status": "ok",
"service": "rustfs-endpoint",
"timestamp": chrono::Utc::now().to_rfc3339(),
"timestamp": jiff::Zoned::now().to_string(),
"version": env!("CARGO_PKG_VERSION")
});
+1 -2
View File
@@ -14,7 +14,6 @@
use crate::storage::ecfs::{process_lambda_configurations, process_queue_configurations, process_topic_configurations};
use crate::{admin, config, version};
use chrono::Datelike;
use rustfs_config::{DEFAULT_UPDATE_CHECK, ENV_UPDATE_CHECK};
use rustfs_ecstore::bucket::metadata_sys;
use rustfs_notify::notifier_global;
@@ -26,7 +25,7 @@ use tracing::{debug, error, info, instrument, warn};
#[instrument]
pub(crate) fn print_server_info() {
let current_year = chrono::Utc::now().year();
let current_year = jiff::Zoned::now().year();
// Use custom macros to print server information
info!("RustFS Object Storage Server");
info!("Copyright: 2024-{} RustFS, Inc", current_year);
+10 -4
View File
@@ -71,11 +71,16 @@ static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
fn main() -> Result<()> {
fn main() {
let runtime = server::get_tokio_runtime_builder()
.build()
.expect("Failed to build Tokio runtime");
runtime.block_on(async_main())
let result = runtime.block_on(async_main());
if let Err(ref e) = result {
eprintln!("{} Server encountered an error and is shutting down: {}", jiff::Zoned::now(), e);
error!("Server encountered an error and is shutting down: {}", e);
std::process::exit(1);
}
}
async fn async_main() -> Result<()> {
// Parse the obtained parameters
@@ -365,9 +370,10 @@ async fn run(opt: config::Opt) -> Result<()> {
init_update_check();
println!(
"RustFS server started successfully at {}, current time: {}",
"RustFS server version: {} started successfully at {}, current time: {}",
version::get_version(),
&server_address,
chrono::offset::Utc::now().to_string()
jiff::Zoned::now()
);
info!(target: "rustfs::main::run","server started successfully at {}", &server_address);
// 4. Mark as Full Ready now that critical components are warm
+1 -2
View File
@@ -54,7 +54,6 @@ pub async fn dump_memory_pprof_now() -> Result<std::path::PathBuf, String> {
#[cfg(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))]
mod linux_impl {
use chrono::Utc;
use jemalloc_pprof::PROF_CTL;
use pprof::protos::Message;
use rustfs_config::{
@@ -104,7 +103,7 @@ mod linux_impl {
/// Generate timestamp string for filenames
fn ts() -> String {
Utc::now().format("%Y%m%dT%H%M%S").to_string()
jiff::Zoned::now().strftime("%Y%m%dT%H%M%S").to_string()
}
/// Write pprof report to file in protobuf format
+2 -2
View File
@@ -85,7 +85,7 @@ pub(crate) async fn start_audit_system() -> AuditResult<()> {
info!(
target: "rustfs::main::start_audit_system",
"Audit system started successfully with time: {}.",
chrono::Utc::now()
jiff::Zoned::now()
);
Ok(())
}
@@ -114,7 +114,7 @@ pub(crate) async fn stop_audit_system() -> AuditResult<()> {
// Prepare before stopping
system.close().await?;
// Record after stopping
info!("Audit system stopped at {}", chrono::Utc::now());
info!("Audit system stopped at {}", jiff::Zoned::now());
Ok(())
} else {
warn!("Audit system not initialized, cannot stop");
+1 -1
View File
@@ -169,7 +169,7 @@ pub async fn start_http_server(
// Detailed endpoint information (showing all API endpoints)
let api_endpoints = format!("{protocol}://{local_ip_str}:{server_port}");
let localhost_endpoint = format!("{protocol}://127.0.0.1:{server_port}");
let now_time = chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string();
let now_time = jiff::Zoned::now().strftime("%Y-%m-%d %H:%M:%S").to_string();
if opt.console_enable {
admin::console::init_console_cfg(local_ip, server_port);
+2 -2
View File
@@ -132,7 +132,7 @@ pub(crate) fn get_tokio_runtime_builder() -> tokio::runtime::Builder {
let id = std::thread::current().id();
println!(
"RustFS Worker Thread running - initializing resources time: {:?}, thread id: {:?}",
chrono::Utc::now().to_rfc3339(),
jiff::Zoned::now().to_string(),
id
);
})
@@ -140,7 +140,7 @@ pub(crate) fn get_tokio_runtime_builder() -> tokio::runtime::Builder {
let id = std::thread::current().id();
println!(
"RustFS Worker Thread stopping - cleaning up resources time: {:?}, thread id: {:?}",
chrono::Utc::now().to_rfc3339(),
jiff::Zoned::now().to_string(),
id
)
});
+7 -10
View File
@@ -34,7 +34,6 @@ use crate::storage::{
};
use base64::{Engine, engine::general_purpose::STANDARD as BASE64_STANDARD};
use bytes::Bytes;
use chrono::{DateTime, Utc};
use datafusion::arrow::{
csv::WriterBuilder as CsvWriterBuilder, json::WriterBuilder as JsonWriterBuilder, json::writer::JsonArray,
};
@@ -319,7 +318,7 @@ async fn create_managed_encryption_material(
iv: data_key.nonce.to_vec(),
tag: None,
encryption_context: context.encryption_context.clone(),
encrypted_at: Utc::now(),
encrypted_at: jiff::Zoned::now(),
original_size: if original_size >= 0 { original_size as u64 } else { 0 },
encrypted_data_key,
};
@@ -3360,7 +3359,7 @@ impl S3 for FS {
// Per S3 API spec, this header should be present in HEAD object response when tags exist
if tag_count > 0 {
let header_name = http::HeaderName::from_static(AMZ_TAG_COUNT);
if let Ok(header_value) = tag_count.to_string().parse::<http::HeaderValue>() {
if let Ok(header_value) = tag_count.to_string().parse::<HeaderValue>() {
response.headers.insert(header_name, header_value);
} else {
warn!("Failed to parse x-amz-tagging-count header value, skipping");
@@ -4105,9 +4104,7 @@ impl S3 for FS {
if dsc.replicate_any() {
let k = format!("{}{}", RESERVED_METADATA_PREFIX_LOWER, "replication-timestamp");
let now: DateTime<Utc> = Utc::now();
let formatted_time = now.to_rfc3339();
opts.user_defined.insert(k, formatted_time);
opts.user_defined.insert(k, jiff::Zoned::now().to_string());
let k = format!("{}{}", RESERVED_METADATA_PREFIX_LOWER, "replication-status");
opts.user_defined.insert(k, dsc.pending_status().unwrap_or_default());
}
@@ -7807,7 +7804,7 @@ mod tests {
let result = process_queue_configurations(
&mut event_rules,
Some(vec![s3s::dto::QueueConfiguration {
Some(vec![QueueConfiguration {
events: vec!["s3:ObjectCreated:*".to_string().into()],
queue_arn: invalid_arn.to_string(),
filter: None,
@@ -7833,7 +7830,7 @@ mod tests {
let result = process_topic_configurations(
&mut event_rules,
Some(vec![s3s::dto::TopicConfiguration {
Some(vec![TopicConfiguration {
events: vec!["s3:ObjectCreated:*".to_string().into()],
topic_arn: invalid_arn.to_string(),
filter: None,
@@ -7859,7 +7856,7 @@ mod tests {
let result = process_lambda_configurations(
&mut event_rules,
Some(vec![s3s::dto::LambdaFunctionConfiguration {
Some(vec![LambdaFunctionConfiguration {
events: vec!["s3:ObjectCreated:*".to_string().into()],
lambda_function_arn: invalid_arn.to_string(),
filter: None,
@@ -7885,7 +7882,7 @@ mod tests {
let result = process_queue_configurations(
&mut event_rules,
Some(vec![s3s::dto::QueueConfiguration {
Some(vec![QueueConfiguration {
events: vec!["s3:ObjectCreated:*".to_string().into()],
queue_arn: valid_arn.to_string(),
filter: None,
+6 -8
View File
@@ -55,7 +55,7 @@ pub struct UpdateCheckResult {
/// Latest version information
pub latest_version: Option<VersionInfo>,
/// Check time
pub check_time: chrono::DateTime<chrono::Utc>,
pub check_time: jiff::Zoned,
}
/// Version checker
@@ -146,7 +146,7 @@ impl VersionChecker {
update_available,
current_version,
latest_version: Some(version_info),
check_time: chrono::Utc::now(),
check_time: jiff::Zoned::now(),
};
if result.update_available {
@@ -194,8 +194,6 @@ mod tests {
#[test]
fn test_update_check_result() {
use chrono::Utc;
// Test creating UpdateCheckResult with update available
let version_info = VersionInfo {
version: "1.2.0".to_string(),
@@ -204,12 +202,12 @@ mod tests {
download_url: Some("https://github.com/rustfs/rustfs/releases/tag/v1.2.0".to_string()),
};
let check_time = Utc::now();
let check_time = jiff::Zoned::now();
let result = UpdateCheckResult {
update_available: true,
current_version: "1.1.0".to_string(),
latest_version: Some(version_info.clone()),
check_time,
check_time: check_time.clone(),
};
debug!("Update check result: {:?}", serde_json::to_string(&result).unwrap());
@@ -253,7 +251,7 @@ mod tests {
release_notes: None,
download_url: None,
}),
check_time: Utc::now(),
check_time: jiff::Zoned::now(),
};
assert!(!no_update_result.update_available);
@@ -264,7 +262,7 @@ mod tests {
update_available: false,
current_version: "1.1.0".to_string(),
latest_version: None,
check_time: Utc::now(),
check_time: jiff::Zoned::now(),
};
assert!(!error_result.update_available);