mirror of
https://github.com/rustfs/rustfs.git
synced 2026-12-02 22:26:21 +00:00
fix(scanner): read startup policies from the scanned store
This commit is contained in:
@@ -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<metadata_sys::BucketMetadataSys> {
|
||||
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
|
||||
|
||||
@@ -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";
|
||||
@@ -1470,9 +1469,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("");
|
||||
}
|
||||
@@ -1494,7 +1512,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);
|
||||
}
|
||||
|
||||
@@ -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#"<LifecycleConfiguration><Rule><ID>expire</ID><Status>Enabled</Status><Filter><Prefix></Prefix></Filter><Expiration><Days>1</Days></Expiration></Rule></LifecycleConfiguration>"#;
|
||||
const REPLICATION_POLICY: &[u8] = br#"<ReplicationConfiguration><Role>arn:aws:iam::123456789012:role/replication-role</Role><Rule><ID>replicate</ID><Status>Enabled</Status><Prefix></Prefix><Destination><Bucket>arn:aws:s3:::destination-bucket</Bucket></Destination></Rule></ReplicationConfiguration>"#;
|
||||
|
||||
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#"<LifecycleConfiguration><Rule><ID>expire</ID><Status>Enabled</Status><Filter><Prefix></Prefix></Filter><Expiration><Days>1</Days></Expiration></Rule></LifecycleConfiguration>"#;
|
||||
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#"<ReplicationConfiguration><Role>arn:aws:iam::123456789012:role/replication-role</Role><Rule><ID>replicate</ID><Status>Enabled</Status><Prefix></Prefix><Destination><Bucket>arn:aws:s3:::destination-bucket</Bucket></Destination></Rule></ReplicationConfiguration>"#;
|
||||
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#"<ReplicationConfiguration><Role>arn:aws:iam::123456789012:role/replication-role</Role><Rule><ID>replicate</ID><Status>Enabled</Status><Prefix></Prefix><Destination><Bucket>arn:aws:s3:::destination-bucket</Bucket></Destination></Rule></ReplicationConfiguration>"#;
|
||||
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#"<LifecycleConfiguration><Rule><ID>expire</ID><Status>Enabled</Status><Filter><Prefix></Prefix></Filter><Expiration><Days>1</Days></Expiration></Rule></LifecycleConfiguration>"#;
|
||||
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() {
|
||||
|
||||
@@ -70,7 +70,7 @@ pub(crate) use rustfs_ecstore::api::bucket::lifecycle::lifecycle::object_opts_fr
|
||||
#[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,
|
||||
@@ -465,6 +465,7 @@ pub(crate) trait ScannerStorage:
|
||||
+ storage_contracts::NamespaceLocking<Error = EcstoreErrorType, NamespaceLock = NamespaceLockWrapper>
|
||||
{
|
||||
fn scanner_topology_digest(&self) -> [u8; 32];
|
||||
async fn scanner_bucket_metadata_sys(&self) -> EcstoreResultType<EcstoreBucketMetadataSys>;
|
||||
fn scanner_local_node_name(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
@@ -503,6 +504,10 @@ pub(crate) trait ScannerStorage:
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ScannerStorage for EcstoreStore {
|
||||
async fn scanner_bucket_metadata_sys(&self) -> EcstoreResultType<EcstoreBucketMetadataSys> {
|
||||
self.instance_bucket_metadata_sys().await
|
||||
}
|
||||
|
||||
async fn scanner_usage_watch_store_handle(&self) -> Option<Arc<EcstoreStore>> {
|
||||
EcstoreStore::scanner_usage_watch_store_handle(self).await
|
||||
}
|
||||
@@ -706,6 +711,10 @@ mod tests {
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ScannerStorage for FakeScannerStorage {
|
||||
async fn scanner_bucket_metadata_sys(&self) -> EcstoreResultType<EcstoreBucketMetadataSys> {
|
||||
Err(EcstoreErrorType::other("fake scanner storage has no bucket metadata"))
|
||||
}
|
||||
|
||||
fn scanner_topology_digest(&self) -> [u8; 32] {
|
||||
[0; 32]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user