Skip to content

Port akka-core#31859: Improve StopShards coordinator command#2783

Merged
pjfanning merged 5 commits intoapache:mainfrom
pjfanning:copilot/copy-akka-core-pr-31859
Mar 24, 2026
Merged

Port akka-core#31859: Improve StopShards coordinator command#2783
pjfanning merged 5 commits intoapache:mainfrom
pjfanning:copilot/copy-akka-core-pr-31859

Conversation

@pjfanning
Copy link
Copy Markdown
Member

Part of #2730

See #2782

Ports akka/akka-core#31859 — improves the StopShards coordinator command with proper guards, correctness fixes, and serialization support.

ShardCoordinator changes

  • Guard: rememberEntities — logs error and ignores StopShards (incompatible combination)
  • Guard: no known regions / shutting down — logs warning and ignores instead of silently misbehaving
  • Immediate ack for already-stopped shards — sends ShardStopped immediately rather than hanging
  • Skip already-rebalancing shards — avoids double-stopping; they'll ack when rebalance completes
  • Timeout mechanismStopShardTimeout cleans up waiting actors after handOffTimeout elapses

Serialization

Added protobuf serialization for StopShards so the command can be sent across nodes (e.g., from a ShardRegion proxy to the coordinator):

  • Added StopShards message to ClusterShardingMessages.proto
  • Updated generated ClusterShardingMessages.java
  • Added "ST" manifest + stopShardsToProto/stopShardsFromBinary to ClusterShardingMessageSerializer

Tests

  • StopShardsSpec — 2-node cluster test verifying full stop flow including ShardStopped acks and entity termination
  • ClusterShardingMessageSerializerSpec — serialization roundtrip for StopShards

Usage

// Send from any node (via ShardRegion proxy or directly to coordinator)
shardRegion ! ShardCoordinator.Internal.StopShards(Set("shard-1", "shard-2"))
// Receive one ShardStopped per shard once stopped
expectMsgType[ShardStopped]

@pjfanning pjfanning requested a review from Copilot March 23, 2026 18:45
@pjfanning pjfanning marked this pull request as draft March 23, 2026 18:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports Akka improvements to the Cluster Sharding StopShards coordinator command, making it safer/correcter under various coordinator states and enabling cross-node usage via protobuf serialization.

Changes:

  • Harden ShardCoordinator handling of StopShards (guards, correct region targeting, immediate acks, timeout cleanup).
  • Add protobuf schema + serializer support for StopShards ("ST" manifest).
  • Add/extend tests covering StopShards serialization and a 2-node stop flow.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cluster-sharding/src/test/scala/org/apache/pekko/cluster/sharding/protobuf/ClusterShardingMessageSerializerSpec.scala Adds a serialization roundtrip test for StopShards.
cluster-sharding/src/test/scala/org/apache/pekko/cluster/sharding/StopShardsSpec.scala New 2-node cluster spec exercising StopShards and ShardStopped acks.
cluster-sharding/src/main/scala/org/apache/pekko/cluster/sharding/protobuf/ClusterShardingMessageSerializer.scala Adds "ST" manifest and protobuf (de)serialization for StopShards.
cluster-sharding/src/main/scala/org/apache/pekko/cluster/sharding/ShardCoordinator.scala Implements guarded, region-aware StopShards execution plus timeout cleanup.
cluster-sharding/src/main/protobuf/ClusterShardingMessages.proto Adds protobuf message definition for StopShards.
cluster-sharding/src/main/java/org/apache/pekko/cluster/sharding/protobuf/msg/ClusterShardingMessages.java Regenerated protobuf Java output including StopShards.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…ing/StopShardsSpec.scala

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pjfanning pjfanning marked this pull request as ready for review March 23, 2026 21:41
@pjfanning pjfanning added this to the 2.0.0-M2 milestone Mar 23, 2026
Copy link
Copy Markdown
Member

@He-Pin He-Pin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@pjfanning pjfanning merged commit f7cb660 into apache:main Mar 24, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants