首页 > 解决方案 > Cassandra - 无法删除行

问题描述

我想从 Casandra 表中删除一个特定的行,但我不能。除了这个,我可以从表中删除任何其他人。我放了休闲删除查询,但没有任何反应:

cqlsh> delete from sales.tbl where orderid=999999 and orderdate='2019/01/01';
cqlsh>
cqlsh> select * from sales.tbl where orderid=999999 and orderdate='2019/01/01';

 orderid | orderdate  | country | itemtype | orderpriority | region        | saleschannel | shipdate   | totalcost | totalprofit | totalrevenue | unitcost | unitprice | unitssold
---------+------------+---------+----------+---------------+---------------+--------------+------------+-----------+-------------+--------------+----------+-----------+-----------
  999999 | 2019/01/01 |  Canada |    Stuff |             N | North America |      Offline | 2019/01/02 |       100 |           0 |          100 |        0 |         1 |         1

(1 rows)
cqlsh>

这是这张桌子的shema:

    CREATE TABLE sales.tbl1 (
        orderid bigint,
        orderdate text,
        country text,
        itemtype text,
        orderpriority text,
        region text,
        saleschannel text,
        shipdate text,
        totalcost float,
        totalprofit float,
        totalrevenue float,
        unitcost float,
        unitprice float,
        unitssold int,
        PRIMARY KEY (orderid, orderdate) ) WITH CLUSTERING ORDER BY (orderdate ASC)
        AND bloom_filter_fp_chance = 0.01
        AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
        AND comment = ''
        AND compaction = {'class': 'SizeTieredCompactionStrategy'}
        AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
        AND crc_check_chance = 1.0
        AND dclocal_read_repair_chance = 0.1
        AND default_time_to_live = 0
        AND gc_grace_seconds = 1
        AND max_index_interval = 2048
        AND memtable_flush_period_in_ms = 0
        AND min_index_interval = 128
        AND read_repair_chance = 0.0
        AND speculative_retry = '99.0PERCENTILE';

有什么建议吗?

标签: linuxcassandrascylla

解决方案


如果该行是在很远的将来使用时间戳创建的,则可能会发生这种奇怪的情况。在 Cassandra 和 Scylla 中,客户端可以为每次写入指定一个时间戳,并且最新的时间戳获胜 - 无论更新的实际时间顺序如何。

例如,假设一个客户端写入了一个时间戳为 1000 的行,稍后另一个客户端在时间戳 900 发送了一个删除。该删除不会删除任何内容 - 写入被认为是在删除之后发生的,因此删除被简单地忽略。

这可能正是发生在您身上的事情:一个时钟配置错误的客户端使用了这个时钟,并在很远的将来创建了一个带有时间戳的行。当您现在尝试delete from sales.tbl where orderid=999999 and orderdate='2019/01/01'; 时,当前时间用作此次删除的时间戳,并且它比未来的时间戳更早,因此删除被忽略。

要检查是否是这种情况,请尝试

select writetime(region) from sales.tbl where orderid=999999 and orderdate='2019/01/01';

这将显示项目中“区域”列(例如)的写入时间(即时间戳)。这个时间是自 UNIX 纪元(格林威治标准时间午夜,1970 年 1 月 1 日)以来的微秒。如果是在未来,那么我正确地猜到了你的问题。如果是这种情况,那么要真正删除这一行,您将需要执行类似的操作

delete from sales.tbl using timestamp 111111111 where orderid=999999 and orderdate='2019/01/01';

其中时间戳“111111111”是一个(至少)比select显示给您的时间戳高一的数字。


推荐阅读