Skip to content

Remove and inline methods in SnapshotsService.deleteSnapshots() #76079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2021

Conversation

tlrx
Copy link
Member

@tlrx tlrx commented Aug 4, 2021

I'd like to make some minor changes in the cluster state update task executed to delete snapshots:

  • make the method ensureNoCleanupInProgress() accept a reason as a parameter and reuse it also in deletion logic
  • remove the matchingSnapshotIds() and findInProgressSnapshots() methods that I find a bit confusing and inline their code in the deletion logic, so that we can in the future use the deleteSnapshots(DeleteSnapshotRequest, ActionListener<Void> listener) to also find snapshots to delete by UUID and not only by name (relates Delete backing snapshot when searchable snapshot index is deleted #75565 (comment)).

@elasticmachine elasticmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Aug 4, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@tlrx tlrx requested a review from original-brownbear August 4, 2021 12:55
Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 100% on board with drying things up :) Not so sure about inlining things as suggested though

@@ -2130,14 +2170,15 @@ public ClusterState execute(ClusterState currentState) {
// add the snapshot deletion to the cluster state
final SnapshotDeletionsInProgress.Entry replacedEntry = deletionsInProgress.getEntries()
.stream()
.filter(entry -> entry.repository().equals(repoName) && entry.state() == SnapshotDeletionsInProgress.State.WAITING)
.filter(entry -> entry.repository().equals(repositoryName))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why split into multiple filters here? (doesn't matter much here but it's slightly harder to read IMO)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it easier that way 😅

@@ -2049,61 +2062,88 @@ public void deleteSnapshots(final DeleteSnapshotRequest request, final ActionLis

@Override
public ClusterState execute(ClusterState currentState) {
ensureRepositoryExists(repoName, currentState);
final SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY);
final List<SnapshotsInProgress.Entry> snapshotEntries = findInProgressSnapshots(snapshots, snapshotNames, repoName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh. I'm not the biggest fan of inlining this code. These CS updates are already too complex/long even without inlining these loops? Maybe we could improve the state of things through better naming that makes it clear that these methods are filtering by snapshot name to make the different paths with resolving by uuid clearer instead?

Copy link
Member Author

@tlrx tlrx Aug 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I read that code recently I had to go jump to the methods and go back multiple times to be sure to understand which snapshots where filtered and why. I don't think the findInProgressSnapshots() had any value and it's easier to read inline.

Maybe I can keep that one inline and revert+rename the matchinSnapshotsIds one? In the future I'd like this method to be able to match on snapshot names or snapshot uuids by passing a SnapshotId -> String mapping function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can keep that one inline and revert+rename the matchinSnapshotsIds one?

That variant makes good sense to me :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with these being inline, the comments tell us what's going on well enough. I do like that we now just have the one set of snapshot IDs rather than using a list for the first bit and then copying it over to a set for the second, then back to a list again. If we extract methods again it'd be great if we could keep this improvement.

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice simplification, LGTM. I left a couple of tiny (optional) comments.

final String[] snapshotNames = request.snapshots();
final String repoName = request.repository();
final String repositoryName = request.repository();
final String[] snapshots = request.snapshots();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a slight preference to keep this called snapshotNames.

"cannot "
+ reason
+ " while a repository cleanup is in-progress in ["
+ Strings.collectionToCommaDelimitedString(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Set#toString already does the right thing here, I think we don't need this or the [ and ] around it.

@mark-vieira mark-vieira added auto-backport Automatically create backport pull requests when merged and removed auto-backport-and-merge labels Aug 4, 2021
Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM2, nice to get rid of the copying indeed. That's a remnant of when this logic was used by other APIs as well I think

@tlrx tlrx merged commit ee66de9 into elastic:master Aug 5, 2021
@tlrx tlrx deleted the minor-changes-in-delete-snapshots-method branch August 5, 2021 07:45
@tlrx
Copy link
Member Author

tlrx commented Aug 5, 2021

Thanks Armin and David!

@tlrx tlrx removed the auto-backport Automatically create backport pull requests when merged label Aug 5, 2021
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
7.13 Commit could not be cherrypicked due to conflicts
7.14 Commit could not be cherrypicked due to conflicts
7.x Commit could not be cherrypicked due to conflicts

To backport manually run:
backport --pr 76079

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >non-issue Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v7.14.1 v7.15.0 v8.0.0-alpha2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants