1818package org .apache .ignite .internal .processors .rollingupgrade ;
1919
2020import java .util .Objects ;
21+ import java .util .SortedSet ;
22+ import java .util .TreeSet ;
2123import java .util .UUID ;
2224import java .util .concurrent .CountDownLatch ;
2325import org .apache .ignite .IgniteCheckedException ;
2426import org .apache .ignite .IgniteException ;
2527import org .apache .ignite .cluster .ClusterNode ;
2628import org .apache .ignite .events .DiscoveryEvent ;
27- import org .apache .ignite .events .Event ;
2829import org .apache .ignite .internal .GridKernalContext ;
29- import org .apache .ignite .internal .managers .eventstorage .GridLocalEventListener ;
3030import org .apache .ignite .internal .processors .GridProcessorAdapter ;
3131import org .apache .ignite .internal .processors .metastorage .DistributedMetaStorage ;
3232import org .apache .ignite .internal .processors .metastorage .DistributedMetastorageLifecycleListener ;
3939import org .apache .ignite .lang .IgniteProductVersion ;
4040import org .apache .ignite .plugin .security .SecurityPermission ;
4141import org .apache .ignite .spi .IgniteNodeValidationResult ;
42- import org .apache .ignite .spi .discovery .DiscoverySpi ;
4342import org .apache .ignite .spi .discovery .tcp .TcpDiscoverySpi ;
44- import org .apache .ignite .spi .discovery .tcp .internal .TcpDiscoveryNodesRing ;
4543import org .jetbrains .annotations .Nullable ;
4644
4745import static org .apache .ignite .events .EventType .EVT_NODE_FAILED ;
4846import static org .apache .ignite .events .EventType .EVT_NODE_JOINED ;
4947import static org .apache .ignite .events .EventType .EVT_NODE_LEFT ;
48+ import static org .apache .ignite .events .EventType .EVT_NODE_VALIDATION_FAILED ;
5049import static org .apache .ignite .internal .IgniteNodeAttributes .ATTR_BUILD_VER ;
5150import static org .apache .ignite .internal .processors .metastorage .DistributedMetaStorage .IGNITE_INTERNAL_KEY_PREFIX ;
5251
@@ -58,15 +57,9 @@ public class RollingUpgradeProcessor extends GridProcessorAdapter implements Dis
5857 /** Metastorage with the write access. */
5958 @ Nullable private volatile DistributedMetaStorage metastorage ;
6059
61- /** TCP discovery nodes ring. */
62- private TcpDiscoveryNodesRing ring ;
63-
6460 /** Last joining node. */
6561 private ClusterNode lastJoiningNode ;
6662
67- /** Last joining node timestamp. */
68- private long lastJoiningNodeTimestamp ;
69-
7063 /** Lock for synchronization between tcp-disco-msg-worker thread and management operations. */
7164 private final Object lock = new Object ();
7265
@@ -85,26 +78,25 @@ public RollingUpgradeProcessor(GridKernalContext ctx) {
8578
8679 /** {@inheritDoc} */
8780 @ Override public void onKernalStart (boolean active ) throws IgniteCheckedException {
88- DiscoverySpi spi = ctx .config ().getDiscoverySpi ();
89-
90- if (spi instanceof TcpDiscoverySpi )
91- ring = ((TcpDiscoverySpi )spi ).discoveryRing ();
92-
9381 startLatch .countDown ();
9482 }
9583
9684 /** {@inheritDoc} */
9785 @ Override public void start () throws IgniteCheckedException {
98- ctx .event ().addLocalEventListener (new GridLocalEventListener () {
99- @ Override public void onEvent ( Event evt ) {
86+ ctx .event ().addLocalEventListener (
87+ evt -> {
10088 UUID nodeId = ((DiscoveryEvent )evt ).eventNode ().id ();
10189
10290 synchronized (lock ) {
10391 if (lastJoiningNode != null && lastJoiningNode .id ().equals (nodeId ))
10492 lastJoiningNode = null ;
10593 }
106- }
107- }, EVT_NODE_JOINED , EVT_NODE_FAILED , EVT_NODE_LEFT );
94+ },
95+ EVT_NODE_JOINED ,
96+ EVT_NODE_FAILED ,
97+ EVT_NODE_LEFT ,
98+ EVT_NODE_VALIDATION_FAILED
99+ );
108100
109101 ctx .internalSubscriptionProcessor ().registerDistributedMetastorageListener (new DistributedMetastorageLifecycleListener () {
110102 @ Override public void onReadyForWrite (DistributedMetaStorage metastorage ) {
@@ -131,8 +123,6 @@ public RollingUpgradeProcessor(GridKernalContext ctx) {
131123 @ Override public @ Nullable IgniteNodeValidationResult validateNode (ClusterNode node ) {
132124 synchronized (lock ) {
133125 lastJoiningNode = node ;
134-
135- lastJoiningNodeTimestamp = U .currentTimeMillis ();
136126 }
137127
138128 ClusterNode locNode = ctx .discovery ().localNode ();
@@ -247,21 +237,14 @@ public void disable() throws IgniteCheckedException {
247237 if (rollUpVers == null )
248238 return ;
249239
250- IgnitePair <IgniteProductVersion > minMaxVerPair = ring .minMaxNodeVersions ();
251-
252- if (!minMaxVerPair .get1 ().equals (minMaxVerPair .get2 ()))
253- throw new IgniteCheckedException ("Can't disable rolling upgrade with different versions in cluster: "
254- + minMaxVerPair .get1 () + ", " + minMaxVerPair .get2 ());
240+ IgnitePair <IgniteProductVersion > minMaxVerPair ;
255241
256242 synchronized (lock ) {
257- if (lastJoiningNode != null ) {
258- // Use 3 * joinTimeout as an upper time bound for joining nodes that may drop during validation
259- // without sending NODE_LEFT / NODE_FAILED events.
260- long timeout = ((TcpDiscoverySpi )ctx .config ().getDiscoverySpi ()).getJoinTimeout () * 3 ;
243+ minMaxVerPair = resolveMinMaxNodeVersions ();
261244
262- if (ring . node ( lastJoiningNode . id ()) != null || ( timeout > 0 && U . currentTimeMillis () - lastJoiningNodeTimestamp > timeout ))
263- lastJoiningNode = null ;
264- }
245+ if (! minMaxVerPair . get1 (). equals ( minMaxVerPair . get2 () ))
246+ throw new IgniteCheckedException ( "Can't disable rolling upgrade with different versions in cluster: "
247+ + minMaxVerPair . get1 () + ", " + minMaxVerPair . get2 ());
265248
266249 if (lastJoiningNode != null ) {
267250 IgniteProductVersion lastJoiningNodeVer = IgniteProductVersion .fromString (lastJoiningNode .attribute (ATTR_BUILD_VER ));
@@ -280,6 +263,20 @@ public void disable() throws IgniteCheckedException {
280263 log .info ("Rolling upgrade disabled. Current version of nodes in cluster: " + minMaxVerPair .get1 ());
281264 }
282265
266+ /** */
267+ private IgnitePair <IgniteProductVersion > resolveMinMaxNodeVersions () {
268+ assert Thread .holdsLock (lock );
269+
270+ SortedSet <IgniteProductVersion > clusterNodes = new TreeSet <>();
271+
272+ for (ClusterNode node : ctx .discovery ().discoverySpiRemoteNodes ())
273+ clusterNodes .add (node .version ());
274+
275+ clusterNodes .add (ctx .discovery ().localNode ().version ());
276+
277+ return new IgnitePair <>(clusterNodes .first (), clusterNodes .last ());
278+ }
279+
283280 /**
284281 * Returns a pair containing the current and target versions of the cluster.
285282 * <p>
0 commit comments