Cassandra-行を削除できません

Aug 22 2020

Casandraテーブルから特定の行を1つ削除したいのですが、削除できません。これ以外はテーブルから削除できます。私は休眠削除クエリを入れましたが、何も起こりません:

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>

これがこの表のシェマです:

    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';

なにか提案を?

回答

3 NadavHar'El Aug 22 2020 at 18:36

この奇妙な状況は、行がはるか将来のタイムスタンプで作成された場合に発生する可能性があります。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日午前0時GMT)からのマイクロ秒単位です。それが将来の場合、私はあなたの問題を正しく推測しました。この場合、この行を実際に削除するには、次のような操作を行う必要があります。

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

ここで、タイムスタンプ「111111111」は、表示されたタイムスタンプよりも(少なくとも)1つ大きい数値selectです。