2017-07-04 09:09:40 +01:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
|
|
|
|
*/
|
|
|
|
|
package akka.cluster
|
|
|
|
|
|
|
|
|
|
import akka.remote.testkit.{ MultiNodeConfig, MultiNodeSpec }
|
|
|
|
|
import akka.remote.transport.ThrottlerTransportAdapter.Direction
|
|
|
|
|
import com.typesafe.config.ConfigFactory
|
|
|
|
|
|
|
|
|
|
import scala.concurrent.duration._
|
|
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
object MultiDcSplitBrainMultiJvmSpec extends MultiNodeConfig {
|
2017-07-04 09:09:40 +01:00
|
|
|
val first = role("first")
|
|
|
|
|
val second = role("second")
|
|
|
|
|
val third = role("third")
|
|
|
|
|
val fourth = role("fourth")
|
|
|
|
|
|
|
|
|
|
commonConfig(MultiNodeClusterSpec.clusterConfig)
|
|
|
|
|
|
|
|
|
|
nodeConfig(first, second)(ConfigFactory.parseString(
|
|
|
|
|
"""
|
2017-07-04 17:11:21 +02:00
|
|
|
akka.cluster.data-center = "dc1"
|
2017-07-04 09:09:40 +01:00
|
|
|
akka.loglevel = INFO
|
|
|
|
|
"""))
|
|
|
|
|
|
|
|
|
|
nodeConfig(third, fourth)(ConfigFactory.parseString(
|
|
|
|
|
"""
|
2017-07-04 17:11:21 +02:00
|
|
|
akka.cluster.data-center = "dc2"
|
2017-07-04 09:09:40 +01:00
|
|
|
akka.loglevel = INFO
|
|
|
|
|
"""))
|
|
|
|
|
|
|
|
|
|
testTransport(on = true)
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
class MultiDcSplitBrainMultiJvmNode1 extends MultiDcSpec
|
|
|
|
|
class MultiDcSplitBrainMultiJvmNode2 extends MultiDcSpec
|
|
|
|
|
class MultiDcSplitBrainMultiJvmNode3 extends MultiDcSpec
|
|
|
|
|
class MultiDcSplitBrainMultiJvmNode4 extends MultiDcSpec
|
|
|
|
|
class MultiDcSplitBrainMultiJvmNode5 extends MultiDcSpec
|
2017-07-04 09:09:40 +01:00
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
abstract class MultiDcSplitBrainSpec
|
|
|
|
|
extends MultiNodeSpec(MultiDcSplitBrainMultiJvmSpec)
|
2017-07-04 09:09:40 +01:00
|
|
|
with MultiNodeClusterSpec {
|
|
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
import MultiDcSplitBrainMultiJvmSpec._
|
2017-07-04 09:09:40 +01:00
|
|
|
|
|
|
|
|
val dc1 = List(first, second)
|
|
|
|
|
val dc2 = List(third, fourth)
|
|
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
def splitDataCenters(): Unit = {
|
2017-07-04 09:09:40 +01:00
|
|
|
runOn(first) {
|
|
|
|
|
for {
|
|
|
|
|
dc1Node ← dc1
|
|
|
|
|
dc2Node ← dc2
|
|
|
|
|
} {
|
|
|
|
|
testConductor.blackhole(dc1Node, dc2Node, Direction.Both).await
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runOn(dc1: _*) {
|
|
|
|
|
awaitAssert(clusterView.unreachableMembers.map(_.address) should ===(dc2.map(address)))
|
|
|
|
|
}
|
|
|
|
|
runOn(dc2: _*) {
|
|
|
|
|
awaitAssert(clusterView.unreachableMembers.map(_.address) should ===(dc1.map(address)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
def unsplitDataCenters(): Unit = {
|
2017-07-04 09:09:40 +01:00
|
|
|
runOn(first) {
|
|
|
|
|
for {
|
|
|
|
|
dc1Node ← dc1
|
|
|
|
|
dc2Node ← dc2
|
|
|
|
|
} {
|
|
|
|
|
testConductor.passThrough(dc1Node, dc2Node, Direction.Both).await
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
awaitAllReachable()
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
"A cluster with multiple data centers" must {
|
|
|
|
|
"be able to form two data centers" in {
|
2017-07-04 09:09:40 +01:00
|
|
|
awaitClusterUp(first, second, third)
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
"be able to have a data center member join while there is inter data center split" in within(20.seconds) {
|
|
|
|
|
// introduce a split between data centers
|
|
|
|
|
splitDataCenters()
|
|
|
|
|
enterBarrier("data-center-split-1")
|
2017-07-04 09:09:40 +01:00
|
|
|
|
|
|
|
|
runOn(fourth) {
|
|
|
|
|
cluster.join(third)
|
|
|
|
|
}
|
2017-07-04 17:11:21 +02:00
|
|
|
enterBarrier("inter-data-center unreachability")
|
2017-07-04 09:09:40 +01:00
|
|
|
|
|
|
|
|
// should be able to join and become up since the
|
|
|
|
|
// split is between dc1 and dc2
|
|
|
|
|
runOn(third, fourth) {
|
|
|
|
|
awaitAssert(clusterView.members.collect {
|
2017-07-04 17:11:21 +02:00
|
|
|
case m if m.dataCenter == "dc2" && m.status == MemberStatus.Up ⇒ m.address
|
2017-07-04 09:09:40 +01:00
|
|
|
}) should ===(Set(address(third), address(fourth)))
|
|
|
|
|
}
|
|
|
|
|
enterBarrier("dc2-join-completed")
|
|
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
unsplitDataCenters()
|
|
|
|
|
enterBarrier("data-center-unsplit-1")
|
2017-07-04 09:09:40 +01:00
|
|
|
|
|
|
|
|
runOn(dc1: _*) {
|
|
|
|
|
awaitAssert(clusterView.members.collect {
|
2017-07-04 17:11:21 +02:00
|
|
|
case m if m.dataCenter == "dc2" && m.status == MemberStatus.Up ⇒ m.address
|
2017-07-04 09:09:40 +01:00
|
|
|
}) should ===(Set(address(third), address(fourth)))
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
enterBarrier("inter-data-center-split-1-done")
|
2017-07-04 09:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
"be able to have data center member leave while there is inter data center split" in within(20.seconds) {
|
|
|
|
|
splitDataCenters()
|
|
|
|
|
enterBarrier("data-center-split-2")
|
2017-07-04 09:09:40 +01:00
|
|
|
|
|
|
|
|
runOn(fourth) {
|
|
|
|
|
cluster.leave(third)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runOn(third, fourth) {
|
|
|
|
|
awaitAssert(clusterView.members.filter(_.address == address(fourth)) should ===(Set.empty))
|
|
|
|
|
}
|
|
|
|
|
enterBarrier("node-4-left")
|
|
|
|
|
|
2017-07-04 17:11:21 +02:00
|
|
|
unsplitDataCenters()
|
|
|
|
|
enterBarrier("data-center-unsplit-2")
|
2017-07-04 09:09:40 +01:00
|
|
|
|
|
|
|
|
runOn(first, second) {
|
|
|
|
|
awaitAssert(clusterView.members.filter(_.address == address(fourth)) should ===(Set.empty))
|
|
|
|
|
}
|
2017-07-04 17:11:21 +02:00
|
|
|
enterBarrier("inter-data-center-split-2-done")
|
2017-07-04 09:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|