2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2021-01-08 17:55:38 +01:00
|
|
|
* Copyright (C) 2015-2021 Lightbend Inc. <https://www.lightbend.com>
|
2015-06-07 14:49:38 +02:00
|
|
|
*/
|
2018-03-13 23:45:55 +09:00
|
|
|
|
2015-06-07 14:49:38 +02:00
|
|
|
package akka.cluster.sharding
|
|
|
|
|
|
|
|
|
|
import akka.actor.ActorSystem
|
|
|
|
|
import akka.actor.NoSerializationVerificationNeeded
|
2021-11-04 21:10:04 +13:00
|
|
|
import akka.annotation.{ ApiMayChange, InternalApi }
|
2019-03-29 14:27:08 +01:00
|
|
|
import akka.cluster.Cluster
|
2015-06-07 15:34:21 +02:00
|
|
|
import akka.cluster.singleton.ClusterSingletonManagerSettings
|
2019-03-29 14:27:08 +01:00
|
|
|
import akka.coordination.lease.LeaseUsageSettings
|
2021-12-08 13:31:01 +13:00
|
|
|
import akka.japi.Util.immutableSeq
|
2021-11-04 21:10:04 +13:00
|
|
|
import akka.util.Helpers.toRootLowerCase
|
2018-11-06 19:15:23 +01:00
|
|
|
import akka.util.JavaDurationConverters._
|
2021-11-24 01:45:41 +13:00
|
|
|
import com.typesafe.config.Config
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
import scala.collection.immutable
|
2021-11-24 01:45:41 +13:00
|
|
|
import scala.concurrent.duration._
|
2015-06-07 14:49:38 +02:00
|
|
|
|
|
|
|
|
object ClusterShardingSettings {
|
2017-01-18 16:28:24 +01:00
|
|
|
|
|
|
|
|
val StateStoreModePersistence = "persistence"
|
|
|
|
|
val StateStoreModeDData = "ddata"
|
2020-05-11 12:17:29 +02:00
|
|
|
|
|
|
|
|
/**
|
2020-06-11 15:45:00 +02:00
|
|
|
* Only for testing
|
2020-05-11 12:17:29 +02:00
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
|
|
|
|
@InternalApi
|
|
|
|
|
private[akka] val RememberEntitiesStoreCustom = "custom"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
|
|
|
|
@InternalApi
|
|
|
|
|
private[akka] val RememberEntitiesStoreDData = "ddata"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
|
|
|
|
@InternalApi
|
|
|
|
|
private[akka] val RememberEntitiesStoreEventsourced = "eventsourced"
|
2017-01-18 16:28:24 +01:00
|
|
|
|
2015-06-07 14:49:38 +02:00
|
|
|
/**
|
|
|
|
|
* Create settings from the default configuration
|
|
|
|
|
* `akka.cluster.sharding`.
|
|
|
|
|
*/
|
|
|
|
|
def apply(system: ActorSystem): ClusterShardingSettings =
|
|
|
|
|
apply(system.settings.config.getConfig("akka.cluster.sharding"))
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create settings from a configuration with the same layout as
|
|
|
|
|
* the default configuration `akka.cluster.sharding`.
|
|
|
|
|
*/
|
|
|
|
|
def apply(config: Config): ClusterShardingSettings = {
|
2020-05-20 08:34:22 +02:00
|
|
|
|
|
|
|
|
def configMajorityPlus(p: String): Int = {
|
|
|
|
|
toRootLowerCase(config.getString(p)) match {
|
|
|
|
|
case "all" => Int.MaxValue
|
|
|
|
|
case _ => config.getInt(p)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-07 14:49:38 +02:00
|
|
|
val tuningParameters = new TuningParameters(
|
|
|
|
|
coordinatorFailureBackoff = config.getDuration("coordinator-failure-backoff", MILLISECONDS).millis,
|
|
|
|
|
retryInterval = config.getDuration("retry-interval", MILLISECONDS).millis,
|
|
|
|
|
bufferSize = config.getInt("buffer-size"),
|
|
|
|
|
handOffTimeout = config.getDuration("handoff-timeout", MILLISECONDS).millis,
|
|
|
|
|
shardStartTimeout = config.getDuration("shard-start-timeout", MILLISECONDS).millis,
|
|
|
|
|
shardFailureBackoff = config.getDuration("shard-failure-backoff", MILLISECONDS).millis,
|
2015-06-09 12:25:58 +02:00
|
|
|
entityRestartBackoff = config.getDuration("entity-restart-backoff", MILLISECONDS).millis,
|
2015-06-07 14:49:38 +02:00
|
|
|
rebalanceInterval = config.getDuration("rebalance-interval", MILLISECONDS).millis,
|
2015-06-08 11:57:12 +02:00
|
|
|
snapshotAfter = config.getInt("snapshot-after"),
|
2017-02-21 16:17:19 +03:00
|
|
|
keepNrOfBatches = config.getInt("keep-nr-of-batches"),
|
2019-03-11 10:38:24 +01:00
|
|
|
leastShardAllocationRebalanceThreshold = config.getInt("least-shard-allocation-strategy.rebalance-threshold"),
|
2015-06-07 14:49:38 +02:00
|
|
|
leastShardAllocationMaxSimultaneousRebalance =
|
2015-08-20 13:24:39 +03:00
|
|
|
config.getInt("least-shard-allocation-strategy.max-simultaneous-rebalance"),
|
|
|
|
|
waitingForStateTimeout = config.getDuration("waiting-for-state-timeout", MILLISECONDS).millis,
|
2016-08-01 09:46:09 +01:00
|
|
|
updatingStateTimeout = config.getDuration("updating-state-timeout", MILLISECONDS).millis,
|
|
|
|
|
entityRecoveryStrategy = config.getString("entity-recovery-strategy"),
|
2019-03-11 10:38:24 +01:00
|
|
|
entityRecoveryConstantRateStrategyFrequency =
|
|
|
|
|
config.getDuration("entity-recovery-constant-rate-strategy.frequency", MILLISECONDS).millis,
|
|
|
|
|
entityRecoveryConstantRateStrategyNumberOfEntities =
|
2020-05-20 08:34:22 +02:00
|
|
|
config.getInt("entity-recovery-constant-rate-strategy.number-of-entities"),
|
|
|
|
|
coordinatorStateWriteMajorityPlus = configMajorityPlus("coordinator-state.write-majority-plus"),
|
2020-09-11 08:49:45 +02:00
|
|
|
coordinatorStateReadMajorityPlus = configMajorityPlus("coordinator-state.read-majority-plus"),
|
|
|
|
|
leastShardAllocationAbsoluteLimit = config.getInt("least-shard-allocation-strategy.rebalance-absolute-limit"),
|
|
|
|
|
leastShardAllocationRelativeLimit = config.getDouble("least-shard-allocation-strategy.rebalance-relative-limit"))
|
2015-06-07 14:49:38 +02:00
|
|
|
|
2015-06-07 15:34:21 +02:00
|
|
|
val coordinatorSingletonSettings = ClusterSingletonManagerSettings(config.getConfig("coordinator-singleton"))
|
|
|
|
|
|
2021-11-04 21:10:04 +13:00
|
|
|
val passivationStrategySettings = PassivationStrategySettings(config)
|
2018-11-06 19:15:23 +01:00
|
|
|
|
2019-03-28 13:24:46 +01:00
|
|
|
val lease = config.getString("use-lease") match {
|
2019-04-15 17:40:26 +02:00
|
|
|
case s if s.isEmpty => None
|
|
|
|
|
case other => Some(new LeaseUsageSettings(other, config.getDuration("lease-retry-interval").asScala))
|
2019-03-28 13:24:46 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-13 10:56:20 +01:00
|
|
|
new ClusterShardingSettings(
|
|
|
|
|
role = roleOption(config.getString("role")),
|
|
|
|
|
rememberEntities = config.getBoolean("remember-entities"),
|
|
|
|
|
journalPluginId = config.getString("journal-plugin-id"),
|
|
|
|
|
snapshotPluginId = config.getString("snapshot-plugin-id"),
|
|
|
|
|
stateStoreMode = config.getString("state-store-mode"),
|
2020-05-13 10:38:11 +01:00
|
|
|
rememberEntitiesStore = config.getString("remember-entities-store"),
|
2021-11-04 21:10:04 +13:00
|
|
|
passivationStrategySettings = passivationStrategySettings,
|
2019-07-08 08:00:08 -07:00
|
|
|
shardRegionQueryTimeout = config.getDuration("shard-region-query-timeout", MILLISECONDS).millis,
|
2019-03-13 10:56:20 +01:00
|
|
|
tuningParameters,
|
2019-03-28 13:24:46 +01:00
|
|
|
coordinatorSingletonSettings,
|
|
|
|
|
lease)
|
2015-06-07 14:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Java API: Create settings from the default configuration
|
|
|
|
|
* `akka.cluster.sharding`.
|
|
|
|
|
*/
|
|
|
|
|
def create(system: ActorSystem): ClusterShardingSettings = apply(system)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Java API: Create settings from a configuration with the same layout as
|
|
|
|
|
* the default configuration `akka.cluster.sharding`.
|
|
|
|
|
*/
|
|
|
|
|
def create(config: Config): ClusterShardingSettings = apply(config)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
|
|
|
|
private[akka] def roleOption(role: String): Option[String] =
|
|
|
|
|
if (role == "") None else Option(role)
|
|
|
|
|
|
2021-11-04 21:10:04 +13:00
|
|
|
@ApiMayChange
|
|
|
|
|
final class PassivationStrategySettings private (
|
|
|
|
|
val strategy: String,
|
2021-11-24 01:45:41 +13:00
|
|
|
val idleSettings: PassivationStrategySettings.IdleSettings,
|
|
|
|
|
val leastRecentlyUsedSettings: PassivationStrategySettings.LeastRecentlyUsedSettings,
|
|
|
|
|
val mostRecentlyUsedSettings: PassivationStrategySettings.MostRecentlyUsedSettings,
|
|
|
|
|
val leastFrequentlyUsedSettings: PassivationStrategySettings.LeastFrequentlyUsedSettings,
|
2021-11-04 21:10:04 +13:00
|
|
|
private[akka] val oldSettingUsed: Boolean) {
|
|
|
|
|
|
2021-11-19 00:09:05 +13:00
|
|
|
def this(
|
|
|
|
|
strategy: String,
|
2021-11-24 01:45:41 +13:00
|
|
|
idleSettings: PassivationStrategySettings.IdleSettings,
|
|
|
|
|
leastRecentlyUsedSettings: PassivationStrategySettings.LeastRecentlyUsedSettings,
|
|
|
|
|
mostRecentlyUsedSettings: PassivationStrategySettings.MostRecentlyUsedSettings,
|
|
|
|
|
leastFrequentlyUsedSettings: PassivationStrategySettings.LeastFrequentlyUsedSettings) =
|
2021-11-19 00:09:05 +13:00
|
|
|
this(
|
|
|
|
|
strategy,
|
2021-11-24 01:45:41 +13:00
|
|
|
idleSettings,
|
|
|
|
|
leastRecentlyUsedSettings,
|
|
|
|
|
mostRecentlyUsedSettings,
|
|
|
|
|
leastFrequentlyUsedSettings,
|
2021-11-19 00:09:05 +13:00
|
|
|
oldSettingUsed = false)
|
2021-11-04 21:10:04 +13:00
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
import PassivationStrategySettings._
|
2021-11-24 01:45:41 +13:00
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withIdleStrategy(settings: IdleSettings): PassivationStrategySettings =
|
|
|
|
|
copy(strategy = "idle", idleSettings = settings, oldSettingUsed = false)
|
|
|
|
|
|
|
|
|
|
def withLeastRecentlyUsedStrategy(settings: LeastRecentlyUsedSettings): PassivationStrategySettings =
|
|
|
|
|
copy(strategy = "least-recently-used", leastRecentlyUsedSettings = settings)
|
2021-11-04 21:10:04 +13:00
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withMostRecentlyUsedStrategy(settings: MostRecentlyUsedSettings): PassivationStrategySettings =
|
|
|
|
|
copy(strategy = "most-recently-used", mostRecentlyUsedSettings = settings)
|
|
|
|
|
|
|
|
|
|
def withLeastFrequentlyUsedStrategy(settings: LeastFrequentlyUsedSettings): PassivationStrategySettings =
|
|
|
|
|
copy(strategy = "least-frequently-used", leastFrequentlyUsedSettings = settings)
|
2021-11-19 00:09:05 +13:00
|
|
|
|
2021-11-04 21:10:04 +13:00
|
|
|
private[akka] def withOldIdleStrategy(timeout: FiniteDuration): PassivationStrategySettings =
|
2021-11-24 01:45:41 +13:00
|
|
|
copy(strategy = "idle", idleSettings = idleSettings.withTimeout(timeout), oldSettingUsed = true)
|
2021-11-04 21:10:04 +13:00
|
|
|
|
|
|
|
|
private def copy(
|
|
|
|
|
strategy: String,
|
2021-12-08 13:31:01 +13:00
|
|
|
idleSettings: IdleSettings = idleSettings,
|
|
|
|
|
leastRecentlyUsedSettings: LeastRecentlyUsedSettings = leastRecentlyUsedSettings,
|
|
|
|
|
mostRecentlyUsedSettings: MostRecentlyUsedSettings = mostRecentlyUsedSettings,
|
|
|
|
|
leastFrequentlyUsedSettings: LeastFrequentlyUsedSettings = leastFrequentlyUsedSettings,
|
2021-11-04 21:10:04 +13:00
|
|
|
oldSettingUsed: Boolean = oldSettingUsed): PassivationStrategySettings =
|
2021-11-17 21:54:02 +13:00
|
|
|
new PassivationStrategySettings(
|
|
|
|
|
strategy,
|
2021-11-24 01:45:41 +13:00
|
|
|
idleSettings,
|
|
|
|
|
leastRecentlyUsedSettings,
|
|
|
|
|
mostRecentlyUsedSettings,
|
|
|
|
|
leastFrequentlyUsedSettings,
|
2021-11-17 21:54:02 +13:00
|
|
|
oldSettingUsed)
|
2021-11-04 21:10:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object PassivationStrategySettings {
|
2021-12-08 13:31:01 +13:00
|
|
|
val defaults = new PassivationStrategySettings(
|
|
|
|
|
strategy = "idle",
|
|
|
|
|
IdleSettings.defaults,
|
|
|
|
|
LeastRecentlyUsedSettings.defaults,
|
|
|
|
|
MostRecentlyUsedSettings.defaults,
|
|
|
|
|
LeastFrequentlyUsedSettings.defaults,
|
2021-11-04 21:10:04 +13:00
|
|
|
oldSettingUsed = false)
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
val disabled: PassivationStrategySettings = defaults.copy(strategy = "none")
|
|
|
|
|
|
2021-11-24 01:45:41 +13:00
|
|
|
object IdleSettings {
|
2021-12-08 13:31:01 +13:00
|
|
|
val defaults: IdleSettings = new IdleSettings(timeout = 2.minutes, interval = None)
|
2021-11-24 01:45:41 +13:00
|
|
|
|
|
|
|
|
def apply(config: Config): IdleSettings = {
|
|
|
|
|
val timeout = config.getDuration("timeout", MILLISECONDS).millis
|
|
|
|
|
val interval =
|
|
|
|
|
if (toRootLowerCase(config.getString("interval")) == "default") None
|
|
|
|
|
else Some(config.getDuration("interval", MILLISECONDS).millis)
|
|
|
|
|
new IdleSettings(timeout, interval)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def optional(config: Config): Option[IdleSettings] = {
|
|
|
|
|
if (toRootLowerCase(config.getString("timeout")) == "off") None else Some(IdleSettings(config))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final class IdleSettings(val timeout: FiniteDuration, val interval: Option[FiniteDuration]) {
|
|
|
|
|
|
|
|
|
|
def withTimeout(timeout: FiniteDuration): IdleSettings = copy(timeout = timeout)
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withTimeout(timeout: java.time.Duration): IdleSettings = withTimeout(timeout.asScala)
|
|
|
|
|
|
2021-11-24 01:45:41 +13:00
|
|
|
def withInterval(interval: FiniteDuration): IdleSettings = copy(interval = Some(interval))
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withInterval(interval: java.time.Duration): IdleSettings = withInterval(interval.asScala)
|
|
|
|
|
|
2021-11-24 01:45:41 +13:00
|
|
|
private def copy(timeout: FiniteDuration = timeout, interval: Option[FiniteDuration] = interval): IdleSettings =
|
|
|
|
|
new IdleSettings(timeout, interval)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object LeastRecentlyUsedSettings {
|
2021-12-08 13:31:01 +13:00
|
|
|
val defaults: LeastRecentlyUsedSettings =
|
|
|
|
|
new LeastRecentlyUsedSettings(limit = 100000, segmentedSettings = None, idleSettings = None)
|
2021-11-24 01:45:41 +13:00
|
|
|
|
|
|
|
|
def apply(config: Config): LeastRecentlyUsedSettings = {
|
|
|
|
|
val limit = config.getInt("limit")
|
|
|
|
|
val idleSettings = IdleSettings.optional(config.getConfig("idle"))
|
2021-12-08 13:31:01 +13:00
|
|
|
val segmentedSettings = SegmentedSettings.optional(config.getConfig("segmented"))
|
|
|
|
|
new LeastRecentlyUsedSettings(limit, segmentedSettings, idleSettings)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object SegmentedSettings {
|
|
|
|
|
def apply(config: Config): SegmentedSettings = {
|
|
|
|
|
val levels = config.getInt("levels")
|
|
|
|
|
val proportions = immutableSeq(config.getDoubleList("proportions")).map(_.toDouble)
|
|
|
|
|
new SegmentedSettings(levels, proportions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def optional(config: Config): Option[SegmentedSettings] = {
|
|
|
|
|
toRootLowerCase(config.getString("levels")) match {
|
|
|
|
|
case "off" | "none" => None
|
|
|
|
|
case _ => Some(SegmentedSettings(config))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final class SegmentedSettings(val levels: Int, val proportions: immutable.Seq[Double]) {
|
|
|
|
|
|
|
|
|
|
def withLevels(levels: Int): SegmentedSettings = copy(levels = levels)
|
|
|
|
|
|
|
|
|
|
def withProportions(proportions: immutable.Seq[Double]): SegmentedSettings = copy(proportions = proportions)
|
|
|
|
|
|
|
|
|
|
def withProportions(proportions: java.util.List[java.lang.Double]): SegmentedSettings =
|
|
|
|
|
copy(proportions = immutableSeq(proportions).map(_.toDouble))
|
|
|
|
|
|
|
|
|
|
private def copy(levels: Int = levels, proportions: immutable.Seq[Double] = proportions): SegmentedSettings =
|
|
|
|
|
new SegmentedSettings(levels, proportions)
|
2021-11-24 01:45:41 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
final class LeastRecentlyUsedSettings(
|
|
|
|
|
val limit: Int,
|
|
|
|
|
val segmentedSettings: Option[LeastRecentlyUsedSettings.SegmentedSettings],
|
|
|
|
|
val idleSettings: Option[IdleSettings]) {
|
2021-11-24 01:45:41 +13:00
|
|
|
|
|
|
|
|
def withLimit(limit: Int): LeastRecentlyUsedSettings = copy(limit = limit)
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withSegmented(levels: Int): LeastRecentlyUsedSettings = withSegmented(levels, Nil)
|
|
|
|
|
|
|
|
|
|
def withSegmented(levels: Int, proportions: immutable.Seq[Double]): LeastRecentlyUsedSettings =
|
|
|
|
|
copy(segmentedSettings = Some(new LeastRecentlyUsedSettings.SegmentedSettings(levels, proportions)))
|
|
|
|
|
|
|
|
|
|
def withSegmentedProportions(
|
|
|
|
|
levels: Int,
|
|
|
|
|
proportions: java.util.List[java.lang.Double]): LeastRecentlyUsedSettings =
|
|
|
|
|
withSegmented(levels, immutableSeq(proportions).map(_.toDouble))
|
|
|
|
|
|
2021-11-24 01:45:41 +13:00
|
|
|
def withIdle(timeout: FiniteDuration): LeastRecentlyUsedSettings =
|
|
|
|
|
copy(idleSettings = Some(new IdleSettings(timeout, None)))
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withIdle(timeout: java.time.Duration): LeastRecentlyUsedSettings =
|
|
|
|
|
withIdle(timeout.asScala)
|
|
|
|
|
|
2021-11-24 01:45:41 +13:00
|
|
|
def withIdle(timeout: FiniteDuration, interval: FiniteDuration): LeastRecentlyUsedSettings =
|
|
|
|
|
copy(idleSettings = Some(new IdleSettings(timeout, Some(interval))))
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withIdle(timeout: java.time.Duration, interval: java.time.Duration): LeastRecentlyUsedSettings =
|
|
|
|
|
withIdle(timeout.asScala, interval.asScala)
|
|
|
|
|
|
2021-11-24 01:45:41 +13:00
|
|
|
private def copy(
|
|
|
|
|
limit: Int = limit,
|
2021-12-08 13:31:01 +13:00
|
|
|
segmentedSettings: Option[LeastRecentlyUsedSettings.SegmentedSettings] = segmentedSettings,
|
2021-11-24 01:45:41 +13:00
|
|
|
idleSettings: Option[IdleSettings] = idleSettings): LeastRecentlyUsedSettings =
|
2021-12-08 13:31:01 +13:00
|
|
|
new LeastRecentlyUsedSettings(limit, segmentedSettings, idleSettings)
|
2021-11-24 01:45:41 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object MostRecentlyUsedSettings {
|
2021-12-08 13:31:01 +13:00
|
|
|
val defaults: MostRecentlyUsedSettings = new MostRecentlyUsedSettings(limit = 100000, idleSettings = None)
|
2021-11-24 01:45:41 +13:00
|
|
|
|
|
|
|
|
def apply(config: Config): MostRecentlyUsedSettings = {
|
|
|
|
|
val limit = config.getInt("limit")
|
|
|
|
|
val idleSettings = IdleSettings.optional(config.getConfig("idle"))
|
|
|
|
|
new MostRecentlyUsedSettings(limit, idleSettings)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final class MostRecentlyUsedSettings(val limit: Int, val idleSettings: Option[IdleSettings]) {
|
|
|
|
|
|
|
|
|
|
def withLimit(limit: Int): MostRecentlyUsedSettings = copy(limit = limit)
|
|
|
|
|
|
|
|
|
|
def withIdle(timeout: FiniteDuration): MostRecentlyUsedSettings =
|
|
|
|
|
copy(idleSettings = Some(new IdleSettings(timeout, None)))
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withIdle(timeout: java.time.Duration): MostRecentlyUsedSettings =
|
|
|
|
|
withIdle(timeout.asScala)
|
|
|
|
|
|
2021-11-24 01:45:41 +13:00
|
|
|
def withIdle(timeout: FiniteDuration, interval: FiniteDuration): MostRecentlyUsedSettings =
|
|
|
|
|
copy(idleSettings = Some(new IdleSettings(timeout, Some(interval))))
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withIdle(timeout: java.time.Duration, interval: java.time.Duration): MostRecentlyUsedSettings =
|
|
|
|
|
withIdle(timeout.asScala, interval.asScala)
|
|
|
|
|
|
2021-11-24 01:45:41 +13:00
|
|
|
private def copy(
|
|
|
|
|
limit: Int = limit,
|
|
|
|
|
idleSettings: Option[IdleSettings] = idleSettings): MostRecentlyUsedSettings =
|
|
|
|
|
new MostRecentlyUsedSettings(limit, idleSettings)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object LeastFrequentlyUsedSettings {
|
2021-12-08 13:31:01 +13:00
|
|
|
val defaults: LeastFrequentlyUsedSettings =
|
|
|
|
|
new LeastFrequentlyUsedSettings(limit = 100000, dynamicAging = false, idleSettings = None)
|
2021-11-24 01:45:41 +13:00
|
|
|
|
|
|
|
|
def apply(config: Config): LeastFrequentlyUsedSettings = {
|
|
|
|
|
val limit = config.getInt("limit")
|
2021-12-08 13:31:01 +13:00
|
|
|
val dynamicAging = config.getBoolean("dynamic-aging")
|
2021-11-24 01:45:41 +13:00
|
|
|
val idleSettings = IdleSettings.optional(config.getConfig("idle"))
|
2021-12-08 13:31:01 +13:00
|
|
|
new LeastFrequentlyUsedSettings(limit, dynamicAging, idleSettings)
|
2021-11-24 01:45:41 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
final class LeastFrequentlyUsedSettings(
|
|
|
|
|
val limit: Int,
|
|
|
|
|
val dynamicAging: Boolean,
|
|
|
|
|
val idleSettings: Option[IdleSettings]) {
|
2021-11-24 01:45:41 +13:00
|
|
|
|
|
|
|
|
def withLimit(limit: Int): LeastFrequentlyUsedSettings = copy(limit = limit)
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withDynamicAging(): LeastFrequentlyUsedSettings = withDynamicAging(enabled = true)
|
|
|
|
|
|
|
|
|
|
def withDynamicAging(enabled: Boolean): LeastFrequentlyUsedSettings = copy(dynamicAging = enabled)
|
|
|
|
|
|
2021-11-24 01:45:41 +13:00
|
|
|
def withIdle(timeout: FiniteDuration): LeastFrequentlyUsedSettings =
|
|
|
|
|
copy(idleSettings = Some(new IdleSettings(timeout, None)))
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withIdle(timeout: java.time.Duration): LeastFrequentlyUsedSettings =
|
|
|
|
|
withIdle(timeout.asScala)
|
|
|
|
|
|
2021-11-24 01:45:41 +13:00
|
|
|
def withIdle(timeout: FiniteDuration, interval: FiniteDuration): LeastFrequentlyUsedSettings =
|
|
|
|
|
copy(idleSettings = Some(new IdleSettings(timeout, Some(interval))))
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withIdle(timeout: java.time.Duration, interval: java.time.Duration): LeastFrequentlyUsedSettings =
|
|
|
|
|
withIdle(timeout.asScala, interval.asScala)
|
|
|
|
|
|
2021-11-24 01:45:41 +13:00
|
|
|
private def copy(
|
|
|
|
|
limit: Int = limit,
|
2021-12-08 13:31:01 +13:00
|
|
|
dynamicAging: Boolean = dynamicAging,
|
2021-11-24 01:45:41 +13:00
|
|
|
idleSettings: Option[IdleSettings] = idleSettings): LeastFrequentlyUsedSettings =
|
2021-12-08 13:31:01 +13:00
|
|
|
new LeastFrequentlyUsedSettings(limit, dynamicAging, idleSettings)
|
2021-11-24 01:45:41 +13:00
|
|
|
}
|
|
|
|
|
|
2021-11-04 21:10:04 +13:00
|
|
|
def apply(config: Config): PassivationStrategySettings = {
|
2021-11-24 01:45:41 +13:00
|
|
|
val settings =
|
|
|
|
|
new PassivationStrategySettings(
|
|
|
|
|
strategy = toRootLowerCase(config.getString("passivation.strategy")),
|
|
|
|
|
idleSettings = IdleSettings(config.getConfig("passivation.idle")),
|
|
|
|
|
leastRecentlyUsedSettings = LeastRecentlyUsedSettings(config.getConfig("passivation.least-recently-used")),
|
|
|
|
|
mostRecentlyUsedSettings = MostRecentlyUsedSettings(config.getConfig("passivation.most-recently-used")),
|
|
|
|
|
leastFrequentlyUsedSettings = LeastFrequentlyUsedSettings(
|
|
|
|
|
config.getConfig("passivation.least-frequently-used")))
|
2021-11-04 21:10:04 +13:00
|
|
|
// default to old setting if it exists (defined in application.conf), overriding the new settings
|
|
|
|
|
if (config.hasPath("passivate-idle-entity-after")) {
|
|
|
|
|
val timeout =
|
|
|
|
|
if (toRootLowerCase(config.getString("passivate-idle-entity-after")) == "off") Duration.Zero
|
|
|
|
|
else config.getDuration("passivate-idle-entity-after", MILLISECONDS).millis
|
|
|
|
|
settings.withOldIdleStrategy(timeout)
|
|
|
|
|
} else {
|
|
|
|
|
settings
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private[akka] def oldDefault(idleTimeout: FiniteDuration): PassivationStrategySettings =
|
2021-12-08 13:31:01 +13:00
|
|
|
defaults.withOldIdleStrategy(idleTimeout)
|
2021-11-04 21:10:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
|
|
|
|
@InternalApi
|
|
|
|
|
private[akka] sealed trait PassivationStrategy
|
2021-11-24 01:45:41 +13:00
|
|
|
|
2021-11-04 21:10:04 +13:00
|
|
|
private[akka] case object NoPassivationStrategy extends PassivationStrategy
|
2021-11-24 01:45:41 +13:00
|
|
|
|
|
|
|
|
private[akka] object IdlePassivationStrategy {
|
|
|
|
|
def apply(settings: PassivationStrategySettings.IdleSettings): IdlePassivationStrategy =
|
|
|
|
|
IdlePassivationStrategy(settings.timeout, settings.interval.getOrElse(settings.timeout / 2))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private[akka] case class IdlePassivationStrategy(timeout: FiniteDuration, interval: FiniteDuration)
|
|
|
|
|
extends PassivationStrategy
|
|
|
|
|
|
|
|
|
|
private[akka] object LeastRecentlyUsedPassivationStrategy {
|
2021-12-08 13:31:01 +13:00
|
|
|
def apply(settings: PassivationStrategySettings.LeastRecentlyUsedSettings): LeastRecentlyUsedPassivationStrategy = {
|
|
|
|
|
val limit = settings.limit
|
|
|
|
|
val idle = settings.idleSettings.map(IdlePassivationStrategy.apply)
|
|
|
|
|
settings.segmentedSettings match {
|
|
|
|
|
case Some(segmented) =>
|
|
|
|
|
val proportions =
|
|
|
|
|
if (segmented.levels < 2) Nil
|
|
|
|
|
else if (segmented.proportions.isEmpty) List.fill(segmented.levels)(1.0 / segmented.levels)
|
|
|
|
|
else segmented.proportions
|
|
|
|
|
LeastRecentlyUsedPassivationStrategy(limit, proportions, idle)
|
|
|
|
|
case _ => LeastRecentlyUsedPassivationStrategy(limit, Nil, idle)
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-24 01:45:41 +13:00
|
|
|
}
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
private[akka] case class LeastRecentlyUsedPassivationStrategy(
|
|
|
|
|
limit: Int,
|
|
|
|
|
segmented: immutable.Seq[Double],
|
|
|
|
|
idle: Option[IdlePassivationStrategy])
|
2021-11-24 01:45:41 +13:00
|
|
|
extends PassivationStrategy
|
|
|
|
|
|
|
|
|
|
private[akka] object MostRecentlyUsedPassivationStrategy {
|
|
|
|
|
def apply(settings: PassivationStrategySettings.MostRecentlyUsedSettings): MostRecentlyUsedPassivationStrategy =
|
|
|
|
|
MostRecentlyUsedPassivationStrategy(settings.limit, settings.idleSettings.map(IdlePassivationStrategy.apply))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private[akka] case class MostRecentlyUsedPassivationStrategy(limit: Int, idle: Option[IdlePassivationStrategy])
|
|
|
|
|
extends PassivationStrategy
|
|
|
|
|
|
|
|
|
|
private[akka] object LeastFrequentlyUsedPassivationStrategy {
|
|
|
|
|
def apply(
|
|
|
|
|
settings: PassivationStrategySettings.LeastFrequentlyUsedSettings): LeastFrequentlyUsedPassivationStrategy =
|
2021-12-08 13:31:01 +13:00
|
|
|
LeastFrequentlyUsedPassivationStrategy(
|
|
|
|
|
settings.limit,
|
|
|
|
|
settings.dynamicAging,
|
|
|
|
|
settings.idleSettings.map(IdlePassivationStrategy.apply))
|
2021-11-24 01:45:41 +13:00
|
|
|
}
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
private[akka] case class LeastFrequentlyUsedPassivationStrategy(
|
|
|
|
|
limit: Int,
|
|
|
|
|
dynamicAging: Boolean,
|
|
|
|
|
idle: Option[IdlePassivationStrategy])
|
2021-11-24 01:45:41 +13:00
|
|
|
extends PassivationStrategy
|
2021-11-04 21:10:04 +13:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
* Determine the passivation strategy to use from settings.
|
|
|
|
|
*/
|
|
|
|
|
@InternalApi
|
|
|
|
|
private[akka] object PassivationStrategy {
|
|
|
|
|
def apply(settings: ClusterShardingSettings): PassivationStrategy = {
|
|
|
|
|
if (settings.rememberEntities) {
|
|
|
|
|
NoPassivationStrategy
|
|
|
|
|
} else
|
|
|
|
|
settings.passivationStrategySettings.strategy match {
|
2021-11-24 01:45:41 +13:00
|
|
|
case "idle" if settings.passivationStrategySettings.idleSettings.timeout > Duration.Zero =>
|
|
|
|
|
IdlePassivationStrategy(settings.passivationStrategySettings.idleSettings)
|
2021-11-04 21:10:04 +13:00
|
|
|
case "least-recently-used" =>
|
2021-11-24 01:45:41 +13:00
|
|
|
LeastRecentlyUsedPassivationStrategy(settings.passivationStrategySettings.leastRecentlyUsedSettings)
|
2021-11-17 21:54:02 +13:00
|
|
|
case "most-recently-used" =>
|
2021-11-24 01:45:41 +13:00
|
|
|
MostRecentlyUsedPassivationStrategy(settings.passivationStrategySettings.mostRecentlyUsedSettings)
|
2021-11-19 00:09:05 +13:00
|
|
|
case "least-frequently-used" =>
|
2021-11-24 01:45:41 +13:00
|
|
|
LeastFrequentlyUsedPassivationStrategy(settings.passivationStrategySettings.leastFrequentlyUsedSettings)
|
2021-11-04 21:10:04 +13:00
|
|
|
case _ => NoPassivationStrategy
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 10:56:20 +01:00
|
|
|
class TuningParameters(
|
|
|
|
|
val coordinatorFailureBackoff: FiniteDuration,
|
|
|
|
|
val retryInterval: FiniteDuration,
|
|
|
|
|
val bufferSize: Int,
|
|
|
|
|
val handOffTimeout: FiniteDuration,
|
|
|
|
|
val shardStartTimeout: FiniteDuration,
|
|
|
|
|
val shardFailureBackoff: FiniteDuration,
|
|
|
|
|
val entityRestartBackoff: FiniteDuration,
|
|
|
|
|
val rebalanceInterval: FiniteDuration,
|
|
|
|
|
val snapshotAfter: Int,
|
|
|
|
|
val keepNrOfBatches: Int,
|
|
|
|
|
val leastShardAllocationRebalanceThreshold: Int,
|
|
|
|
|
val leastShardAllocationMaxSimultaneousRebalance: Int,
|
|
|
|
|
val waitingForStateTimeout: FiniteDuration,
|
|
|
|
|
val updatingStateTimeout: FiniteDuration,
|
|
|
|
|
val entityRecoveryStrategy: String,
|
|
|
|
|
val entityRecoveryConstantRateStrategyFrequency: FiniteDuration,
|
2020-05-20 08:34:22 +02:00
|
|
|
val entityRecoveryConstantRateStrategyNumberOfEntities: Int,
|
|
|
|
|
val coordinatorStateWriteMajorityPlus: Int,
|
2020-09-11 08:49:45 +02:00
|
|
|
val coordinatorStateReadMajorityPlus: Int,
|
|
|
|
|
val leastShardAllocationAbsoluteLimit: Int,
|
|
|
|
|
val leastShardAllocationRelativeLimit: Double) {
|
2019-03-13 10:56:20 +01:00
|
|
|
|
|
|
|
|
require(
|
|
|
|
|
entityRecoveryStrategy == "all" || entityRecoveryStrategy == "constant",
|
|
|
|
|
s"Unknown 'entity-recovery-strategy' [$entityRecoveryStrategy], valid values are 'all' or 'constant'")
|
2016-08-01 09:46:09 +01:00
|
|
|
|
2020-09-11 08:49:45 +02:00
|
|
|
// included for binary compatibility
|
|
|
|
|
@deprecated(
|
|
|
|
|
"Use the ClusterShardingSettings factory methods or the constructor including " +
|
|
|
|
|
"leastShardAllocationAbsoluteLimit and leastShardAllocationRelativeLimit instead",
|
|
|
|
|
since = "2.6.10")
|
|
|
|
|
def this(
|
|
|
|
|
coordinatorFailureBackoff: FiniteDuration,
|
|
|
|
|
retryInterval: FiniteDuration,
|
|
|
|
|
bufferSize: Int,
|
|
|
|
|
handOffTimeout: FiniteDuration,
|
|
|
|
|
shardStartTimeout: FiniteDuration,
|
|
|
|
|
shardFailureBackoff: FiniteDuration,
|
|
|
|
|
entityRestartBackoff: FiniteDuration,
|
|
|
|
|
rebalanceInterval: FiniteDuration,
|
|
|
|
|
snapshotAfter: Int,
|
|
|
|
|
keepNrOfBatches: Int,
|
|
|
|
|
leastShardAllocationRebalanceThreshold: Int,
|
|
|
|
|
leastShardAllocationMaxSimultaneousRebalance: Int,
|
|
|
|
|
waitingForStateTimeout: FiniteDuration,
|
|
|
|
|
updatingStateTimeout: FiniteDuration,
|
|
|
|
|
entityRecoveryStrategy: String,
|
|
|
|
|
entityRecoveryConstantRateStrategyFrequency: FiniteDuration,
|
|
|
|
|
entityRecoveryConstantRateStrategyNumberOfEntities: Int,
|
|
|
|
|
coordinatorStateWriteMajorityPlus: Int,
|
|
|
|
|
coordinatorStateReadMajorityPlus: Int) =
|
|
|
|
|
this(
|
|
|
|
|
coordinatorFailureBackoff,
|
|
|
|
|
retryInterval,
|
|
|
|
|
bufferSize,
|
|
|
|
|
handOffTimeout,
|
|
|
|
|
shardStartTimeout,
|
|
|
|
|
shardFailureBackoff,
|
|
|
|
|
entityRestartBackoff,
|
|
|
|
|
rebalanceInterval,
|
|
|
|
|
snapshotAfter,
|
|
|
|
|
keepNrOfBatches,
|
|
|
|
|
leastShardAllocationRebalanceThreshold,
|
|
|
|
|
leastShardAllocationMaxSimultaneousRebalance,
|
|
|
|
|
waitingForStateTimeout,
|
|
|
|
|
updatingStateTimeout,
|
|
|
|
|
entityRecoveryStrategy,
|
|
|
|
|
entityRecoveryConstantRateStrategyFrequency,
|
|
|
|
|
entityRecoveryConstantRateStrategyNumberOfEntities,
|
|
|
|
|
coordinatorStateWriteMajorityPlus,
|
|
|
|
|
coordinatorStateReadMajorityPlus,
|
|
|
|
|
leastShardAllocationAbsoluteLimit = 100,
|
|
|
|
|
leastShardAllocationRelativeLimit = 0.1)
|
|
|
|
|
|
2017-02-21 16:17:19 +03:00
|
|
|
// included for binary compatibility
|
2020-05-20 08:34:22 +02:00
|
|
|
@deprecated(
|
|
|
|
|
"Use the ClusterShardingSettings factory methods or the constructor including " +
|
|
|
|
|
"coordinatorStateWriteMajorityPlus and coordinatorStateReadMajorityPlus instead",
|
|
|
|
|
since = "2.6.5")
|
|
|
|
|
def this(
|
|
|
|
|
coordinatorFailureBackoff: FiniteDuration,
|
|
|
|
|
retryInterval: FiniteDuration,
|
|
|
|
|
bufferSize: Int,
|
|
|
|
|
handOffTimeout: FiniteDuration,
|
|
|
|
|
shardStartTimeout: FiniteDuration,
|
|
|
|
|
shardFailureBackoff: FiniteDuration,
|
|
|
|
|
entityRestartBackoff: FiniteDuration,
|
|
|
|
|
rebalanceInterval: FiniteDuration,
|
|
|
|
|
snapshotAfter: Int,
|
|
|
|
|
keepNrOfBatches: Int,
|
|
|
|
|
leastShardAllocationRebalanceThreshold: Int,
|
|
|
|
|
leastShardAllocationMaxSimultaneousRebalance: Int,
|
|
|
|
|
waitingForStateTimeout: FiniteDuration,
|
|
|
|
|
updatingStateTimeout: FiniteDuration,
|
|
|
|
|
entityRecoveryStrategy: String,
|
|
|
|
|
entityRecoveryConstantRateStrategyFrequency: FiniteDuration,
|
|
|
|
|
entityRecoveryConstantRateStrategyNumberOfEntities: Int) =
|
|
|
|
|
this(
|
|
|
|
|
coordinatorFailureBackoff,
|
|
|
|
|
retryInterval,
|
|
|
|
|
bufferSize,
|
|
|
|
|
handOffTimeout,
|
|
|
|
|
shardStartTimeout,
|
|
|
|
|
shardFailureBackoff,
|
|
|
|
|
entityRestartBackoff,
|
|
|
|
|
rebalanceInterval,
|
|
|
|
|
snapshotAfter,
|
|
|
|
|
keepNrOfBatches,
|
|
|
|
|
leastShardAllocationRebalanceThreshold,
|
|
|
|
|
leastShardAllocationMaxSimultaneousRebalance,
|
|
|
|
|
waitingForStateTimeout,
|
|
|
|
|
updatingStateTimeout,
|
|
|
|
|
entityRecoveryStrategy,
|
|
|
|
|
entityRecoveryConstantRateStrategyFrequency,
|
|
|
|
|
entityRecoveryConstantRateStrategyNumberOfEntities,
|
|
|
|
|
coordinatorStateWriteMajorityPlus = 5,
|
|
|
|
|
coordinatorStateReadMajorityPlus = 5)
|
|
|
|
|
|
|
|
|
|
// included for binary compatibility
|
|
|
|
|
@deprecated("Use the ClusterShardingSettings factory methods or the full constructor instead", since = "2.6.5")
|
2019-03-13 10:56:20 +01:00
|
|
|
def this(
|
|
|
|
|
coordinatorFailureBackoff: FiniteDuration,
|
|
|
|
|
retryInterval: FiniteDuration,
|
|
|
|
|
bufferSize: Int,
|
|
|
|
|
handOffTimeout: FiniteDuration,
|
|
|
|
|
shardStartTimeout: FiniteDuration,
|
|
|
|
|
shardFailureBackoff: FiniteDuration,
|
|
|
|
|
entityRestartBackoff: FiniteDuration,
|
|
|
|
|
rebalanceInterval: FiniteDuration,
|
|
|
|
|
snapshotAfter: Int,
|
|
|
|
|
leastShardAllocationRebalanceThreshold: Int,
|
|
|
|
|
leastShardAllocationMaxSimultaneousRebalance: Int,
|
|
|
|
|
waitingForStateTimeout: FiniteDuration,
|
|
|
|
|
updatingStateTimeout: FiniteDuration,
|
|
|
|
|
entityRecoveryStrategy: String,
|
|
|
|
|
entityRecoveryConstantRateStrategyFrequency: FiniteDuration,
|
|
|
|
|
entityRecoveryConstantRateStrategyNumberOfEntities: Int) = {
|
|
|
|
|
this(
|
|
|
|
|
coordinatorFailureBackoff,
|
|
|
|
|
retryInterval,
|
|
|
|
|
bufferSize,
|
|
|
|
|
handOffTimeout,
|
|
|
|
|
shardStartTimeout,
|
|
|
|
|
shardFailureBackoff,
|
|
|
|
|
entityRestartBackoff,
|
|
|
|
|
rebalanceInterval,
|
|
|
|
|
snapshotAfter,
|
|
|
|
|
2,
|
|
|
|
|
leastShardAllocationRebalanceThreshold,
|
|
|
|
|
leastShardAllocationMaxSimultaneousRebalance,
|
|
|
|
|
waitingForStateTimeout,
|
|
|
|
|
updatingStateTimeout,
|
|
|
|
|
entityRecoveryStrategy,
|
|
|
|
|
entityRecoveryConstantRateStrategyFrequency,
|
|
|
|
|
entityRecoveryConstantRateStrategyNumberOfEntities)
|
2017-02-21 16:17:19 +03:00
|
|
|
}
|
|
|
|
|
|
2016-08-01 09:46:09 +01:00
|
|
|
// included for binary compatibility
|
2020-05-20 08:34:22 +02:00
|
|
|
@deprecated("Use the ClusterShardingSettings factory methods or the full constructor instead", since = "2.6.5")
|
2019-03-13 10:56:20 +01:00
|
|
|
def this(
|
|
|
|
|
coordinatorFailureBackoff: FiniteDuration,
|
|
|
|
|
retryInterval: FiniteDuration,
|
|
|
|
|
bufferSize: Int,
|
|
|
|
|
handOffTimeout: FiniteDuration,
|
|
|
|
|
shardStartTimeout: FiniteDuration,
|
|
|
|
|
shardFailureBackoff: FiniteDuration,
|
|
|
|
|
entityRestartBackoff: FiniteDuration,
|
|
|
|
|
rebalanceInterval: FiniteDuration,
|
|
|
|
|
snapshotAfter: Int,
|
|
|
|
|
leastShardAllocationRebalanceThreshold: Int,
|
|
|
|
|
leastShardAllocationMaxSimultaneousRebalance: Int,
|
|
|
|
|
waitingForStateTimeout: FiniteDuration,
|
|
|
|
|
updatingStateTimeout: FiniteDuration) = {
|
|
|
|
|
this(
|
|
|
|
|
coordinatorFailureBackoff,
|
|
|
|
|
retryInterval,
|
|
|
|
|
bufferSize,
|
|
|
|
|
handOffTimeout,
|
|
|
|
|
shardStartTimeout,
|
|
|
|
|
shardFailureBackoff,
|
|
|
|
|
entityRestartBackoff,
|
|
|
|
|
rebalanceInterval,
|
|
|
|
|
snapshotAfter,
|
|
|
|
|
leastShardAllocationRebalanceThreshold,
|
|
|
|
|
leastShardAllocationMaxSimultaneousRebalance,
|
|
|
|
|
waitingForStateTimeout,
|
|
|
|
|
updatingStateTimeout,
|
|
|
|
|
"all",
|
|
|
|
|
100.milliseconds,
|
|
|
|
|
5)
|
2016-08-01 09:46:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
2015-06-07 14:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-09 12:25:58 +02:00
|
|
|
* @param role specifies that this entity type requires cluster nodes with a specific role.
|
2015-06-07 14:49:38 +02:00
|
|
|
* If the role is not specified all nodes in the cluster are used.
|
2015-06-09 12:25:58 +02:00
|
|
|
* @param rememberEntities true if active entity actors shall be automatically restarted upon `Shard`
|
2015-06-07 14:49:38 +02:00
|
|
|
* restart. i.e. if the `Shard` is started on a different `ShardRegion` due to rebalance or crash.
|
2015-06-09 12:25:58 +02:00
|
|
|
* @param journalPluginId Absolute path to the journal plugin configuration entity that is to
|
2015-06-07 14:49:38 +02:00
|
|
|
* be used for the internal persistence of ClusterSharding. If not defined the default
|
2015-06-09 12:25:58 +02:00
|
|
|
* journal plugin is used. Note that this is not related to persistence used by the entity
|
2015-06-07 14:49:38 +02:00
|
|
|
* actors.
|
2015-06-09 12:25:58 +02:00
|
|
|
* @param snapshotPluginId Absolute path to the snapshot plugin configuration entity that is to
|
2015-06-07 14:49:38 +02:00
|
|
|
* be used for the internal persistence of ClusterSharding. If not defined the default
|
2015-06-09 12:25:58 +02:00
|
|
|
* snapshot plugin is used. Note that this is not related to persistence used by the entity
|
2015-06-07 14:49:38 +02:00
|
|
|
* actors.
|
2021-11-04 21:10:04 +13:00
|
|
|
* @param passivationStrategySettings settings for automatic passivation strategy, see descriptions in reference.conf
|
2015-06-07 14:49:38 +02:00
|
|
|
* @param tuningParameters additional tuning parameters, see descriptions in reference.conf
|
2019-07-08 08:00:08 -07:00
|
|
|
* @param shardRegionQueryTimeout the timeout for querying a shard region, see descriptions in reference.conf
|
2015-06-07 14:49:38 +02:00
|
|
|
*/
|
2019-03-13 10:56:20 +01:00
|
|
|
final class ClusterShardingSettings(
|
|
|
|
|
val role: Option[String],
|
|
|
|
|
val rememberEntities: Boolean,
|
|
|
|
|
val journalPluginId: String,
|
|
|
|
|
val snapshotPluginId: String,
|
|
|
|
|
val stateStoreMode: String,
|
2020-05-13 10:38:11 +01:00
|
|
|
val rememberEntitiesStore: String,
|
2021-11-04 21:10:04 +13:00
|
|
|
val passivationStrategySettings: ClusterShardingSettings.PassivationStrategySettings,
|
2019-07-08 08:00:08 -07:00
|
|
|
val shardRegionQueryTimeout: FiniteDuration,
|
2019-03-13 10:56:20 +01:00
|
|
|
val tuningParameters: ClusterShardingSettings.TuningParameters,
|
2019-03-28 13:24:46 +01:00
|
|
|
val coordinatorSingletonSettings: ClusterSingletonManagerSettings,
|
2019-03-29 14:27:08 +01:00
|
|
|
val leaseSettings: Option[LeaseUsageSettings])
|
2019-03-11 10:38:24 +01:00
|
|
|
extends NoSerializationVerificationNeeded {
|
2015-06-07 14:49:38 +02:00
|
|
|
|
2021-11-04 21:10:04 +13:00
|
|
|
@deprecated(
|
|
|
|
|
"Use the ClusterShardingSettings factory methods or the constructor including passivationStrategySettings instead",
|
|
|
|
|
"2.6.18")
|
|
|
|
|
def this(
|
|
|
|
|
role: Option[String],
|
|
|
|
|
rememberEntities: Boolean,
|
|
|
|
|
journalPluginId: String,
|
|
|
|
|
snapshotPluginId: String,
|
|
|
|
|
stateStoreMode: String,
|
|
|
|
|
rememberEntitiesStore: String,
|
|
|
|
|
passivateIdleEntityAfter: FiniteDuration,
|
|
|
|
|
shardRegionQueryTimeout: FiniteDuration,
|
|
|
|
|
tuningParameters: ClusterShardingSettings.TuningParameters,
|
|
|
|
|
coordinatorSingletonSettings: ClusterSingletonManagerSettings,
|
|
|
|
|
leaseSettings: Option[LeaseUsageSettings]) =
|
|
|
|
|
this(
|
|
|
|
|
role,
|
|
|
|
|
rememberEntities,
|
|
|
|
|
journalPluginId,
|
|
|
|
|
snapshotPluginId,
|
|
|
|
|
stateStoreMode,
|
|
|
|
|
rememberEntitiesStore,
|
|
|
|
|
ClusterShardingSettings.PassivationStrategySettings.oldDefault(passivateIdleEntityAfter),
|
|
|
|
|
shardRegionQueryTimeout,
|
|
|
|
|
tuningParameters,
|
|
|
|
|
coordinatorSingletonSettings,
|
|
|
|
|
leaseSettings)
|
|
|
|
|
|
2020-05-13 10:38:11 +01:00
|
|
|
@deprecated(
|
2020-06-11 16:04:23 +02:00
|
|
|
"Use the ClusterShardingSettings factory methods or the constructor including rememberedEntitiesStore instead",
|
|
|
|
|
"2.6.7")
|
2020-05-13 10:38:11 +01:00
|
|
|
def this(
|
|
|
|
|
role: Option[String],
|
|
|
|
|
rememberEntities: Boolean,
|
|
|
|
|
journalPluginId: String,
|
|
|
|
|
snapshotPluginId: String,
|
|
|
|
|
stateStoreMode: String,
|
|
|
|
|
passivateIdleEntityAfter: FiniteDuration,
|
|
|
|
|
shardRegionQueryTimeout: FiniteDuration,
|
|
|
|
|
tuningParameters: ClusterShardingSettings.TuningParameters,
|
|
|
|
|
coordinatorSingletonSettings: ClusterSingletonManagerSettings,
|
|
|
|
|
leaseSettings: Option[LeaseUsageSettings]) =
|
|
|
|
|
this(
|
|
|
|
|
role,
|
|
|
|
|
rememberEntities,
|
|
|
|
|
journalPluginId,
|
|
|
|
|
snapshotPluginId,
|
|
|
|
|
stateStoreMode,
|
|
|
|
|
"ddata",
|
|
|
|
|
passivateIdleEntityAfter,
|
|
|
|
|
shardRegionQueryTimeout,
|
|
|
|
|
tuningParameters,
|
|
|
|
|
coordinatorSingletonSettings,
|
|
|
|
|
leaseSettings)
|
|
|
|
|
|
2019-07-08 08:00:08 -07:00
|
|
|
// bin compat for 2.5.23
|
|
|
|
|
@deprecated(
|
|
|
|
|
"Use the ClusterShardingSettings factory methods or the constructor including shardRegionQueryTimeout instead",
|
|
|
|
|
since = "2.6.0")
|
|
|
|
|
def this(
|
|
|
|
|
role: Option[String],
|
|
|
|
|
rememberEntities: Boolean,
|
|
|
|
|
journalPluginId: String,
|
|
|
|
|
snapshotPluginId: String,
|
|
|
|
|
stateStoreMode: String,
|
|
|
|
|
passivateIdleEntityAfter: FiniteDuration,
|
|
|
|
|
tuningParameters: ClusterShardingSettings.TuningParameters,
|
|
|
|
|
coordinatorSingletonSettings: ClusterSingletonManagerSettings,
|
|
|
|
|
leaseSettings: Option[LeaseUsageSettings]) =
|
|
|
|
|
this(
|
|
|
|
|
role,
|
|
|
|
|
rememberEntities,
|
|
|
|
|
journalPluginId,
|
|
|
|
|
snapshotPluginId,
|
|
|
|
|
stateStoreMode,
|
|
|
|
|
passivateIdleEntityAfter,
|
|
|
|
|
3.seconds,
|
|
|
|
|
tuningParameters,
|
|
|
|
|
coordinatorSingletonSettings,
|
2020-05-13 10:38:11 +01:00
|
|
|
leaseSettings)
|
2019-07-08 08:00:08 -07:00
|
|
|
|
2019-03-28 13:24:46 +01:00
|
|
|
// bin compat for 2.5.21
|
2019-07-08 08:00:08 -07:00
|
|
|
@deprecated(
|
|
|
|
|
"Use the ClusterShardingSettings factory methods or the constructor including shardRegionQueryTimeout instead",
|
|
|
|
|
since = "2.5.21")
|
2019-03-28 13:24:46 +01:00
|
|
|
def this(
|
|
|
|
|
role: Option[String],
|
|
|
|
|
rememberEntities: Boolean,
|
|
|
|
|
journalPluginId: String,
|
|
|
|
|
snapshotPluginId: String,
|
|
|
|
|
stateStoreMode: String,
|
|
|
|
|
passivateIdleEntityAfter: FiniteDuration,
|
|
|
|
|
tuningParameters: ClusterShardingSettings.TuningParameters,
|
|
|
|
|
coordinatorSingletonSettings: ClusterSingletonManagerSettings) =
|
|
|
|
|
this(
|
|
|
|
|
role,
|
|
|
|
|
rememberEntities,
|
|
|
|
|
journalPluginId,
|
|
|
|
|
snapshotPluginId,
|
|
|
|
|
stateStoreMode,
|
|
|
|
|
passivateIdleEntityAfter,
|
2019-07-08 08:00:08 -07:00
|
|
|
3.seconds,
|
2019-03-28 13:24:46 +01:00
|
|
|
tuningParameters,
|
|
|
|
|
coordinatorSingletonSettings,
|
|
|
|
|
None)
|
|
|
|
|
|
2018-11-06 19:15:23 +01:00
|
|
|
// included for binary compatibility reasons
|
2019-03-11 10:38:24 +01:00
|
|
|
@deprecated(
|
|
|
|
|
"Use the ClusterShardingSettings factory methods or the constructor including passivateIdleEntityAfter instead",
|
2019-07-08 08:00:08 -07:00
|
|
|
since = "2.5.18")
|
2019-03-13 10:56:20 +01:00
|
|
|
def this(
|
|
|
|
|
role: Option[String],
|
|
|
|
|
rememberEntities: Boolean,
|
|
|
|
|
journalPluginId: String,
|
|
|
|
|
snapshotPluginId: String,
|
|
|
|
|
stateStoreMode: String,
|
|
|
|
|
tuningParameters: ClusterShardingSettings.TuningParameters,
|
|
|
|
|
coordinatorSingletonSettings: ClusterSingletonManagerSettings) =
|
|
|
|
|
this(
|
|
|
|
|
role,
|
|
|
|
|
rememberEntities,
|
|
|
|
|
journalPluginId,
|
|
|
|
|
snapshotPluginId,
|
|
|
|
|
stateStoreMode,
|
|
|
|
|
Duration.Zero,
|
|
|
|
|
tuningParameters,
|
|
|
|
|
coordinatorSingletonSettings)
|
2019-03-11 10:38:24 +01:00
|
|
|
|
2020-05-11 12:17:29 +02:00
|
|
|
import ClusterShardingSettings.{ RememberEntitiesStoreCustom, StateStoreModeDData, StateStoreModePersistence }
|
2019-03-13 10:56:20 +01:00
|
|
|
require(
|
2020-05-11 12:17:29 +02:00
|
|
|
stateStoreMode == StateStoreModePersistence || stateStoreMode == StateStoreModeDData || stateStoreMode == RememberEntitiesStoreCustom,
|
2019-03-13 10:56:20 +01:00
|
|
|
s"Unknown 'state-store-mode' [$stateStoreMode], valid values are '$StateStoreModeDData' or '$StateStoreModePersistence'")
|
2015-08-21 09:53:53 +02:00
|
|
|
|
2018-03-07 05:17:56 +01:00
|
|
|
/** 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)
|
|
|
|
|
|
2019-09-19 04:23:27 -07:00
|
|
|
@InternalApi
|
2021-11-04 21:10:04 +13:00
|
|
|
private[akka] val passivationStrategy: ClusterShardingSettings.PassivationStrategy =
|
|
|
|
|
ClusterShardingSettings.PassivationStrategy(this)
|
2019-09-19 04:23:27 -07:00
|
|
|
|
2015-06-07 14:49:38 +02:00
|
|
|
def withRole(role: String): ClusterShardingSettings = copy(role = ClusterShardingSettings.roleOption(role))
|
|
|
|
|
|
|
|
|
|
def withRole(role: Option[String]): ClusterShardingSettings = copy(role = role)
|
|
|
|
|
|
2015-06-09 12:25:58 +02:00
|
|
|
def withRememberEntities(rememberEntities: Boolean): ClusterShardingSettings =
|
|
|
|
|
copy(rememberEntities = rememberEntities)
|
2015-06-07 14:49:38 +02:00
|
|
|
|
|
|
|
|
def withJournalPluginId(journalPluginId: String): ClusterShardingSettings =
|
|
|
|
|
copy(journalPluginId = journalPluginId)
|
|
|
|
|
|
|
|
|
|
def withSnapshotPluginId(snapshotPluginId: String): ClusterShardingSettings =
|
|
|
|
|
copy(snapshotPluginId = snapshotPluginId)
|
|
|
|
|
|
|
|
|
|
def withTuningParameters(tuningParameters: ClusterShardingSettings.TuningParameters): ClusterShardingSettings =
|
|
|
|
|
copy(tuningParameters = tuningParameters)
|
|
|
|
|
|
2016-04-18 11:37:56 +02:00
|
|
|
def withStateStoreMode(stateStoreMode: String): ClusterShardingSettings =
|
|
|
|
|
copy(stateStoreMode = stateStoreMode)
|
|
|
|
|
|
2021-11-04 21:10:04 +13:00
|
|
|
@deprecated("See passivationStrategySettings.idleTimeout instead", since = "2.6.18")
|
2021-11-24 01:45:41 +13:00
|
|
|
def passivateIdleEntityAfter: FiniteDuration = passivationStrategySettings.idleSettings.timeout
|
2021-11-04 21:10:04 +13:00
|
|
|
|
|
|
|
|
@deprecated("Use withIdlePassivationStrategy instead", since = "2.6.18")
|
2018-11-06 19:15:23 +01:00
|
|
|
def withPassivateIdleAfter(duration: FiniteDuration): ClusterShardingSettings =
|
2021-11-04 21:10:04 +13:00
|
|
|
copy(passivationStrategySettings = passivationStrategySettings.withOldIdleStrategy(duration))
|
2018-11-06 19:15:23 +01:00
|
|
|
|
2021-11-04 21:10:04 +13:00
|
|
|
@deprecated("Use withIdlePassivationStrategy instead", since = "2.6.18")
|
2018-11-06 19:15:23 +01:00
|
|
|
def withPassivateIdleAfter(duration: java.time.Duration): ClusterShardingSettings =
|
2021-11-04 21:10:04 +13:00
|
|
|
copy(passivationStrategySettings = passivationStrategySettings.withOldIdleStrategy(duration.asScala))
|
|
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withPassivationStrategy(settings: ClusterShardingSettings.PassivationStrategySettings): ClusterShardingSettings =
|
|
|
|
|
copy(passivationStrategySettings = settings)
|
2021-11-04 21:10:04 +13:00
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withNoPassivationStrategy(): ClusterShardingSettings =
|
|
|
|
|
copy(passivationStrategySettings = ClusterShardingSettings.PassivationStrategySettings.disabled)
|
2021-11-24 01:45:41 +13:00
|
|
|
|
2021-12-08 13:31:01 +13:00
|
|
|
def withIdlePassivationStrategy(
|
|
|
|
|
settings: ClusterShardingSettings.PassivationStrategySettings.IdleSettings): ClusterShardingSettings =
|
|
|
|
|
copy(passivationStrategySettings = passivationStrategySettings.withIdleStrategy(settings))
|
2021-11-24 01:45:41 +13:00
|
|
|
|
|
|
|
|
def withLeastRecentlyUsedPassivationStrategy(
|
2021-12-08 13:31:01 +13:00
|
|
|
settings: ClusterShardingSettings.PassivationStrategySettings.LeastRecentlyUsedSettings)
|
|
|
|
|
: ClusterShardingSettings =
|
|
|
|
|
copy(passivationStrategySettings = passivationStrategySettings.withLeastRecentlyUsedStrategy(settings))
|
2021-11-24 01:45:41 +13:00
|
|
|
|
|
|
|
|
def withMostRecentlyUsedPassivationStrategy(
|
2021-12-08 13:31:01 +13:00
|
|
|
settings: ClusterShardingSettings.PassivationStrategySettings.MostRecentlyUsedSettings): ClusterShardingSettings =
|
|
|
|
|
copy(passivationStrategySettings = passivationStrategySettings.withMostRecentlyUsedStrategy(settings))
|
2021-11-24 01:45:41 +13:00
|
|
|
|
|
|
|
|
def withLeastFrequentlyUsedPassivationStrategy(
|
2021-12-08 13:31:01 +13:00
|
|
|
settings: ClusterShardingSettings.PassivationStrategySettings.LeastFrequentlyUsedSettings)
|
|
|
|
|
: ClusterShardingSettings =
|
|
|
|
|
copy(passivationStrategySettings = passivationStrategySettings.withLeastFrequentlyUsedStrategy(settings))
|
2021-11-24 01:45:41 +13:00
|
|
|
|
2019-07-08 08:00:08 -07:00
|
|
|
def withShardRegionQueryTimeout(duration: FiniteDuration): ClusterShardingSettings =
|
|
|
|
|
copy(shardRegionQueryTimeout = duration)
|
|
|
|
|
|
|
|
|
|
def withShardRegionQueryTimeout(duration: java.time.Duration): ClusterShardingSettings =
|
|
|
|
|
copy(shardRegionQueryTimeout = duration.asScala)
|
|
|
|
|
|
2019-03-29 14:27:08 +01:00
|
|
|
def withLeaseSettings(leaseSettings: LeaseUsageSettings): ClusterShardingSettings =
|
2019-03-28 13:24:46 +01:00
|
|
|
copy(leaseSettings = Some(leaseSettings))
|
|
|
|
|
|
2015-12-18 11:15:06 +01:00
|
|
|
/**
|
|
|
|
|
* The `role` of the `ClusterSingletonManagerSettings` is not used. The `role` of the
|
|
|
|
|
* coordinator singleton will be the same as the `role` of `ClusterShardingSettings`.
|
|
|
|
|
*/
|
2019-03-11 10:38:24 +01:00
|
|
|
def withCoordinatorSingletonSettings(
|
|
|
|
|
coordinatorSingletonSettings: ClusterSingletonManagerSettings): ClusterShardingSettings =
|
2015-06-07 15:34:21 +02:00
|
|
|
copy(coordinatorSingletonSettings = coordinatorSingletonSettings)
|
|
|
|
|
|
2019-03-13 10:56:20 +01:00
|
|
|
private def copy(
|
|
|
|
|
role: Option[String] = role,
|
|
|
|
|
rememberEntities: Boolean = rememberEntities,
|
|
|
|
|
journalPluginId: String = journalPluginId,
|
|
|
|
|
snapshotPluginId: String = snapshotPluginId,
|
|
|
|
|
stateStoreMode: String = stateStoreMode,
|
2021-11-04 21:10:04 +13:00
|
|
|
passivationStrategySettings: ClusterShardingSettings.PassivationStrategySettings = passivationStrategySettings,
|
2019-07-08 08:00:08 -07:00
|
|
|
shardRegionQueryTimeout: FiniteDuration = shardRegionQueryTimeout,
|
2019-03-13 10:56:20 +01:00
|
|
|
tuningParameters: ClusterShardingSettings.TuningParameters = tuningParameters,
|
2019-03-28 13:24:46 +01:00
|
|
|
coordinatorSingletonSettings: ClusterSingletonManagerSettings = coordinatorSingletonSettings,
|
2019-03-29 14:27:08 +01:00
|
|
|
leaseSettings: Option[LeaseUsageSettings] = leaseSettings): ClusterShardingSettings =
|
2019-03-13 10:56:20 +01:00
|
|
|
new ClusterShardingSettings(
|
|
|
|
|
role,
|
|
|
|
|
rememberEntities,
|
|
|
|
|
journalPluginId,
|
|
|
|
|
snapshotPluginId,
|
|
|
|
|
stateStoreMode,
|
2020-05-13 10:38:11 +01:00
|
|
|
rememberEntitiesStore,
|
2021-11-04 21:10:04 +13:00
|
|
|
passivationStrategySettings,
|
2019-07-08 08:00:08 -07:00
|
|
|
shardRegionQueryTimeout,
|
2019-03-13 10:56:20 +01:00
|
|
|
tuningParameters,
|
2019-03-28 13:24:46 +01:00
|
|
|
coordinatorSingletonSettings,
|
|
|
|
|
leaseSettings)
|
2015-06-07 14:49:38 +02:00
|
|
|
}
|