feat(cluster): opt-in leader-auto-down strategy - in-repo port of Akka AutoDowning (ScadaBridge#106)
Adds LeaderAutoDowningProvider (Host/Actors), a line-for-line port of Akka.NET 1.5.62 AutoDowning/AutoDown/AutoDownBase read from the decompiled assembly: the leader among the reachable members downs a peer unreachable for StableAfter; a non-leader records it as pending and downs it on becoming leader; reachable-again or removed members are forgotten; Down/Exiting members are skipped. Its window is carried under scadabridge.cluster.leader-auto-down.unreachable-after, so no deprecated auto-down-unreachable-after key is emitted and Akka's boot-time "keep-majority will be used instead" warning goes away. DownRemovalMargin reads akka.cluster.down-removal-margin exactly as AutoDowning does (default off). New SplitBrainResolverStrategy value "leader-auto-down", wired through BuildHocon and ClusterOptionsValidator. The default stays "auto-down"; auto-down and keep-oldest HOCON is byte-identical to before. Placed in Host, not ClusterInfrastructure, per the Code Placement rule (ClusterInfrastructure stays Akka-free). Tests: HOCON + validator units; LeaderAutoDownTests ports Akka's AutoDownSpec cases (leader-only, pending-on-leader-change, losing leadership, reachable again, removed, Down/Exiting skipped, single Down per member); LeaderAutoDownFailoverTests clones SbrFailoverTests' oldest-crash and younger-crash cases on a real two-node cluster plus a test that Akka actually loaded the provider and its downing actor. Mutation-checked: a provider that never calls Cluster.Down fails both failover tests; never-downs, leader-check-dropped, reachable-ignored and pending-not-flushed mutations each fail the unit tests. Remaining gate before switching the default: the docker failover drill (DRILL_MODE=active and standby mode) on leader-auto-down. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -250,4 +250,76 @@ public class HoconBuilderTests
|
||||
Assert.Equal(1, config.GetInt("akka.cluster.min-nr-of-members"));
|
||||
Assert.True(config.GetBoolean("akka.cluster.run-coordinated-shutdown-when-down"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the leader-auto-down strategy (ScadaBridge#106) installs the in-repo
|
||||
/// provider, carries StableAfter under its own key, and emits neither Akka's deprecated
|
||||
/// auto-down key nor an SBR section.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void BuildHocon_LeaderAutoDownStrategy_EmitsInRepoProvider_AndNoDeprecatedKey()
|
||||
{
|
||||
var cluster = DefaultCluster();
|
||||
cluster.SplitBrainResolverStrategy = "leader-auto-down";
|
||||
cluster.StableAfter = TimeSpan.FromMilliseconds(15250);
|
||||
|
||||
var hocon = AkkaHostedService.BuildHocon(
|
||||
DefaultNode(), cluster, new[] { "Central" },
|
||||
TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(15));
|
||||
|
||||
var config = ConfigurationFactory.ParseString(hocon);
|
||||
Assert.Equal(
|
||||
"ZB.MOM.WW.ScadaBridge.Host.Actors.LeaderAutoDowningProvider, ZB.MOM.WW.ScadaBridge.Host",
|
||||
config.GetString("akka.cluster.downing-provider-class"));
|
||||
// The emitted name must resolve the way Akka resolves it (Type.GetType(name, true)).
|
||||
Assert.Equal(typeof(LeaderAutoDowningProvider),
|
||||
Type.GetType(config.GetString("akka.cluster.downing-provider-class"), throwOnError: true));
|
||||
Assert.Equal(
|
||||
TimeSpan.FromMilliseconds(15250),
|
||||
config.GetTimeSpan(LeaderAutoDowningProvider.UnreachableAfterPath));
|
||||
// No deprecated key (that is what triggers Akka's "keep-majority will be used" warning)
|
||||
// and no SBR section alongside the provider.
|
||||
Assert.False(config.HasPath("akka.cluster.auto-down-unreachable-after"));
|
||||
Assert.False(config.HasPath("akka.cluster.split-brain-resolver.active-strategy"));
|
||||
// Document stays intact after the downing block.
|
||||
Assert.Equal(1, config.GetInt("akka.cluster.min-nr-of-members"));
|
||||
Assert.True(config.GetBoolean("akka.cluster.run-coordinated-shutdown-when-down"));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the leader-auto-down strategy name is case-insensitive.</summary>
|
||||
[Fact]
|
||||
public void BuildHocon_LeaderAutoDownStrategy_IsCaseInsensitive()
|
||||
{
|
||||
var cluster = DefaultCluster();
|
||||
cluster.SplitBrainResolverStrategy = "Leader-Auto-Down";
|
||||
|
||||
var config = ConfigurationFactory.ParseString(AkkaHostedService.BuildHocon(
|
||||
DefaultNode(), cluster, new[] { "Central" },
|
||||
TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(15)));
|
||||
|
||||
Assert.Equal(LeaderAutoDowningProvider.ProviderClassName,
|
||||
config.GetString("akka.cluster.downing-provider-class"));
|
||||
Assert.Equal(TimeSpan.FromSeconds(15), config.GetTimeSpan(LeaderAutoDowningProvider.UnreachableAfterPath));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the leader-auto-down key is emitted ONLY for that strategy: the existing
|
||||
/// auto-down and keep-oldest documents are unchanged by ScadaBridge#106.
|
||||
/// </summary>
|
||||
/// <param name="strategy">An existing strategy.</param>
|
||||
[Theory]
|
||||
[InlineData("auto-down")]
|
||||
[InlineData("keep-oldest")]
|
||||
public void BuildHocon_OtherStrategies_DoNotEmitLeaderAutoDownKey(string strategy)
|
||||
{
|
||||
var cluster = DefaultCluster();
|
||||
cluster.SplitBrainResolverStrategy = strategy;
|
||||
|
||||
var hocon = AkkaHostedService.BuildHocon(
|
||||
DefaultNode(), cluster, new[] { "Central" },
|
||||
TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(15));
|
||||
|
||||
Assert.DoesNotContain("leader-auto-down", hocon);
|
||||
Assert.DoesNotContain(nameof(LeaderAutoDowningProvider), hocon);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user