timoninmaxim commented on code in PR #12301: URL: https://github.com/apache/ignite/pull/12301#discussion_r2472669414
########## modules/core/src/main/java/org/apache/ignite/internal/processors/rollingupgrade/RollingUpgradeProcessor.java: ########## @@ -0,0 +1,310 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.rollingupgrade; + +import java.util.HashSet; +import java.util.Set; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.processors.GridProcessorAdapter; +import org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage; +import org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener; +import org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage; +import org.apache.ignite.internal.processors.nodevalidation.DiscoveryNodeValidationProcessor; +import org.apache.ignite.internal.util.lang.IgnitePair; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.A; +import org.apache.ignite.internal.util.typedef.internal.LT; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteProductVersion; +import org.apache.ignite.spi.IgniteNodeValidationResult; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNodesRing; +import org.jetbrains.annotations.Nullable; + +import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_BUILD_VER; +import static org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage.IGNITE_INTERNAL_KEY_PREFIX; + +/** Rolling upgrade processor. Manages current and target versions of cluster. */ +public class RollingUpgradeProcessor extends GridProcessorAdapter implements DiscoveryNodeValidationProcessor { + /** Key for the distributed property that holds current and target versions. */ + private static final String ROLLING_UPGRADE_VERSIONS_KEY = IGNITE_INTERNAL_KEY_PREFIX + "rolling.upgrade.versions"; + + /** Metastorage with the write access. */ + @Nullable private volatile DistributedMetaStorage metastorage; + + /** TCP discovery nodes ring. */ + private TcpDiscoveryNodesRing ring; + + /** Last joining node. */ + private ClusterNode lastJoiningNode; + + /** Last joining node timestamp. */ + private long lastJoiningNodeTimestamp; + + /** Lock for synchronization between tcp-disco-msg-worker thread and management operations. */ + private final Object lock = new Object(); + + /** Pair with current and target versions. */ + private volatile IgnitePair<IgniteProductVersion> verPair = null; + + /** + * @param ctx Context. + */ + public RollingUpgradeProcessor(GridKernalContext ctx) { + super(ctx); + } + + /** {@inheritDoc} */ + @Override public void start() throws IgniteCheckedException { + ctx.internalSubscriptionProcessor().registerDistributedMetastorageListener(new DistributedMetastorageLifecycleListener() { + @Override public void onReadyForWrite(DistributedMetaStorage metastorage) { + RollingUpgradeProcessor.this.metastorage = metastorage; + } + + @Override public void onReadyForRead(ReadableDistributedMetaStorage metastorage) { + try { + verPair = metastorage.read(ROLLING_UPGRADE_VERSIONS_KEY); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + + metastorage.listen(ROLLING_UPGRADE_VERSIONS_KEY::equals, (key, oldVal, newVal) -> { + verPair = (IgnitePair<IgniteProductVersion>)newVal; + }); + } + }); + } + + /** {@inheritDoc} */ + @Override public @Nullable IgniteNodeValidationResult validateNode(ClusterNode node) { + synchronized (lock) { Review Comment: You missed this comment -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
