fix(ecstore): clear lifecycle metadata cache (#4416)

This commit is contained in:
Zhengchao An
2026-07-08 15:01:09 +08:00
committed by GitHub
parent 7cd7c84e71
commit f327707321
2 changed files with 20 additions and 28 deletions
+18
View File
@@ -689,6 +689,7 @@ impl BucketMetadata {
}
BUCKET_LIFECYCLE_CONFIG => {
self.lifecycle_config_xml = data;
self.lifecycle_config = None;
self.lifecycle_config_updated_at = updated;
}
BUCKET_SSECONFIG => {
@@ -1240,6 +1241,23 @@ mod test {
assert_eq!(bucket_targets.targets[0].target_bucket, "target-bucket");
}
#[test]
fn lifecycle_update_config_clears_parsed_config_on_delete() {
let mut bm = BucketMetadata::new("test-bucket");
let lifecycle_xml = br#"<LifecycleConfiguration><Rule><ID>rule1</ID><Status>Enabled</Status><Expiration><Days>30</Days></Expiration></Rule></LifecycleConfiguration>"#;
bm.update_config(BUCKET_LIFECYCLE_CONFIG, lifecycle_xml.to_vec())
.expect("lifecycle config should update");
bm.parse_all_configs().expect("lifecycle config should parse");
assert!(bm.lifecycle_config.is_some());
bm.update_config(BUCKET_LIFECYCLE_CONFIG, Vec::new())
.expect("lifecycle config delete should update metadata");
assert!(bm.lifecycle_config_xml.is_empty());
assert!(bm.lifecycle_config.is_none());
}
#[tokio::test]
async fn marshal_msg_complete_example() {
// Create a complete BucketMetadata with various configurations
+2 -28
View File
@@ -16,8 +16,8 @@ use super::metadata::{BucketMetadata, load_bucket_metadata};
use super::quota::BucketQuota;
use super::target::BucketTargets;
use crate::bucket::bucket_target_sys::BucketTargetSys;
use crate::bucket::metadata::{BUCKET_LIFECYCLE_CONFIG, load_bucket_metadata_parse};
use crate::bucket::utils::{deserialize, is_meta_bucketname};
use crate::bucket::metadata::load_bucket_metadata_parse;
use crate::bucket::utils::is_meta_bucketname;
use crate::error::{Error, Result, is_err_bucket_not_found};
use crate::runtime::sources as runtime_sources;
use crate::storage_api_contracts::heal::HealOperations as _;
@@ -454,32 +454,6 @@ impl BucketMetadataSys {
}
pub async fn delete(&mut self, bucket: &str, config_file: &str) -> Result<OffsetDateTime> {
if config_file == BUCKET_LIFECYCLE_CONFIG {
let meta = match self.get_config_from_disk(bucket).await {
Ok(res) => res,
Err(err) => {
if err != Error::ConfigNotFound {
return Err(err);
} else {
BucketMetadata::new(bucket)
}
}
};
if !meta.lifecycle_config_xml.is_empty() {
if let Ok(cfg) = deserialize::<BucketLifecycleConfiguration>(&meta.lifecycle_config_xml) {
if let Some(_v) = cfg.rules.first() {}
} else {
tracing::warn!(
bucket = %bucket,
"delete: failed to parse lifecycle config XML"
);
}
}
// TODO: other lifecycle handle
}
self.update_and_parse(bucket, config_file, Vec::new(), false).await
}