【问题标题】:Not able to to delete or update a record in Cassandra 3.11.2 using cqlsh无法使用 cqlsh 删除或更新 Cassandra 3.11.2 中的记录
【发布时间】:2020-08-09 15:48:04
【问题描述】:

我在 Cassandra 中有一个具有以下架构的列族。

CREATE TABLE app_documents (
    key text PRIMARY KEY,
    created_at timestamp,
    created_by text,
    details text,
    id text
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': '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 = 864000
    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 = '99PERCENTILE';
CREATE INDEX app_documents_id_idx ON app_documents (id);

在这个 CF 中,我有一个键为“abc”的记录,我可以使用查询来选择记录

select * from app_documents WHERE key = 'abc';

现在我正在尝试使用以下查询删除或更新它。

delete from app_documents WHERE key = 'abc';
update app_documents set created_by = 'pd' where key = 'abc';

但上述命令对记录没有影响。表中的其他记录按预期工作,但只有这条记录有点卡在这种状态。

我的 Cassandra 设置只有一个节点。

【问题讨论】:

  • 你可以select writetime(created_by) from app_documents WHERE key = 'abc';吗?
  • @AlexOtt 这里是输出 writetime(created_by) ----------- 1597006849482020
  • 似乎是未来的时间戳

标签: cassandra nosql


【解决方案1】:

通常当数据库中的数据有未来的时间戳时会发生这种情况,并且通过select writetime(created_by) from app_documents WHERE key = 'abc'; 进行确认 - 记录的时间戳为 8 月 9 日 - 未来 2 天。获得此类条目的通常原因是:

  • 客户端计算机上的时钟已关闭一段时间 - 始终建议在客户端计算机上也运行 ntp,而不仅仅是在 Cassandra 服务器上
  • 时间戳由客户端显式设置 - 这可能导致不可预知的行为,并且显式时间戳应仅在需要时设置,例如业务逻辑,但即使在这种情况下,进行一些检查以防止插入远在未来的时间戳

【讨论】:

  • 嗨@Alex:根据你的建议,我可以通过明确设置时间戳来删除条目。但是删除后前夕,我无法使用相同的键创建新记录。对此有何建议?
猜你喜欢
  • 2015-12-22
  • 2017-12-31
  • 2018-07-30
  • 1970-01-01
  • 2017-08-14
  • 2017-09-28
  • 2016-02-14
  • 1970-01-01
  • 2016-06-30
相关资源
最近更新 更多