From 00d8008a8960cbaad53ebecb5a40501fd964084e Mon Sep 17 00:00:00 2001 From: weisd Date: Wed, 9 Jul 2025 14:48:51 +0800 Subject: [PATCH] Feat/region (#132) * add region config --- crates/ecstore/src/global.rs | 12 +++++++++++- rustfs/src/config/mod.rs | 3 +++ rustfs/src/main.rs | 4 ++++ rustfs/src/storage/ecfs.rs | 6 ++++++ scripts/run.sh | 2 ++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/ecstore/src/global.rs b/crates/ecstore/src/global.rs index e809d2e9..37760eee 100644 --- a/crates/ecstore/src/global.rs +++ b/crates/ecstore/src/global.rs @@ -62,7 +62,9 @@ static ref globalDeploymentIDPtr: OnceLock = OnceLock::new(); pub static ref GLOBAL_BOOT_TIME: OnceCell = OnceCell::new(); pub static ref GLOBAL_LocalNodeName: String = "127.0.0.1:9000".to_string(); pub static ref GLOBAL_LocalNodeNameHex: String = rustfs_utils::crypto::hex(GLOBAL_LocalNodeName.as_bytes()); -pub static ref GLOBAL_NodeNamesHex: HashMap = HashMap::new();} +pub static ref GLOBAL_NodeNamesHex: HashMap = HashMap::new(); +pub static ref GLOBAL_REGION: OnceLock = OnceLock::new(); +} static GLOBAL_ACTIVE_CRED: OnceLock = OnceLock::new(); @@ -182,3 +184,11 @@ pub async fn update_erasure_type(setup_type: SetupType) { // } type TypeLocalDiskSetDrives = Vec>>>; + +pub fn set_global_region(region: String) { + GLOBAL_REGION.set(region).unwrap(); +} + +pub fn get_global_region() -> Option { + GLOBAL_REGION.get().cloned() +} diff --git a/rustfs/src/config/mod.rs b/rustfs/src/config/mod.rs index fc869937..8b93801b 100644 --- a/rustfs/src/config/mod.rs +++ b/rustfs/src/config/mod.rs @@ -86,6 +86,9 @@ pub struct Opt { #[arg(long, env = "RUSTFS_LICENSE")] pub license: Option, + + #[arg(long, env = "RUSTFS_REGION")] + pub region: Option, } // lazy_static::lazy_static! { diff --git a/rustfs/src/main.rs b/rustfs/src/main.rs index 673b8871..19b39ba5 100644 --- a/rustfs/src/main.rs +++ b/rustfs/src/main.rs @@ -174,6 +174,10 @@ async fn setup_tls_acceptor(tls_path: &str) -> Result> { async fn run(opt: config::Opt) -> Result<()> { debug!("opt: {:?}", &opt); + if let Some(region) = opt.region { + rustfs_ecstore::global::set_global_region(region); + } + let server_addr = parse_and_resolve_address(opt.address.as_str()).map_err(Error::other)?; let server_port = server_addr.port(); let server_address = server_addr.to_string(); diff --git a/rustfs/src/storage/ecfs.rs b/rustfs/src/storage/ecfs.rs index 6782f5c0..0c2f0ccd 100644 --- a/rustfs/src/storage/ecfs.rs +++ b/rustfs/src/storage/ecfs.rs @@ -703,6 +703,12 @@ impl S3 for FS { .await .map_err(ApiError::from)?; + if let Some(region) = rustfs_ecstore::global::get_global_region() { + return Ok(S3Response::new(GetBucketLocationOutput { + location_constraint: Some(BucketLocationConstraint::from(region)), + })); + } + let output = GetBucketLocationOutput::default(); Ok(S3Response::new(output)) } diff --git a/scripts/run.sh b/scripts/run.sh index 34b08fec..fa53566a 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -100,6 +100,8 @@ export RUSTFS_NS_SCANNER_INTERVAL=60 # 对象扫描间隔时间,单位为秒 export RUSTFS_COMPRESSION_ENABLED=true # 是否启用压缩 +#export RUSTFS_REGION="us-east-1" + # 事件消息配置 #export RUSTFS_EVENT_CONFIG="./deploy/config/event.example.toml"