-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Skip unnecessary loading of IndexMetadata during snapshot deletion
#134441
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
Closed
joshua-adams-1
wants to merge
28
commits into
elastic:main
from
joshua-adams-1:unnecessary-loading-index-metadata
Closed
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
fa08233
Skip unnecessary loading of `IndexMetadata` during snapshot deletion
joshua-adams-1 ecf8bbf
Skip unnecessary loading of `IndexMetadata` during snapshot deletion
joshua-adams-1 83114dd
[CI] Auto commit changes from spotless
1c8ac70
Skip unnecessary loading of `IndexMetadata` during snapshot deletion
joshua-adams-1 7478143
Merge branch 'unnecessary-loading-index-metadata' of github.com:joshu…
joshua-adams-1 2ba5675
Merge branch 'main' into unnecessary-loading-index-metadata
joshua-adams-1 ba5bf13
Moves indexUUIDToShardCountMap into IndexSnapshotsDeletion
joshua-adams-1 2f69539
Refactors determineShardCount
joshua-adams-1 00e264b
Extend tests to delete and recreate indices
joshua-adams-1 cf5abfe
Merge branch 'unnecessary-loading-index-metadata' of https://github.c…
joshua-adams-1 3293762
Merge branch 'main' into unnecessary-loading-index-metadata
joshua-adams-1 f76ad00
Fix comments
joshua-adams-1 c181d77
David comments
joshua-adams-1 ab17c35
Clean up
joshua-adams-1 10f710d
Further clea up:
joshua-adams-1 31de1cb
Refactor Tests
joshua-adams-1 309a019
Merge branch 'main' into unnecessary-loading-index-metadata
joshua-adams-1 1910411
Comments for IndexMetaDataGenerations
joshua-adams-1 a2becd1
Merge branch 'unnecessary-loading-index-metadata' of https://github.c…
joshua-adams-1 706f6e5
Merge branch 'main' into unnecessary-loading-index-metadata
joshua-adams-1 434b88f
David Comments
joshua-adams-1 822f968
Merge branch 'main' into unnecessary-loading-index-metadata
joshua-adams-1 830d64b
Fixing comment and variable name
joshua-adams-1 b8bd53c
[CI] Auto commit changes from spotless
42a2830
Move blobIdToIndexUuidMap int snapshots deletion
joshua-adams-1 4960b0b
Merge branch 'unnecessary-loading-index-metadata' of https://github.c…
joshua-adams-1 4986354
Merge branch 'main' into unnecessary-loading-index-metadata
joshua-adams-1 000c0dc
Merge branch 'main' into unnecessary-loading-index-metadata
joshua-adams-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
server/src/test/java/org/elasticsearch/repositories/IndexMetaDataGenerationsTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.repositories; | ||
|
|
||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.common.UUIDs; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.snapshots.SnapshotId; | ||
| import org.elasticsearch.test.ESTestCase; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| public class IndexMetaDataGenerationsTests extends ESTestCase { | ||
|
|
||
| public void testIndexMetaDataGenerations() { | ||
| Map<String, String> identifiers = new HashMap<>(); | ||
| Map<IndexId, String> lookupInternal = new HashMap<>(); | ||
|
|
||
| int numberOfMetadataIdentifiers = randomIntBetween(5, 10); | ||
| for (int i = 0; i < numberOfMetadataIdentifiers; i++) { | ||
| String indexUUID = generateUUID(); | ||
| String metaIdentifier = generateMetaIdentifier(indexUUID); | ||
| String blobUUID = randomAlphanumericOfLength(randomIntBetween(5, 10)); | ||
| identifiers.put(metaIdentifier, blobUUID); | ||
|
|
||
| IndexId indexId = new IndexId(randomAlphanumericOfLength(10), indexUUID); | ||
| lookupInternal.put(indexId, metaIdentifier); | ||
| } | ||
|
|
||
| SnapshotId snapshotId = new SnapshotId(randomAlphanumericOfLength(10), randomUUID()); | ||
| Map<SnapshotId, Map<IndexId, String>> lookup = Map.of(snapshotId, lookupInternal); | ||
|
|
||
| IndexMetaDataGenerations generations = new IndexMetaDataGenerations(lookup, identifiers); | ||
|
|
||
| assertEquals(lookup, generations.lookup); | ||
| assertEquals(identifiers, generations.identifiers); | ||
| } | ||
|
|
||
| public void testBuildUniqueIdentifierWithAllFieldsPresent() { | ||
| String indexUUID = generateUUID(); | ||
| String historyUUID = randomAlphanumericOfLength(randomIntBetween(10, 64)); | ||
| long settingsVersion = randomLong(); | ||
| long mappingVersion = randomLong(); | ||
| long aliasesVersion = randomLong(); | ||
|
|
||
| IndexMetadata indexMetadata = createIndexMetadata(indexUUID, historyUUID, settingsVersion, mappingVersion, aliasesVersion); | ||
|
|
||
| String result = IndexMetaDataGenerations.buildUniqueIdentifier(indexMetadata); | ||
| assertEquals(indexUUID + "-" + historyUUID + "-" + settingsVersion + "-" + mappingVersion + "-" + aliasesVersion, result); | ||
| } | ||
|
|
||
| public void testBuildUniqueIdentifierWithMissingHistoryUUID() { | ||
| String indexUUID = generateUUID(); | ||
| long settingsVersion = randomLong(); | ||
| long mappingVersion = randomLong(); | ||
| long aliasesVersion = randomLong(); | ||
|
|
||
| IndexMetadata indexMetadata = createIndexMetadata(indexUUID, null, settingsVersion, mappingVersion, aliasesVersion); | ||
|
|
||
| String result = IndexMetaDataGenerations.buildUniqueIdentifier(indexMetadata); | ||
| assertEquals(indexUUID + "-_na_-" + settingsVersion + "-" + mappingVersion + "-" + aliasesVersion, result); | ||
| } | ||
|
|
||
| public void testGetBlobIdToIndexUuidMap() { | ||
| String indexUUID = generateUUID(); | ||
| String randomSetting = randomAlphaOfLength(randomIntBetween(5, 10)); | ||
| long settingsVersion = randomNonNegativeLong(); | ||
| long mappingsVersion = randomNonNegativeLong(); | ||
| long aliasesVersion = randomNonNegativeLong(); | ||
| String uniqueIdentifier = indexUUID + "-" + randomSetting + "-" + settingsVersion + "-" + mappingsVersion + "-" + aliasesVersion; | ||
| String blobId = randomAlphanumericOfLength(randomIntBetween(5, 10)); | ||
|
|
||
| // Creates the lookup map | ||
| SnapshotId snapshotId = new SnapshotId("snapshot", randomUUID()); | ||
| IndexId indexId = new IndexId("index", indexUUID); | ||
| Map<SnapshotId, Map<IndexId, String>> lookup = Map.of(snapshotId, Map.of(indexId, uniqueIdentifier)); | ||
|
|
||
| IndexMetaDataGenerations generations = new IndexMetaDataGenerations(lookup, Map.of(uniqueIdentifier, blobId)); | ||
|
|
||
| Map<String, String> expectedBlobIdToindexUuidMap = Map.of(blobId, indexUUID); | ||
| assertEquals(expectedBlobIdToindexUuidMap, generations.getBlobIdToIndexUuidMap()); | ||
| } | ||
|
|
||
| public void testGetBlobIdToIndexUuidMapWithNoIdentifierMap() { | ||
| IndexMetaDataGenerations generations = new IndexMetaDataGenerations(Map.of(), Map.of()); | ||
| assertEquals(Collections.emptyMap(), generations.getBlobIdToIndexUuidMap()); | ||
| } | ||
|
|
||
| private String generateUUID() { | ||
| return UUIDs.randomBase64UUID(random()); | ||
| } | ||
|
|
||
| private String generateMetaIdentifier(String indexUUID) { | ||
| String historyUUID = generateUUID(); | ||
| long settingsVersion = randomLong(); | ||
| long mappingVersion = randomLong(); | ||
| long aliasesVersion = randomLong(); | ||
| return indexUUID + "-" + historyUUID + "-" + settingsVersion + "-" + mappingVersion + "-" + aliasesVersion; | ||
| } | ||
|
|
||
| private IndexMetadata createIndexMetadata( | ||
| String indexUUID, | ||
| String historyUUID, | ||
| long settingsVersion, | ||
| long mappingVersion, | ||
| long aliasesVersion | ||
| ) { | ||
| IndexMetadata indexMetadata = mock(IndexMetadata.class); | ||
| Settings.Builder settingsBuilder = Settings.builder(); | ||
| if (historyUUID != null) { | ||
| settingsBuilder.put(IndexMetadata.SETTING_HISTORY_UUID, historyUUID); | ||
| } | ||
| when(indexMetadata.getIndexUUID()).thenReturn(indexUUID); | ||
| when(indexMetadata.getSettings()).thenReturn(settingsBuilder.build()); | ||
| when(indexMetadata.getSettingsVersion()).thenReturn(settingsVersion); | ||
| when(indexMetadata.getMappingVersion()).thenReturn(mappingVersion); | ||
| when(indexMetadata.getAliasesVersion()).thenReturn(aliasesVersion); | ||
| return indexMetadata; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a field here we will be retaining this map until the very end of the post-deletion cleanup when the
SnapshotsDeletioninstance becomes unreachable, but that will overlap with the next snapshot operation (which may be another deletion, generating another such map, etc).However, we only need this map for the
determineShardCountcalls at the start of eachIndexSnapshotsDeletion, all of which happen before we update theRepositoryDataroot blob. I'd rather we dropped this potentially-large map as soon as possible, and definitely before allowing the next snapshot operation to proceed. It'd be best if it were a local variable computed inwriteUpdatedShardMetadataAndComputeDeletesand passed as an argument to eachdetermineShardCountcall viaIndexSnapshotsDeletion#run.