Skip to content

Commit 2af0e4b

Browse files
chesnokoffzstan
authored andcommitted
IGNITE-27684 Update IGNITE_HEADER for discovery protocol (#12671)
(cherry picked from commit 5999c49)
1 parent a535985 commit 2af0e4b

4 files changed

Lines changed: 119 additions & 6 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.compatibility.spi.discovery;
19+
20+
import java.util.Collection;
21+
import java.util.List;
22+
import org.apache.ignite.compatibility.IgniteReleasedVersion;
23+
import org.apache.ignite.compatibility.testframework.junits.IgniteCompatibilityAbstractTest;
24+
import org.apache.ignite.configuration.IgniteConfiguration;
25+
import org.apache.ignite.lang.IgniteInClosure;
26+
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
27+
import org.apache.ignite.testframework.GridTestUtils;
28+
import org.apache.ignite.testframework.ListeningTestLogger;
29+
import org.apache.ignite.testframework.LogListener;
30+
import org.junit.Test;
31+
import org.junit.runner.RunWith;
32+
import org.junit.runners.Parameterized;
33+
34+
/** */
35+
@RunWith(Parameterized.class)
36+
public class TcpDiscoveryDifferentClusterVersionsTest extends IgniteCompatibilityAbstractTest {
37+
/** */
38+
private static final String INCOMPATIBLE_NODE_MSG = "is this an incompatible Ignite node?";
39+
40+
/** */
41+
private static final IgniteReleasedVersion OLD_VERSION = IgniteReleasedVersion.VER_2_17_0;
42+
43+
/** */
44+
private ListeningTestLogger listeningLog;
45+
46+
/** */
47+
@Parameterized.Parameter
48+
public boolean client;
49+
50+
/** */
51+
@Parameterized.Parameters(name = "client={0}")
52+
public static Collection<?> client() {
53+
return List.of(true, false);
54+
}
55+
56+
/** {@inheritDoc} */
57+
@Override protected void afterTest() throws Exception {
58+
super.afterTest();
59+
60+
stopAllGrids();
61+
}
62+
63+
/** {@inheritDoc} */
64+
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
65+
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
66+
67+
if (listeningLog != null)
68+
cfg.setGridLogger(listeningLog);
69+
70+
return cfg;
71+
}
72+
73+
/** Tests that connection from node of old version is properly refused. */
74+
@Test
75+
public void testOldNodeRejected() throws Exception {
76+
setLoggerDebugLevel();
77+
78+
listeningLog = new ListeningTestLogger(log);
79+
80+
LogListener logListener = LogListener.matches(INCOMPATIBLE_NODE_MSG).build();
81+
82+
listeningLog.registerListener(logListener);
83+
84+
startGrid(0);
85+
86+
GridTestUtils.assertThrows(
87+
log,
88+
() -> startGrid("old-node", OLD_VERSION.toString(), new ConfigurationClosure()),
89+
AssertionError.class,
90+
null
91+
);
92+
93+
assertTrue("Expected log about unknown connection.", logListener.check(getTestTimeout()));
94+
}
95+
96+
/** Setup node closure. */
97+
private class ConfigurationClosure implements IgniteInClosure<IgniteConfiguration> {
98+
/** {@inheritDoc} */
99+
@Override public void apply(IgniteConfiguration cfg) {
100+
cfg.setClientMode(client);
101+
102+
cfg.setLocalHost("127.0.0.1");
103+
TcpDiscoverySpi disco = new TcpDiscoverySpi();
104+
disco.setIpFinder(LOCAL_IP_FINDER);
105+
106+
cfg.setDiscoverySpi(disco);
107+
}
108+
}
109+
}

modules/compatibility/src/test/java/org/apache/ignite/compatibility/testsuites/IgniteCompatibilityBasicTestSuite.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.ignite.compatibility.persistence.MoveBinaryMetadataCompatibility;
3131
import org.apache.ignite.compatibility.persistence.PersistenceBasicCompatibilityTest;
3232
import org.apache.ignite.compatibility.persistence.SnapshotCompatibilityTest;
33+
import org.apache.ignite.compatibility.spi.discovery.TcpDiscoveryDifferentClusterVersionsTest;
3334
import org.apache.ignite.compatibility.testframework.util.MavenUtilsTest;
3435
import org.junit.runner.RunWith;
3536
import org.junit.runners.Suite;
@@ -52,7 +53,8 @@
5253
JavaThinCompatibilityStoragePathTest.class,
5354
IgnitePKIndexesMigrationToUnwrapPkTest.class,
5455
CompoundIndexCompatibilityTest.class,
55-
SnapshotCompatibilityTest.class
56+
SnapshotCompatibilityTest.class,
57+
TcpDiscoveryDifferentClusterVersionsTest.class
5658
})
5759
public class IgniteCompatibilityBasicTestSuite {
5860
}

modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public abstract class IgniteUtils extends CommonUtils {
350350
indexOf('.', IgniteUtils.class.getName().indexOf('.') + 1));
351351

352352
/** Network packet header. */
353-
public static final byte[] IGNITE_HEADER = intToBytes(0x00004747);
353+
public static final byte[] IGNITE_HEADER = intToBytes(0x0049474E);
354354

355355
/** Default buffer size = 4K. */
356356
private static final int BUF_SIZE = 4096;

modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6613,14 +6613,16 @@ private class SocketReader extends IgniteSpiThread {
66136613
if (!Arrays.equals(buf, U.IGNITE_HEADER)) {
66146614
if (log.isDebugEnabled())
66156615
log.debug("Unknown connection detected (is some other software connecting to " +
6616-
"this Ignite port?" +
6616+
"this Ignite port, or is this an incompatible Ignite node?" +
66176617
(!spi.isSslEnabled() ? " missed SSL configuration?" : "" ) +
6618-
") [rmtAddr=" + rmtAddr + ", locAddr=" + sock.getLocalSocketAddress() + ']');
6618+
") [rmtAddr=" + rmtAddr +
6619+
", locAddr=" + sock.getLocalSocketAddress() +
6620+
", rcvdHdr=" + U.byteArray2HexString(buf) + ']');
66196621

66206622
LT.warn(log, "Unknown connection detected (is some other software connecting to " +
6621-
"this Ignite port?" +
6623+
"this Ignite port, or is this an incompatible Ignite node?" +
66226624
(!spi.isSslEnabled() ? " missing SSL configuration on remote node?" : "" ) +
6623-
") [rmtAddr=" + sock.getInetAddress() + ']', true);
6625+
") [rmtAddr=" + sock.getInetAddress() + ", rcvdHdr=" + U.byteArray2HexString(buf) + ']', true);
66246626

66256627
return;
66266628
}

0 commit comments

Comments
 (0)