Skip to content

Commit e4fa6f5

Browse files
sadekmunawarSadek Munawar
andauthored
Allow cluster formation with mixed protocols (#1567)
Co-authored-by: Sadek Munawar <[email protected]>
1 parent e004814 commit e4fa6f5

File tree

2 files changed

+100
-6
lines changed

2 files changed

+100
-6
lines changed

cluster/src/main/scala/org/apache/pekko/cluster/ClusterDaemon.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ private[cluster] class ClusterCoreDaemon(publisher: ActorRef, joinConfigCompatCh
365365
val statsEnabled = PublishStatsInterval.isFinite
366366
var gossipStats = GossipStats()
367367

368+
val acceptedProtocols = context.system.settings.config.getStringList("pekko.remote.accept-protocol-names")
369+
368370
var seedNodes = SeedNodes
369371
var seedNodeProcess: Option[ActorRef] = None
370372
var seedNodeProcessCounter = 0 // for unique names
@@ -701,10 +703,10 @@ private[cluster] class ClusterCoreDaemon(publisher: ActorRef, joinConfigCompatCh
701703
* which will reply with a `Welcome` message.
702704
*/
703705
def join(address: Address): Unit = {
704-
if (address.protocol != selfAddress.protocol)
706+
if (!acceptedProtocols.contains(address.protocol))
705707
logWarning(
706-
"Trying to join member with wrong protocol, but was ignored, expected [{}] but was [{}]",
707-
selfAddress.protocol,
708+
"Trying to join member with wrong protocol, but was ignored, expected any of {} but was [{}]",
709+
acceptedProtocols,
708710
address.protocol)
709711
else if (address.system != selfAddress.system)
710712
logWarning(
@@ -750,10 +752,10 @@ private[cluster] class ClusterCoreDaemon(publisher: ActorRef, joinConfigCompatCh
750752
def joining(joiningNode: UniqueAddress, roles: Set[String], appVersion: Version): Unit = {
751753
if (!preparingForShutdown) {
752754
val selfStatus = latestGossip.member(selfUniqueAddress).status
753-
if (joiningNode.address.protocol != selfAddress.protocol)
755+
if (!acceptedProtocols.contains(joiningNode.address.protocol))
754756
logWarning(
755-
"Member with wrong protocol tried to join, but was ignored, expected [{}] but was [{}]",
756-
selfAddress.protocol,
757+
"Member with wrong protocol tried to join, but was ignored, expected any of {} but was [{}]",
758+
acceptedProtocols,
757759
joiningNode.address.protocol)
758760
else if (joiningNode.address.system != selfAddress.system)
759761
logWarning(
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.pekko.cluster
19+
20+
import com.typesafe.config.{ Config, ConfigFactory }
21+
22+
import org.apache.pekko.testkit.{ LongRunningTest, PekkoSpec }
23+
24+
object MixedProtocolClusterSpec {
25+
26+
val baseConfig: Config =
27+
ConfigFactory.parseString("""
28+
pekko.actor.provider = "cluster"
29+
pekko.coordinated-shutdown.terminate-actor-system = on
30+
31+
pekko.remote.classic.netty.tcp.port = 0
32+
pekko.remote.artery.canonical.port = 0
33+
pekko.remote.artery.advanced.aeron.idle-cpu-level = 3
34+
pekko.remote.accept-protocol-names = ["pekko", "akka"]
35+
36+
pekko.cluster.jmx.multi-mbeans-in-same-jvm = on
37+
pekko.cluster.configuration-compatibility-check.enforce-on-join = off
38+
""")
39+
40+
val configWithPekko: Config =
41+
ConfigFactory.parseString("""
42+
pekko.remote.protocol-name = "pekko"
43+
""").withFallback(baseConfig)
44+
45+
val configWithAkka: Config =
46+
ConfigFactory.parseString("""
47+
pekko.remote.protocol-name = "akka"
48+
""").withFallback(baseConfig)
49+
}
50+
51+
class MixedProtocolClusterSpec extends PekkoSpec with ClusterTestKit {
52+
53+
import MixedProtocolClusterSpec._
54+
55+
"A node using the akka protocol" must {
56+
57+
"be allowed to join a cluster with a node using the pekko protocol" taggedAs LongRunningTest in {
58+
59+
val clusterTestUtil = new ClusterTestUtil(system.name)
60+
// start the first node with the "pekko" protocol
61+
clusterTestUtil.newActorSystem(configWithPekko)
62+
63+
// have a node using the "akka" protocol join
64+
val joiningNode = clusterTestUtil.newActorSystem(configWithAkka)
65+
clusterTestUtil.formCluster()
66+
67+
try {
68+
awaitCond(clusterTestUtil.isMemberUp(joiningNode), message = "awaiting joining node to be 'Up'")
69+
} finally {
70+
clusterTestUtil.shutdownAll()
71+
}
72+
}
73+
74+
"allow a node using the pekko protocol to join the cluster" taggedAs LongRunningTest in {
75+
76+
val clusterTestUtil = new ClusterTestUtil(system.name)
77+
78+
// create the first node with the "akka" protocol
79+
clusterTestUtil.newActorSystem(configWithAkka)
80+
81+
// have a node using the "pekko" protocol join
82+
val joiningNode = clusterTestUtil.newActorSystem(configWithPekko)
83+
clusterTestUtil.formCluster()
84+
85+
try {
86+
awaitCond(clusterTestUtil.isMemberUp(joiningNode), message = "awaiting joining node to be 'Up'")
87+
} finally {
88+
clusterTestUtil.shutdownAll()
89+
}
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)