You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "SammyVimes (via GitHub)" <gi...@apache.org> on 2023/04/28 13:48:01 UTC

[GitHub] [ignite-3] SammyVimes commented on a diff in pull request #1978: IGNITE-18712 Do not allow a node excluded from Physical Topology to enter the topology again

SammyVimes commented on code in PR #1978:
URL: https://github.com/apache/ignite-3/pull/1978#discussion_r1180406997


##########
modules/network/src/integrationTest/java/org/apache/ignite/network/scalecube/ItScaleCubeNetworkMessagingTest.java:
##########
@@ -320,6 +323,69 @@ public void testMessageGroupsHandlers(TestInfo testInfo) throws Exception {
         assertThat(networkMessageFuture, willBe(equalTo(networkMessage)));
     }
 
+    /**
+     * Makes sure that a node that dropped out from the Physical Topology cannot reappear with same ID.
+     *
+     * @throws Exception in case of errors.
+     */
+    @Test
+    public void nodeCannotReuseOldId(TestInfo testInfo) throws Exception {
+        testCluster = new Cluster(3, testInfo);
+
+        testCluster.startAwait();
+
+        String outcastName = testCluster.members.get(testCluster.members.size() - 1).nodeName();
+
+        knockOutNode(outcastName);
+
+        CountDownLatch appeared = reanimateNode(outcastName);
+
+        assertFalse(appeared.await(3, TimeUnit.SECONDS), "Node reappeared");

Review Comment:
   So this test is always 3 seconds, right? Can we maybe listen for some event like "Node failed to join because of the stale id"? I see we have a FailureHandler, that can be used for that, right?



##########
build.gradle:
##########
@@ -119,6 +119,10 @@ subprojects {
                 releasesOnly()
             }
         }
+
+        maven {
+            url "https://jitpack.io"

Review Comment:
   ```suggestion
           maven {
               // TODO: IGNITE-19386 - switch to io.scalecube:scalecube-cluster
               url "https://jitpack.io"
   ```



##########
modules/table/src/integrationTest/java/org/apache/ignite/distributed/ItTxDistributedTestThreeNodesThreeReplicas.java:
##########
@@ -51,9 +51,11 @@ protected int replicas() {
     @Override
     @AfterEach
     public void after() throws Exception {
-        assertTrue(IgniteTestUtils.waitForCondition(() -> assertPartitionsSame(accounts, 0), 5_000));
-        assertTrue(IgniteTestUtils.waitForCondition(() -> assertPartitionsSame(customers, 0), 5_000));
-
-        super.after();
+        try {
+            assertTrue(IgniteTestUtils.waitForCondition(() -> assertPartitionsSame(accounts, 0), 5_000));

Review Comment:
   `TimeUnit.SECONDS.toMillis(5)` looks a bit better



##########
modules/network/src/main/java/org/apache/ignite/internal/network/netty/HandshakeHandler.java:
##########
@@ -67,7 +67,13 @@ public void handlerAdded(ChannelHandlerContext ctx) {
     /** {@inheritDoc} */
     @Override
     public void channelActive(ChannelHandlerContext ctx) {
-        manager.onConnectionOpen();
+        try {
+            manager.onConnectionOpen();
+        } catch (RuntimeException | AssertionError e) {
+            LOG.error("Error in onConnectionOpen()", e);

Review Comment:
   Probably some debugging leftovers?



##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/VaultStateIds.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.network.recovery;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import org.apache.ignite.internal.vault.VaultEntry;
+import org.apache.ignite.internal.vault.VaultManager;
+import org.apache.ignite.lang.ByteArray;
+
+/**
+ * {@link StaleIds} implementating using Vault as a persistent storage.
+ */
+public class VaultStateIds implements StaleIds {
+    private static final ByteArray STALE_IDS_KEY = new ByteArray("network.staleIds");
+
+    private static final int DEFAULT_MAX_IDS_TO_REMEMBER = 10_000;
+
+    private final VaultManager vaultManager;
+
+    private final int maxIdsToRemember;
+
+    private Set<String> staleIds;
+
+    public VaultStateIds(VaultManager vaultManager) {
+        this(vaultManager, DEFAULT_MAX_IDS_TO_REMEMBER);
+    }
+
+    public VaultStateIds(VaultManager vaultManager, int maxIdsToRemember) {
+        this.vaultManager = vaultManager;
+        this.maxIdsToRemember = maxIdsToRemember;
+    }
+
+    @Override
+    public synchronized boolean isIdStale(String nodeId) {
+        if (staleIds == null) {
+            staleIds = loadStaleIdsFromVault();
+        }
+
+        return staleIds.contains(nodeId);
+    }
+
+    private Set<String> loadStaleIdsFromVault() {
+        VaultEntry entry = vaultManager.get(STALE_IDS_KEY).join();
+
+        if (entry == null) {
+            return new LinkedHashSet<>();
+        }
+
+        String[] idsArray = new String(entry.value(), UTF_8).split("\n");
+
+        Set<String> result = new LinkedHashSet<>();
+
+        Collections.addAll(result, idsArray);
+
+        return result;
+    }
+
+    @Override
+    public synchronized void markAsStale(String nodeId) {
+        if (staleIds == null) {
+            staleIds = new LinkedHashSet<>();

Review Comment:
   Why don't we use `loadStaleIdsFromVault()` here?
   
   And a side note, can't we do `loadStaleIdsFromVault` on start?



##########
modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java:
##########
@@ -199,6 +219,25 @@ public void updateMetadata(NodeMetadata metadata) {
                 cluster.updateMetadata(metadata).subscribe();
                 topologyService.updateLocalMetadata(metadata);
             }
+
+            private String notNullClusterMemberId() {

Review Comment:
   Looks like we don't need it anymore



##########
modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java:
##########
@@ -199,6 +219,25 @@ public void updateMetadata(NodeMetadata metadata) {
                 cluster.updateMetadata(metadata).subscribe();
                 topologyService.updateLocalMetadata(metadata);
             }
+
+            private String notNullClusterMemberId() {
+                while (true) {
+                    // clusterMemberId() reads a volatile variable, so we actually read the member when it gets assigned.
+                    String memberId = clusterMemberId();
+                    if (memberId != null) {
+                        return memberId;
+                    }
+
+                    LockSupport.parkNanos(10_000_000);
+                }
+            }
+
+            @Nullable
+            private String clusterMemberId() {

Review Comment:
   This too, right? We can just use launchId directly



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org