Skip to content

Commit c31762a

Browse files
Pass XContentParserConfiguration into ChecksumBlobStoreFormat
Passes an optional parameter into `ChecksumBlobStoreFormat.read` to specify the XContentParserConfiguration of the parser Relates to: ES-12539
1 parent 76fa0d5 commit c31762a

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,11 +1329,17 @@ private void getOneShardCount(String indexMetaGeneration) {
13291329
try {
13301330
// As per ES-12539, there is no need to load the entire IndexMetadata object just to read the shard count
13311331
// Instead, we read the minimum fields necessary, including the setting index.number_of_shards
1332-
XContentParserConfiguration xContentParserConfiguration = XContentParserConfiguration.EMPTY.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE)
1333-
.withFiltering(Set.of("*.settings", "*.mapping_version", "*.settings_version", "*.aliases_version"), null, false);
1332+
XContentParserConfiguration xContentParserConfiguration = XContentParserConfiguration.EMPTY.withDeprecationHandler(
1333+
LoggingDeprecationHandler.INSTANCE
1334+
).withFiltering(Set.of("*.settings", "*.mapping_version", "*.settings_version", "*.aliases_version"), null, false);
13341335
updateShardCount(
1335-
INDEX_METADATA_FORMAT.read(getProjectRepo(), indexContainer, indexMetaGeneration, namedXContentRegistry, xContentParserConfiguration)
1336-
.getNumberOfShards()
1336+
INDEX_METADATA_FORMAT.read(
1337+
getProjectRepo(),
1338+
indexContainer,
1339+
indexMetaGeneration,
1340+
namedXContentRegistry,
1341+
xContentParserConfiguration
1342+
).getNumberOfShards()
13371343
);
13381344
} catch (Exception ex) {
13391345
logger.warn(() -> format("[%s] [%s] failed to read metadata for index", indexMetaGeneration, indexId.getName()), ex);

server/src/main/java/org/elasticsearch/repositories/blobstore/ChecksumBlobStoreFormat.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,13 @@ public T read(ProjectRepo projectRepo, BlobContainer blobContainer, String name,
136136
* @return the deserialized object of type {@code T} read from the blob
137137
* @throws IOException if an I/O error occurs while reading or parsing the blob
138138
*/
139-
public T read(ProjectRepo projectRepo, BlobContainer blobContainer, String name, NamedXContentRegistry namedXContentRegistry, XContentParserConfiguration xContentParserConfiguration)
140-
throws IOException {
139+
public T read(
140+
ProjectRepo projectRepo,
141+
BlobContainer blobContainer,
142+
String name,
143+
NamedXContentRegistry namedXContentRegistry,
144+
XContentParserConfiguration xContentParserConfiguration
145+
) throws IOException {
141146
String blobName = blobName(name);
142147
try (InputStream in = blobContainer.readBlob(OperationPurpose.SNAPSHOT_METADATA, blobName)) {
143148
return deserialize(projectRepo, namedXContentRegistry, in, xContentParserConfiguration);
@@ -152,7 +157,12 @@ public T deserialize(ProjectRepo projectRepo, NamedXContentRegistry namedXConten
152157
return deserialize(projectRepo, namedXContentRegistry, input, null);
153158
}
154159

155-
public T deserialize(ProjectRepo projectRepo, NamedXContentRegistry namedXContentRegistry, InputStream input, XContentParserConfiguration xContentParserConfiguration) throws IOException {
160+
public T deserialize(
161+
ProjectRepo projectRepo,
162+
NamedXContentRegistry namedXContentRegistry,
163+
InputStream input,
164+
XContentParserConfiguration xContentParserConfiguration
165+
) throws IOException {
156166
final DeserializeMetaBlobInputStream deserializeMetaBlobInputStream = new DeserializeMetaBlobInputStream(input);
157167
try {
158168
CodecUtil.checkHeader(new InputStreamDataInput(deserializeMetaBlobInputStream), codec, VERSION, VERSION);
@@ -185,7 +195,7 @@ public T deserialize(ProjectRepo projectRepo, NamedXContentRegistry namedXConten
185195
XContentParser parser = XContentHelper.createParserNotCompressed(
186196
xContentParserConfiguration == null
187197
? XContentParserConfiguration.EMPTY.withRegistry(namedXContentRegistry)
188-
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE)
198+
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE)
189199
: xContentParserConfiguration,
190200
bytesReference,
191201
XContentType.SMILE
@@ -417,10 +427,10 @@ public void close() {
417427
// in order to write the footer we need to prevent closing the actual index input.
418428
}
419429
};
420-
XContentBuilder builder = XContentFactory.contentBuilder(
421-
XContentType.SMILE,
422-
compress ? CompressorFactory.COMPRESSOR.threadLocalOutputStream(indexOutputOutputStream) : indexOutputOutputStream
423-
)
430+
XContentBuilder builder = XContentFactory.contentBuilder(
431+
XContentType.SMILE,
432+
compress ? CompressorFactory.COMPRESSOR.threadLocalOutputStream(indexOutputOutputStream) : indexOutputOutputStream
433+
)
424434
) {
425435
ToXContent.Params params = extraParams.isEmpty()
426436
? SNAPSHOT_ONLY_FORMAT_PARAMS

0 commit comments

Comments
 (0)