Merge pull request #18490 from akka/wip-16948-singleton-retries-patriknw

=clt #16948 Use min retries for singleton leaving scenario
This commit is contained in:
Patrik Nordwall 2015-09-17 10:39:19 +02:00
commit a45f31cecb
3 changed files with 20 additions and 2 deletions

View file

@ -141,6 +141,11 @@ akka.cluster.singleton {
# the previous oldest confirms that the hand over has started or the previous
# oldest member is removed from the cluster (+ akka.cluster.down-removal-margin).
hand-over-retry-interval = 1s
# The number of retries are derived from hand-over-retry-interval and
# akka.cluster.down-removal-margin (or ClusterSingletonManagerSettings.removalMargin),
# but it will never be less than this property.
min-number-of-hand-over-retries = 10
}
# //#singleton-config

View file

@ -387,7 +387,13 @@ class ClusterSingletonManager(
val (maxHandOverRetries, maxTakeOverRetries) = {
val n = (removalMargin.toMillis / handOverRetryInterval.toMillis).toInt
(n + 3, math.max(1, n - 3))
val minRetries = context.system.settings.config.getInt(
"akka.cluster.singleton.min-number-of-hand-over-retries")
require(minRetries >= 1, "min-number-of-hand-over-retries must be >= 1")
val handOverRetries = math.max(minRetries, n + 3)
val takeOverRetries = math.max(1, handOverRetries - 3)
(handOverRetries, takeOverRetries)
}
// started when when self member is Up

View file

@ -115,15 +115,21 @@ object ClusterSingletonManagerSpec extends MultiNodeConfig {
/**
* The Singleton actor
*/
class Consumer(queue: ActorRef, delegateTo: ActorRef) extends Actor {
class Consumer(queue: ActorRef, delegateTo: ActorRef) extends Actor with ActorLogging {
import Consumer._
import PointToPointChannel._
var current = 0
var stoppedBeforeUnregistration = true
override def preStart(): Unit = queue ! RegisterConsumer
override def postStop(): Unit = {
if (stoppedBeforeUnregistration)
log.warning("Stopped before unregistration")
}
def receive = {
case n: Int if n <= current
context.stop(self)
@ -138,6 +144,7 @@ object ClusterSingletonManagerSpec extends MultiNodeConfig {
case End
queue ! UnregisterConsumer
case UnregistrationOk
stoppedBeforeUnregistration = false
context stop self
case Ping
sender() ! Pong