pub struct LifecycleManager { /* private fields */ }Expand description
Per-bucket lifecycle configuration manager.
All read / write operations go through RwLock for thread safety;
clones are cheap (Arc<LifecycleManager> is the expected handle shape).
actions_total is a parallel RwLock<HashMap<...>> of (bucket, action_label) -> count so the future background scanner can stamp
successful actions and operators can GET /metrics to see the running
totals (the metric is also surfaced via metrics::counter! — see
crate::metrics::record_lifecycle_action).
Implementations§
Source§impl LifecycleManager
impl LifecycleManager
Sourcepub fn put(&self, bucket: &str, config: LifecycleConfig)
pub fn put(&self, bucket: &str, config: LifecycleConfig)
Replace (or create) the lifecycle configuration for bucket. Drops
any previously-attached rules in one shot — matches AWS S3
PutBucketLifecycleConfiguration (full replace, no merge).
Sourcepub fn get(&self, bucket: &str) -> Option<LifecycleConfig>
pub fn get(&self, bucket: &str) -> Option<LifecycleConfig>
Return a clone of the bucket’s configuration, if any.
Sourcepub fn delete(&self, bucket: &str)
pub fn delete(&self, bucket: &str)
Drop the bucket’s lifecycle configuration (idempotent — missing bucket is OK).
Sourcepub fn to_json(&self) -> Result<String, Error>
pub fn to_json(&self) -> Result<String, Error>
JSON snapshot for restart-recoverable state. Pair with
Self::from_json.
Sourcepub fn from_json(s: &str) -> Result<Self, Error>
pub fn from_json(s: &str) -> Result<Self, Error>
Restore from a JSON snapshot produced by Self::to_json. Action
counters are intentionally not snapshotted — they’re transient
observability data and should reset across process restarts so
rate(s4_lifecycle_actions_total[1h]) doesn’t double-count.
Sourcepub fn evaluate(
&self,
bucket: &str,
key: &str,
object_age: Duration,
object_size: u64,
object_tags: &[(String, String)],
) -> Option<LifecycleAction>
pub fn evaluate( &self, bucket: &str, key: &str, object_age: Duration, object_size: u64, object_tags: &[(String, String)], ) -> Option<LifecycleAction>
Evaluate which rule (if any) applies to a single current-version
object right now. Walks the bucket’s rules in declaration order;
returns the first matching action. Returns None when no rule
matches (or when the matching rule is Disabled, or when the
bucket has no lifecycle configuration).
Within a single rule the precedence is:
- Pick the deepest transition whose
daysthreshold is currently met (= largestdays ≤ object age). - Conflict with expiration: if
expiration_days <= transition_daysfor the chosen transition, expiration wins (the rule wants the object gone before it would have been transitioned). Otherwise transition wins (e.g. transition at 30d, expiration at 365d, age 60d → transition fires now, expiration is future). expiration_datematches whennow >= expiration_dateand no transition is currently applicable.
object_age is “now - created_at” supplied by the caller — keeping
the evaluator pure of the wall clock makes deterministic testing
trivial.
Sourcepub fn evaluate_with_flags(
&self,
bucket: &str,
key: &str,
object_age: Duration,
object_size: u64,
object_tags: &[(String, String)],
flags: EvaluateFlags,
) -> Option<LifecycleAction>
pub fn evaluate_with_flags( &self, bucket: &str, key: &str, object_age: Duration, object_size: u64, object_tags: &[(String, String)], flags: EvaluateFlags, ) -> Option<LifecycleAction>
Full-form evaluator with flags for noncurrent-version handling.
Use this when the scanner is walking a versioning-enabled bucket;
pass is_noncurrent = true for entries that are not the latest
non-delete-marker version.
Sourcepub fn evaluate_in_flight_multipart(
&self,
bucket: &str,
upload: &MultipartUploadCandidate,
now: DateTime<Utc>,
) -> Option<LifecycleAction>
pub fn evaluate_in_flight_multipart( &self, bucket: &str, upload: &MultipartUploadCandidate, now: DateTime<Utc>, ) -> Option<LifecycleAction>
v0.8.3 #69 (audit M-2): evaluate one in-flight multipart upload
against the bucket’s rules. Returns
LifecycleAction::AbortMultipartUpload when at least one
Enabled rule (a) accepts the upload’s key via its filter and
(b) carries an abort_incomplete_multipart_upload_days
threshold whose age (now - initiated) is currently met.
Returns None otherwise (no matching rule, no
abort-multipart-upload-days set, or the upload is too young).
Filter matching reuses LifecycleFilter::matches with
object_size = 0 — in-flight uploads have no assembled size
yet (the parts are stored independently in the backend), so
any rule whose filter sets object_size_greater_than /
object_size_less_than is treated as if the upload were
0 bytes. AWS S3 itself does not gate
AbortIncompleteMultipartUpload on size; this matches the
AWS semantic (size predicates simply do not apply to the
abort path) for the typical filter shape (no size predicate).
Operators wanting size-gated abort can carry the upload’s
declared part length on the MultipartUploadCandidate in a
follow-up issue — the API extension is additive.
Sourcepub fn record_action(&self, bucket: &str, action: &LifecycleAction)
pub fn record_action(&self, bucket: &str, action: &LifecycleAction)
Stamp the per-bucket action counter and bump the matching Prometheus counter. Called by the future scanner after a successful delete / metadata rewrite.
Trait Implementations§
Source§impl Debug for LifecycleManager
impl Debug for LifecycleManager
Source§impl Default for LifecycleManager
impl Default for LifecycleManager
Source§fn default() -> LifecycleManager
fn default() -> LifecycleManager
Auto Trait Implementations§
impl !Freeze for LifecycleManager
impl RefUnwindSafe for LifecycleManager
impl Send for LifecycleManager
impl Sync for LifecycleManager
impl Unpin for LifecycleManager
impl UnsafeUnpin for LifecycleManager
impl UnwindSafe for LifecycleManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more