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

Cassandra.UnavailableExeption thrown in small test environments with only one node #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ namespace Orleans.Persistence.Cassandra.Storage
internal sealed class CassandraGrainStorage : IGrainStorage, ILifecycleParticipant<ISiloLifecycle>
{
private const ConsistencyLevel SerialConsistencyLevel = ConsistencyLevel.Serial;
private const ConsistencyLevel DefaultConsistencyLevel = ConsistencyLevel.Quorum;
private ConsistencyLevel DefaultConsistencyLevel = ConsistencyLevel.Quorum;

private static readonly CqlQueryOptions SerialConsistencyQueryOptions =
CqlQueryOptions.New().SetSerialConsistencyLevel(SerialConsistencyLevel);

private static readonly CqlQueryOptions DefaultConsistencyQueryOptions =
CqlQueryOptions.New().SetConsistencyLevel(DefaultConsistencyLevel);
CqlQueryOptions.New().SetConsistencyLevel(ConsistencyLevel.Quorum);

private readonly string _name;
private readonly string _serviceId;
Expand Down Expand Up @@ -310,6 +310,13 @@ private async Task Init(CancellationToken cancellationToken)
.AddContactPoints(cassandraOptions.ContactPoints.Split(','))
.Build();

// when there are less nodes, the driver throws Cassandra.UnavailableExeption with Quorum
if (cassandraOptions.ReplicationFactor < 3)
{
DefaultConsistencyLevel = ConsistencyLevel.One;
DefaultConsistencyQueryOptions.SetConsistencyLevel(DefaultConsistencyLevel);

Choose a reason for hiding this comment

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

This is updating a global static field. Better to have an instance field instead

}

var session = await _cluster.ConnectAsync();
await Task.Run(
() =>
Expand Down