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

Ensure that ClusterMembershipOptions.NumVotesForDeathDeclaration is not greater than NumProbedSilos on startup #8679

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,6 +1,8 @@
using System;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Orleans.Configuration;
using Orleans.Configuration.Validators;

namespace Orleans.Runtime.Configuration
Expand All @@ -25,6 +27,20 @@ public void ValidateConfiguration()
{
throw new OrleansConfigurationException(ClientClusteringValidator.ClusteringNotConfigured);
}

var clusterMembershipOptions = this.serviceProvider.GetRequiredService<IOptions<ClusterMembershipOptions>>().Value;
if (clusterMembershipOptions.LivenessEnabled)
{
if (clusterMembershipOptions.NumVotesForDeathDeclaration > clusterMembershipOptions.NumProbedSilos)
{
throw new OrleansConfigurationException($"{nameof(ClusterMembershipOptions)}.{nameof(ClusterMembershipOptions.NumVotesForDeathDeclaration)} ({clusterMembershipOptions.NumVotesForDeathDeclaration}) must be less than or equal to {nameof(ClusterMembershipOptions)}.{nameof(ClusterMembershipOptions.NumProbedSilos)} ({clusterMembershipOptions.NumProbedSilos}).");
}

if (clusterMembershipOptions.NumVotesForDeathDeclaration <= 0)
{
throw new OrleansConfigurationException($"{nameof(ClusterMembershipOptions)}.{nameof(ClusterMembershipOptions.NumVotesForDeathDeclaration)} ({clusterMembershipOptions.NumVotesForDeathDeclaration}) must be greater than 0.");
}
}
}
}
}
27 changes: 27 additions & 0 deletions test/NonSilo.Tests/SiloBuilderTests.cs
Expand Up @@ -105,6 +105,33 @@ public async Task SiloBuilder_GrainCollectionOptionsForZeroSecondsAgeLimitTest()
});
}

/// <summary>
/// ClusterMembershipOptions.NumProbedSilos must be greater than ClusterMembershipOptions.NumVotesForDeathDeclaration.
/// </summary>
[Fact]
public async Task SiloBuilder_ClusterMembershipOptionsValidators()
{
await Assert.ThrowsAsync<OrleansConfigurationException>(async () =>
{
await new HostBuilder().UseOrleans((ctx, siloBuilder) =>
{
siloBuilder
.UseLocalhostClustering()
.Configure<ClusterMembershipOptions>(options => { options.NumVotesForDeathDeclaration = 10; options.NumProbedSilos = 1; });
}).RunConsoleAsync();
});

await Assert.ThrowsAsync<OrleansConfigurationException>(async () =>
{
await new HostBuilder().UseOrleans((ctx, siloBuilder) =>
{
siloBuilder
.UseLocalhostClustering()
.Configure<ClusterMembershipOptions>(options => { options.NumVotesForDeathDeclaration = 0; });
}).RunConsoleAsync();
});
}

/// <summary>
/// Ensures <see cref="LoadSheddingValidator"/> fails when LoadSheddingLimit greater than 100.
/// </summary>
Expand Down