mirror of
https://github.com/rustfs/rustfs.git
synced 2026-09-03 10:48:13 +00:00
refactor: replace lazy_static with LazyLock (#164)
* refactor: replace `lazy_static` with `LazyLock` * update cursorrules --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
+1
-1
@@ -517,7 +517,7 @@ let results = join_all(futures).await;
|
|||||||
|
|
||||||
### 3. Caching Strategy
|
### 3. Caching Strategy
|
||||||
|
|
||||||
- Use `lazy_static` or `OnceCell` for global caching
|
- Use `LazyLock` for global caching
|
||||||
- Implement LRU cache to avoid memory leaks
|
- Implement LRU cache to avoid memory leaks
|
||||||
|
|
||||||
## Testing Guidelines
|
## Testing Guidelines
|
||||||
|
|||||||
Generated
-8
@@ -7848,7 +7848,6 @@ dependencies = [
|
|||||||
"http-body 1.0.1",
|
"http-body 1.0.1",
|
||||||
"hyper 1.6.0",
|
"hyper 1.6.0",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"lazy_static",
|
|
||||||
"libsystemd",
|
"libsystemd",
|
||||||
"matchit",
|
"matchit",
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
@@ -7940,7 +7939,6 @@ dependencies = [
|
|||||||
name = "rustfs-common"
|
name = "rustfs-common"
|
||||||
version = "0.0.5"
|
version = "0.0.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"tonic",
|
"tonic",
|
||||||
]
|
]
|
||||||
@@ -8077,7 +8075,6 @@ dependencies = [
|
|||||||
"dirs",
|
"dirs",
|
||||||
"hex",
|
"hex",
|
||||||
"keyring",
|
"keyring",
|
||||||
"lazy_static",
|
|
||||||
"rfd 0.15.3",
|
"rfd 0.15.3",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"rust-i18n",
|
"rust-i18n",
|
||||||
@@ -8098,7 +8095,6 @@ dependencies = [
|
|||||||
"base64-simd",
|
"base64-simd",
|
||||||
"futures",
|
"futures",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
"lazy_static",
|
|
||||||
"rand 0.9.1",
|
"rand 0.9.1",
|
||||||
"rustfs-crypto",
|
"rustfs-crypto",
|
||||||
"rustfs-ecstore",
|
"rustfs-ecstore",
|
||||||
@@ -8118,7 +8114,6 @@ name = "rustfs-lock"
|
|||||||
version = "0.0.5"
|
version = "0.0.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"lazy_static",
|
|
||||||
"rand 0.9.1",
|
"rand 0.9.1",
|
||||||
"rustfs-protos",
|
"rustfs-protos",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -8315,7 +8310,6 @@ dependencies = [
|
|||||||
"datafusion",
|
"datafusion",
|
||||||
"derive_builder",
|
"derive_builder",
|
||||||
"futures",
|
"futures",
|
||||||
"lazy_static",
|
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"rustfs-s3select-api",
|
"rustfs-s3select-api",
|
||||||
"s3s",
|
"s3s",
|
||||||
@@ -8331,7 +8325,6 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"http 1.3.1",
|
"http 1.3.1",
|
||||||
"hyper 1.6.0",
|
"hyper 1.6.0",
|
||||||
"lazy_static",
|
|
||||||
"rand 0.9.1",
|
"rand 0.9.1",
|
||||||
"rustfs-utils",
|
"rustfs-utils",
|
||||||
"s3s",
|
"s3s",
|
||||||
@@ -8358,7 +8351,6 @@ dependencies = [
|
|||||||
"hmac 0.12.1",
|
"hmac 0.12.1",
|
||||||
"hyper 1.6.0",
|
"hyper 1.6.0",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"lazy_static",
|
|
||||||
"local-ip-address",
|
"local-ip-address",
|
||||||
"lz4",
|
"lz4",
|
||||||
"md-5",
|
"md-5",
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ dioxus = { workspace = true, features = ["router"] }
|
|||||||
dirs = { workspace = true }
|
dirs = { workspace = true }
|
||||||
hex = { workspace = true }
|
hex = { workspace = true }
|
||||||
keyring = { workspace = true }
|
keyring = { workspace = true }
|
||||||
lazy_static = { workspace = true }
|
|
||||||
rfd = { workspace = true }
|
rfd = { workspace = true }
|
||||||
rust-embed = { workspace = true, features = ["interpolate-folder-path"] }
|
rust-embed = { workspace = true, features = ["interpolate-folder-path"] }
|
||||||
rust-i18n = { workspace = true }
|
rust-i18n = { workspace = true }
|
||||||
|
|||||||
@@ -14,12 +14,12 @@
|
|||||||
|
|
||||||
use crate::utils::RustFSConfig;
|
use crate::utils::RustFSConfig;
|
||||||
use dioxus::logger::tracing::{debug, error, info};
|
use dioxus::logger::tracing::{debug, error, info};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command as StdCommand;
|
use std::process::Command as StdCommand;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
@@ -31,15 +31,13 @@ use tokio::sync::{Mutex, mpsc};
|
|||||||
#[folder = "$CARGO_MANIFEST_DIR/embedded-rustfs/"]
|
#[folder = "$CARGO_MANIFEST_DIR/embedded-rustfs/"]
|
||||||
struct Asset;
|
struct Asset;
|
||||||
|
|
||||||
// Use `lazy_static` to cache the checksum of embedded resources
|
// Use `LazyLock` to cache the checksum of embedded resources
|
||||||
lazy_static! {
|
static RUSTFS_HASH: LazyLock<Mutex<String>> = LazyLock::new(|| {
|
||||||
static ref RUSTFS_HASH: Mutex<String> = {
|
let rustfs_file = if cfg!(windows) { "rustfs.exe" } else { "rustfs" };
|
||||||
let rustfs_file = if cfg!(windows) { "rustfs.exe" } else { "rustfs" };
|
let rustfs_data = Asset::get(rustfs_file).expect("RustFs binary not embedded");
|
||||||
let rustfs_data = Asset::get(rustfs_file).expect("RustFs binary not embedded");
|
let hash = hex::encode(Sha256::digest(&rustfs_data.data));
|
||||||
let hash = hex::encode(Sha256::digest(&rustfs_data.data));
|
Mutex::new(hash)
|
||||||
Mutex::new(hash)
|
});
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Service command
|
/// Service command
|
||||||
/// This enum represents the commands that can be sent to the service manager
|
/// This enum represents the commands that can be sent to the service manager
|
||||||
|
|||||||
@@ -28,6 +28,5 @@ categories = ["web-programming", "development-tools", "data-structures"]
|
|||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lazy_static.workspace = true
|
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
tonic = { workspace = true }
|
tonic = { workspace = true }
|
||||||
|
|||||||
@@ -12,19 +12,19 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::collections::HashMap;
|
#![allow(non_upper_case_globals)] // FIXME
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tonic::transport::Channel;
|
use tonic::transport::Channel;
|
||||||
|
|
||||||
lazy_static! {
|
pub static GLOBAL_Local_Node_Name: LazyLock<RwLock<String>> = LazyLock::new(|| RwLock::new("".to_string()));
|
||||||
pub static ref GLOBAL_Local_Node_Name: RwLock<String> = RwLock::new("".to_string());
|
pub static GLOBAL_Rustfs_Host: LazyLock<RwLock<String>> = LazyLock::new(|| RwLock::new("".to_string()));
|
||||||
pub static ref GLOBAL_Rustfs_Host: RwLock<String> = RwLock::new("".to_string());
|
pub static GLOBAL_Rustfs_Port: LazyLock<RwLock<String>> = LazyLock::new(|| RwLock::new("9000".to_string()));
|
||||||
pub static ref GLOBAL_Rustfs_Port: RwLock<String> = RwLock::new("9000".to_string());
|
pub static GLOBAL_Rustfs_Addr: LazyLock<RwLock<String>> = LazyLock::new(|| RwLock::new("".to_string()));
|
||||||
pub static ref GLOBAL_Rustfs_Addr: RwLock<String> = RwLock::new("".to_string());
|
pub static GLOBAL_Conn_Map: LazyLock<RwLock<HashMap<String, Channel>>> = LazyLock::new(|| RwLock::new(HashMap::new()));
|
||||||
pub static ref GLOBAL_Conn_Map: RwLock<HashMap<String, Channel>> = RwLock::new(HashMap::new());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn set_global_addr(addr: &str) {
|
pub async fn set_global_addr(addr: &str) {
|
||||||
*GLOBAL_Rustfs_Addr.write().await = addr.to_string();
|
*GLOBAL_Rustfs_Addr.write().await = addr.to_string();
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ base64-simd = { workspace = true }
|
|||||||
jsonwebtoken = { workspace = true }
|
jsonwebtoken = { workspace = true }
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
rustfs-madmin.workspace = true
|
rustfs-madmin.workspace = true
|
||||||
lazy_static.workspace = true
|
|
||||||
rustfs-utils = { workspace = true, features = ["path"] }
|
rustfs-utils = { workspace = true, features = ["path"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ use crate::{
|
|||||||
manager::{extract_jwt_claims, get_default_policyes},
|
manager::{extract_jwt_claims, get_default_policyes},
|
||||||
};
|
};
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use rustfs_ecstore::{
|
use rustfs_ecstore::{
|
||||||
config::{
|
config::{
|
||||||
RUSTFS_CONFIG_PREFIX,
|
RUSTFS_CONFIG_PREFIX,
|
||||||
@@ -34,25 +33,28 @@ use rustfs_ecstore::{
|
|||||||
use rustfs_policy::{auth::UserIdentity, policy::PolicyDoc};
|
use rustfs_policy::{auth::UserIdentity, policy::PolicyDoc};
|
||||||
use rustfs_utils::path::{SLASH_SEPARATOR, path_join_buf};
|
use rustfs_utils::path::{SLASH_SEPARATOR, path_join_buf};
|
||||||
use serde::{Serialize, de::DeserializeOwned};
|
use serde::{Serialize, de::DeserializeOwned};
|
||||||
|
use std::sync::LazyLock;
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
use tokio::sync::broadcast::{self, Receiver as B_Receiver};
|
use tokio::sync::broadcast::{self, Receiver as B_Receiver};
|
||||||
use tokio::sync::mpsc::{self, Sender};
|
use tokio::sync::mpsc::{self, Sender};
|
||||||
use tracing::{debug, info, warn};
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
lazy_static! {
|
pub static IAM_CONFIG_PREFIX: LazyLock<String> = LazyLock::new(|| format!("{RUSTFS_CONFIG_PREFIX}/iam"));
|
||||||
pub static ref IAM_CONFIG_PREFIX: String = format!("{}/iam", RUSTFS_CONFIG_PREFIX);
|
pub static IAM_CONFIG_USERS_PREFIX: LazyLock<String> = LazyLock::new(|| format!("{RUSTFS_CONFIG_PREFIX}/iam/users/"));
|
||||||
pub static ref IAM_CONFIG_USERS_PREFIX: String = format!("{}/iam/users/", RUSTFS_CONFIG_PREFIX);
|
pub static IAM_CONFIG_SERVICE_ACCOUNTS_PREFIX: LazyLock<String> =
|
||||||
pub static ref IAM_CONFIG_SERVICE_ACCOUNTS_PREFIX: String = format!("{}/iam/service-accounts/", RUSTFS_CONFIG_PREFIX);
|
LazyLock::new(|| format!("{RUSTFS_CONFIG_PREFIX}/iam/service-accounts/"));
|
||||||
pub static ref IAM_CONFIG_GROUPS_PREFIX: String = format!("{}/iam/groups/", RUSTFS_CONFIG_PREFIX);
|
pub static IAM_CONFIG_GROUPS_PREFIX: LazyLock<String> = LazyLock::new(|| format!("{RUSTFS_CONFIG_PREFIX}/iam/groups/"));
|
||||||
pub static ref IAM_CONFIG_POLICIES_PREFIX: String = format!("{}/iam/policies/", RUSTFS_CONFIG_PREFIX);
|
pub static IAM_CONFIG_POLICIES_PREFIX: LazyLock<String> = LazyLock::new(|| format!("{RUSTFS_CONFIG_PREFIX}/iam/policies/"));
|
||||||
pub static ref IAM_CONFIG_STS_PREFIX: String = format!("{}/iam/sts/", RUSTFS_CONFIG_PREFIX);
|
pub static IAM_CONFIG_STS_PREFIX: LazyLock<String> = LazyLock::new(|| format!("{RUSTFS_CONFIG_PREFIX}/iam/sts/"));
|
||||||
pub static ref IAM_CONFIG_POLICY_DB_PREFIX: String = format!("{}/iam/policydb/", RUSTFS_CONFIG_PREFIX);
|
pub static IAM_CONFIG_POLICY_DB_PREFIX: LazyLock<String> = LazyLock::new(|| format!("{RUSTFS_CONFIG_PREFIX}/iam/policydb/"));
|
||||||
pub static ref IAM_CONFIG_POLICY_DB_USERS_PREFIX: String = format!("{}/iam/policydb/users/", RUSTFS_CONFIG_PREFIX);
|
pub static IAM_CONFIG_POLICY_DB_USERS_PREFIX: LazyLock<String> =
|
||||||
pub static ref IAM_CONFIG_POLICY_DB_STS_USERS_PREFIX: String = format!("{}/iam/policydb/sts-users/", RUSTFS_CONFIG_PREFIX);
|
LazyLock::new(|| format!("{RUSTFS_CONFIG_PREFIX}/iam/policydb/users/"));
|
||||||
pub static ref IAM_CONFIG_POLICY_DB_SERVICE_ACCOUNTS_PREFIX: String =
|
pub static IAM_CONFIG_POLICY_DB_STS_USERS_PREFIX: LazyLock<String> =
|
||||||
format!("{}/iam/policydb/service-accounts/", RUSTFS_CONFIG_PREFIX);
|
LazyLock::new(|| format!("{RUSTFS_CONFIG_PREFIX}/iam/policydb/sts-users/"));
|
||||||
pub static ref IAM_CONFIG_POLICY_DB_GROUPS_PREFIX: String = format!("{}/iam/policydb/groups/", RUSTFS_CONFIG_PREFIX);
|
pub static IAM_CONFIG_POLICY_DB_SERVICE_ACCOUNTS_PREFIX: LazyLock<String> =
|
||||||
}
|
LazyLock::new(|| format!("{RUSTFS_CONFIG_PREFIX}/iam/policydb/service-accounts/"));
|
||||||
|
pub static IAM_CONFIG_POLICY_DB_GROUPS_PREFIX: LazyLock<String> =
|
||||||
|
LazyLock::new(|| format!("{RUSTFS_CONFIG_PREFIX}/iam/policydb/groups/"));
|
||||||
|
|
||||||
const IAM_IDENTITY_FILE: &str = "identity.json";
|
const IAM_IDENTITY_FILE: &str = "identity.json";
|
||||||
const IAM_POLICY_FILE: &str = "policy.json";
|
const IAM_POLICY_FILE: &str = "policy.json";
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ workspace = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-trait.workspace = true
|
async-trait.workspace = true
|
||||||
lazy_static.workspace = true
|
|
||||||
rustfs-protos.workspace = true
|
rustfs-protos.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
|
|||||||
@@ -14,12 +14,12 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use local_locker::LocalLocker;
|
use local_locker::LocalLocker;
|
||||||
use lock_args::LockArgs;
|
use lock_args::LockArgs;
|
||||||
use remote_client::RemoteClient;
|
use remote_client::RemoteClient;
|
||||||
use std::io::Result;
|
use std::io::Result;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
pub mod drwmutex;
|
pub mod drwmutex;
|
||||||
@@ -29,9 +29,7 @@ pub mod lrwmutex;
|
|||||||
pub mod namespace_lock;
|
pub mod namespace_lock;
|
||||||
pub mod remote_client;
|
pub mod remote_client;
|
||||||
|
|
||||||
lazy_static! {
|
pub static GLOBAL_LOCAL_SERVER: LazyLock<Arc<RwLock<LocalLocker>>> = LazyLock::new(|| Arc::new(RwLock::new(LocalLocker::new())));
|
||||||
pub static ref GLOBAL_LOCAL_SERVER: Arc<RwLock<LocalLocker>> = Arc::new(RwLock::new(LocalLocker::new()));
|
|
||||||
}
|
|
||||||
|
|
||||||
type LockClient = dyn Locker;
|
type LockClient = dyn Locker;
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ async-trait.workspace = true
|
|||||||
datafusion = { workspace = true }
|
datafusion = { workspace = true }
|
||||||
derive_builder = { workspace = true }
|
derive_builder = { workspace = true }
|
||||||
futures = { workspace = true }
|
futures = { workspace = true }
|
||||||
lazy_static = { workspace = true }
|
|
||||||
parking_lot = { workspace = true }
|
parking_lot = { workspace = true }
|
||||||
s3s.workspace = true
|
s3s.workspace = true
|
||||||
snafu = { workspace = true, features = ["backtrace"] }
|
snafu = { workspace = true, features = ["backtrace"] }
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ use datafusion::{
|
|||||||
execution::{RecordBatchStream, SendableRecordBatchStream},
|
execution::{RecordBatchStream, SendableRecordBatchStream},
|
||||||
};
|
};
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use rustfs_s3select_api::{
|
use rustfs_s3select_api::{
|
||||||
QueryError, QueryResult,
|
QueryError, QueryResult,
|
||||||
query::{
|
query::{
|
||||||
@@ -48,6 +47,7 @@ use rustfs_s3select_api::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use s3s::dto::{FileHeaderInfo, SelectObjectContentInput};
|
use s3s::dto::{FileHeaderInfo, SelectObjectContentInput};
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
execution::factory::QueryExecutionFactoryRef,
|
execution::factory::QueryExecutionFactoryRef,
|
||||||
@@ -55,11 +55,9 @@ use crate::{
|
|||||||
sql::logical::planner::DefaultLogicalPlanner,
|
sql::logical::planner::DefaultLogicalPlanner,
|
||||||
};
|
};
|
||||||
|
|
||||||
lazy_static! {
|
static IGNORE: LazyLock<FileHeaderInfo> = LazyLock::new(|| FileHeaderInfo::from_static(FileHeaderInfo::IGNORE));
|
||||||
static ref IGNORE: FileHeaderInfo = FileHeaderInfo::from_static(FileHeaderInfo::IGNORE);
|
static NONE: LazyLock<FileHeaderInfo> = LazyLock::new(|| FileHeaderInfo::from_static(FileHeaderInfo::NONE));
|
||||||
static ref NONE: FileHeaderInfo = FileHeaderInfo::from_static(FileHeaderInfo::NONE);
|
static USE: LazyLock<FileHeaderInfo> = LazyLock::new(|| FileHeaderInfo::from_static(FileHeaderInfo::USE));
|
||||||
static ref USE: FileHeaderInfo = FileHeaderInfo::from_static(FileHeaderInfo::USE);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SimpleQueryDispatcher {
|
pub struct SimpleQueryDispatcher {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ documentation = "https://docs.rs/rustfs-signer/latest/rustfs_signer/"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
lazy_static.workspace = true
|
|
||||||
bytes = { workspace = true }
|
bytes = { workspace = true }
|
||||||
http.workspace = true
|
http.workspace = true
|
||||||
time.workspace = true
|
time.workspace = true
|
||||||
|
|||||||
@@ -13,8 +13,6 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use http::{HeaderMap, HeaderValue, request};
|
use http::{HeaderMap, HeaderValue, request};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use time::{OffsetDateTime, macros::format_description};
|
use time::{OffsetDateTime, macros::format_description};
|
||||||
|
|
||||||
use super::request_signature_v4::{SERVICE_TYPE_S3, get_scope, get_signature, get_signing_key};
|
use super::request_signature_v4::{SERVICE_TYPE_S3, get_scope, get_signature, get_signing_key};
|
||||||
@@ -32,15 +30,13 @@ const _CRLF_LEN: i64 = 2;
|
|||||||
const _TRAILER_KV_SEPARATOR: &str = ":";
|
const _TRAILER_KV_SEPARATOR: &str = ":";
|
||||||
const _TRAILER_SIGNATURE: &str = "x-amz-trailer-signature";
|
const _TRAILER_SIGNATURE: &str = "x-amz-trailer-signature";
|
||||||
|
|
||||||
lazy_static! {
|
// static ignored_streaming_headers: LazyLock<HashMap<String, bool>> = LazyLock::new(|| {
|
||||||
static ref ignored_streaming_headers: HashMap<String, bool> = {
|
// let mut m = <HashMap<String, bool>>::new();
|
||||||
let mut m = <HashMap<String, bool>>::new();
|
// m.insert("authorization".to_string(), true);
|
||||||
m.insert("authorization".to_string(), true);
|
// m.insert("user-agent".to_string(), true);
|
||||||
m.insert("user-agent".to_string(), true);
|
// m.insert("content-type".to_string(), true);
|
||||||
m.insert("content-type".to_string(), true);
|
// m
|
||||||
m
|
// });
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_chunk_string_to_sign(t: OffsetDateTime, region: &str, previous_sig: &str, chunk_check_sum: &str) -> String {
|
fn build_chunk_string_to_sign(t: OffsetDateTime, region: &str, previous_sig: &str, chunk_check_sum: &str) -> String {
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ use bytes::BytesMut;
|
|||||||
use http::HeaderMap;
|
use http::HeaderMap;
|
||||||
use http::Uri;
|
use http::Uri;
|
||||||
use http::request;
|
use http::request;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use time::{OffsetDateTime, macros::format_description};
|
use time::{OffsetDateTime, macros::format_description};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
@@ -32,15 +32,14 @@ pub const SIGN_V4_ALGORITHM: &str = "AWS4-HMAC-SHA256";
|
|||||||
pub const SERVICE_TYPE_S3: &str = "s3";
|
pub const SERVICE_TYPE_S3: &str = "s3";
|
||||||
pub const SERVICE_TYPE_STS: &str = "sts";
|
pub const SERVICE_TYPE_STS: &str = "sts";
|
||||||
|
|
||||||
lazy_static! {
|
#[allow(non_upper_case_globals)] // FIXME
|
||||||
static ref v4_ignored_headers: HashMap<String, bool> = {
|
static v4_ignored_headers: LazyLock<HashMap<String, bool>> = LazyLock::new(|| {
|
||||||
let mut m = <HashMap<String, bool>>::new();
|
let mut m = <HashMap<String, bool>>::new();
|
||||||
m.insert("accept-encoding".to_string(), true);
|
m.insert("accept-encoding".to_string(), true);
|
||||||
m.insert("authorization".to_string(), true);
|
m.insert("authorization".to_string(), true);
|
||||||
m.insert("user-agent".to_string(), true);
|
m.insert("user-agent".to_string(), true);
|
||||||
m
|
m
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_signing_key(secret: &str, loc: &str, t: OffsetDateTime, service_type: &str) -> [u8; 32] {
|
pub fn get_signing_key(secret: &str, loc: &str, t: OffsetDateTime, service_type: &str) -> [u8; 32] {
|
||||||
let mut s = "AWS4".to_string();
|
let mut s = "AWS4".to_string();
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ blake3 = { workspace = true, optional = true }
|
|||||||
crc32fast.workspace = true
|
crc32fast.workspace = true
|
||||||
hex-simd = { workspace = true, optional = true }
|
hex-simd = { workspace = true, optional = true }
|
||||||
highway = { workspace = true, optional = true }
|
highway = { workspace = true, optional = true }
|
||||||
lazy_static = { workspace = true, optional = true }
|
|
||||||
local-ip-address = { workspace = true, optional = true }
|
local-ip-address = { workspace = true, optional = true }
|
||||||
md-5 = { workspace = true, optional = true }
|
md-5 = { workspace = true, optional = true }
|
||||||
netif = { workspace = true, optional = true }
|
netif = { workspace = true, optional = true }
|
||||||
@@ -77,12 +76,12 @@ workspace = true
|
|||||||
default = ["ip"] # features that are enabled by default
|
default = ["ip"] # features that are enabled by default
|
||||||
ip = ["dep:local-ip-address"] # ip characteristics and their dependencies
|
ip = ["dep:local-ip-address"] # ip characteristics and their dependencies
|
||||||
tls = ["dep:rustls", "dep:rustls-pemfile", "dep:rustls-pki-types"] # tls characteristics and their dependencies
|
tls = ["dep:rustls", "dep:rustls-pemfile", "dep:rustls-pki-types"] # tls characteristics and their dependencies
|
||||||
net = ["ip", "dep:url", "dep:netif", "dep:lazy_static", "dep:futures", "dep:transform-stream", "dep:bytes", "dep:s3s", "dep:hyper", "dep:hyper-util"] # empty network features
|
net = ["ip", "dep:url", "dep:netif", "dep:futures", "dep:transform-stream", "dep:bytes", "dep:s3s", "dep:hyper", "dep:hyper-util"] # empty network features
|
||||||
io = ["dep:tokio"]
|
io = ["dep:tokio"]
|
||||||
path = []
|
path = []
|
||||||
notify = ["dep:hyper", "dep:s3s"] # file system notification features
|
notify = ["dep:hyper", "dep:s3s"] # file system notification features
|
||||||
compress = ["dep:flate2", "dep:brotli", "dep:snap", "dep:lz4", "dep:zstd"]
|
compress = ["dep:flate2", "dep:brotli", "dep:snap", "dep:lz4", "dep:zstd"]
|
||||||
string = ["dep:regex", "dep:lazy_static", "dep:rand"]
|
string = ["dep:regex", "dep:rand"]
|
||||||
crypto = ["dep:base64-simd", "dep:hex-simd", "dep:hmac", "dep:hyper", "dep:sha1"]
|
crypto = ["dep:base64-simd", "dep:hex-simd", "dep:hmac", "dep:hyper", "dep:sha1"]
|
||||||
hash = ["dep:highway", "dep:md-5", "dep:sha2", "dep:blake3", "dep:serde", "dep:siphasher", "dep:hex-simd", "dep:base64-simd"]
|
hash = ["dep:highway", "dep:md-5", "dep:sha2", "dep:blake3", "dep:serde", "dep:siphasher", "dep:hex-simd", "dep:base64-simd"]
|
||||||
os = ["dep:nix", "dep:tempfile", "winapi"] # operating system utilities
|
os = ["dep:nix", "dep:tempfile", "winapi"] # operating system utilities
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ use futures::pin_mut;
|
|||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
use hyper::client::conn::http2::Builder;
|
use hyper::client::conn::http2::Builder;
|
||||||
use hyper_util::rt::TokioExecutor;
|
use hyper_util::rt::TokioExecutor;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use std::net::Ipv6Addr;
|
use std::net::Ipv6Addr;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
@@ -27,9 +27,7 @@ use std::{
|
|||||||
use transform_stream::AsyncTryStream;
|
use transform_stream::AsyncTryStream;
|
||||||
use url::{Host, Url};
|
use url::{Host, Url};
|
||||||
|
|
||||||
lazy_static! {
|
static LOCAL_IPS: LazyLock<Vec<IpAddr>> = LazyLock::new(|| must_get_local_ips().unwrap());
|
||||||
static ref LOCAL_IPS: Vec<IpAddr> = must_get_local_ips().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// helper for validating if the provided arg is an ip address.
|
/// helper for validating if the provided arg is an ip address.
|
||||||
pub fn is_socket_addr(addr: &str) -> bool {
|
pub fn is_socket_addr(addr: &str) -> bool {
|
||||||
|
|||||||
@@ -12,10 +12,10 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use lazy_static::*;
|
|
||||||
use rand::{Rng, RngCore};
|
use rand::{Rng, RngCore};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::io::{Error, Result};
|
use std::io::{Error, Result};
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
pub fn parse_bool(str: &str) -> Result<bool> {
|
pub fn parse_bool(str: &str) -> Result<bool> {
|
||||||
match str {
|
match str {
|
||||||
@@ -116,9 +116,7 @@ pub fn match_as_pattern_prefix(pattern: &str, text: &str) -> bool {
|
|||||||
text.len() <= pattern.len()
|
text.len() <= pattern.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
static ELLIPSES_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(.*)(\{[0-9a-z]*\.\.\.[0-9a-z]*\})(.*)").unwrap());
|
||||||
static ref ELLIPSES_RE: Regex = Regex::new(r"(.*)(\{[0-9a-z]*\.\.\.[0-9a-z]*\})(.*)").unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ellipses constants
|
/// Ellipses constants
|
||||||
const OPEN_BRACES: &str = "{";
|
const OPEN_BRACES: &str = "{";
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ hyper.workspace = true
|
|||||||
hyper-util.workspace = true
|
hyper-util.workspace = true
|
||||||
http.workspace = true
|
http.workspace = true
|
||||||
http-body.workspace = true
|
http-body.workspace = true
|
||||||
lazy_static.workspace = true
|
|
||||||
matchit = { workspace = true }
|
matchit = { workspace = true }
|
||||||
mime_guess = { workspace = true }
|
mime_guess = { workspace = true }
|
||||||
opentelemetry = { workspace = true }
|
opentelemetry = { workspace = true }
|
||||||
|
|||||||
@@ -20,9 +20,7 @@ use std::time::UNIX_EPOCH;
|
|||||||
use tracing::error;
|
use tracing::error;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
static LICENSE: OnceLock<Token> = OnceLock::new();
|
||||||
static ref LICENSE: OnceLock<Token> = OnceLock::new();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Initialize the license
|
/// Initialize the license
|
||||||
pub fn init_license(license: Option<String>) {
|
pub fn init_license(license: Option<String>) {
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ use rustfs_s3select_api::server::dbms::DatabaseManagerSystem;
|
|||||||
// use rustfs_ecstore::store_api::RESERVED_METADATA_PREFIX;
|
// use rustfs_ecstore::store_api::RESERVED_METADATA_PREFIX;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use http::HeaderMap;
|
use http::HeaderMap;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use rustfs_ecstore::bucket::lifecycle::bucket_lifecycle_ops::validate_transition_tier;
|
use rustfs_ecstore::bucket::lifecycle::bucket_lifecycle_ops::validate_transition_tier;
|
||||||
use rustfs_ecstore::bucket::lifecycle::lifecycle::Lifecycle;
|
use rustfs_ecstore::bucket::lifecycle::lifecycle::Lifecycle;
|
||||||
use rustfs_ecstore::bucket::metadata::BUCKET_LIFECYCLE_CONFIG;
|
use rustfs_ecstore::bucket::metadata::BUCKET_LIFECYCLE_CONFIG;
|
||||||
@@ -102,6 +101,7 @@ use std::fmt::Debug;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use time::format_description::well_known::Rfc3339;
|
use time::format_description::well_known::Rfc3339;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
@@ -126,12 +126,10 @@ macro_rules! try_ {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
static RUSTFS_OWNER: LazyLock<Owner> = LazyLock::new(|| Owner {
|
||||||
static ref RUSTFS_OWNER: Owner = Owner {
|
display_name: Some("rustfs".to_owned()),
|
||||||
display_name: Some("rustfs".to_owned()),
|
id: Some("c19050dbcee97fda828689dda99097a6321af2248fa760517237346e5d9c8a66".to_owned()),
|
||||||
id: Some("c19050dbcee97fda828689dda99097a6321af2248fa760517237346e5d9c8a66".to_owned()),
|
});
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct FS {
|
pub struct FS {
|
||||||
|
|||||||
@@ -13,13 +13,13 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use http::{HeaderMap, HeaderValue};
|
use http::{HeaderMap, HeaderValue};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use rustfs_ecstore::bucket::versioning_sys::BucketVersioningSys;
|
use rustfs_ecstore::bucket::versioning_sys::BucketVersioningSys;
|
||||||
use rustfs_ecstore::error::Result;
|
use rustfs_ecstore::error::Result;
|
||||||
use rustfs_ecstore::error::StorageError;
|
use rustfs_ecstore::error::StorageError;
|
||||||
use rustfs_ecstore::store_api::ObjectOptions;
|
use rustfs_ecstore::store_api::ObjectOptions;
|
||||||
use rustfs_utils::path::is_dir_object;
|
use rustfs_utils::path::is_dir_object;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// Creates options for deleting an object in a bucket.
|
/// Creates options for deleting an object in a bucket.
|
||||||
@@ -214,9 +214,9 @@ pub fn extract_metadata_from_mime(headers: &HeaderMap<HeaderValue>, metadata: &m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
/// List of supported headers.
|
||||||
/// List of supported headers.
|
static SUPPORTED_HEADERS: LazyLock<Vec<&'static str>> = LazyLock::new(|| {
|
||||||
static ref SUPPORTED_HEADERS: Vec<&'static str> = vec![
|
vec![
|
||||||
"content-type",
|
"content-type",
|
||||||
"cache-control",
|
"cache-control",
|
||||||
"content-language",
|
"content-language",
|
||||||
@@ -225,9 +225,9 @@ lazy_static! {
|
|||||||
"x-amz-storage-class",
|
"x-amz-storage-class",
|
||||||
"x-amz-tagging",
|
"x-amz-tagging",
|
||||||
"expires",
|
"expires",
|
||||||
"x-amz-replication-status"
|
"x-amz-replication-status",
|
||||||
];
|
]
|
||||||
}
|
});
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user