tkalkirill commented on code in PR #5514:
URL: https://github.com/apache/ignite-3/pull/5514#discussion_r2019745511


##########
modules/network/src/integrationTest/java/org/apache/ignite/internal/network/scalecube/ItScaleCubeNetworkMessagingTest.java:
##########
@@ -1109,6 +1112,44 @@ public void 
nodeWithNonNullClusterIdCanCommunicateNodeWithNullClusterId(boolean
         );
     }
 
+    @Test
+    public void nodesWithDifferentProductNamesCannotCommunicate() throws 
Exception {
+        Map<NetworkAddress, ProductVersionSource> productVersionSourcesMap = 
new ConcurrentHashMap<>();

Review Comment:
   ```suggestion
           var productVersionSourcesMap = new ConcurrentHashMap<NetworkAddress, 
ProductVersionSource>();
   ```



##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/HandshakeManagerUtils.java:
##########
@@ -62,6 +62,12 @@ static void sendRejectionMessageAndFailHandshake(
             CompletableFuture<NettySender> handshakeFuture,
             Function<String, Exception> exceptionFactory
     ) {
+        if (rejectionReason.logAsWarn()) {
+            LOG.warn("Rejecting handshake: " + messageText);
+        } else {
+            LOG.debug("Rejecting handshake: " + messageText);

Review Comment:
   ```suggestion
               LOG.debug("Rejecting handshake: {}", messageText);
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/version/DefaultProductVersionSource.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.version;
+
+import org.apache.ignite.internal.properties.IgniteProductVersion;
+
+/**
+ * {@link ProductVersionSource} that takes product name and version from the 
properties.
+ */
+public class DefaultProductVersionSource implements ProductVersionSource {

Review Comment:
   Mybe rename to `DefaultIgniteProductVersionSource`?



##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/HandshakeManagerUtils.java:
##########
@@ -62,6 +62,12 @@ static void sendRejectionMessageAndFailHandshake(
             CompletableFuture<NettySender> handshakeFuture,
             Function<String, Exception> exceptionFactory
     ) {
+        if (rejectionReason.logAsWarn()) {
+            LOG.warn("Rejecting handshake: " + messageText);

Review Comment:
   ```suggestion
               LOG.warn("Rejecting handshake: {}", messageText);
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/version/ProductVersionSource.java:
##########
@@ -0,0 +1,31 @@
+/*
+ * 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.version;
+
+import org.apache.ignite.internal.properties.IgniteProductVersion;
+
+/**
+ * Allows to obtain product name and version.
+ */
+public interface ProductVersionSource {

Review Comment:
   Maybe rename to `IgniteProductVersionSource` ?



##########
modules/network/src/integrationTest/java/org/apache/ignite/internal/network/scalecube/ItScaleCubeNetworkMessagingTest.java:
##########
@@ -1109,6 +1112,44 @@ public void 
nodeWithNonNullClusterIdCanCommunicateNodeWithNullClusterId(boolean
         );
     }
 
+    @Test
+    public void nodesWithDifferentProductNamesCannotCommunicate() throws 
Exception {
+        Map<NetworkAddress, ProductVersionSource> productVersionSourcesMap = 
new ConcurrentHashMap<>();
+        Function<NetworkAddress, ProductVersionSource> versionSourceFactory = 
addr -> productVersionSourcesMap.computeIfAbsent(
+                addr,
+                k -> new ArbitraryProductVersionSource("product-" + k, 
IgniteProductVersion.CURRENT_VERSION)
+        );
+        testCluster = new Cluster(2, testInfo, 
Cluster.normalClusterIdSupplierFactory, versionSourceFactory);
+
+        assertThat(startAsync(new ComponentContext(), testCluster.members), 
willCompleteSuccessfully());
+
+        assertFalse(
+                waitForCondition(testCluster::anyMembersSeeEachOther, 
SECONDS.toMillis(1)),
+                "Nodes with different product names are able to communicate"
+        );
+    }
+
+    @Test
+    public void nodesWithDifferentVersionsCannotCommunicate() throws Exception 
{
+        Map<NetworkAddress, ProductVersionSource> productVersionSourcesMap = 
new ConcurrentHashMap<>();
+        AtomicInteger addressCounter = new AtomicInteger();

Review Comment:
   ```suggestion
           var addressCounter = new AtomicInteger();
   ```



##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/RecoveryClientHandshakeManager.java:
##########
@@ -319,6 +317,18 @@ private boolean 
possiblyRejectHandshakeStart(HandshakeStartMessage message) {
             return true;
         }
 
+        if (!Objects.equals(message.productName(), 
productVersionSource.productName())) {

Review Comment:
   Some name or version can be `null`? why?



##########
modules/network/src/integrationTest/java/org/apache/ignite/internal/network/scalecube/ArbitraryProductVersionSource.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.scalecube;
+
+import org.apache.ignite.internal.properties.IgniteProductVersion;
+import org.apache.ignite.internal.version.ProductVersionSource;
+
+/**
+ * {@link ProductVersionSource} that allows arbitrary product name and version 
to be specified.
+ */
+class ArbitraryProductVersionSource implements ProductVersionSource {

Review Comment:
   As far as I understand, this class is used in tests, let's add the prefix 
`Test` to it?



##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/RecoveryClientHandshakeManager.java:
##########
@@ -354,6 +364,22 @@ private void handleClusterIdMismatch(HandshakeStartMessage 
msg) {
         sendRejectionMessageAndFailHandshake(message, 
HandshakeRejectionReason.CLUSTER_ID_MISMATCH, HandshakeException::new);
     }
 
+    private void handleProductNameMismatch(HandshakeStartMessage msg) {
+        String message = msg.serverNode().name() + ":" + msg.serverNode().id()

Review Comment:
   I think the code won't be hot and you can use a formatted string to make it 
more visual. It's up to you.



##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/RecoveryClientHandshakeManager.java:
##########
@@ -354,6 +364,22 @@ private void handleClusterIdMismatch(HandshakeStartMessage 
msg) {
         sendRejectionMessageAndFailHandshake(message, 
HandshakeRejectionReason.CLUSTER_ID_MISMATCH, HandshakeException::new);
     }
 
+    private void handleProductNameMismatch(HandshakeStartMessage msg) {
+        String message = msg.serverNode().name() + ":" + msg.serverNode().id()
+                + " runs product '" + msg.productName() + "' which is 
different from this one '"
+                + productVersionSource.productName() + "', connection 
rejected";
+
+        sendRejectionMessageAndFailHandshake(message, 
HandshakeRejectionReason.PRODUCT_MISMATCH, HandshakeException::new);
+    }
+
+    private void handleProductVersionMismatch(HandshakeStartMessage msg) {
+        String message = msg.serverNode().name() + ":" + msg.serverNode().id()

Review Comment:
   Same about format



##########
modules/network/src/test/java/org/apache/ignite/internal/network/recovery/message/HandshakeRejectionReasonTest.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.message;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+class HandshakeRejectionReasonTest {
+    @Test
+    void logAsWarn() {

Review Comment:
   And if a new one appears, they can forget about it.



##########
modules/network/src/integrationTest/java/org/apache/ignite/internal/network/scalecube/ItScaleCubeNetworkMessagingTest.java:
##########
@@ -1109,6 +1112,44 @@ public void 
nodeWithNonNullClusterIdCanCommunicateNodeWithNullClusterId(boolean
         );
     }
 
+    @Test
+    public void nodesWithDifferentProductNamesCannotCommunicate() throws 
Exception {
+        Map<NetworkAddress, ProductVersionSource> productVersionSourcesMap = 
new ConcurrentHashMap<>();
+        Function<NetworkAddress, ProductVersionSource> versionSourceFactory = 
addr -> productVersionSourcesMap.computeIfAbsent(
+                addr,
+                k -> new ArbitraryProductVersionSource("product-" + k, 
IgniteProductVersion.CURRENT_VERSION)
+        );
+        testCluster = new Cluster(2, testInfo, 
Cluster.normalClusterIdSupplierFactory, versionSourceFactory);
+
+        assertThat(startAsync(new ComponentContext(), testCluster.members), 
willCompleteSuccessfully());
+
+        assertFalse(
+                waitForCondition(testCluster::anyMembersSeeEachOther, 
SECONDS.toMillis(1)),
+                "Nodes with different product names are able to communicate"
+        );
+    }
+
+    @Test
+    public void nodesWithDifferentVersionsCannotCommunicate() throws Exception 
{
+        Map<NetworkAddress, ProductVersionSource> productVersionSourcesMap = 
new ConcurrentHashMap<>();

Review Comment:
   ```suggestion
           var productVersionSourcesMap = new ConcurrentHashMap<NetworkAddress, 
ProductVersionSource>();
   ```



##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/RecoveryClientHandshakeManager.java:
##########
@@ -376,24 +402,17 @@ private void sendRejectionMessageAndFailHandshake(
     }
 
     private void onHandshakeRejectedMessage(HandshakeRejectedMessage msg) {
-        boolean ignorable = stopping.getAsBoolean() || 
!msg.reason().critical();
-
-        if (ignorable) {
-            LOG.debug("Handshake rejected by server: {}", msg.message());
-        } else {
+        if (!stopping.getAsBoolean() && msg.reason().logAsWarn()) {
             LOG.warn("Handshake rejected by server: {}", msg.message());
+        } else {
+            LOG.debug("Handshake rejected by server: {}", msg.message());
         }
 
         if (msg.reason() == HandshakeRejectionReason.CLINCH) {
             giveUpClinch();
         } else {
             localHandshakeCompleteFuture.completeExceptionally(new 
HandshakeException(msg.message()));
         }
-
-        if (!ignorable) {
-            failureManager.process(

Review Comment:
   Please tell me why you removed this?



-- 
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-unsubscr...@ignite.apache.org

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

Reply via email to