mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-27 16:48:58 +00:00
73bde843d6
* refactor(common): introduce rustfs-data-usage core crate * refactor(concurrency): migrate workers crate into concurrency * refactor(crypto): migrate appauth token APIs into crypto * fix docs urls * remove unused crate * refactor(data-usage): switch consumers to rustfs-data-usage * chore(fmt): apply cargo fmt and lockfile sync * refactor(common): remove data_usage compatibility re-export * refactor(capacity): move capacity_scope to object-capacity * refactor(io-metrics): relocate internode metrics from common * refactor(common): decouple scanner report from madmin * chore(fmt): normalize import ordering after pre-commit * refactor(s3): split s3 types and ops crates * refactor(s3): centralize event version and safe parsing * refactor(s3): add op-event compatibility guardrails * refactor(s3): add runtime op-event mismatch observability * refactor(s3): extract delete event mapping helper * refactor(s3): extract put event mapping helper * refactor(s3): consolidate remaining event semantic helpers * refactor(s3): add op-event coverage checks and observability alerts * refactor(s3-ops): consolidate op-event semantic mapping * refactor(scanner): remove last_minute wrapper module * refactor(scanner): consolidate duplicated data usage models
75 lines
2.8 KiB
Rust
75 lines
2.8 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 crate::BucketNotificationConfig;
|
|
use crate::rules::{BucketRulesSnapshot, DynRulesContainer, SubscriberIndex};
|
|
use rustfs_s3_types::EventName;
|
|
|
|
/// NotificationSystemSubscriberView - Provides an interface to manage and query
|
|
/// the subscription status of buckets in the notification system.
|
|
#[derive(Debug)]
|
|
pub struct NotificationSystemSubscriberView {
|
|
index: SubscriberIndex,
|
|
}
|
|
|
|
impl NotificationSystemSubscriberView {
|
|
/// Creates a new NotificationSystemSubscriberView with an empty SubscriberIndex.
|
|
///
|
|
/// Returns a new instance of NotificationSystemSubscriberView.
|
|
pub fn new() -> Self {
|
|
Self {
|
|
index: SubscriberIndex::default(),
|
|
}
|
|
}
|
|
|
|
/// Checks if a bucket has any subscribers for a specific event.
|
|
/// This is a quick check using the event mask in the snapshot.
|
|
///
|
|
/// # Arguments
|
|
/// * `bucket` - The name of the bucket to check.
|
|
/// * `event` - The event name to check for subscriptions.
|
|
///
|
|
/// Returns `true` if there are subscribers for the event, `false` otherwise.
|
|
#[inline]
|
|
pub fn has_subscriber(&self, bucket: &str, event: &EventName) -> bool {
|
|
self.index.has_subscriber(bucket, event)
|
|
}
|
|
|
|
/// Builds and atomically replaces a bucket's subscription snapshot from the configuration.
|
|
///
|
|
/// Core principle: masks and rules are calculated and stored together in the same update.
|
|
///
|
|
/// # Arguments
|
|
/// * `bucket` - The name of the bucket to update.
|
|
/// * `cfg` - The bucket notification configuration to compile into a snapshot.
|
|
pub fn apply_bucket_config(&self, bucket: &str, cfg: &BucketNotificationConfig) {
|
|
// *It is recommended to merge compile into one function to ensure the same origin.
|
|
let snapshot: BucketRulesSnapshot<DynRulesContainer> = cfg.compile_snapshot();
|
|
|
|
// *debug to prevent inconsistencies from being introduced when modifying the compile logic in the future.
|
|
snapshot.debug_assert_mask_consistent();
|
|
|
|
self.index.store_snapshot(bucket, snapshot);
|
|
}
|
|
|
|
/// Clears a bucket's subscription snapshot.
|
|
///
|
|
/// #Arguments
|
|
/// * `bucket` - The name of the bucket to clear.
|
|
#[inline]
|
|
pub fn clear_bucket(&self, bucket: &str) {
|
|
self.index.clear_bucket(bucket);
|
|
}
|
|
}
|