You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cassandra.apache.org by Benjamin Stadin <be...@bridging-it.de> on 2020/11/09 22:09:33 UTC

Merge implementation details

Hi List,

I need to synchronize Cassandra with some sort of proprietary distributed cache. One of the things I‘m looking at is the exact behaviour of the merge operation (LWW) as it is implemented in Cassandra, in order to maintain an (eventually) consistent state between Cassandra and this cache.

Could you point me to actual source code and test cases, and eventually to documentation? I didn‘t find much, other than a short hint in the docs. For example, what‘s the exact behaviour on delete when timestamps are equal? My guess is that writes are prioritized over deletes (since there is a -1 applied to the timestamp in the paxos code path), but I need to figure those details exactly.

 Cheers
Ben



Re: Merge implementation details

Posted by Sylvain Lebresne <le...@gmail.com>.
If you want something precise, I'm afraid you'll have to go to the source
code.

The code to merge "cells" (internally, a "cell" corresponds pretty much to
the
value of specific column in a specific row, though a non-frozen collection
column is actually multiple cells) is in `Cells#reconcile` at:

https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/db/rows/Cells.java#L117

You may also want to look one step up at `Rows#merge` (which calls the
former
`Cells#reconcile`):

https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/db/rows/Rows.java#L278

You'll also find a few unit tests for those methods in:

https://github.com/apache/cassandra/blob/trunk/test/unit/org/apache/cassandra/db/CellTest.java

https://github.com/apache/cassandra/blob/trunk/test/unit/org/apache/cassandra/db/rows/RowsTest.java
but it's not necessarily exhaustive.

That said, you'll see that on equal timestamps, tombstones do have
priorities,
and otherwise the "biggest" value has priority (comparing the underlying
values as unsigned byte arrays). The latter rule is fairly random and just
a deterministic way to break ties.

--
Sylvain


On Mon, Nov 9, 2020 at 11:10 PM Benjamin Stadin <
benjamin.stadin@bridging-it.de> wrote:

> Hi List,
>
> I need to synchronize Cassandra with some sort of proprietary distributed
> cache. One of the things I‘m looking at is the exact behaviour of the merge
> operation (LWW) as it is implemented in Cassandra, in order to maintain an
> (eventually) consistent state between Cassandra and this cache.
>
> Could you point me to actual source code and test cases, and eventually to
> documentation? I didn‘t find much, other than a short hint in the docs. For
> example, what‘s the exact behaviour on delete when timestamps are equal? My
> guess is that writes are prioritized over deletes (since there is a -1
> applied to the timestamp in the paxos code path), but I need to figure
> those details exactly.
>
>  Cheers
> Ben
>
>
>