-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade API: fix excessive logging and unnecessary template updates (#…
…26698) TemplateUpgradeService might get stuck in repeatedly upgrading templates after upgrade to 5.6.0. This is caused by shuffling mappings definition in the template during template serialization. This commit makes the template serialization consistent. Closes #26673
- Loading branch information
Showing
3 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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
69 changes: 69 additions & 0 deletions
69
core/src/test/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaDataTests.java
This file contains 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,69 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.cluster.metadata; | ||
|
||
import org.elasticsearch.common.bytes.BytesArray; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.common.xcontent.ToXContent; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentHelper; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.common.xcontent.json.JsonXContent; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import static java.util.Collections.singletonMap; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
public class IndexTemplateMetaDataTests extends ESTestCase { | ||
|
||
public void testIndexTemplateMetaDataXContentRoundTrip() throws Exception { | ||
ToXContent.Params params = new ToXContent.MapParams(singletonMap("reduce_mappings", "true")); | ||
|
||
String template = "{\"template\" : [ \".test-*\" ],\"order\" : 1000," + | ||
"\"settings\" : {\"number_of_shards\" : 1,\"number_of_replicas\" : 0}," + | ||
"\"mappings\" : {\"doc\" :" + | ||
"{\"properties\":{\"" + | ||
randomAlphaOfLength(10) + "\":{\"type\":\"text\"},\"" + | ||
randomAlphaOfLength(10) + "\":{\"type\":\"keyword\"}}" + | ||
"}}}"; | ||
|
||
BytesReference templateBytes = new BytesArray(template); | ||
final IndexTemplateMetaData indexTemplateMetaData; | ||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, templateBytes, XContentType.JSON)) { | ||
indexTemplateMetaData = IndexTemplateMetaData.Builder.fromXContent(parser, "test"); | ||
} | ||
|
||
final BytesReference templateBytesRoundTrip; | ||
try (XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent)) { | ||
builder.startObject(); | ||
IndexTemplateMetaData.Builder.toXContent(indexTemplateMetaData, builder, params); | ||
builder.endObject(); | ||
templateBytesRoundTrip = builder.bytes(); | ||
} | ||
|
||
final IndexTemplateMetaData indexTemplateMetaDataRoundTrip; | ||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, templateBytesRoundTrip, XContentType.JSON)) { | ||
indexTemplateMetaDataRoundTrip = IndexTemplateMetaData.Builder.fromXContent(parser, "test"); | ||
} | ||
assertThat(indexTemplateMetaData, equalTo(indexTemplateMetaDataRoundTrip)); | ||
} | ||
|
||
} |