7

It's my understanding that LWT inserts are always done with SERIAL consistency level. If true, does that mean that reading a row inserted as LWT, can be safely read with a consistency level of ANY?

In other words, I assume an LWT insert is fully consistent, making any subsequent read also fully consistent, regardless of consistency level?

nilskp
  • 3,097
  • 1
  • 30
  • 34
  • ANY is not an acceptable consistency level for reads: ONE is the minimum. ANY is for write only. – G Quintana Mar 03 '15 at 17:54
  • @GQuintana, thanks for the clarification. Is ONE for read only then, and if not, what's the difference between ANY and ONE for writes? – nilskp Mar 03 '15 at 19:43
  • 2
    For writes, ANY means fire request and forget, while ONE means fire request and wait for one replica to acknowledge. You can't use ANY for reads because you need at least one replica to get a response. – G Quintana Mar 04 '15 at 08:21
  • To clarify ANY, it means "A write must be written to at least one node. If all replica nodes for the given partition key are down, the write can still succeed after a hinted handoff has been written." – Brad Schoening Jul 21 '21 at 02:21
  • @brad-schoening The question was about ANY reads, not writes. – nilskp Jul 22 '21 at 06:15

1 Answers1

13

Your assumption is incorrect due to two reasons.

  1. SERIAL only implies QUORUM consistency level for writes
  2. There is a possibility that a single LWT will only be partially applied at time of reading and thus cannot be safely read with any CL

Therefor you need to use SERIAL for all queries that will read LWT writes. This will make sure that there are no pending LWTs while reading QUORUM.

Stefan Podkowinski
  • 5,206
  • 1
  • 20
  • 25
  • I do not understand your second point. Serial is like Quorum (even stronger) and Quorum + One > RF/2. – G Quintana Mar 03 '15 at 18:00
  • "Fully consistent" in context of a LWT implies that all replicas have been successfully written with QUORUM. If you do a read, while the LWT is still getting executed, you might read partial committed results. Only reading with SERIAL makes sure you never see incomplete writes for this case as a SERIAL read will make sure that there a no pending LWTs. – Stefan Podkowinski Mar 03 '15 at 19:30
  • @StefanPodkowinski, does this apply in the case where the LWT involves a single row, both reads and writes? And if so, is that because columns are applied individually? – nilskp Mar 03 '15 at 19:41
  • @nilskp LWTs always only effect a single row. Column updates are never applied individually during a single write, as all columns for a single row partition key will be applied atomically (also holds true without LWTs): http://www.datastax.com/dev/blog/row-level-isolation – Stefan Podkowinski Mar 04 '15 at 09:29
  • @StefanPodkowinski, that was my understanding too, but then I'm not following your comment, specifically "If you do a read, while the LWT is still getting executed, you might read partial committed results". Are you here referring to reading a write that eventually fails to get quorum and will thus be corrected later (the equivalent to a dirty read in RDBMS)? Or what constitutes "partial committed results"? – nilskp Mar 04 '15 at 14:10
  • 1
    @nilskp partial committed as in not fully written/acknowledged on all replicas. – Stefan Podkowinski Mar 04 '15 at 14:26
  • Stefan, what do you think might be the impact if there is a pending LWT write while executing a QOURUM read? You will either get (1) the old value, (2) the new value or (3) you can also read an incomplete write that is later rolled back? Is (3) possible at all? – bodrin Feb 08 '17 at 13:31