有时;当我执行DELETE时;它不起作用 .
我的配置:[cqlsh 5.0.1 | Cassandra 3.0.3 | CQL规范3.4.0 |原生协议v4]
cqlsh:my_db> SELECT * FROM conversations WHERE user_id=120 AND conversation_id=2 AND peer_type=1;
user_id | conversation_id | peer_type | message_map
---------+-----------------+-----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
120 | 2 | 1 | {0: {real_id: 68438, date: 1455453523, sent: True}, 1: {real_id: 68437, date: 1455453520, sent: True}, 2: {real_id: 68436, date: 1455453517, sent: True}, 3: {real_id: 68435, date: 1455453501, sent: True}, 4: {real_id: 68434, date: 1455453500, sent: True}, 5: {real_id: 68433, date: 1455453499, sent: True}, 6: {real_id: 68432, date: 1455453498, sent: True}, 7: {real_id: 68431, date: 1455453494, sent: True}, 8: {real_id: 68430, date: 1455453480, sent: True}}
(1 rows)
cqlsh:my_db> DELETE message_map FROM conversations WHERE user_id=120 AND conversation_id=2 AND peer_type=1;
cqlsh:my_db> SELECT * FROM conversations WHERE user_id=120 AND conversation_id=2 AND peer_type=1;
user_id | conversation_id | peer_type | message_map
---------+-----------------+-----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
120 | 2 | 1 | {0: {real_id: 68438, date: 1455453523, sent: True}, 1: {real_id: 68437, date: 1455453520, sent: True}, 2: {real_id: 68436, date: 1455453517, sent: True}, 3: {real_id: 68435, date: 1455453501, sent: True}, 4: {real_id: 68434, date: 1455453500, sent: True}, 5: {real_id: 68433, date: 1455453499, sent: True}, 6: {real_id: 68432, date: 1455453498, sent: True}, 7: {real_id: 68431, date: 1455453494, sent: True}, 8: {real_id: 68430, date: 1455453480, sent: True}}
(1 rows)
CQLSH不会在DELETE指令上返回任何错误,但是如果它没有被考虑在内 .
你知道为什么吗 ?
注意:这是我的表定义:
CREATE TABLE be_telegram.conversations (
user_id bigint,
conversation_id int,
peer_type int,
message_map map<int, frozen<message>>,
PRIMARY KEY (user_id, conversation_id, peer_type)
) WITH CLUSTERING ORDER BY (conversation_id ASC, peer_type ASC)
AND 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';
1 回答
DELETE
语句从表中的一行或多行中删除一个或多个列,如果未指定列,则删除整行 . Cassandra在原子上和孤立地应用选择partition key
.删除列时,不会立即从磁盘中删除该列 . 已删除的列标有
tombstone
,然后在配置的宽限期到期后删除 . 可选的timestamp
定义了新的tombstone
记录 .关于Cassandra中的删除
Cassandra删除数据的方式与关系数据库删除数据的方式不同 . 关系数据库可能会花时间扫描数据以查找过期数据并将其丢弃,或者管理员可能必须按月对过期数据进行分区,例如,以便更快地清除它 . Cassandra列中的数据可以具有可选的到期日期,称为TTL(生存时间) .
要记住删除数据的事实是:
Cassandra不会立即删除标记为从磁盘删除的数据 . 在压缩期间发生删除 .
如果使用sized-tiered或date-tiered压缩策略,则可以通过manually starting the compaction process立即删除数据 . 在此之前,请了解该过程的文档缺点 .
如果您不经常运行node repair,则可以重新显示已删除的列 .
为什么删除的数据可以重新出现
在您的情况下,
compaction
是sized-tiered
. 所以请尝试压实过程 .试试吧
此命令在使用
SizeTieredCompactionStrategy
或DateTieredCompactionStrategy
的表上启动压缩过程 . 您可以指定用于压缩的键空间 . 如果未指定keyspace
,则为nodetool
命令使用current keyspace
. 您可以为compaction
指定一个或多个表 . 如果未指定表,则会对键空间中的所有表进行压缩 . 这被称为 major compaction . 如果确实指定了表,则会发生指定表的压缩 . 这被称为 minor compaction . 主要压缩将所有现有SSTable合并为单个SSTable . 在压缩过程中,磁盘空间使用和磁盘I / O会出现临时峰值,因为旧的和新的SSTable共存 . 主要压缩可能会导致相当大的磁盘I / O.