-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Introduce INDEX_SHARD_COUNT_FORMAT #137210
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
Open
joshua-adams-1
wants to merge
19
commits into
elastic:main
Choose a base branch
from
joshua-adams-1:new-index-metadata-format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+390
−10
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
53076ab
Replace INDEX_METADATA_FORMAT with INDEX_SHARD_COUNT_FORMAT
joshua-adams-1 ddd46e5
Remove unused code
joshua-adams-1 9818db7
Update docs/changelog/137210.yaml
joshua-adams-1 133f3f2
Introduces a new reader to only read the shard count
joshua-adams-1 90d8b90
Merge branch 'new-index-metadata-format' of https://github.com/joshua…
joshua-adams-1 448a9ea
Merge branch 'main' into new-index-metadata-format
joshua-adams-1 a584d0f
Comments
joshua-adams-1 d52a8f9
Merge branch 'main' into new-index-metadata-format
joshua-adams-1 fa08eac
Fix tests
joshua-adams-1 d699adf
Cleanup
joshua-adams-1 a951977
Minor tweaks
joshua-adams-1 399b7f1
Merge branch 'new-index-metadata-format' of https://github.com/joshua…
joshua-adams-1 8850b8b
Adds testSnapshotCreatedInOldVersionCanBeDeletedInNew test
joshua-adams-1 e213e01
Update changelog file
joshua-adams-1 d21f336
Comments
joshua-adams-1 5a8b53a
Merge branch 'main' into new-index-metadata-format
joshua-adams-1 a9c22ad
Revert IndexMetadataTests change that appeared after merging main
joshua-adams-1 52dac2e
Comments
joshua-adams-1 b1ab237
Merge branch 'main' into new-index-metadata-format
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 137210 | ||
| summary: "Introduce INDEX_SHARD_COUNT_FORMAT" | ||
| area: Snapshot/Restore | ||
| type: bug | ||
| issues: | ||
| - 131822 |
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
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
71 changes: 71 additions & 0 deletions
71
server/src/main/java/org/elasticsearch/repositories/blobstore/IndexShardCount.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,71 @@ | ||
| /* | ||
| * 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.blobstore; | ||
|
|
||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.common.xcontent.XContentParserUtils; | ||
| import org.elasticsearch.xcontent.XContentParser; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.KEY_SETTINGS; | ||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS; | ||
|
|
||
| /** | ||
| * A subset of {@link IndexMetadata} storing only the shard count of an index | ||
| * Prior to v9.3, the entire {@link IndexMetadata} object was stored in heap and then loaded during snapshotting to determine | ||
| * the shard count. As per ES-12539, this is replaced with the {@link IndexShardCount} class that writes and loads only the index's | ||
| * shard count to and from heap memory, reducing the possibility of smaller nodes going OOMe during snapshotting | ||
| */ | ||
| public record IndexShardCount(int count) { | ||
| /** | ||
| * Parses an {@link IndexMetadata} object, reading only the shard count and skipping the rest | ||
| * @param parser The parser of the {@link IndexMetadata} object | ||
| * @return Returns an {@link IndexShardCount} containing the shard count for the index | ||
| * @throws IOException Thrown if the {@link IndexMetadata} object cannot be parsed correctly | ||
| */ | ||
| public static IndexShardCount fromIndexMetadata(XContentParser parser) throws IOException { | ||
| parser.nextToken(); // fresh parser so move to the first token | ||
| parser.nextToken(); // on a start object move to next token | ||
| XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser); | ||
| String currentFieldName; | ||
| XContentParser.Token token = parser.nextToken(); | ||
| XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); | ||
|
|
||
| IndexShardCount indexShardCount = null; | ||
| // Skip over everything except the index.number_of_shards setting, or any unexpected tokens | ||
| while ((currentFieldName = parser.nextFieldName()) != null) { | ||
| token = parser.nextToken(); | ||
| if (token == XContentParser.Token.START_OBJECT) { | ||
| if (currentFieldName.equals(KEY_SETTINGS)) { | ||
| while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
| String fieldName = parser.currentName(); | ||
| parser.nextToken(); | ||
| if (SETTING_NUMBER_OF_SHARDS.equals(fieldName)) { | ||
| indexShardCount = new IndexShardCount(parser.intValue()); | ||
| } else { | ||
| parser.skipChildren(); | ||
| } | ||
| } | ||
| } else { | ||
| parser.skipChildren(); | ||
| } | ||
| } else if (token == XContentParser.Token.START_ARRAY) { | ||
| parser.skipChildren(); | ||
| } else if (token.isValue() == false) { | ||
| throw new IllegalArgumentException("Unexpected token " + token); | ||
| } | ||
| } | ||
| XContentParserUtils.ensureExpectedToken(XContentParser.Token.END_OBJECT, parser.nextToken(), parser); | ||
|
|
||
| // indexShardCount is null if corruption when parsing | ||
| return indexShardCount != null ? indexShardCount : new IndexShardCount(-1); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.