SaiVikas
SaiVikas

Reputation: 172

Datastax Cassandra - Query Write Times

Will Cassandra generated time vary depending upon app request generated time?

Scenario

Assume that i have two app nodes which sends write request and delete requests to Cassandra node. The order of execution is

  1. Write request
  2. Delete request

App2 node lags App1 node by a difference of about 500ms. So delete request from app2 side gets a timestamp earlier than the wite request, and it never happens.

Induced a sleep between the two request by 1 sec to solves this, but wanted to understand how Cassandra clock works for writes for each request, when app time is not in sync.

TIA

Upvotes: 0

Views: 284

Answers (1)

Imran Saeed
Imran Saeed

Reputation: 3444

Some notable things about Cassandra:

  • Cassandra does not use a last-write-wins policy when resolving write conflicts.
  • CQL does not default to using server-side timestamps.
  • Cassandra writes are based on client's timestamp with some tolerance to lags and time displacements.

So to answer your question directly

  1. app2 adds an earlier timestamped delete request
  2. app1 add a later timestamped write request

Cassandra detects a conflict as (presumably) it's the same record. It therefore applies the client timestamp validation logic to get a winner and app1 write wins and delete is ignored.

When you add a delay of 1 sec, your entries are in correct order and there is no conflict which ensures the writes are deleted correctly.

This old article from DataStax will explain in more details: http://www.datastax.com/dev/blog/why-cassandra-doesnt-need-vector-clocks

The bottom line is that Cassandra CQL relies on client timestamp for such conflict resolutions.

This is a very simplified version of events and does not apply to complex scenarios. Please read the blog for better understanding of conflict resolution w.r.t. clocks in Cassandra.

Upvotes: 1

Related Questions