Skip to content

Commit c87bd30

Browse files
committed
Do not serialize common stats flags using ordinal (#29600)
This commit remove serializing of common stats flags via its enum ordinal and uses an explicit index defined on the enum. This is to enable us to remove an unused flag (Suggest) without ruining the ordering and thus breaking serialization.
1 parent 6d2d509 commit c87bd30

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStatsFlags.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public CommonStatsFlags(StreamInput in) throws IOException {
5353
final long longFlags = in.readLong();
5454
flags.clear();
5555
for (Flag flag : Flag.values()) {
56-
if ((longFlags & (1 << flag.ordinal())) != 0) {
56+
if ((longFlags & (1 << flag.getIndex())) != 0) {
5757
flags.add(flag);
5858
}
5959
}
@@ -68,7 +68,7 @@ public CommonStatsFlags(StreamInput in) throws IOException {
6868
public void writeTo(StreamOutput out) throws IOException {
6969
long longFlags = 0;
7070
for (Flag flag : flags) {
71-
longFlags |= (1 << flag.ordinal());
71+
longFlags |= (1 << flag.getIndex());
7272
}
7373
out.writeLong(longFlags);
7474

@@ -207,34 +207,39 @@ public CommonStatsFlags clone() {
207207
}
208208

209209
public enum Flag {
210-
// Do not change the order of these flags we use
211-
// the ordinal for encoding! Only append to the end!
212-
Store("store"),
213-
Indexing("indexing"),
214-
Get("get"),
215-
Search("search"),
216-
Merge("merge"),
217-
Flush("flush"),
218-
Refresh("refresh"),
219-
QueryCache("query_cache"),
220-
FieldData("fielddata"),
221-
Docs("docs"),
222-
Warmer("warmer"),
223-
Completion("completion"),
224-
Segments("segments"),
225-
Translog("translog"),
226-
Suggest("suggest"), // unused
227-
RequestCache("request_cache"),
228-
Recovery("recovery");
210+
Store("store", 0),
211+
Indexing("indexing", 1),
212+
Get("get", 2),
213+
Search("search", 3),
214+
Merge("merge", 4),
215+
Flush("flush", 5),
216+
Refresh("refresh", 6),
217+
QueryCache("query_cache", 7),
218+
FieldData("fielddata", 8),
219+
Docs("docs", 9),
220+
Warmer("warmer", 10),
221+
Completion("completion", 11),
222+
Segments("segments", 12),
223+
Translog("translog", 13),
224+
Suggest("suggest", 14), // unused
225+
RequestCache("request_cache", 15),
226+
Recovery("recovery", 16);
229227

230228
private final String restName;
229+
private final int index;
231230

232-
Flag(String restName) {
231+
Flag(final String restName, final int index) {
233232
this.restName = restName;
233+
this.index = index;
234234
}
235235

236236
public String getRestName() {
237237
return restName;
238238
}
239+
240+
private int getIndex() {
241+
return index;
242+
}
243+
239244
}
240245
}

0 commit comments

Comments
 (0)