Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved IsClientHealthy/ShouldRetry from the generic CassandraException…

… class and moved it to

CassandraOperationException which makes more sense as that exception should be thrown
anytime we do something with cassandra; connecting, executing a cql query, etc etc.
  • Loading branch information...
commit de1be9790a4d27c77a98a692e10916d2be16625e 1 parent 700adb9
@eplowe eplowe authored
View
17 src/CassandraException.cs
@@ -4,27 +4,10 @@ namespace FluentCassandra
{
public class CassandraException : Exception
{
- public bool IsClientHealthy { get; set; }
- public bool ShouldRetry { get; set; }
-
public CassandraException(string message)
: base(message) { }
public CassandraException(string message, Exception innerException)
: base(message, innerException) { }
-
- public CassandraException(string message, bool isHealthy, bool shouldRetry)
- : base(message)
- {
- IsClientHealthy = isHealthy;
- ShouldRetry = shouldRetry;
- }
-
- public CassandraException(string message, Exception innerException, bool isHealthy, bool shouldRetry)
- : base(message, innerException)
- {
- IsClientHealthy = isHealthy;
- ShouldRetry = shouldRetry;
- }
}
}
View
2  src/CassandraSession.cs
@@ -156,7 +156,7 @@ public void Login(string username, string password)
/// <summary>
/// The last error that occured during the execution of an operation.
/// </summary>
- public CassandraException LastError { get; private set; }
+ public CassandraOperationException LastError { get; private set; }
/// <summary>
/// Indicates if errors should be thrown when occuring on opperation.
View
3  src/Connections/NormalConnectionProvider.cs
@@ -1,5 +1,6 @@
using System;
using System.Net.Sockets;
+using FluentCassandra.Operations;
namespace FluentCassandra.Connections
{
@@ -49,7 +50,7 @@ public override IConnection Open()
}
if (conn == null)
- throw new CassandraException("No connection could be made because all servers have failed.", false, false);
+ throw new CassandraOperationException("No connection could be made because all servers have failed.", false, false);
return conn;
}
View
3  src/Connections/PooledConnectionProvider.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
+using FluentCassandra.Operations;
namespace FluentCassandra.Connections
{
@@ -59,7 +60,7 @@ public override IConnection CreateConnection()
else if (_freeConnections.Count + _usedConnections.Count >= MaxPoolSize)
{
if (!Monitor.Wait(_lock, TimeSpan.FromSeconds(30)))
- throw new CassandraException("No connection could be made, timed out trying to aquire a connection from the connection pool.", false, false);
+ throw new CassandraOperationException("No connection could be made, timed out trying to aquire a connection from the connection pool.", false, false);
return CreateConnection();
}
View
73 src/Operations/CassandraOperationException.cs
@@ -8,28 +8,85 @@ namespace FluentCassandra.Operations
{
public class CassandraOperationException : CassandraException
{
+ public bool IsClientHealthy { get; set; }
+ public bool ShouldRetry { get; set; }
+
public CassandraOperationException(AuthenticationException exc)
- : base(exc.Why, exc, true, false) { }
+ : base(exc.Why, exc)
+ {
+ IsClientHealthy = true;
+ ShouldRetry = false;
+ }
public CassandraOperationException(InvalidRequestException exc)
- : base(exc.Why, exc, true, false) { }
+ : base(exc.Why, exc)
+ {
+ IsClientHealthy = true;
+ ShouldRetry = false;
+ }
public CassandraOperationException(AuthorizationException exc)
- : base(exc.Why, exc, true, false) { }
+ : base(exc.Why, exc)
+ {
+ IsClientHealthy = true;
+ ShouldRetry = false;
+ }
public CassandraOperationException(UnavailableException exc)
- : base("Cassandra server is unavailable.", exc, false, true) { }
+ : base("Cassandra server is unavailable.", exc)
+ {
+ IsClientHealthy = false;
+ ShouldRetry = true;
+ }
public CassandraOperationException(TimedOutException exc)
- : base("Connection to Cassandra has timed out.", exc, true, true) { }
+ : base("Connection to Cassandra has timed out.", exc)
+ {
+ IsClientHealthy = true;
+ ShouldRetry = true;
+ }
public CassandraOperationException(IOException exc)
- : base(exc.Message, exc, false, true) {}
+ : base(exc.Message, exc)
+ {
+ IsClientHealthy = false;
+ ShouldRetry = true;
+ }
public CassandraOperationException(NotFoundException exc)
- : base(exc.Message, false, true) { }
+ : base(exc.Message)
+ {
+ IsClientHealthy = false;
+ ShouldRetry = true;
+ }
public CassandraOperationException(TTransportException exc)
- : base(exc.Message, false, true) { }
+ : base(exc.Message)
+ {
+ IsClientHealthy = true;
+ ShouldRetry = false;
+ }
+
+ public CassandraOperationException(Exception exc)
+ : base(exc.Message, exc)
+ {
+ //Unknown exception type, lets be safe and mark this node as down and not try to retry as well.
+ IsClientHealthy = false;
+ ShouldRetry = false;
+ }
+
+ public CassandraOperationException(string message, bool isClientHealthy, bool shouldRetry)
+ : base(message)
+ {
+ IsClientHealthy = isClientHealthy;
+ ShouldRetry = shouldRetry;
+ }
+
+ public CassandraOperationException(string message, Exception innerException, bool isClientHealthy, bool shouldRetry)
+ : base(message, innerException)
+ {
+ IsClientHealthy = isClientHealthy;
+ ShouldRetry = shouldRetry;
+ }
}
}
View
6 src/Operations/Operation.cs
@@ -16,7 +16,7 @@ public Operation()
public CassandraSession Session { get; set; }
public bool HasError { get; protected set; }
- public CassandraException Error { get; protected set; }
+ public CassandraOperationException Error { get; protected set; }
public virtual bool TryExecute(out TResult result)
{
@@ -56,14 +56,14 @@ public virtual bool TryExecute(out TResult result)
}
catch (Exception exc)
{
- ExceptionOccurred(new CassandraException(exc.Message, exc));
+ ExceptionOccurred(new CassandraOperationException(exc));
result = default(TResult);
}
return !HasError;
}
- private void ExceptionOccurred(CassandraException exc)
+ private void ExceptionOccurred(CassandraOperationException exc)
{
Debug.WriteLine(exc);
Please sign in to comment.
Something went wrong with that request. Please try again.