diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStatsFlags.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStatsFlags.java index 10defa43c57..8aadd618fe0 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStatsFlags.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStatsFlags.java @@ -169,6 +169,8 @@ public class CommonStatsFlags implements Streamable { } public static enum Flag { + // Do not change the order of these flags we use + // the ordinal for encoding! Only append to the end! Store("store"), Indexing("indexing"), Get("get"), diff --git a/src/test/java/org/elasticsearch/test/integration/indices/stats/SimpleIndexStatsTests.java b/src/test/java/org/elasticsearch/test/integration/indices/stats/SimpleIndexStatsTests.java index e68e2972b89..3927b5c7867 100644 --- a/src/test/java/org/elasticsearch/test/integration/indices/stats/SimpleIndexStatsTests.java +++ b/src/test/java/org/elasticsearch/test/integration/indices/stats/SimpleIndexStatsTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.test.integration.indices.stats; import java.io.IOException; +import java.util.Arrays; import java.util.EnumSet; import java.util.Random; @@ -285,6 +286,17 @@ public class SimpleIndexStatsTests extends AbstractNodesTests { } } + @Test + public void testFlagOrdinalOrder() { + Flag[] flags = new Flag[] { Flag.Store, Flag.Indexing, Flag.Get, Flag.Search, Flag.Merge, Flag.Flush, Flag.Refresh, + Flag.FilterCache, Flag.IdCache, Flag.FieldData, Flag.Docs, Flag.Warmer }; + + assertThat(flags.length, equalTo(Flag.values().length)); + for (int i = 0; i < flags.length; i++) { + assertThat("ordinal has changed - this breaks the wire protocol. Only append to new values", i, equalTo(flags[i].ordinal())); + } + } + private static void set(Flag flag, IndicesStatsRequestBuilder builder, boolean set) { switch(flag) { case Docs: