Class DowngradingConsistencyRetryPolicy
A retry policy that sometimes retry with a lower consistency level than the one initially requested.
BEWARE: This policy may retry queries
using a lower consistency level than the one initially requested. By doing
so, it may break consistency guarantees. In other words, if you use this
retry policy, there are cases (documented below) where a read at
Quorum
may not see a preceding write at
Quorum
. Do not use this policy unless you have understood the
cases where this can happen and are OK with that. It is also highly
recommended to always wrap this policy into LoggingRetryPolicy
to log the occurrences of such consistency break. This policy behaves in the
same way as the DefaultRetryPolicy policy, except for the
following cases:
- On a read timeout: if the number of replica that responded is greater than one but lower than is required by the requested consistency level, the operation is retried at a lower consistency level.
- On a write timeout: if the operation is an
UNLOGGED_BATCH
and at least one replica acknowledged the write, the operation is retried at a lower consistency level. Furthermore, for other operation, if at least one replica acknowledged the write, the timeout is ignored. - On an unavailable exception: if at least one replica is alive, the operation is retried at a lower consistency level.
The reasoning behind this retry policy is the following one. If, based on the information the Cassandra coordinator node returns, retrying the operation with the initially requested consistency has a change to succeed, do it. Otherwise, if based on these informations we know the initially requested consistency level cannot be achieve currently, then:
- For writes, ignore the exception (thus silently failing the consistency requirement) if we know the write has been persisted on at least one replica.
- For reads, try reading at a lower consistency level (thus silently failing the consistency requirement).
In other words, this policy : the idea that if the requested consistency level cannot be achieved, the next best thing for writes is to make sure the data is persisted, and that reading something is better than reading nothing, even if there is a risk of reading stale data.
Inheritance
Implements
Inherited Members
Namespace: Cassandra
Assembly: Cassandra.dll
Syntax
[Obsolete("This retry policy has been deprecated and will be removed in future versions. See the upgrade guide (Docs » Upgrade Guide) for more information")]
public class DowngradingConsistencyRetryPolicy : IRetryPolicy
Fields
Instance
Declaration
public static DowngradingConsistencyRetryPolicy Instance
Field Value
Type | Description |
---|---|
DowngradingConsistencyRetryPolicy |
Methods
OnReadTimeout(IStatement, ConsistencyLevel, int, int, bool, int)
Defines whether to retry and at which consistency level on a read timeout.
This method triggers a maximum of one retry. If less replica responsed than required by the consistency level (but at least one replica did respond), the operation is retried at a lower consistency level. If enough replica responded but data was not retrieve, the operation is retried with the initial consistency level. Otherwise, an exception is thrown.
Declaration
public RetryDecision OnReadTimeout(IStatement query, ConsistencyLevel cl, int requiredResponses, int receivedResponses, bool dataRetrieved, int nbRetry)
Parameters
Type | Name | Description |
---|---|---|
IStatement | query | the original query that timeouted. |
ConsistencyLevel | cl | the original consistency level of the read that timeouted. |
int | requiredResponses | the number of responses that were required to achieve the requested consistency level. |
int | receivedResponses | the number of responses that had been received by the time the timeout exception was raised. |
bool | dataRetrieved | whether actual data (by opposition to data checksum) was present in the received responses. |
int | nbRetry | the number of retry already performed for this operation. |
Returns
Type | Description |
---|---|
RetryDecision | a RetryDecision as defined above. |
OnUnavailable(IStatement, ConsistencyLevel, int, int, int)
Defines whether to retry and at which consistency level on an unavailable exception.
This method triggers a maximum of one retry. If at least one replica is know to be alive, the operation is retried at a lower consistency level.
Declaration
public RetryDecision OnUnavailable(IStatement query, ConsistencyLevel cl, int requiredReplica, int aliveReplica, int nbRetry)
Parameters
Type | Name | Description |
---|---|---|
IStatement | query | the original query for which the consistency level cannot be achieved. |
ConsistencyLevel | cl | the original consistency level for the operation. |
int | requiredReplica | the number of replica that should have been (known) alive for the operation to be attempted. |
int | aliveReplica | the number of replica that were know to be alive by the coordinator of the operation. |
int | nbRetry | the number of retry already performed for this operation. |
Returns
Type | Description |
---|---|
RetryDecision | a RetryDecision as defined above. |
OnWriteTimeout(IStatement, ConsistencyLevel, string, int, int, int)
Defines whether to retry and at which consistency level on a write timeout.
This method triggers a maximum of one retry. If writeType ==
WriteType.BATCH_LOG
, the write is retried with the initial consistency
level. If writeType == WriteType.UNLOGGED_BATCH
and at least one
replica acknowleged, the write is retried with a lower consistency level
(with unlogged batch, a write timeout can always mean that part of the
batch haven't been persisted at' all, even if receivedAcks > 0
).
For other writeType
, if we know the write has been persisted on
at least one replica, we ignore the exception. Otherwise, an exception is
thrown.
Declaration
public RetryDecision OnWriteTimeout(IStatement query, ConsistencyLevel cl, string writeType, int requiredAcks, int receivedAcks, int nbRetry)
Parameters
Type | Name | Description |
---|---|---|
IStatement | query | the original query that timeouted. |
ConsistencyLevel | cl | the original consistency level of the write that timeouted. |
string | writeType | the type of the write that timeouted. |
int | requiredAcks | the number of acknowledgments that were required to achieve the requested consistency level. |
int | receivedAcks | the number of acknowledgments that had been received by the time the timeout exception was raised. |
int | nbRetry | the number of retry already performed for this operation. |
Returns
Type | Description |
---|---|
RetryDecision | a RetryDecision as defined above. |