Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/137335.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 137335
summary: Pass XContentParserConfiguration into `ChecksumBlobStoreFormat`
area: Distributed
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -1326,9 +1327,19 @@ private void determineShardCount(ActionListener<Void> listener) {

private void getOneShardCount(String indexMetaGeneration) {
try {
// As per ES-12539, there is no need to load the entire IndexMetadata object just to read the shard count
// Instead, we read the minimum fields necessary, including the setting index.number_of_shards
XContentParserConfiguration xContentParserConfiguration = XContentParserConfiguration.EMPTY.withDeprecationHandler(
LoggingDeprecationHandler.INSTANCE
).withFiltering(Set.of("*.settings", "*.mapping_version", "*.settings_version", "*.aliases_version"), null, false);
updateShardCount(
INDEX_METADATA_FORMAT.read(getProjectRepo(), indexContainer, indexMetaGeneration, namedXContentRegistry)
.getNumberOfShards()
INDEX_METADATA_FORMAT.read(
getProjectRepo(),
indexContainer,
indexMetaGeneration,
namedXContentRegistry,
xContentParserConfiguration
).getNumberOfShards()
);
} catch (Exception ex) {
logger.warn(() -> format("[%s] [%s] failed to read metadata for index", indexMetaGeneration, indexId.getName()), ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,38 @@ public ChecksumBlobStoreFormat(

/**
* Reads and parses the blob with given name, applying name translation using the {link #blobName} method
*
* @param blobContainer blob container
* @param name name to be translated into
* @return parsed blob object
* @param projectRepo the project repository context, used for deserialization
* @param blobContainer the {@link BlobContainer} from which to read the blob
* @param name the logical name of the blob to read (will be formatted to the actual blob name)
* @param namedXContentRegistry the {@link NamedXContentRegistry} to use for parser construction
* @return the deserialized object of type {@code T} read from the blob
* @throws IOException if an I/O error occurs while reading or parsing the blob
*/
public T read(ProjectRepo projectRepo, BlobContainer blobContainer, String name, NamedXContentRegistry namedXContentRegistry)
throws IOException {
return read(projectRepo, blobContainer, name, namedXContentRegistry, null);
}

/**
* Reads and parses the blob with given name, applying name translation using the {link #blobName} method
* @param projectRepo the project repository context, used for deserialization
* @param blobContainer the {@link BlobContainer} from which to read the blob
* @param name the logical name of the blob to read (will be formatted to the actual blob name)
* @param namedXContentRegistry the {@link NamedXContentRegistry} to use for parser construction
* @param xContentParserConfiguration An optional {@link XContentParserConfiguration} to use when deserializing the blob
* @return the deserialized object of type {@code T} read from the blob
* @throws IOException if an I/O error occurs while reading or parsing the blob
*/
public T read(
ProjectRepo projectRepo,
BlobContainer blobContainer,
String name,
NamedXContentRegistry namedXContentRegistry,
XContentParserConfiguration xContentParserConfiguration
) throws IOException {
String blobName = blobName(name);
try (InputStream in = blobContainer.readBlob(OperationPurpose.SNAPSHOT_METADATA, blobName)) {
return deserialize(projectRepo, namedXContentRegistry, in);
return deserialize(projectRepo, namedXContentRegistry, in, xContentParserConfiguration);
}
}

Expand All @@ -132,6 +154,15 @@ public String blobName(String name) {
}

public T deserialize(ProjectRepo projectRepo, NamedXContentRegistry namedXContentRegistry, InputStream input) throws IOException {
return deserialize(projectRepo, namedXContentRegistry, input, null);
}

public T deserialize(
ProjectRepo projectRepo,
NamedXContentRegistry namedXContentRegistry,
InputStream input,
XContentParserConfiguration xContentParserConfiguration
) throws IOException {
final DeserializeMetaBlobInputStream deserializeMetaBlobInputStream = new DeserializeMetaBlobInputStream(input);
try {
CodecUtil.checkHeader(new InputStreamDataInput(deserializeMetaBlobInputStream), codec, VERSION, VERSION);
Expand All @@ -149,8 +180,10 @@ public T deserialize(ProjectRepo projectRepo, NamedXContentRegistry namedXConten
deserializeMetaBlobInputStream.verifyFooter();
try (
XContentParser parser = XContentHelper.createParserNotCompressed(
XContentParserConfiguration.EMPTY.withRegistry(namedXContentRegistry)
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE),
xContentParserConfiguration == null
? XContentParserConfiguration.EMPTY.withRegistry(namedXContentRegistry)
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE)
: xContentParserConfiguration,
bytesReference,
XContentType.SMILE
)
Expand All @@ -160,8 +193,10 @@ public T deserialize(ProjectRepo projectRepo, NamedXContentRegistry namedXConten
} catch (Exception e) {
try (
XContentParser parser = XContentHelper.createParserNotCompressed(
XContentParserConfiguration.EMPTY.withRegistry(namedXContentRegistry)
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE),
xContentParserConfiguration == null
? XContentParserConfiguration.EMPTY.withRegistry(namedXContentRegistry)
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE)
: xContentParserConfiguration,
bytesReference,
XContentType.SMILE
)
Expand All @@ -173,7 +208,13 @@ public T deserialize(ProjectRepo projectRepo, NamedXContentRegistry namedXConten
} else {
try (
XContentParser parser = XContentType.SMILE.xContent()
.createParser(namedXContentRegistry, LoggingDeprecationHandler.INSTANCE, wrappedStream)
.createParser(
xContentParserConfiguration == null
? XContentParserConfiguration.EMPTY.withRegistry(namedXContentRegistry)
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE)
: xContentParserConfiguration,
wrappedStream
)
) {
result = reader.apply(projectRepo, parser);
XContentParserUtils.ensureExpectedToken(null, parser.nextToken(), parser);
Expand Down