Notes

Tuesday, January 25, 2022

.NET Orleans and multiple grain activations

It’s possible to have multiple activations of the same grain when adding and removing nodes in the cluster.

GitHub issue #5112: Is it possible for a new node to cause duplicate activation when it joins?

Yes you are correct, it is possible to have two activations for the same grain id at a given time, in the scenario you describe. But, when the cluster will "stabilize" (in your example when the handoff will occur), one activation will "win": the directory will always returns the same activation address for a given grain id. And this should happen very quickly. The grain that lost the race will not be deactivated right away, but it will be isolated and should not receive requests anymore.

GitHub issue #6403: Same grain activated multiple times

OnActivateAsync() is only called on the activation which wins the race however this isn't enough to guarantee that there is a single activation of that grain. The in-built directory is not strong-consistency, so you can still have short periods where duplicates exist. They will be quickly resolved as the directory converges. The conditions which can cause this to happen are adding and removing nodes in the cluster (eg, due to scale out/in/crash/restart/upgrade). The pluggable directory can allow for stronger guarantees, since external storage can be strong-consistency and durable

It’s also mentionned in the Grain Directory documentation

Which Grain Directory should you use? We recommend to always start with the default one (built-in in-memory distributed directory). Even though it is eventually consistent and allows for occasional duplicate activation when cluster is unstable...

Alternatives to in-memory grain directory

There are two storage-based implementations of Grain Directory: Redis and Table storage

Try using it for one or a few grain types first, starting with those that are long-lived and have a significant amount of state or an expensive initialization process.