use of org.opensearch.LegacyESVersion in project OpenSearch by opensearch-project.
the class ReplicationTracker method createMissingPeerRecoveryRetentionLeases.
/**
* Create any required peer-recovery retention leases that do not currently exist because we just did a rolling upgrade from a version
* prior to {@link LegacyESVersion#V_7_4_0} that does not create peer-recovery retention leases.
*/
public synchronized void createMissingPeerRecoveryRetentionLeases(ActionListener<Void> listener) {
if (hasAllPeerRecoveryRetentionLeases == false) {
final List<ShardRouting> shardRoutings = routingTable.assignedShards();
final GroupedActionListener<ReplicationResponse> groupedActionListener = new GroupedActionListener<>(ActionListener.wrap(vs -> {
setHasAllPeerRecoveryRetentionLeases();
listener.onResponse(null);
}, listener::onFailure), shardRoutings.size());
for (ShardRouting shardRouting : shardRoutings) {
if (retentionLeases.contains(getPeerRecoveryRetentionLeaseId(shardRouting))) {
groupedActionListener.onResponse(null);
} else {
final CheckpointState checkpointState = checkpoints.get(shardRouting.allocationId().getId());
if (checkpointState.tracked == false) {
groupedActionListener.onResponse(null);
} else {
logger.trace("createMissingPeerRecoveryRetentionLeases: adding missing lease for {}", shardRouting);
try {
addPeerRecoveryRetentionLease(shardRouting.currentNodeId(), Math.max(SequenceNumbers.NO_OPS_PERFORMED, checkpointState.globalCheckpoint), groupedActionListener);
} catch (Exception e) {
groupedActionListener.onFailure(e);
}
}
}
}
} else {
logger.trace("createMissingPeerRecoveryRetentionLeases: nothing to do");
listener.onResponse(null);
}
}
use of org.opensearch.LegacyESVersion in project OpenSearch by opensearch-project.
the class VersionUtils method resolveReleasedVersions.
/**
* Sort versions that have backwards compatibility guarantees from
* those that don't. Doesn't actually check whether or not the versions
* are released, instead it relies on gradle to have already checked
* this which it does in {@code :core:verifyVersions}. So long as the
* rules here match up with the rules in gradle then this should
* produce sensible results.
* @return a tuple containing versions with backwards compatibility
* guarantees in v1 and versions without the guarantees in v2
*/
static Tuple<List<Version>, List<Version>> resolveReleasedVersions(Version current, Class<?> versionClass) {
// group versions into major version
Map<Integer, List<Version>> majorVersions = Version.getDeclaredVersions(versionClass).stream().collect(Collectors.groupingBy(v -> (int) v.major));
// this breaks b/c 5.x is still in version list but master doesn't care about it!
// assert majorVersions.size() == 2;
List<List<Version>> oldVersions = new ArrayList<>(0);
List<List<Version>> previousMajor = new ArrayList<>(0);
if (current.major == 2) {
// add legacy first
oldVersions.addAll(splitByMinor(majorVersions.getOrDefault(6, Collections.emptyList())));
previousMajor.addAll(splitByMinor(majorVersions.getOrDefault(7, Collections.emptyList())));
}
// TODO: remove oldVersions, we should only ever have 2 majors in Version
// rebasing OpenSearch to 1.0.0 means the previous major version was Legacy 7.0.0
int previousMajorID = current.major == 1 ? 7 : current.major - 1;
oldVersions.addAll(splitByMinor(majorVersions.getOrDefault(previousMajorID - 1, Collections.emptyList())));
previousMajor.addAll(splitByMinor(majorVersions.getOrDefault(previousMajorID, Collections.emptyList())));
List<List<Version>> currentMajor = splitByMinor(majorVersions.get((int) current.major));
List<Version> unreleasedVersions = new ArrayList<>();
final List<List<Version>> stableVersions;
if (currentMajor.size() == 1) {
// on master branch
stableVersions = previousMajor;
// remove current
moveLastToUnreleased(currentMajor, unreleasedVersions);
} else if (current.major != 1 && current.major != 2) {
// on a stable or release branch, ie N.x
stableVersions = currentMajor;
// remove the next maintenance bugfix
final Version prevMajorLastMinor = moveLastToUnreleased(previousMajor, unreleasedVersions);
if (prevMajorLastMinor.revision == 0 && previousMajor.isEmpty() == false) {
// The latest minor in the previous major is a ".0" release, so there must be an unreleased bugfix for the minor before that
moveLastToUnreleased(previousMajor, unreleasedVersions);
}
} else {
stableVersions = currentMajor;
}
// all Legacy ES versions are released, so we don't exclude any.
if (current.equals(Version.V_1_0_0) == false) {
List<Version> lastMinorLine = stableVersions.get(stableVersions.size() - 1);
if (lastMinorLine.get(lastMinorLine.size() - 1) instanceof LegacyESVersion == false) {
// if the last minor line is Legacy there are no more staged releases; do nothing
Version lastMinor = moveLastToUnreleased(stableVersions, unreleasedVersions);
if (lastMinor instanceof LegacyESVersion == false && lastMinor.revision == 0) {
// no more staged legacy versions
if (stableVersions.get(stableVersions.size() - 1).size() == 1) {
// a minor is being staged, which is also unreleased
moveLastToUnreleased(stableVersions, unreleasedVersions);
}
// remove the next bugfix
if (stableVersions.isEmpty() == false) {
moveLastToUnreleased(stableVersions, unreleasedVersions);
}
}
}
}
// If none of the previous major was released, then the last minor and bugfix of the old version was not released either.
if (previousMajor.isEmpty()) {
assert currentMajor.isEmpty() : currentMajor;
// minor of the old version is being staged
moveLastToUnreleased(oldVersions, unreleasedVersions);
// bugix of the old version is also being staged
moveLastToUnreleased(oldVersions, unreleasedVersions);
}
List<Version> releasedVersions = Stream.of(oldVersions, previousMajor, currentMajor).flatMap(List::stream).flatMap(List::stream).collect(Collectors.toList());
// we add unreleased out of order, so need to sort here
Collections.sort(unreleasedVersions);
return new Tuple<>(Collections.unmodifiableList(releasedVersions), Collections.unmodifiableList(unreleasedVersions));
}
Aggregations