Replicated Sharding improvements (#29483)
* WIP * Finishing touches to sharding updates * Review feedback
This commit is contained in:
parent
779e827495
commit
849018b81e
38 changed files with 615 additions and 266 deletions
|
|
@ -298,27 +298,50 @@ When comparing two version vectors `v1` and `v2`:
|
|||
|
||||
## Sharded Replicated Event Sourced entities
|
||||
|
||||
To simplify what probably are the most common use cases for how you will want to distribute the replicated actors there is a minimal API for running multiple instances of @ref[Akka Cluster Sharding](cluster-sharding.md),
|
||||
each instance holding the entities for a single replica.
|
||||
There are three ways to integrate replicated event sourced entities with sharding:
|
||||
|
||||
The distribution of the replicas can be controlled either through cluster roles or using the @ref[multi datacenter](cluster-dc.md) support in Akka Cluster.
|
||||
* Ensure that each replica has a unique entity id by using the replica id as part of the entity id
|
||||
* Use @ref[multi datacenter](cluster-dc.md) to run a full copy of sharding per replica
|
||||
* Use roles to run a full copy of sharding per replica
|
||||
|
||||
The API consists of bootstrapping logic for starting the sharding instances through @apidoc[ReplicatedShardingExtension] available from the
|
||||
|
||||
To simplify all three cases the @apidoc[ReplicatedShardingExtension] is available from the
|
||||
`akka-cluster-sharding-typed` module.
|
||||
|
||||
Scala
|
||||
: @@snip [ReplicatedShardingSpec.scala](/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ReplicatedShardingSpec.scala) { #bootstrap }
|
||||
: @@snip [ReplicatedShardingSpec.scala](/akka-cluster-sharding-typed/src/test/scala/docs/akka/cluster/sharding/typed/ReplicatedShardingCompileOnlySpec.scala) { #bootstrap }
|
||||
|
||||
Java
|
||||
: @@snip [ReplicatedShardingTest.java](/akka-cluster-sharding-typed/src/test/java/akka/cluster/sharding/typed/ReplicatedShardingTest.java) { #bootstrap }
|
||||
: @@snip [ReplicatedShardingTest.java](/akka-cluster-sharding-typed/src/test/java/jdocs/akka/cluster/sharding/typed/ReplicatedShardingCompileOnlySpec.java) { #bootstrap }
|
||||
|
||||
This will run a single instance of sharding and the replicas will be differentiated by having the replica id in the sharding entity id.
|
||||
Replicas could be on the same node if they end up in the same shard or if the shards get allocated to the same node.
|
||||
|
||||
To prevent this roles can be used. You could for instance add a cluster role per availability zone / rack and have a replica per rack.
|
||||
|
||||
Scala
|
||||
: @@snip [ReplicatedShardingSpec.scala](/akka-cluster-sharding-typed/src/test/scala/docs/akka/cluster/sharding/typed/ReplicatedShardingCompileOnlySpec.scala) { #bootstrap-role }
|
||||
|
||||
Java
|
||||
: @@snip [ReplicatedShardingTest.java](/akka-cluster-sharding-typed/src/test/java/jdocs/akka/cluster/sharding/typed/ReplicatedShardingCompileOnlySpec.java) { #bootstrap-role }
|
||||
|
||||
Lastly if your Akka Cluster is setup across DCs you can run a replica per DC.
|
||||
|
||||
Scala
|
||||
: @@snip [ReplicatedShardingSpec.scala](/akka-cluster-sharding-typed/src/test/scala/docs/akka/cluster/sharding/typed/ReplicatedShardingCompileOnlySpec.scala) { #bootstrap-dc }
|
||||
|
||||
Java
|
||||
: @@snip [ReplicatedShardingTest.java](/akka-cluster-sharding-typed/src/test/java/jdocs/akka/cluster/sharding/typed/ReplicatedShardingCompileOnlySpec.java) { #bootstrap-dc }
|
||||
|
||||
Regardless of which replication strategy you use sending messages to the replicated entities is the same.
|
||||
|
||||
`init` returns an @apidoc[ReplicatedSharding] instance which gives access to @apidoc[EntityRef]s for each of the replicas for arbitrary routing logic:
|
||||
|
||||
Scala
|
||||
: @@snip [ReplicatedShardingSpec.scala](/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ReplicatedShardingSpec.scala) { #all-entity-refs }
|
||||
: @@snip [ReplicatedShardingSpec.scala](/akka-cluster-sharding-typed/src/test/scala/docs/akka/cluster/sharding/typed/ReplicatedShardingCompileOnlySpec.scala) { #sending-messages }
|
||||
|
||||
Java
|
||||
: @@snip [ReplicatedShardingTest.java](/akka-cluster-sharding-typed/src/test/java/akka/cluster/sharding/typed/ReplicatedShardingTest.java) { #all-entity-refs }
|
||||
: @@snip [ReplicatedShardingTest.java](/akka-cluster-sharding-typed/src/test/java/jdocs/akka/cluster/sharding/typed/ReplicatedShardingCompileOnlySpec.java) { #sending-messages }
|
||||
|
||||
More advanced routing among the replicas is currently left as an exercise for the reader (or may be covered in a future release [#29281](https://github.com/akka/akka/issues/29281), [#29319](https://github.com/akka/akka/issues/29319)).
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue