Skip to content

Commit

Permalink
chore(bors): merge pull request #671
Browse files Browse the repository at this point in the history
671: Cherry pick #669 r=Abhinandan-Purkait a=Abhinandan-Purkait

FIX: The error variant for multi replica snapshot clone/restore creation was the same as multi replica snapshot operations. Add a specific variant for the same.

Co-authored-by: Abhinandan Purkait <[email protected]>
  • Loading branch information
mayastor-bors and Abhinandan-Purkait committed Aug 28, 2023
2 parents 594f3d5 + 8d6758b commit a6902de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 6 additions & 3 deletions control-plane/agents/src/bin/core/volume/clone_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ impl CreateVolumeExeVal for SnapshotCloneOp<'_> {
let new_volume = self.0.params();
let snapshot = self.1.as_ref();

snafu::ensure!(new_volume.replicas == 1, errors::NReplSnapshotNotAllowed {});
snafu::ensure!(
new_volume.replicas == 1,
errors::NReplSnapshotCloneCreationNotAllowed {}
);
snafu::ensure!(
new_volume.allowed_nodes().is_empty()
|| new_volume.allowed_nodes().len() >= new_volume.replicas as usize,
Expand Down Expand Up @@ -171,7 +174,7 @@ impl SnapshotCloneOp<'_> {
None | Some([]) => Err(SvcError::NoHealthyReplicas {
id: new_volume.uuid_str(),
}),
_ => Err(SvcError::NReplSnapshotNotAllowed {}),
_ => Err(SvcError::NReplSnapshotCloneCreationNotAllowed {}),
}?;

let mut pools = CloneVolumeSnapshot::builder_with_defaults(registry, new_volume, snapshot)
Expand All @@ -181,7 +184,7 @@ impl SnapshotCloneOp<'_> {
let pool = match pools.pop() {
Some(pool) if pools.is_empty() => Ok(pool),
// todo: support more than 1 replica snapshots
Some(_) => Err(SvcError::NReplSnapshotNotAllowed {}),
Some(_) => Err(SvcError::NReplSnapshotCloneCreationNotAllowed {}),
// todo: filtering should keep invalid pools/resources and tag them with a reason
// why they cannot be used!
None => Err(SvcError::NoSnapshotPools {
Expand Down
10 changes: 10 additions & 0 deletions control-plane/agents/src/common/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ pub enum SvcError {
},
#[snafu(display("Snapshots for multi-replica volumes are not allowed"))]
NReplSnapshotNotAllowed {},
#[snafu(display(
"Cannot create a multi-replica volume from a snapshot of a single-replica volume"
))]
NReplSnapshotCloneCreationNotAllowed {},
#[snafu(display("Replica's {} snapshot was unexpectedly skipped", replica))]
ReplicaSnapSkipped { replica: String },
#[snafu(display("Replica's {} snapshot was unexpectedly not taken", replica))]
Expand Down Expand Up @@ -830,6 +834,12 @@ impl From<SvcError> for ReplyError {
source,
extra,
},
SvcError::NReplSnapshotCloneCreationNotAllowed {} => ReplyError {
kind: ReplyErrorKind::InvalidArgument,
resource: ResourceKind::VolumeSnapshotClone,
source,
extra,
},
SvcError::ReplicaSnapSkipped { .. } => ReplyError {
kind: ReplyErrorKind::Aborted,
resource: ResourceKind::VolumeSnapshot,
Expand Down

0 comments on commit a6902de

Please sign in to comment.