Search in sources :

Example 1 with LegacyESVersion

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);
    }
}
Also used : LongSupplier(java.util.function.LongSupplier) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) Version(org.opensearch.Version) StreamOutput(org.opensearch.common.io.stream.StreamOutput) HashMap(java.util.HashMap) Writeable(org.opensearch.common.io.stream.Writeable) Function(java.util.function.Function) Supplier(java.util.function.Supplier) HashSet(java.util.HashSet) GroupedActionListener(org.opensearch.action.support.GroupedActionListener) OptionalLong(java.util.OptionalLong) ObjectLongHashMap(com.carrotsearch.hppc.ObjectLongHashMap) IndexShard(org.opensearch.index.shard.IndexShard) LegacyESVersion(org.opensearch.LegacyESVersion) WriteStateException(org.opensearch.gateway.WriteStateException) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) ObjectLongMap(com.carrotsearch.hppc.ObjectLongMap) StreamSupport(java.util.stream.StreamSupport) ActionListener(org.opensearch.action.ActionListener) ToLongFunction(java.util.function.ToLongFunction) Path(java.nio.file.Path) IndexShardRoutingTable(org.opensearch.cluster.routing.IndexShardRoutingTable) StreamInput(org.opensearch.common.io.stream.StreamInput) SuppressForbidden(org.opensearch.common.SuppressForbidden) LongStream(java.util.stream.LongStream) AllocationId(org.opensearch.cluster.routing.AllocationId) AbstractIndexShardComponent(org.opensearch.index.shard.AbstractIndexShardComponent) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Tuple(org.opensearch.common.collect.Tuple) LongConsumer(java.util.function.LongConsumer) ShardRouting(org.opensearch.cluster.routing.ShardRouting) ShardId(org.opensearch.index.shard.ShardId) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) IndexSettings(org.opensearch.index.IndexSettings) ReplicationResponse(org.opensearch.action.support.replication.ReplicationResponse) ReplicationGroup(org.opensearch.index.shard.ReplicationGroup) SafeCommitInfo(org.opensearch.index.engine.SafeCommitInfo) Collections(java.util.Collections) GroupedActionListener(org.opensearch.action.support.GroupedActionListener) ShardRouting(org.opensearch.cluster.routing.ShardRouting) WriteStateException(org.opensearch.gateway.WriteStateException) IOException(java.io.IOException) ReplicationResponse(org.opensearch.action.support.replication.ReplicationResponse)

Example 2 with LegacyESVersion

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));
}
Also used : Version(org.opensearch.Version) Random(java.util.Random) Collectors(java.util.stream.Collectors) Nullable(org.opensearch.common.Nullable) Tuple(org.opensearch.common.collect.Tuple) ArrayList(java.util.ArrayList) List(java.util.List) Stream(java.util.stream.Stream) LegacyESVersion(org.opensearch.LegacyESVersion) Map(java.util.Map) Optional(java.util.Optional) Comparator(java.util.Comparator) Collections(java.util.Collections) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) LegacyESVersion(org.opensearch.LegacyESVersion) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Tuple(org.opensearch.common.collect.Tuple)

Aggregations

Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 LegacyESVersion (org.opensearch.LegacyESVersion)2 Version (org.opensearch.Version)2 Tuple (org.opensearch.common.collect.Tuple)2 ObjectLongHashMap (com.carrotsearch.hppc.ObjectLongHashMap)1 ObjectLongMap (com.carrotsearch.hppc.ObjectLongMap)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 OptionalLong (java.util.OptionalLong)1