Skip to content

Commit

Permalink
Merge branch 'master' into global-checkpoint-sync
Browse files Browse the repository at this point in the history
* master:
  Remove assertion from checkpoint tracker invariants
  Upgrade API: fix excessive logging and unnecessary template updates (elastic#26698)
  • Loading branch information
jasontedor committed Sep 20, 2017
2 parents e0657a7 + 581a873 commit b79b13f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.elasticsearch.cluster.Diff;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.compress.CompressedXContent;
Expand Down Expand Up @@ -405,7 +404,7 @@ public static void toInnerXContent(IndexTemplateMetaData indexTemplateMetaData,
builder.startObject("mappings");
for (ObjectObjectCursor<String, CompressedXContent> cursor : indexTemplateMetaData.mappings()) {
byte[] mappingSource = cursor.value.uncompressed();
Map<String, Object> mapping = XContentHelper.convertToMap(new BytesArray(mappingSource), false).v2();
Map<String, Object> mapping = XContentHelper.convertToMap(new BytesArray(mappingSource), true).v2();
if (mapping.size() == 1 && mapping.containsKey(cursor.key)) {
// the type name is the root value, reduce it
mapping = (Map<String, Object>) mapping.get(cursor.key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ public void clusterChanged(ClusterChangedEvent event) {
lastTemplateMetaData = templates;
Optional<Tuple<Map<String, BytesReference>, Set<String>>> changes = calculateTemplateChanges(templates);
if (changes.isPresent()) {
logger.info("Starting template upgrade to version {}, {} templates will be updated and {} will be removed",
Version.CURRENT,
changes.get().v1().size(),
changes.get().v2().size());
if (updatesInProgress.compareAndSet(0, changes.get().v1().size() + changes.get().v2().size())) {
logger.info("Starting template upgrade to version {}, {} templates will be updated and {} will be removed",
Version.CURRENT,
changes.get().v1().size(),
changes.get().v2().size());
threadPool.generic().execute(() -> updateTemplates(changes.get().v1(), changes.get().v2()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,6 @@ private boolean invariant() {
+ "for primary mode allocation ID [" + shardAllocationId + "] "
+ "more than in-sync local checkpoints [" + checkpoints + "]";

// when in primary mode, the local knowledge of the global checkpoints on shard copies is bounded by the global checkpoint
assert !primaryMode
|| getGlobalCheckpoint() >= inSyncCheckpointStates(checkpoints, CheckpointState::getGlobalCheckpoint, LongStream::max)
: "global checkpoint [" + getGlobalCheckpoint() + "] "
+ "for primary mode allocation ID [" + shardAllocationId + "] "
+ "less than in-sync global checkpoints [" + checkpoints + "]";

// we have a routing table iff we have a replication group
assert (routingTable == null) == (replicationGroup == null) :
"routing table is " + routingTable + " but replication group is " + replicationGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,27 @@

import org.elasticsearch.Version;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.settings.Settings;
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 java.io.IOException;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;

import static java.util.Collections.singletonMap;
import static org.elasticsearch.cluster.metadata.AliasMetaData.newAliasMetaDataBuilder;
import static org.hamcrest.CoreMatchers.equalTo;

public class IndexTemplateMetaDataTests extends ESTestCase {

Expand Down Expand Up @@ -78,4 +88,36 @@ public void testIndexTemplateMetaData510() throws IOException {
}
}

public void testIndexTemplateMetaDataXContentRoundTrip() throws Exception {
ToXContent.Params params = new ToXContent.MapParams(singletonMap("reduce_mappings", "true"));

String template = "{\"index_patterns\" : [ \".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));
}

}

0 comments on commit b79b13f

Please sign in to comment.