Skip to content

Commit

Permalink
chore(bors): merge pull request #608
Browse files Browse the repository at this point in the history
608: chore: add garbage collector for cleaning in creating snapshots with no transactions r=Abhinandan-Purkait a=Abhinandan-Purkait



Co-authored-by: Abhinandan Purkait <[email protected]>
  • Loading branch information
mayastor-bors and Abhinandan-Purkait committed Jul 3, 2023
2 parents 2124d48 + f5181f5 commit ff8e820
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
controller::{
reconciler::{poller::ReconcilerWorker, GarbageCollect},
resources::{
operations::{ResourceLifecycleWithLifetime, ResourcePruning},
operations::{ResourceLifecycleWithLifetime, ResourcePruning, ResourceSnapshotting},
operations_helper::{OperationSequenceGuard, SpecOperationsHelper},
OperationGuardArc,
},
Expand Down Expand Up @@ -59,6 +59,7 @@ impl GarbageCollect for OperationGuardArc<VolumeSnapshot> {
self.destroy_deleting(context).await,
creating_orphaned_volume_snapshot_reconciler(self, context).await,
prune_volume_snapshot_reconciler(self, context).await,
delete_no_transaction_volume_snapshot_reconciler(self, context).await,
])
}

Expand Down Expand Up @@ -90,15 +91,12 @@ async fn deleting_volume_snapshot_reconciler(
return Ok(PollerState::Idle);
}

let Some(snap_rsc) = context.specs().volume_snapshot_rsc(snapshot.uuid()) else {
return Ok(PollerState::Idle);
};
let snap_rsc = snapshot.resource().clone();

let snap_uuid = snapshot.uuid().clone();
match snapshot
.destroy(
context.registry(),
&DestroyVolumeSnapshotRequest::new(snap_rsc, None, snap_uuid),
&DestroyVolumeSnapshotRequest::new(snap_rsc, None, snapshot.uuid().clone()),
)
.await
{
Expand Down Expand Up @@ -133,15 +131,12 @@ async fn creating_orphaned_volume_snapshot_reconciler(
return Ok(PollerState::Idle);
}

let Some(snap_rsc) = context.specs().volume_snapshot_rsc(snapshot.uuid()) else {
return Ok(PollerState::Idle);
};
let snap_rsc = snapshot.resource().clone();

let snap_uuid = snapshot.uuid().clone();
match snapshot
.destroy(
context.registry(),
&DestroyVolumeSnapshotRequest::new(snap_rsc, None, snap_uuid),
&DestroyVolumeSnapshotRequest::new(snap_rsc, None, snapshot.uuid().clone()),
)
.await
{
Expand Down Expand Up @@ -181,3 +176,48 @@ async fn prune_volume_snapshot_reconciler(

Ok(PollerState::Idle)
}

#[tracing::instrument(skip(snapshot, context), level = "trace", fields(snapshot.id = %snapshot.uuid(), request.reconcile = true))]
async fn delete_no_transaction_volume_snapshot_reconciler(
snapshot: &mut OperationGuardArc<VolumeSnapshot>,
context: &PollContext,
) -> PollResult {
// Only proceed if the spec is in creating and has no transactions.
if !snapshot.as_ref().status().creating()
|| !snapshot.as_ref().metadata().transactions().is_empty()
{
return Ok(PollerState::Idle);
}

let snap_rsc = snapshot.resource().clone();

match context
.specs()
.volume(snapshot.as_ref().spec().source_id())
.await
{
Ok(mut vol_op_guard) => {
vol_op_guard
.destroy_snap(
context.registry(),
&DestroyVolumeSnapshotRequest::new(
snap_rsc,
Some(vol_op_guard.uuid().clone()),
snapshot.uuid().clone(),
),
)
.await
}
Err(_) => {
snapshot
.destroy(
context.registry(),
&DestroyVolumeSnapshotRequest::new(snap_rsc, None, snapshot.uuid().clone()),
)
.await
}
}
.ok();

Ok(PollerState::Idle)
}
7 changes: 7 additions & 0 deletions control-plane/agents/src/bin/core/controller/resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ impl<T: OperationSequencer + Sized, R> OperationGuard<T, R> {
}
}

impl<T: Clone + Debug + AsOperationSequencer, R> OperationGuard<ResourceMutex<T>, R> {
/// Get the ResourceMutex for the concerned resource.
pub fn resource(&self) -> &ResourceMutex<T> {
&self.inner
}
}

/// Tracing simple string messages with resource specific information
/// eg, volume.uuid for volumes and replica.uuid for replicas
pub(crate) trait TraceStrLog {
Expand Down

0 comments on commit ff8e820

Please sign in to comment.