diff --git a/core/src/main/scala/com/devsisters/shardcake/package.scala b/core/src/main/scala/com/devsisters/shardcake/package.scala index 06fe68e..e8a925b 100644 --- a/core/src/main/scala/com/devsisters/shardcake/package.scala +++ b/core/src/main/scala/com/devsisters/shardcake/package.scala @@ -1,6 +1,14 @@ package com.devsisters +import scala.collection.mutable + package object shardcake { type ShardId = Int type EpochMillis = Long + + private[shardcake] def renderShardIds(ids: Iterable[ShardId]): String = + ids + .foldLeft(mutable.BitSet.empty)(_ += _) + .mkString("[", ", ", "]") + } diff --git a/entities/src/main/scala/com/devsisters/shardcake/Sharding.scala b/entities/src/main/scala/com/devsisters/shardcake/Sharding.scala index a9c8caa..5d9565d 100644 --- a/entities/src/main/scala/com/devsisters/shardcake/Sharding.scala +++ b/entities/src/main/scala/com/devsisters/shardcake/Sharding.scala @@ -102,7 +102,7 @@ class Sharding private ( shardAssignments.update(shards.foldLeft(_) { case (map, shard) => map.updated(shard, address) }) *> Metrics.shards.incrementBy(shards.size) *> startSingletonsIfNeeded *> - ZIO.logDebug(s"Assigned shards: $shards") + ZIO.logDebug(s"Assigned shards: ${renderShardIds(shards)}") } .unit @@ -110,7 +110,7 @@ class Sharding private ( shardAssignments.update(shards.foldLeft(_) { case (map, shard) => if (map.get(shard).contains(address)) map - shard else map }) *> - ZIO.logDebug(s"Unassigning shards: $shards") *> + ZIO.logDebug(s"Unassigning shards: ${renderShardIds(shards)}") *> entityStates.get.flatMap(state => ZIO.foreachDiscard(state.values)( _.entityManager.terminateEntitiesOnShards(shards) // this will return once all shards are terminated @@ -118,7 +118,7 @@ class Sharding private ( ) *> Metrics.shards.decrementBy(shards.size) *> stopSingletonsIfNeeded *> - ZIO.logDebug(s"Unassigned shards: $shards") + ZIO.logDebug(s"Unassigned shards: ${renderShardIds(shards)}") private[shardcake] def isEntityOnLocalShards(recipientType: RecipientType[_], entityId: String): UIO[Boolean] = for { diff --git a/manager/src/main/scala/com/devsisters/shardcake/GraphQLApi.scala b/manager/src/main/scala/com/devsisters/shardcake/GraphQLApi.scala index 111428e..1992d53 100644 --- a/manager/src/main/scala/com/devsisters/shardcake/GraphQLApi.scala +++ b/manager/src/main/scala/com/devsisters/shardcake/GraphQLApi.scala @@ -24,7 +24,11 @@ object GraphQLApi extends GenericSchema[ShardManager] { val api: GraphQL[ShardManager] = graphQL[ShardManager, Queries, Mutations, Subscriptions]( RootResolver( - Queries(ZIO.serviceWithZIO(_.getAssignments.map(_.map { case (k, v) => Assignment(k, v) }.toList))), + Queries( + ZIO.serviceWithZIO( + _.getAssignments.map(_.map { case (k, v) => Assignment(k, v) }.toList.sortBy(_.shardId)) + ) + ), Mutations( pod => ZIO.serviceWithZIO(_.register(pod)), pod => ZIO.serviceWithZIO(_.unregister(pod.address)), diff --git a/manager/src/main/scala/com/devsisters/shardcake/ShardManager.scala b/manager/src/main/scala/com/devsisters/shardcake/ShardManager.scala index 21d5047..27d5ce7 100644 --- a/manager/src/main/scala/com/devsisters/shardcake/ShardManager.scala +++ b/manager/src/main/scala/com/devsisters/shardcake/ShardManager.scala @@ -321,8 +321,12 @@ object ShardManager { sealed trait ShardingEvent object ShardingEvent { - case class ShardsAssigned(pod: PodAddress, shards: Set[ShardId]) extends ShardingEvent - case class ShardsUnassigned(pod: PodAddress, shards: Set[ShardId]) extends ShardingEvent + case class ShardsAssigned(pod: PodAddress, shards: Set[ShardId]) extends ShardingEvent { + override def toString: String = s"ShardsAssigned(pod=$pod, shards=${renderShardIds(shards)})" + } + case class ShardsUnassigned(pod: PodAddress, shards: Set[ShardId]) extends ShardingEvent { + override def toString: String = s"ShardsUnassigned(pod=$pod, shards=${renderShardIds(shards)})" + } case class PodRegistered(pod: PodAddress) extends ShardingEvent case class PodUnregistered(pod: PodAddress) extends ShardingEvent case class PodHealthChecked(pod: PodAddress) extends ShardingEvent