refactor(config): migrate server config consumers (#3353)

This commit is contained in:
安正超
2026-06-11 17:04:50 +08:00
committed by GitHub
parent 2205991180
commit ca58d7f0ec
53 changed files with 238 additions and 213 deletions
+1 -1
View File
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::config::{KV, KVS};
use rustfs_config::audit::AUDIT_REDIS_DEFAULT_CHANNEL;
use rustfs_config::server_config::{KV, KVS};
use rustfs_config::{
AMQP_EXCHANGE, AMQP_MANDATORY, AMQP_PASSWORD, AMQP_PERSISTENT, AMQP_QUEUE_DIR, AMQP_QUEUE_LIMIT, AMQP_ROUTING_KEY,
AMQP_TLS_CA, AMQP_TLS_CLIENT_CERT, AMQP_TLS_CLIENT_KEY, AMQP_URL, AMQP_USERNAME, COMMENT_KEY, DEFAULT_LIMIT, ENABLE_KEY,
+42 -40
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::config::{Config, KVS, audit, notify, oidc, set_global_storage_class, storageclass};
use crate::config::{audit, notify, oidc, set_global_storage_class, storageclass};
use crate::disk::{MIGRATING_META_BUCKET, RUSTFS_META_BUCKET};
use crate::error::{Error, Result};
use crate::global::is_first_cluster_node_local;
@@ -30,6 +30,7 @@ use rustfs_config::notify::{
NOTIFY_WEBHOOK_KEYS, NOTIFY_WEBHOOK_SUB_SYS,
};
use rustfs_config::oidc::{IDENTITY_OPENID_KEYS, IDENTITY_OPENID_SUB_SYS, OIDC_REDIRECT_URI_DYNAMIC};
use rustfs_config::server_config::{Config, KVS};
use rustfs_config::{COMMENT_KEY, DEFAULT_DELIMITER, ENABLE_KEY, EnableState, RUSTFS_REGION};
use rustfs_storage_api::StorageAdminApi;
use rustfs_utils::path::SLASH_SEPARATOR;
@@ -293,7 +294,7 @@ fn get_config_file() -> String {
format!("{CONFIG_PREFIX}{SLASH_SEPARATOR}{CONFIG_FILE}")
}
fn storage_class_kvs_mut(cfg: &mut Config) -> &mut crate::config::KVS {
fn storage_class_kvs_mut(cfg: &mut Config) -> &mut KVS {
let sub_cfg = cfg.0.entry(STORAGE_CLASS_SUB_SYS.to_string()).or_insert_with(|| {
let mut section = HashMap::new();
section.insert(DEFAULT_DELIMITER.to_string(), storageclass::DEFAULT_KVS.clone());
@@ -1210,7 +1211,7 @@ mod tests {
configs_semantically_equal, decode_server_config_blob, encode_server_config_blob, is_standard_object_server_config,
read_config_with_metadata, storage_class_kvs_mut,
};
use crate::config::{Config, audit, notify, oidc};
use crate::config::{audit, notify, oidc};
use crate::disk::endpoint::Endpoint;
use crate::endpoints::SetupType;
use crate::error::{Error, Result};
@@ -1228,6 +1229,7 @@ mod tests {
NOTIFY_AMQP_SUB_SYS, NOTIFY_KAFKA_SUB_SYS, NOTIFY_MQTT_SUB_SYS, NOTIFY_MYSQL_SUB_SYS, NOTIFY_WEBHOOK_SUB_SYS,
};
use rustfs_config::oidc::IDENTITY_OPENID_SUB_SYS;
use rustfs_config::server_config::{Config, KV, KVS};
use rustfs_config::{
DEFAULT_DELIMITER, ENABLE_KEY, EnableState, MYSQL_DSN_STRING, MYSQL_MAX_OPEN_CONNECTIONS, MYSQL_QUEUE_DIR, MYSQL_TABLE,
};
@@ -2152,18 +2154,18 @@ mod tests {
webhook_section.insert(DEFAULT_DELIMITER.to_string(), notify::DEFAULT_NOTIFY_WEBHOOK_KVS.clone());
webhook_section.insert(
"primary".to_string(),
crate::config::KVS(vec![
crate::config::KV {
KVS(vec![
KV {
key: ENABLE_KEY.to_string(),
value: EnableState::On.to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::WEBHOOK_ENDPOINT.to_string(),
value: "https://example.com/hook".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::WEBHOOK_QUEUE_DIR.to_string(),
value: "/tmp/webhook-queue".to_string(),
hidden_if_empty: false,
@@ -2179,18 +2181,18 @@ mod tests {
mqtt_section.insert(DEFAULT_DELIMITER.to_string(), mqtt_default);
mqtt_section.insert(
"analytics".to_string(),
crate::config::KVS(vec![
crate::config::KV {
KVS(vec![
KV {
key: ENABLE_KEY.to_string(),
value: EnableState::On.to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::MQTT_BROKER.to_string(),
value: "tcp://127.0.0.1:1883".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::MQTT_QUEUE_DIR.to_string(),
value: "".to_string(),
hidden_if_empty: false,
@@ -2206,23 +2208,23 @@ mod tests {
kafka_section.insert(DEFAULT_DELIMITER.to_string(), kafka_default);
kafka_section.insert(
"streaming".to_string(),
crate::config::KVS(vec![
crate::config::KV {
KVS(vec![
KV {
key: ENABLE_KEY.to_string(),
value: EnableState::On.to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::KAFKA_BROKERS.to_string(),
value: "127.0.0.1:9092,127.0.0.1:9093".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::KAFKA_ACKS.to_string(),
value: "all".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::KAFKA_TLS_ENABLE.to_string(),
value: EnableState::On.to_string(),
hidden_if_empty: false,
@@ -2234,33 +2236,33 @@ mod tests {
let mut amqp_section = std::collections::HashMap::new();
amqp_section.insert(
"primary".to_string(),
crate::config::KVS(vec![
crate::config::KV {
KVS(vec![
KV {
key: ENABLE_KEY.to_string(),
value: EnableState::On.to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::AMQP_URL.to_string(),
value: "amqp://127.0.0.1:5672/%2f".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::AMQP_EXCHANGE.to_string(),
value: "rustfs.events".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::AMQP_ROUTING_KEY.to_string(),
value: "objects".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::AMQP_MANDATORY.to_string(),
value: "false".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::AMQP_PERSISTENT.to_string(),
value: "false".to_string(),
hidden_if_empty: false,
@@ -2341,18 +2343,18 @@ mod tests {
webhook_section.insert(DEFAULT_DELIMITER.to_string(), audit::DEFAULT_AUDIT_WEBHOOK_KVS.clone());
webhook_section.insert(
"primary".to_string(),
crate::config::KVS(vec![
crate::config::KV {
KVS(vec![
KV {
key: ENABLE_KEY.to_string(),
value: EnableState::On.to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::WEBHOOK_ENDPOINT.to_string(),
value: "https://example.com/audit-hook".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::WEBHOOK_QUEUE_DIR.to_string(),
value: "/tmp/audit-queue".to_string(),
hidden_if_empty: false,
@@ -2364,33 +2366,33 @@ mod tests {
let mut amqp_section = std::collections::HashMap::new();
amqp_section.insert(
"primary".to_string(),
crate::config::KVS(vec![
crate::config::KV {
KVS(vec![
KV {
key: ENABLE_KEY.to_string(),
value: EnableState::On.to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::AMQP_URL.to_string(),
value: "amqp://127.0.0.1:5672/%2f".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::AMQP_EXCHANGE.to_string(),
value: "rustfs.audit".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::AMQP_ROUTING_KEY.to_string(),
value: "audit".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::AMQP_MANDATORY.to_string(),
value: "false".to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::AMQP_PERSISTENT.to_string(),
value: "false".to_string(),
hidden_if_empty: false,
@@ -2406,13 +2408,13 @@ mod tests {
mqtt_section.insert(DEFAULT_DELIMITER.to_string(), mqtt_default);
mqtt_section.insert(
"analytics".to_string(),
crate::config::KVS(vec![
crate::config::KV {
KVS(vec![
KV {
key: ENABLE_KEY.to_string(),
value: EnableState::On.to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::MQTT_BROKER.to_string(),
value: "tcp://127.0.0.1:1883".to_string(),
hidden_if_empty: false,
@@ -2428,13 +2430,13 @@ mod tests {
kafka_section.insert(DEFAULT_DELIMITER.to_string(), kafka_default);
kafka_section.insert(
"auditlog".to_string(),
crate::config::KVS(vec![
crate::config::KV {
KVS(vec![
KV {
key: ENABLE_KEY.to_string(),
value: EnableState::On.to_string(),
hidden_if_empty: false,
},
crate::config::KV {
KV {
key: rustfs_config::KAFKA_BROKERS.to_string(),
value: "127.0.0.1:9092".to_string(),
hidden_if_empty: false,
+1 -1
View File
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::config::{KV, KVS};
use crate::error::{Error, Result};
use rustfs_config::server_config::{KV, KVS};
use rustfs_config::{DEFAULT_HEAL_BITROT_CYCLE_SECS, HEAL_BITROT_CYCLE};
use rustfs_utils::string::parse_bool;
use std::sync::LazyLock;
+1 -1
View File
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::config::{KV, KVS};
use rustfs_config::notify::NOTIFY_REDIS_DEFAULT_CHANNEL;
use rustfs_config::server_config::{KV, KVS};
use rustfs_config::{
AMQP_EXCHANGE, AMQP_MANDATORY, AMQP_PASSWORD, AMQP_PERSISTENT, AMQP_QUEUE_DIR, AMQP_QUEUE_LIMIT, AMQP_ROUTING_KEY,
AMQP_TLS_CA, AMQP_TLS_CLIENT_CERT, AMQP_TLS_CLIENT_KEY, AMQP_URL, AMQP_USERNAME, COMMENT_KEY, DEFAULT_LIMIT, ENABLE_KEY,
+1 -1
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::config::{KV, KVS};
use rustfs_config::server_config::{KV, KVS};
use rustfs_config::{
ENABLE_KEY, EnableState,
oidc::{
+1 -1
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::config::{KV, KVS};
use rustfs_config::server_config::{KV, KVS};
use rustfs_config::{
DEFAULT_SCANNER_BITROT_CYCLE_SECS, DEFAULT_SCANNER_CACHE_SAVE_TIMEOUT_SECS, DEFAULT_SCANNER_CYCLE_MAX_DIRECTORIES,
DEFAULT_SCANNER_CYCLE_MAX_DURATION_SECS, DEFAULT_SCANNER_CYCLE_MAX_OBJECTS, DEFAULT_SCANNER_IDLE_MODE,
+1 -2
View File
@@ -12,9 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use super::KVS;
use crate::config::KV;
use crate::error::{Error, Result};
use rustfs_config::server_config::{KV, KVS};
use serde::{Deserialize, Serialize};
use std::env;
use std::sync::LazyLock;
+4 -3
View File
@@ -77,6 +77,7 @@ use lazy_static::lazy_static;
use rand::RngExt as _;
use rustfs_common::heal_channel::{HealItemType, HealOpts};
use rustfs_common::{GLOBAL_LOCAL_NODE_NAME, GLOBAL_RUSTFS_ADDR, GLOBAL_RUSTFS_HOST, GLOBAL_RUSTFS_PORT};
use rustfs_config::server_config::Config;
use rustfs_filemeta::FileInfo;
use rustfs_lock::{LocalClient, LockClient, NamespaceLockWrapper};
use rustfs_madmin::heal_commands::HealResultItem;
@@ -214,12 +215,12 @@ impl std::fmt::Debug for ECStore {
/// remain the single source of truth until the migration is complete.
impl ECStore {
/// Get server configuration (delegates to global)
pub fn get_server_config(&self) -> Option<crate::config::Config> {
pub fn get_server_config(&self) -> Option<Config> {
crate::config::get_global_server_config()
}
/// Set server configuration (delegates to global)
pub fn set_server_config(&self, cfg: crate::config::Config) {
pub fn set_server_config(&self, cfg: Config) {
crate::config::set_global_server_config(cfg);
}
@@ -264,7 +265,7 @@ impl ECStore {
}
/// Get the server configuration
pub fn server_config(&self) -> Option<crate::config::Config> {
pub fn server_config(&self) -> Option<Config> {
get_global_server_config()
}
+2 -1
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::config::{KVS, storageclass};
use crate::config::storageclass;
use crate::disk::error_reduce::{count_errs, reduce_write_quorum_errs};
use crate::disk::{self, DiskAPI};
use crate::error::{Error, Result};
@@ -26,6 +26,7 @@ use crate::{
endpoints::Endpoints,
};
use futures::future::join_all;
use rustfs_config::server_config::KVS;
use std::collections::{HashMap, hash_map::Entry};
use tracing::{debug, info, warn};
use uuid::Uuid;