[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cassandra-user
Subject:    Re: why returned achievedConsistencyLevel is null
From:       Andy Tolbert <andrew.tolbert () datastax ! com>
Date:       2018-08-25 14:02:18
Message-ID: CABckJc7XS-mbH15bxhR1AxZhEEhLAfuGqjaVpVtf-9zDbhD+Aw () mail ! gmail ! com
[Download RAW message or body]

Hi Vitaliy,

That method (https://docs.datastax.com/en/latest-java-driver-api/com/datast=
ax/driver/core/ExecutionInfo.html#getAchievedConsistencyLevel--)
is a bit confusing as it will return null when your desired
consistency level is achieved:

> If the query returned without achieving the requested consistency level d=
ue to the RetryPolicy, this return the biggest consistency level that has b=
een actually achieved by the query.
>
> Note that the default RetryPolicy (DefaultRetryPolicy) will never allow a=
 query to be successful without achieving the initially requested consisten=
cy level and hence with that default policy, this method will always return=
 null. However, it might occasionally return a non-null with say, Downgradi=
ngConsistencyRetryPolicy.

As long as you are using a RetryPolicy that doesn't downgrade
Consistency Level on retry, you can expect this method to always
return null.  I heavily discourage downgrading consistency levels on
retry, you can read the driver team's rationale about it here
(https://docs.datastax.com/en/developer/java-driver/3.5/upgrade_guide/#3-5-=
0).

> Is it possible to make DataStax driver throw an exception in case
> desired consistency level was not achieved during the insert?

This is actually the default behavior.  If consistency level cannot be
met within Cassandra's configured timeouts, or if not enough replicas
are available to service the consistency level from the start, C* will
raise ReadTimeout, WriteTimeout or Unavailable exceptions
respectively.  The driver can be configured to retry on those errors
per RetryPolicy, although there is some nuance when it comes to it not
retrying statements that are non-idempotent
(https://docs.datastax.com/en/developer/java-driver/3.5/manual/retries/#ret=
ries-and-idempotence).
If the driver is not configured to retry, it will raise the exception
to the user.

In summary, as long as you aren't using some form of downgrading
consistency retry policy, if you get a successfully completed request,
you can assume the consistency level you have configured was met for
your operations.

Thanks,
Andy



On Fri, Aug 24, 2018 at 4:14 PM Vitaliy Semochkin <vitaliy.se@gmail.com> wr=
ote:
>
> HI,
>
> While using DataStax driver
> session.execute("some insert
> query")getExecutionInfo().getAchievedConsistencyLevel()
> is already returned as null, despite data is stored. Why could it be?
>
> Is it possible to make DataStax driver throw an exception in case
> desired consistency level was not achieved during the insert?
>
> Regards,
> Vitaliy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@cassandra.apache.org
> For additional commands, e-mail: user-help@cassandra.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@cassandra.apache.org
For additional commands, e-mail: user-help@cassandra.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic