Files
rustfs/crates/iam/src/storage_api.rs
T
Zhengchao An 476352106e refactor(app): per-context server-config handle and Arc-owned notification system (#4621)
* refactor(app): give each context's server-config handle its own copy

backlog#1052 S3, first slice: establish the per-context state pattern on
the smallest subsystem. ServerConfigHandle was a unit struct forwarding
both get and set to the process-global GLOBAL_SERVER_CONFIG, so every
AppContext shared one config regardless of which context a caller held.

The handle now keeps its own copy: a set lands on the owning context and
on the process global (ambient readers — the config loader path, the
scanner — keep working), and a get prefers the owned copy, falling back
to the global while the initial load still publishes there. Single
instance: the owned copy and the global are written together, so reads
are unchanged. Two contexts that both published stay isolated even though
the shared global only remembers the last write (covered by a new test).

The global write in set() is the transitional bridge for ambient readers;
it goes away when those readers migrate and multi-instance flips on
(backlog#1052 S5).

* refactor(notify): hand out the notification system as an owned Arc

backlog#1052 S3, second slice. GLOBAL_NOTIFICATION_SYS stored the
NotificationSys by value and every accessor returned
Option<&'static NotificationSys> — a process-lifetime borrow that a
per-server AppContext can never hold. The global now stores an Arc and
the accessor chain (ecstore runtime sources, ECStore::notification_system,
the iam forwarders, the rustfs shims, NotificationSystemInterface and the
AppContext resolvers) hands out owned Arcs instead.

Call sites are unchanged apart from two borrow adjustments in the
rebalance admin handler (pass &Arc where a reference is expected; borrow
with as_ref() so the handle survives to the second use). Behavior is
identical — same single global instance, first init still wins — but the
type now permits a future per-server context to own its notification
system (backlog#1052 S3 follow-up).
2026-07-09 20:07:09 +08:00

99 lines
4.0 KiB
Rust

// Copyright 2024 RustFS Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use std::sync::Arc;
pub(crate) use rustfs_ecstore::api::config::RUSTFS_CONFIG_PREFIX as IAM_CONFIG_ROOT_PREFIX;
use rustfs_ecstore::api::config::com::{
delete_config as ecstore_delete_config, read_config_no_lock as ecstore_read_config_no_lock,
read_config_with_metadata as ecstore_read_config_with_metadata, save_config as ecstore_save_config,
save_config_with_opts as ecstore_save_config_with_opts,
};
use rustfs_ecstore::api::error::{
Error as EcstoreErrorType, Result as EcstoreResultType, StorageError as EcstoreStorageError,
classify_system_path_failure_reason as ecstore_classify_system_path_failure_reason,
};
use rustfs_ecstore::api::notification::{
NotificationPeerErr as EcstoreNotificationPeerErr, NotificationSys as EcstoreNotificationSys, get_global_notification_sys,
};
use rustfs_ecstore::api::runtime::first_cluster_node_is_local as ecstore_first_cluster_node_is_local;
use rustfs_ecstore::api::storage::ECStore as EcstoreStore;
use rustfs_storage_api as storage_contracts;
pub(crate) type IamEcstoreError = EcstoreErrorType;
pub(crate) type IamStorageError = EcstoreStorageError;
pub(crate) type IamStorageResult<T> = EcstoreResultType<T>;
pub(crate) type IamStore = EcstoreStore;
pub(crate) type IamConfigObjectInfo = <IamStore as storage_contracts::ObjectOperations>::ObjectInfo;
pub(crate) type IamConfigObjectOptions = <IamStore as storage_contracts::ObjectOperations>::ObjectOptions;
pub(crate) type IamNotificationSys = EcstoreNotificationSys;
pub(crate) type IamEcstoreNotificationPeerErr = EcstoreNotificationPeerErr;
pub(crate) async fn read_iam_config_no_lock(api: Arc<IamStore>, file: &str) -> IamStorageResult<Vec<u8>> {
ecstore_read_config_no_lock(api, file).await
}
pub(crate) async fn read_iam_config_with_metadata(
api: Arc<IamStore>,
file: &str,
opts: &IamConfigObjectOptions,
) -> IamStorageResult<(Vec<u8>, IamConfigObjectInfo)> {
ecstore_read_config_with_metadata(api, file, opts).await
}
pub(crate) async fn save_iam_config(api: Arc<IamStore>, file: &str, data: Vec<u8>) -> IamStorageResult<()> {
ecstore_save_config(api, file, data).await
}
pub(crate) async fn save_iam_config_with_opts(
api: Arc<IamStore>,
file: &str,
data: Vec<u8>,
opts: &IamConfigObjectOptions,
) -> IamStorageResult<()> {
ecstore_save_config_with_opts(api, file, data, opts).await
}
pub(crate) async fn delete_iam_config(api: Arc<IamStore>, file: &str) -> IamStorageResult<()> {
ecstore_delete_config(api, file).await
}
pub(crate) fn classify_iam_system_path_failure_reason(err: &IamEcstoreError) -> &'static str {
ecstore_classify_system_path_failure_reason(err)
}
pub(crate) async fn is_iam_first_cluster_node_local() -> bool {
ecstore_first_cluster_node_is_local().await
}
pub(crate) fn notification_sys() -> Option<std::sync::Arc<IamNotificationSys>> {
get_global_notification_sys()
}
pub(crate) mod crate_boundary {
pub(crate) use super::{
IAM_CONFIG_ROOT_PREFIX, IamEcstoreError, IamEcstoreNotificationPeerErr, IamStorageError, IamStore,
classify_iam_system_path_failure_reason, delete_iam_config, is_iam_first_cluster_node_local, read_iam_config_no_lock,
read_iam_config_with_metadata, save_iam_config, save_iam_config_with_opts,
};
}
pub(crate) mod object_store {
pub(crate) use super::storage_contracts::{HTTPPreconditions, ListOperations, ObjectInfoOrErr, ObjectOperations};
}
pub(crate) mod runtime {
pub(crate) use super::{IamNotificationSys, notification_sys};
}