Skip to content

Commit

Permalink
Add comment explaining lazy declared versions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasontedor committed Feb 15, 2018
1 parent 452bfc0 commit cd54c96
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions server/src/main/java/org/elasticsearch/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ public class Version implements Comparable<Version> {
+ org.apache.lucene.util.Version.LATEST + "] is still set to [" + CURRENT.luceneVersion + "]";
}

private static class DeclaredVersionsHolder {
static final List<Version> DECLARED_VERSIONS = Collections.unmodifiableList(getDeclaredVersions(Version.class));
}

public static Version readVersion(StreamInput in) throws IOException {
return fromId(in.readVInt());
}
Expand Down Expand Up @@ -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<Version> 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
Expand Down

0 comments on commit cd54c96

Please sign in to comment.