我在Cassandra中运行DELETE查询。这与具有IF EXISTS子句的多个UPDATE查询同时发生。预期的行为是当DELETE到达时,它将被执行,然后后续的UPDATE将不会执行,因为IF EXISTS子句将解析为false,因为删除将会发生。
这不是一个一致性问题,因为Cassandra'集群'是在docker容器中运行的单个节点。我查看了日志,并在跟踪级别捕获了cassandra日志输出,以便与不成功的删除相比成功删除。在失败的情况下,删除似乎没有被执行。
成功删除:
删除在第2行处理。
由于已删除的行不再存在,因此会立即处理更新,但不会应用更新。
TRACE [Native-Transport-Requests-4] 2017-07-21 14:27:37,012 Message.java:516 - Received: QUERY DELETE FROM monitored_compliance_rules WHERE organisation_id='2' AND id=2cde2468-1c04-480c-9e24-681c04480c9e[pageSize = 5000], v=4/v4
TRACE [Native-Transport-Requests-4] 2017-07-21 14:27:37,012 QueryProcessor.java:212 - Process org.apache.cassandra.cql3.statements.DeleteStatement@77bb560f @CL.LOCAL_ONE
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,013 Message.java:516 - Received: EXECUTE 346d975e583adeeb6aadbf60e16d9d26 with 4 values at consistency LOCAL_ONE, v=4/v4
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,013 QueryProcessor.java:519 - [1] 'java.nio.HeapByteBuffer[pos=0 lim=4 cap=4]'
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,013 QueryProcessor.java:519 - [2] 'java.nio.HeapByteBuffer[pos=0 lim=12 cap=12]'
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,013 QueryProcessor.java:519 - [3] 'java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]'
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,013 QueryProcessor.java:519 - [4] 'java.nio.HeapByteBuffer[pos=0 lim=16 cap=16]'
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,013 QueryProcessor.java:212 - Process org.apache.cassandra.cql3.statements.UpdateStatement@6d551622 @CL.LOCAL_ONE
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,013 MessagingService.java:945 - /172.18.0.4 sending PAXOS_PREPARE to 3255@/172.18.0.4
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,013 MessagingService.java:948 - Message-to-self TYPE:MUTATION VERB:PAXOS_PREPARE going over MessagingService
TRACE [MutationStage-3] 2017-07-21 14:27:37,015 MessagingService.java:945 - /172.18.0.4 sending REQUEST_RESPONSE to 3255@/172.18.0.4
TRACE [MutationStage-3] 2017-07-21 14:27:37,015 MessagingService.java:948 - Message-to-self TYPE:REQUEST_RESPONSE VERB:REQUEST_RESPONSE going over MessagingService
TRACE [RequestResponseStage-5] 2017-07-21 14:27:37,016 PrepareCallback.java:64 - Prepare response PrepareResponse(true, Commit(bdbe3ea0-6e20-11e7-bc6a-52488cbcfc11, [analytics.monitored_compliance_rules] key=2 columns=[[] | [days_processed days_to_process state]]
Row: id=4c6ddcbe-c3f7-4287-addc-bec3f7628718 | days_processed=0, days_to_process=180, state=initializing), Commit(13814000-1dd2-11b2-8080-808080808080, [analytics.monitored_compliance_rules] key=2 columns=[[] | []])) from /172.18.0.4
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,016 ReadCallback.java:101 - Blockfor is 1; setting up requests to /172.18.0.4
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,016 AbstractReadExecutor.java:116 - reading data locally
TRACE [Native-Transport-Requests-4] 2017-07-21 14:27:37,016 Tracing.java:188 - request complete
TRACE [Native-Transport-Requests-4] 2017-07-21 14:27:37,017 Message.java:535 - Responding: EMPTY RESULT, v=4/v4
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,018 ReadCallback.java:147 - Read: 5 ms.
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,019 Tracing.java:188 - request complete
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,019 Message.java:535 - Responding: ROWS [[applied](analytics, monitored_compliance_rules), org.apache.cassandra.db.marshal.BooleanType]
| false
---, v=4/v4
不成功删除
第1行收到删除但未处理。
更新在第2行收到并成功发生,因为IF EXISTS子句解析为true,因为删除从未发生过。
TRACE [Native-Transport-Requests-1] 2017-07-21 14:27:37,353 Message.java:516 - Received: QUERY DELETE FROM monitored_compliance_rules WHERE organisation_id='2' AND id=5c1b69cd-653d-4d6b-9b69-cd653dbd6b8c[pageSize = 5000], v=4/v4
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,369 Message.java:516 - Received: EXECUTE 346d975e583adeeb6aadbf60e16d9d26 with 4 values at consistency LOCAL_ONE, v=4/v4
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,369 QueryProcessor.java:519 - [1] 'java.nio.HeapByteBuffer[pos=0 lim=4 cap=4]'
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,369 QueryProcessor.java:519 - [2] 'java.nio.HeapByteBuffer[pos=0 lim=12 cap=12]'
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,369 QueryProcessor.java:519 - [3] 'java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]'
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,369 QueryProcessor.java:519 - [4] 'java.nio.HeapByteBuffer[pos=0 lim=16 cap=16]'
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,369 QueryProcessor.java:212 - Process org.apache.cassandra.cql3.statements.UpdateStatement@6d551622 @CL.LOCAL_ONE
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,369 MessagingService.java:945 - /172.18.0.4 sending PAXOS_PREPARE to 3263@/172.18.0.4
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,370 MessagingService.java:948 - Message-to-self TYPE:MUTATION VERB:PAXOS_PREPARE going over MessagingService
TRACE [MutationStage-2] 2017-07-21 14:27:37,374 MessagingService.java:945 - /172.18.0.4 sending REQUEST_RESPONSE to 3263@/172.18.0.4
TRACE [MutationStage-2] 2017-07-21 14:27:37,376 MessagingService.java:948 - Message-to-self TYPE:REQUEST_RESPONSE VERB:REQUEST_RESPONSE going over MessagingService
TRACE [RequestResponseStage-4] 2017-07-21 14:27:37,377 PrepareCallback.java:64 - Prepare response PrepareResponse(true, Commit(bdbe3ea0-6e20-11e7-bc6a-52488cbcfc11, [analytics.monitored_compliance_rules] key=2 columns=[[] | [days_processed days_to_process state]]
Row: id=4c6ddcbe-c3f7-4287-addc-bec3f7628718 | days_processed=0, days_to_process=180, state=initializing), Commit(13814000-1dd2-11b2-8080-808080808080, [analytics.monitored_compliance_rules] key=2 columns=[[] | []])) from /172.18.0.4
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,378 ReadCallback.java:101 - Blockfor is 1; setting up requests to /172.18.0.4
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,378 AbstractReadExecutor.java:116 - reading data locally
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,379 ReadCallback.java:147 - Read: 10 ms.
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,380 MessagingService.java:945 - /172.18.0.4 sending PAXOS_PROPOSE to 3264@/172.18.0.4
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,380 MessagingService.java:948 - Message-to-self TYPE:MUTATION VERB:PAXOS_PROPOSE going over MessagingService
TRACE [MutationStage-2] 2017-07-21 14:27:37,381 MessagingService.java:945 - /172.18.0.4 sending REQUEST_RESPONSE to 3264@/172.18.0.4
TRACE [MutationStage-2] 2017-07-21 14:27:37,383 MessagingService.java:948 - Message-to-self TYPE:REQUEST_RESPONSE VERB:REQUEST_RESPONSE going over MessagingService
TRACE [RequestResponseStage-2] 2017-07-21 14:27:37,383 ProposeCallback.java:62 - Propose response true from /172.18.0.4
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,383 Tracing.java:188 - request complete
TRACE [Native-Transport-Requests-3] 2017-07-21 14:27:37,383 Message.java:535 - Responding: ROWS [[applied](analytics, monitored_compliance_rules), org.apache.cassandra.db.marshal.BooleanType]
| true
---, v=4/v4
失败不会在驱动程序中返回异常。它只是完全无声地失败。
为什么这种删除有时不会发生?这是否表明Cassandra本身存在某种错误?
答案 0 :(得分:0)
这里有一些问题。
我在Cassandra中运行DELETE查询。这与几个具有IF NOT EXISTS子句的UPDATE查询同时发生。预期的行为是当DELETE到达时,它将被执行,然后后续的UPDATE将不会执行,因为IF NOT EXISTS子句将解析为删除将发生的真实。
0)2
可能会删除该节点,然后DELETE
将为true,因此它会发出IF NOT EXISTS
,这实际上是一个UPSERT(如果不存在则插入),所以根据你的描述(如果它没有拼写错误),它正在做正确的事情?
第1行收到删除但未处理。
更新在第2行收到并成功发生,因为IF NOT NOT EXISTS子句解析为true,因为删除从未发生过。
1)您的查询使用CL:UPDATE
,这意味着在返回客户端之前,修改会被单个节点激活。您无法保证任何其他节点实际确认写入,更不用说多数。此外,即使您向同一协调员发出查询,协调员也可以将它们发送到不同的副本。
2)日志行并不表示写入实际命中memtable的顺序(这需要写入commitlog,这可能不会以您期望的方式排序)。