ClusterSharding: automatically choose start or startProxy by a node role (#23934) (#24669)

This commit is contained in:
Patrik Nordwall 2018-03-07 05:17:56 +01:00 committed by Konrad `ktoso` Malawski
parent d55990fa64
commit a13f5cab00
7 changed files with 114 additions and 38 deletions

View file

@ -7,7 +7,9 @@ import scala.concurrent.duration._
import scala.concurrent.duration.FiniteDuration
import akka.actor.ActorSystem
import akka.actor.NoSerializationVerificationNeeded
import akka.annotation.InternalApi
import com.typesafe.config.Config
import akka.cluster.Cluster
import akka.cluster.singleton.ClusterSingletonManagerSettings
object ClusterShardingSettings {
@ -204,6 +206,11 @@ final class ClusterShardingSettings(
stateStoreMode == StateStoreModePersistence || stateStoreMode == StateStoreModeDData,
s"Unknown 'state-store-mode' [$stateStoreMode], valid values are '$StateStoreModeDData' or '$StateStoreModePersistence'")
/** If true, this node should run the shard region, otherwise just a shard proxy should started on this node. */
@InternalApi
private[akka] def shouldHostShard(cluster: Cluster): Boolean =
role.forall(cluster.selfMember.roles.contains)
def withRole(role: String): ClusterShardingSettings = copy(role = ClusterShardingSettings.roleOption(role))
def withRole(role: Option[String]): ClusterShardingSettings = copy(role = role)