Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨feat: Distribute the shards to nodes fairly #82

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
[Unreleased]: https://github.com/lerna-stack/akka-entity-replication/compare/.v1.0.0...master

### Breaking Change

- Change the shard-distribution-strategy to distribute shard (`RaftActor`) more evenly [PR#82](https://github.com/lerna-stack/akka-entity-replication/pull/82)

⚠️ This change does not allow rolling updates. You have to update your system by stopping the whole cluster.

### Added
- Java11 support
- Add new typed API based on Akka Typed [PR#79](https://github.com/lerna-stack/akka-entity-replication/pull/79)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ To use this library, you must add a dependency into your sbt project, add the fo

**Stable Release**

[![Maven Central](https://img.shields.io/maven-central/v/com.lerna-stack/akka-entity-replication_2.13?color=%23005cb2&label=stable)](https://mvnrepository.com/artifact/com.lerna-stack/akka-entity-replication)
[![Maven Central](https://img.shields.io/maven-central/v/com.lerna-stack/akka-entity-replication_2.13?color=%23005cb2&label=stable)](https://mvnrepository.com/artifact/com.lerna-stack/akka-entity-replication)

⚠️ `v2.0.0` will contain breaking changes. For more details see [CHANGELOG](./CHANGELOG.md).

```scala
libraryDependencies += "com.lerna-stack" %% "akka-entity-replication" % "X.X.X"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package lerna.akka.entityreplication

import akka.actor.{ Actor, ActorLogging, ActorPath, ActorRef, OneForOneStrategy, Props, Stash, SupervisorStrategy }
import akka.cluster.ClusterEvent._
import akka.cluster.sharding.ShardRegion.{ GracefulShutdown, HashCodeMessageExtractor }
import akka.cluster.sharding.ShardRegion.GracefulShutdown
import akka.cluster.sharding.{ ClusterSharding, ClusterShardingSettings, ShardRegion }
import akka.cluster.{ Cluster, Member, MemberStatus }
import akka.routing.{ ActorRefRoutee, ConsistentHashingRouter, ConsistentHashingRoutingLogic, Router }
Expand Down Expand Up @@ -118,15 +118,20 @@ private[entityreplication] class ReplicationRegion(

// TODO 変数名を実態にあったものに変更
private[this] val shardingRouters: Map[MemberIndex, ActorRef] = allMemberIndexes.map { memberIndex =>
def clusterReplicationShardId(message: Any): String = extractNormalizedShardIdInternal(message).raw
val extractEntityId: ShardRegion.ExtractEntityId = message => (clusterReplicationShardId(message), message)
val extractShardId: ShardRegion.ExtractShardId = {
case ShardRegion.StartEntity(id) => id
case message => clusterReplicationShardId(message)
}
tksugimoto marked this conversation as resolved.
Show resolved Hide resolved
memberIndex -> {
ClusterSharding(context.system).start(
typeName = s"raft-shard-$typeName-${memberIndex.role}",
entityProps = createRaftActorProps(),
settings = ClusterShardingSettings(settings.raftSettings.clusterShardingConfig)
.withRole(memberIndex.role),
messageExtractor = new HashCodeMessageExtractor(maxNumberOfShards = 50) {
override def entityId(message: Any): String = extractNormalizedShardIdInternal(message).raw
},
extractEntityId,
extractShardId,
)
}
}.toMap
Expand Down