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.
This commit is contained in:
Jason Tedor 2018-04-19 20:12:24 -04:00 committed by GitHub
parent a829d920ee
commit d1670a18e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 22 deletions

View File

@ -53,7 +53,7 @@ public class CommonStatsFlags implements Writeable, Cloneable {
final long longFlags = in.readLong(); final long longFlags = in.readLong();
flags.clear(); flags.clear();
for (Flag flag : Flag.values()) { for (Flag flag : Flag.values()) {
if ((longFlags & (1 << flag.ordinal())) != 0) { if ((longFlags & (1 << flag.getIndex())) != 0) {
flags.add(flag); flags.add(flag);
} }
} }
@ -68,7 +68,7 @@ public class CommonStatsFlags implements Writeable, Cloneable {
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
long longFlags = 0; long longFlags = 0;
for (Flag flag : flags) { for (Flag flag : flags) {
longFlags |= (1 << flag.ordinal()); longFlags |= (1 << flag.getIndex());
} }
out.writeLong(longFlags); out.writeLong(longFlags);
@ -207,34 +207,39 @@ public class CommonStatsFlags implements Writeable, Cloneable {
} }
public enum Flag { public enum Flag {
// Do not change the order of these flags we use Store("store", 0),
// the ordinal for encoding! Only append to the end! Indexing("indexing", 1),
Store("store"), Get("get", 2),
Indexing("indexing"), Search("search", 3),
Get("get"), Merge("merge", 4),
Search("search"), Flush("flush", 5),
Merge("merge"), Refresh("refresh", 6),
Flush("flush"), QueryCache("query_cache", 7),
Refresh("refresh"), FieldData("fielddata", 8),
QueryCache("query_cache"), Docs("docs", 9),
FieldData("fielddata"), Warmer("warmer", 10),
Docs("docs"), Completion("completion", 11),
Warmer("warmer"), Segments("segments", 12),
Completion("completion"), Translog("translog", 13),
Segments("segments"), Suggest("suggest", 14), // unused
Translog("translog"), RequestCache("request_cache", 15),
Suggest("suggest"), // unused Recovery("recovery", 16);
RequestCache("request_cache"),
Recovery("recovery");
private final String restName; private final String restName;
private final int index;
Flag(String restName) { Flag(final String restName, final int index) {
this.restName = restName; this.restName = restName;
this.index = index;
} }
public String getRestName() { public String getRestName() {
return restName; return restName;
} }
private int getIndex() {
return index;
}
} }
} }