From b8fe8f342a73cf691f263ce156b26fb9a93d807e Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Sun, 7 Jul 2019 22:10:39 +0200 Subject: [PATCH] FIX: when there are less nodes, the driver throws Cassandra.UnavailableExeption with Quorum --- .../Storage/CassandraGrainStorage.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Orleans.Persistence.Cassandra/Storage/CassandraGrainStorage.cs b/src/Orleans.Persistence.Cassandra/Storage/CassandraGrainStorage.cs index 968549d..397062c 100644 --- a/src/Orleans.Persistence.Cassandra/Storage/CassandraGrainStorage.cs +++ b/src/Orleans.Persistence.Cassandra/Storage/CassandraGrainStorage.cs @@ -26,13 +26,13 @@ namespace Orleans.Persistence.Cassandra.Storage internal sealed class CassandraGrainStorage : IGrainStorage, ILifecycleParticipant { 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; @@ -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); + } + var session = await _cluster.ConnectAsync(); await Task.Run( () =>