Adam Wołek
Adam Wołek

Reputation: 21

Delete doesn't work immediately on single node Cassandra database

My problem is that I am not getting immediate delete on single node Cassandra. The problem occurs only on Windows, when I run Cassandra in Docker container. There is no problem on Linux. I am using datastax driver to connect to Cassandra from Java application. Flow in test looks like:

  1. Insert single row to my_lock_table
  2. Modify schema (same keyspace, creating additional tables, it takes about 300ms)
  3. Delete row from my_lock_table by partition key
  4. Select row from my_lock_table by partition key - on Linux there is no result as I expected. But on Windows row that is supposed to be removed is returned by SELECT.

I tried several ways to find out the reason and:

  1. When I added IF EXISTS clause to the delete query, then it works properly row is gone instantly.
  2. I tried to delete row again, and it didn't help. It is strange because it doesn't matter how many times I call DELETE query - it will not work until 10 seconds have passed. And after 10 seconds since INSERT, if I call DELETE query again, then it works and the row is gone.
  3. I checked logs of cassandra, and timestamps of queries are in proper order.

Upvotes: 2

Views: 67

Answers (2)

Erick Ramirez
Erick Ramirez

Reputation: 16353

I haven't had the chance to replicate your issue but based on your description, my suspicion is that the system clock is behind by a few seconds so the DELETE statement appears to be "delayed".

As Andy Tolbert explained in the post you linked in the comments section, the conditional DELETE appears to "immediately remove" the record because the write-time on lightweight transactions (LWTs) are executed using server-side timestamps (instead of the default client-side timestamps for regular DELETE statements).

If the clocks between the driver/client(s) and coordinator are out-of-sync, it can result in inconsistent behaviour for certain scenarios. Cheers!

Upvotes: 1

Aaron
Aaron

Reputation: 57798

So I suspect that this is due to the differences in how the Windows kernel works with certain operations. We had a discussion on this internally (at DataStax), and one thought is that there is likely a race condition with the LWT INSERT, resulting in the DELETE possibly happening before the INSERT takes effect. That's something that would be more apparent on Windows.

Bottom line: We stopped supporting Cassandra on Windows because Windows does some things which get in the way of Cassandra operating normally (issues with deleting active file handles). To test Cassandra single-node-style, use either Linux or MacOS, WSL, or a containerization/virtualization platform instead.

Upvotes: 2

Related Questions