You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by ibrahim El-sanosi <ib...@gmail.com> on 2015/09/04 19:26:05 UTC

who does generate timestamp during the write?

Dear folks,

When we hear about the notion of Last-Write-Wins in Cassandra according to
timestamp, *who does generate this timestamp during the write, coordinator
or each individual replica in which the write is going to be stored?*


*Regards,*



*Ibrahim*

Re: who does generate timestamp during the write?

Posted by ibrahim El-sanosi <ib...@gmail.com>.
Yes, that you a lot

On Tue, Sep 8, 2015 at 5:25 PM, Tyler Hobbs <ty...@datastax.com> wrote:

>
> On Sat, Sep 5, 2015 at 8:32 AM, ibrahim El-sanosi <
> ibrahimsabattt@gmail.com> wrote:
>
>> So in this scenario, the latest data that wrote to the replicas is [K1,
>> V2] which should be the correct one, but it reads [K1,V1] because of divert
>> clock.
>>
>> Can such scenario occur?
>>
>
> Yes, it most certainly can.  There are a couple of pieces of advice for
> this.  First, run NTP on all of your servers.  Second, if clock drift of a
> second or so would cause problems for your data model (like your example),
> change your data model.  Usually this means creating separate rows for each
> version of the value (by adding a timuuid to the primary key, for example),
> but in some cases lightweight transactions may also be suitable.
>
>
> --
> Tyler Hobbs
> DataStax <http://datastax.com/>
>

Re: who does generate timestamp during the write?

Posted by Tyler Hobbs <ty...@datastax.com>.
On Sat, Sep 5, 2015 at 8:32 AM, ibrahim El-sanosi <ib...@gmail.com>
wrote:

> So in this scenario, the latest data that wrote to the replicas is [K1,
> V2] which should be the correct one, but it reads [K1,V1] because of divert
> clock.
>
> Can such scenario occur?
>

Yes, it most certainly can.  There are a couple of pieces of advice for
this.  First, run NTP on all of your servers.  Second, if clock drift of a
second or so would cause problems for your data model (like your example),
change your data model.  Usually this means creating separate rows for each
version of the value (by adding a timuuid to the primary key, for example),
but in some cases lightweight transactions may also be suitable.


-- 
Tyler Hobbs
DataStax <http://datastax.com/>

Re: who does generate timestamp during the write?

Posted by ibrahim El-sanosi <ib...@gmail.com>.
In this cases, assume we have 4-nodes cluster N1, N2, N3, and N4 and
replication factor is 3. Client c1 sends W1 = [k1,V1] to N1 (a
coordinator).  A coordinator (N1) generates timestamp Mon 05-09-2015
11:30:40,200 (according to its local clock) and assigned it to W1 and sends
the W1 to the N2, N3, and N4. After few seconds, Client c2 sends W2 = [K1,
V2] to N4 (a coordinator). A coordinator (N4) generates timestamp Mon
05-09-2015 11:30:38,200 (according to its local clock, but assume here N4
clock a bit behind, nearly 2 seconds) and assigned IT to W2 and sends the
W2 to N2, N3, and N4 (itself).

Assume we have write CL =ALL and read CL = ONE. Now, Client c2 wants to
read K1, connects to a coordinator N1, a coordinator sends read K1 to N1,
picking latest timestamp which is [K1, V1]:Mon 05-09-2015 11:30:40,200.

So in this scenario, the latest data that wrote to the replicas is [K1, V2]
which should be the correct one, but it reads [K1,V1] because of divert
clock.

Can such scenario occur?

Thank you

Re: who does generate timestamp during the write?

Posted by Tyler Hobbs <ty...@datastax.com>.
Timestamps can come from three different places, in order of precedence
from highest to lowest:
* The CQL query itself through the "USING TIMESTAMP" clause
* The driver (or maybe application) at the protocol level when using the v3
native protocol or higher (which is available in Cassandra 2.1+).  This is
what I recommend using in most cases, because the driver can safely retry
idempotent writes.
* The coordinator node

On Fri, Sep 4, 2015 at 1:06 PM, Andrey Ilinykh <ai...@gmail.com> wrote:

> I meant thrift based api. If we are talking about CQL then timestamps are
> generated by node you are connected to. This is a "client".
>
> On Fri, Sep 4, 2015 at 10:49 AM, ibrahim El-sanosi <
> ibrahimsabattt@gmail.com> wrote:
>
>> Hi Andrey,
>>
>> I just came across this articale "
>>
>> "Each cell in a CQL table has a corresponding timestamp
>> which is taken from the clock on *the Cassandra node* *that orchestrates the
>> write.* When you are reading from a Cassandra cluster the node that
>> coordinates the read will compare the timestamps of the values it fetches.
>> Last write(=highest timestamp) wins and will be returned to the client."
>>
>> What do you think?
>>
>> "
>>
>> On Fri, Sep 4, 2015 at 6:41 PM, Andrey Ilinykh <ai...@gmail.com>
>> wrote:
>>
>>> Coordinator doesn't generate timestamp, it is generated by client.
>>>
>>> On Fri, Sep 4, 2015 at 10:37 AM, ibrahim El-sanosi <
>>> ibrahimsabattt@gmail.com> wrote:
>>>
>>>> Ok, why coordinator does generate timesamp, as the write is a part of
>>>> Cassandra process after client submit the request to Cassandra?
>>>>
>>>> On Fri, Sep 4, 2015 at 6:29 PM, Andrey Ilinykh <ai...@gmail.com>
>>>> wrote:
>>>>
>>>>> Your application.
>>>>>
>>>>> On Fri, Sep 4, 2015 at 10:26 AM, ibrahim El-sanosi <
>>>>> ibrahimsabattt@gmail.com> wrote:
>>>>>
>>>>>> Dear folks,
>>>>>>
>>>>>> When we hear about the notion of Last-Write-Wins in Cassandra
>>>>>> according to timestamp, *who does generate this timestamp during the
>>>>>> write, coordinator or each individual replica in which the write is going
>>>>>> to be stored?*
>>>>>>
>>>>>>
>>>>>> *Regards,*
>>>>>>
>>>>>>
>>>>>>
>>>>>> *Ibrahim*
>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>


-- 
Tyler Hobbs
DataStax <http://datastax.com/>

Re: who does generate timestamp during the write?

Posted by Andrey Ilinykh <ai...@gmail.com>.
I meant thrift based api. If we are talking about CQL then timestamps are
generated by node you are connected to. This is a "client".

On Fri, Sep 4, 2015 at 10:49 AM, ibrahim El-sanosi <ibrahimsabattt@gmail.com
> wrote:

> Hi Andrey,
>
> I just came across this articale "
>
> "Each cell in a CQL table has a corresponding timestamp
> which is taken from the clock on *the Cassandra node* *that orchestrates the
> write.* When you are reading from a Cassandra cluster the node that
> coordinates the read will compare the timestamps of the values it fetches.
> Last write(=highest timestamp) wins and will be returned to the client."
>
> What do you think?
>
> "
>
> On Fri, Sep 4, 2015 at 6:41 PM, Andrey Ilinykh <ai...@gmail.com> wrote:
>
>> Coordinator doesn't generate timestamp, it is generated by client.
>>
>> On Fri, Sep 4, 2015 at 10:37 AM, ibrahim El-sanosi <
>> ibrahimsabattt@gmail.com> wrote:
>>
>>> Ok, why coordinator does generate timesamp, as the write is a part of
>>> Cassandra process after client submit the request to Cassandra?
>>>
>>> On Fri, Sep 4, 2015 at 6:29 PM, Andrey Ilinykh <ai...@gmail.com>
>>> wrote:
>>>
>>>> Your application.
>>>>
>>>> On Fri, Sep 4, 2015 at 10:26 AM, ibrahim El-sanosi <
>>>> ibrahimsabattt@gmail.com> wrote:
>>>>
>>>>> Dear folks,
>>>>>
>>>>> When we hear about the notion of Last-Write-Wins in Cassandra
>>>>> according to timestamp, *who does generate this timestamp during the
>>>>> write, coordinator or each individual replica in which the write is going
>>>>> to be stored?*
>>>>>
>>>>>
>>>>> *Regards,*
>>>>>
>>>>>
>>>>>
>>>>> *Ibrahim*
>>>>>
>>>>
>>>>
>>>
>>
>

Re: who does generate timestamp during the write?

Posted by ibrahim El-sanosi <ib...@gmail.com>.
Hi Andrey,

I just came across this articale "

"Each cell in a CQL table has a corresponding timestamp
which is taken from the clock on *the Cassandra node* *that orchestrates the
write.* When you are reading from a Cassandra cluster the node that
coordinates the read will compare the timestamps of the values it fetches.
Last write(=highest timestamp) wins and will be returned to the client."

What do you think?

"

On Fri, Sep 4, 2015 at 6:41 PM, Andrey Ilinykh <ai...@gmail.com> wrote:

> Coordinator doesn't generate timestamp, it is generated by client.
>
> On Fri, Sep 4, 2015 at 10:37 AM, ibrahim El-sanosi <
> ibrahimsabattt@gmail.com> wrote:
>
>> Ok, why coordinator does generate timesamp, as the write is a part of
>> Cassandra process after client submit the request to Cassandra?
>>
>> On Fri, Sep 4, 2015 at 6:29 PM, Andrey Ilinykh <ai...@gmail.com>
>> wrote:
>>
>>> Your application.
>>>
>>> On Fri, Sep 4, 2015 at 10:26 AM, ibrahim El-sanosi <
>>> ibrahimsabattt@gmail.com> wrote:
>>>
>>>> Dear folks,
>>>>
>>>> When we hear about the notion of Last-Write-Wins in Cassandra according
>>>> to timestamp, *who does generate this timestamp during the write,
>>>> coordinator or each individual replica in which the write is going to be
>>>> stored?*
>>>>
>>>>
>>>> *Regards,*
>>>>
>>>>
>>>>
>>>> *Ibrahim*
>>>>
>>>
>>>
>>
>

Re: who does generate timestamp during the write?

Posted by Andrey Ilinykh <ai...@gmail.com>.
Coordinator doesn't generate timestamp, it is generated by client.

On Fri, Sep 4, 2015 at 10:37 AM, ibrahim El-sanosi <ibrahimsabattt@gmail.com
> wrote:

> Ok, why coordinator does generate timesamp, as the write is a part of
> Cassandra process after client submit the request to Cassandra?
>
> On Fri, Sep 4, 2015 at 6:29 PM, Andrey Ilinykh <ai...@gmail.com> wrote:
>
>> Your application.
>>
>> On Fri, Sep 4, 2015 at 10:26 AM, ibrahim El-sanosi <
>> ibrahimsabattt@gmail.com> wrote:
>>
>>> Dear folks,
>>>
>>> When we hear about the notion of Last-Write-Wins in Cassandra according
>>> to timestamp, *who does generate this timestamp during the write,
>>> coordinator or each individual replica in which the write is going to be
>>> stored?*
>>>
>>>
>>> *Regards,*
>>>
>>>
>>>
>>> *Ibrahim*
>>>
>>
>>
>

Re: who does generate timestamp during the write?

Posted by ibrahim El-sanosi <ib...@gmail.com>.
Ok, why coordinator does generate timesamp, as the write is a part of
Cassandra process after client submit the request to Cassandra?

On Fri, Sep 4, 2015 at 6:29 PM, Andrey Ilinykh <ai...@gmail.com> wrote:

> Your application.
>
> On Fri, Sep 4, 2015 at 10:26 AM, ibrahim El-sanosi <
> ibrahimsabattt@gmail.com> wrote:
>
>> Dear folks,
>>
>> When we hear about the notion of Last-Write-Wins in Cassandra according
>> to timestamp, *who does generate this timestamp during the write,
>> coordinator or each individual replica in which the write is going to be
>> stored?*
>>
>>
>> *Regards,*
>>
>>
>>
>> *Ibrahim*
>>
>
>

Re: who does generate timestamp during the write?

Posted by Andrey Ilinykh <ai...@gmail.com>.
Your application.

On Fri, Sep 4, 2015 at 10:26 AM, ibrahim El-sanosi <ibrahimsabattt@gmail.com
> wrote:

> Dear folks,
>
> When we hear about the notion of Last-Write-Wins in Cassandra according to
> timestamp, *who does generate this timestamp during the write,
> coordinator or each individual replica in which the write is going to be
> stored?*
>
>
> *Regards,*
>
>
>
> *Ibrahim*
>