Skip to content

Compute SLM retention from RepositoryData#100092

Merged
elasticsearchmachine merged 11 commits intoelastic:mainfrom
DaveCTurner:2023/09/29/SLMGetExpiredSnapshotsAction
Oct 2, 2023
Merged

Compute SLM retention from RepositoryData#100092
elasticsearchmachine merged 11 commits intoelastic:mainfrom
DaveCTurner:2023/09/29/SLMGetExpiredSnapshotsAction

Conversation

@DaveCTurner
Copy link
Copy Markdown
Member

@DaveCTurner DaveCTurner commented Sep 29, 2023

There is no need to obtain SnapshotInfo for all snapshots in order to
compute SLM retention. With this commit we move to computing it directly
from the RepositoryData in most circumstances, and in rare situations
where we must still retrieve SnapshotInfo blobs we make sure not to
hold many in memory at once.

Closes #99953

@DaveCTurner DaveCTurner added >bug WIP :Data Management/ILM+SLM DO NOT USE. Use ":StorageEngine/ILM" or ":Distributed Coordination/SLM" instead. v8.11.0 labels Sep 29, 2023
@DaveCTurner

This comment was marked as outdated.

@DaveCTurner DaveCTurner force-pushed the 2023/09/29/SLMGetExpiredSnapshotsAction branch 2 times, most recently from f521bc3 to f060f60 Compare September 30, 2023 09:28
@DaveCTurner

This comment was marked as resolved.

There is no need to obtain `SnapshotInfo` for all snapshots in order to
compute SLM retention. With this commit we move to computing it directly
from the `RepositoryData` in most circumstances, and in rare situations
where we must still retrieve `SnapshotInfo` blobs we make sure not to
hold many in memory at once.

Closes elastic#99953
@DaveCTurner DaveCTurner force-pushed the 2023/09/29/SLMGetExpiredSnapshotsAction branch from f060f60 to c8ea2d3 Compare September 30, 2023 12:04
@DaveCTurner DaveCTurner removed the WIP label Sep 30, 2023
@DaveCTurner DaveCTurner marked this pull request as ready for review September 30, 2023 12:53
@elasticsearchmachine elasticsearchmachine added the Team:Data Management (obsolete) DO NOT USE. This team no longer exists. label Sep 30, 2023
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @DaveCTurner, I've created a changelog YAML for you.

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

Copy link
Copy Markdown
Contributor

@andreidan andreidan left a comment

Choose a reason for hiding this comment

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

Thanks for working on this David. This is looking really good.

I left a few minor suggestions

}
}

private static List<Tuple<SnapshotId, String>> getSnapshotsToDelete(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for all the details in this function ❤️ It's a real pleasure to read.

Would we benefit from a bit more targeted testing for this function if it was package-visible and target every if/else branch with unit tests? (similar to the previous SnapshotRetentionTask#snapshotEligibleForDeletion)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure this adds much (the existing test already covers all the branches) but I added some more focussed tests in eef1e63.

}
}

private static void getSnapshotDetailsByPolicy(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as below, perhaps a personal preference, but should we add a bit more targeted unit testing to this function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Likewise, see eef1e63.

}

private static class ResultsBuilder {
private final Map<String, List<Tuple<SnapshotId, String>>> resultsByRepository = ConcurrentCollections.newConcurrentMap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: we could use the ConcurrentMap interface directly here to indicate thread-safety and atomicity guarantees are needed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Eh we could but that makes the declaration long enough that it splits over two lines. Moreover we never mention its type again in its 11-line scope.

import java.util.function.BiFunction;
import java.util.stream.Stream;

public class SLMGetExpiredSnapshotsAction extends ActionType<SLMGetExpiredSnapshotsAction.Response> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As this is a public class, should we add a small javadoc?

@DaveCTurner DaveCTurner added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Oct 2, 2023
@elasticsearchmachine elasticsearchmachine merged commit 1881f79 into elastic:main Oct 2, 2023
@DaveCTurner DaveCTurner deleted the 2023/09/29/SLMGetExpiredSnapshotsAction branch October 2, 2023 16:44
@DaveCTurner DaveCTurner restored the 2023/09/29/SLMGetExpiredSnapshotsAction branch June 17, 2024 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >bug :Data Management/ILM+SLM DO NOT USE. Use ":StorageEngine/ILM" or ":Distributed Coordination/SLM" instead. Team:Data Management (obsolete) DO NOT USE. This team no longer exists. v8.11.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce the number of objects allocated by SLM when listing the snapshots to retain

4 participants