diff --git a/crates/ecstore/src/store/bucket.rs b/crates/ecstore/src/store/bucket.rs index c15f40e8d9..e297a01a81 100644 --- a/crates/ecstore/src/store/bucket.rs +++ b/crates/ecstore/src/store/bucket.rs @@ -861,6 +861,15 @@ impl ECStore { sys.read().await.get(bucket).await } + /// Returns the metadata system that owns this store's bucket configuration. + /// + /// # Errors + /// Returns an error when this store has not initialized its metadata system. + pub async fn instance_bucket_metadata_sys(&self) -> Result { + let sys = metadata_sys::require_bucket_metadata_sys_in(&self.ctx)?; + Ok(sys.read().await.clone()) + } + /// Snapshots this instance's cached bucket metadata without disk IO. /// /// # Errors diff --git a/crates/scanner/src/scanner.rs b/crates/scanner/src/scanner.rs index 04d8c2c6a1..292490463a 100644 --- a/crates/scanner/src/scanner.rs +++ b/crates/scanner/src/scanner.rs @@ -76,11 +76,10 @@ use crate::storage_api::scan::{ use crate::{ DiskError, ECStore, EcstoreError, ListPathRawOptions, RUSTFS_META_BUCKET, SCANNER_PUBLICATION_EPOCH_CHANGED, ScannerLifecycleConfigExt as _, ScannerReplicationConfigExt as _, delete_config_with_publication_admission_for_epoch, - get_lifecycle_config, get_replication_config, invalidate_admin_data_usage_snapshot_cache, - invalidate_data_usage_snapshot_cache, list_path_raw, read_config, replace_bucket_usage_memory_from_info, save_config, - save_config_shared_with_preconditions_and_lease_fence_and_scope, save_config_with_preconditions, - save_config_with_publication_admission_for_epoch, scanner_publication_admission_for_epoch, scanner_publication_epoch, - scanner_publication_epoch_changed, + invalidate_admin_data_usage_snapshot_cache, invalidate_data_usage_snapshot_cache, list_path_raw, read_config, + replace_bucket_usage_memory_from_info, save_config, save_config_shared_with_preconditions_and_lease_fence_and_scope, + save_config_with_preconditions, save_config_with_publication_admission_for_epoch, scanner_publication_admission_for_epoch, + scanner_publication_epoch, scanner_publication_epoch_changed, }; const LOG_COMPONENT_SCANNER: &str = "scanner"; @@ -1493,9 +1492,28 @@ where } }; + if buckets.is_empty() { + return features; + } + let metadata = match storeapi.scanner_bucket_metadata_sys().await { + Ok(metadata) => metadata, + Err(err) => { + warn!( + target: "rustfs::scanner", + event = EVENT_SCANNER_RUNTIME_CONFIG, + component = LOG_COMPONENT_SCANNER, + subsystem = LOG_SUBSYSTEM_RUNTIME, + state = "maintenance_feature_inspect_failed", + error = %err, + "Scanner could not load bucket metadata for this store" + ); + features.inspection_failed = true; + return features; + } + }; for bucket in buckets { if !features.lifecycle { - match get_lifecycle_config(&bucket.name).await { + match metadata.get_lifecycle_config(&bucket.name).await { Ok((lifecycle, _)) => { features.lifecycle = lifecycle.has_active_rules(""); } @@ -1517,7 +1535,7 @@ where } if !features.replication { - match get_replication_config(&bucket.name).await { + match metadata.get_replication_config(&bucket.name).await { Ok((replication, _)) => { features.replication = replication.has_active_rules("", true); } diff --git a/crates/scanner/src/scanner/tests/startup_gate.rs b/crates/scanner/src/scanner/tests/startup_gate.rs index c07b6fc3ae..f3b2455c11 100644 --- a/crates/scanner/src/scanner/tests/startup_gate.rs +++ b/crates/scanner/src/scanner/tests/startup_gate.rs @@ -14,7 +14,10 @@ use super::*; use crate::storage_api::scan::{BucketOperations, DeleteBucketOptions, MakeBucketOptions}; -use crate::storage_api::scanner_io::{BUCKET_LIFECYCLE_CONFIG, BUCKET_REPLICATION_CONFIG, BucketInfo, update_bucket_metadata}; +use crate::storage_api::scanner_io::{BUCKET_LIFECYCLE_CONFIG, BUCKET_REPLICATION_CONFIG, BucketInfo}; + +const LIFECYCLE_POLICY: &[u8] = br#"expireEnabled1"#; +const REPLICATION_POLICY: &[u8] = br#"arn:aws:iam::123456789012:role/replication-rolereplicateEnabledarn:aws:s3:::destination-bucket"#; pub(super) fn startup_config(entries: &[(&str, &str)]) -> rustfs_config::server_config::Config { init_ecstore_config_for_scanner_tests(); @@ -221,12 +224,12 @@ async fn startup_discovers_replication_after_lifecycle_in_another_bucket() { .await .expect("maintenance fixture bucket"); } - let lifecycle = br#"expireEnabled1"#; - update_bucket_metadata("a-lifecycle", BUCKET_LIFECYCLE_CONFIG, lifecycle.to_vec()) + store + .update_bucket_metadata_config("a-lifecycle", BUCKET_LIFECYCLE_CONFIG, LIFECYCLE_POLICY.to_vec()) .await .expect("lifecycle policy"); - let replication = br#"arn:aws:iam::123456789012:role/replication-rolereplicateEnabledarn:aws:s3:::destination-bucket"#; - update_bucket_metadata("z-replication", BUCKET_REPLICATION_CONFIG, replication.to_vec()) + store + .update_bucket_metadata_config("z-replication", BUCKET_REPLICATION_CONFIG, REPLICATION_POLICY.to_vec()) .await .expect("replication policy"); let features = detect_scanner_maintenance_features(&store).await; @@ -259,12 +262,12 @@ async fn startup_replication_discovery_does_not_inspect_irrelevant_lifecycle_tai .await .expect("maintenance fixture bucket"); } - let replication = br#"arn:aws:iam::123456789012:role/replication-rolereplicateEnabledarn:aws:s3:::destination-bucket"#; - update_bucket_metadata("a-replication", BUCKET_REPLICATION_CONFIG, replication.to_vec()) + store + .update_bucket_metadata_config("a-replication", BUCKET_REPLICATION_CONFIG, REPLICATION_POLICY.to_vec()) .await .expect("replication policy"); - let lifecycle = br#"expireEnabled1"#; - update_bucket_metadata("z-lifecycle", BUCKET_LIFECYCLE_CONFIG, lifecycle.to_vec()) + store + .update_bucket_metadata_config("z-lifecycle", BUCKET_LIFECYCLE_CONFIG, LIFECYCLE_POLICY.to_vec()) .await .expect("lifecycle policy"); let features = detect_scanner_maintenance_features(&store).await; @@ -276,6 +279,39 @@ async fn startup_replication_discovery_does_not_inspect_irrelevant_lifecycle_tai assert!(!features.inspection_failed); } +#[tokio::test] +#[serial] +async fn startup_reads_maintenance_policies_from_the_store_being_scanned() { + let (_first_dir, first) = setup_scanner_cycle_store().await; + let (_second_dir, second) = setup_scanner_cycle_store().await; + let bucket = "scanner-owned-policy"; + for store in [&first, &second] { + store + .make_bucket(bucket, &MakeBucketOptions::default()) + .await + .expect("fixture bucket"); + } + first + .update_bucket_metadata_config(bucket, BUCKET_LIFECYCLE_CONFIG, LIFECYCLE_POLICY.to_vec()) + .await + .expect("first store lifecycle"); + second + .update_bucket_metadata_config(bucket, BUCKET_REPLICATION_CONFIG, REPLICATION_POLICY.to_vec()) + .await + .expect("second store replication"); + + let first_features = detect_scanner_maintenance_features(&first).await; + let second_features = detect_scanner_maintenance_features(&second).await; + assert_eq!( + (first_features.lifecycle, first_features.replication, first_features.inspection_failed), + (true, false, false) + ); + assert_eq!( + (second_features.lifecycle, second_features.replication, second_features.inspection_failed), + (false, true, false) + ); +} + #[tokio::test(start_paused = true)] #[serial] async fn startup_equivalent_policies_preserve_the_sampled_deadline() { diff --git a/crates/scanner/src/storage_api.rs b/crates/scanner/src/storage_api.rs index 94a7570188..24a1640cf0 100644 --- a/crates/scanner/src/storage_api.rs +++ b/crates/scanner/src/storage_api.rs @@ -73,7 +73,7 @@ pub(crate) use rustfs_ecstore::api::bucket::metadata::is_vector_pagination_sessi #[cfg(test)] pub(crate) use rustfs_ecstore::api::bucket::metadata_sys::init_bucket_metadata_sys as ecstore_init_bucket_metadata_sys; pub(crate) use rustfs_ecstore::api::bucket::metadata_sys::{ - BucketMetadataMutationGuard as EcstoreBucketMetadataMutationGuard, + BucketMetadataMutationGuard as EcstoreBucketMetadataMutationGuard, BucketMetadataSys as EcstoreBucketMetadataSys, ScannerBucketIncarnationReadGuard as EcstoreScannerBucketIncarnationReadGuard, get_lifecycle_config as ecstore_get_lifecycle_config, get_object_lock_config as ecstore_get_object_lock_config, get_replication_config as ecstore_get_replication_config, @@ -468,6 +468,7 @@ pub(crate) trait ScannerStorage: + storage_contracts::NamespaceLocking { fn scanner_topology_digest(&self) -> [u8; 32]; + async fn scanner_bucket_metadata_sys(&self) -> EcstoreResultType; fn scanner_local_node_name(&self) -> Option { None } @@ -506,6 +507,10 @@ pub(crate) trait ScannerStorage: #[async_trait::async_trait] impl ScannerStorage for EcstoreStore { + async fn scanner_bucket_metadata_sys(&self) -> EcstoreResultType { + self.instance_bucket_metadata_sys().await + } + async fn scanner_usage_watch_store_handle(&self) -> Option> { EcstoreStore::scanner_usage_watch_store_handle(self).await } @@ -709,6 +714,10 @@ mod tests { #[async_trait::async_trait] impl ScannerStorage for FakeScannerStorage { + async fn scanner_bucket_metadata_sys(&self) -> EcstoreResultType { + Err(EcstoreErrorType::other("fake scanner storage has no bucket metadata")) + } + fn scanner_topology_digest(&self) -> [u8; 32] { [0; 32] }