=cls #17846 Use CRDTs instead of PersistentActor to remember the state of the ShardCoordinator #17871
This commit is contained in:
parent
d2f08a3456
commit
6814d08ef1
14 changed files with 654 additions and 360 deletions
|
|
@ -98,7 +98,7 @@ private[akka] class Shard(
|
|||
extractShardId: ShardRegion.ExtractShardId,
|
||||
handOffStopMessage: Any) extends Actor with ActorLogging {
|
||||
|
||||
import ShardRegion.{ handOffStopperProps, EntityId, Msg, Passivate }
|
||||
import ShardRegion.{ handOffStopperProps, EntityId, Msg, Passivate, ShardInitialized }
|
||||
import ShardCoordinator.Internal.{ HandOff, ShardStopped }
|
||||
import Shard.{ State, RestartEntity, EntityStopped, EntityStarted }
|
||||
import akka.cluster.sharding.ShardCoordinator.Internal.CoordinatorMessage
|
||||
|
|
@ -113,6 +113,10 @@ private[akka] class Shard(
|
|||
|
||||
var handOffStopper: Option[ActorRef] = None
|
||||
|
||||
initialized()
|
||||
|
||||
def initialized(): Unit = context.parent ! ShardInitialized(shardId)
|
||||
|
||||
def totalBufferSize = messageBuffers.foldLeft(0) { (sum, entity) ⇒ sum + entity._2.size }
|
||||
|
||||
def processChange[A](event: A)(handler: A ⇒ Unit): Unit =
|
||||
|
|
@ -297,6 +301,9 @@ private[akka] class PersistentShard(
|
|||
|
||||
var persistCount = 0
|
||||
|
||||
// would be initialized after recovery completed
|
||||
override def initialized(): Unit = {}
|
||||
|
||||
override def receive = receiveCommand
|
||||
|
||||
override def processChange[A](event: A)(handler: A ⇒ Unit): Unit = {
|
||||
|
|
@ -316,7 +323,10 @@ private[akka] class PersistentShard(
|
|||
case EntityStarted(id) ⇒ state = state.copy(state.entities + id)
|
||||
case EntityStopped(id) ⇒ state = state.copy(state.entities - id)
|
||||
case SnapshotOffer(_, snapshot: State) ⇒ state = snapshot
|
||||
case RecoveryCompleted ⇒ state.entities foreach getEntity
|
||||
case RecoveryCompleted ⇒
|
||||
state.entities foreach getEntity
|
||||
super.initialized()
|
||||
log.debug("Shard recovery completed {}", shardId)
|
||||
}
|
||||
|
||||
override def entityTerminated(ref: ActorRef): Unit = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue