Record Class IndexVersion

java.lang.Object
java.lang.Record
org.elasticsearch.index.IndexVersion
All Implemented Interfaces:
Comparable<IndexVersion>, VersionId<IndexVersion>, ToXContent, ToXContentFragment

public record IndexVersion(int id, org.apache.lucene.util.Version luceneVersion) extends Record implements VersionId<IndexVersion>, ToXContentFragment
The index version.

Prior to 8.8.0, the node Version was used everywhere. This class separates the index format version from the running node version.

Each index version constant has an id number, which for versions prior to 8.9.0 is the same as the release version for backwards compatibility. In 8.9.0 this is changed to an incrementing number, disconnected from the release version.

Each version constant has a unique id string. This is not actually stored in the index, but is there to ensure each index version is only added to the source file once. This string needs to be unique (normally a UUID, but can be any other unique nonempty string). If two concurrent PRs add the same index version, the different unique ids cause a git conflict, ensuring the second PR to be merged must be updated with the next free version first. Without the unique id string, git will happily merge the two versions together, resulting in the same index version being used across multiple commits, causing problems when you try to upgrade between those two merged commits.

Version compatibility

The earliest compatible version is hardcoded in the MINIMUM_COMPATIBLE field. Previously, this was dynamically calculated from the major/minor versions of Version, but IndexVersion does not have separate major/minor version numbers. So the minimum compatible version is hard-coded as the index version used by the first version of the previous major release. MINIMUM_COMPATIBLE should be updated appropriately whenever a major release happens.

Adding a new version

A new index version should be added every time a change is made to the serialization protocol of one or more classes. Each index version should only be used in a single merged commit (apart from BwC versions copied from Version).

To add a new index version, add a new constant at the bottom of the list that is one greater than the current highest version, ensure it has a unique id, and update the current() constant to point to the new version.

Reverting an index version

If you revert a commit with an index version change, you must ensure there is a new index version representing the reverted change. Do not let the index version go backwards, it must always be incremented.