From cd54c96d56cec08a0ac2415e86ea66e1e8a9d88b Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 14 Feb 2018 23:15:59 -0500 Subject: [PATCH] Add comment explaining lazy declared versions A recent change moved computing declared versions from using reflection which occurred repeatedly to a lazily-initialized holder so that declared versions are computed exactly once. This commit adds a comment explaining the motivation for this change. --- server/src/main/java/org/elasticsearch/Version.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index 0fad0d26c13a7..9d82d3ea69049 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -163,10 +163,6 @@ public class Version implements Comparable { + org.apache.lucene.util.Version.LATEST + "] is still set to [" + CURRENT.luceneVersion + "]"; } - private static class DeclaredVersionsHolder { - static final List DECLARED_VERSIONS = Collections.unmodifiableList(getDeclaredVersions(Version.class)); - } - public static Version readVersion(StreamInput in) throws IOException { return fromId(in.readVInt()); } @@ -406,6 +402,15 @@ public int compareTo(Version other) { return Integer.compare(this.id, other.id); } + /* + * We need the declared versions when computing the minimum compatibility version. As computing the declared versions uses reflection it + * is not cheap. Since computing the minimum compatibility version can occur often, we use this holder to compute the declared versions + * lazily once. + */ + private static class DeclaredVersionsHolder { + static final List DECLARED_VERSIONS = Collections.unmodifiableList(getDeclaredVersions(Version.class)); + } + /** * Returns the minimum compatible version based on the current * version. Ie a node needs to have at least the return version in order