-
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
Changes from all commits
53076ab
ddd46e5
9818db7
133f3f2
90d8b90
448a9ea
a584d0f
d52a8f9
fa08eac
d699adf
a951977
399b7f1
8850b8b
e213e01
d21f336
5a8b53a
a9c22ad
52dac2e
b1ab237
eccdb25
289a5c1
34a5f20
02dfd08
2fa2d06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * 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 | ||
| */ | ||
| public record IndexShardCount(int count) { | ||
| /** | ||
| * Parses an {@link IndexMetadata} object, reading only the shard count and skipping the rest. | ||
| * Assumes that the settings object is flat, and not nested. | ||
| * @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(); | ||
|
Comment on lines
+46
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we have a little more error-checking here? Technically it's possible to de/serialize a |
||
| parser.nextToken(); | ||
| if (SETTING_NUMBER_OF_SHARDS.equals(fieldName)) { | ||
| assert indexShardCount == null : "number_of_shards setting encountered multiple times in index settings"; | ||
| indexShardCount = new IndexShardCount(parser.intValue()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: can we assert |
||
| } else if (parser.currentToken() == XContentParser.Token.START_OBJECT) { | ||
| // Settings should be flat, not nested | ||
| throw new IllegalArgumentException( | ||
| "Settings object contains nested object for key [" + fieldName + "], expected flat settings map" | ||
| ); | ||
| } 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); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.