卡桑德拉墓碑穿越门槛

时间:2019-02-16 03:07:35

标签: cassandra tombstone

在日志中,我看到了墓碑警告阈值。

Read 411 live rows and 1644 tombstone cells for query SELECT * FROM ks.tbl WHERE key = XYZ LIMIT 5000 (see tombstone_warn_threshold)

这是Cassandra 3.11.3,我看到此表有2个sstables,分区XYZ仅存在于一个文件中。现在,我使用sstabledump将这个sstable转储到json中。我只提取了该分区的数据,发现其中只有411行。而且它们都是活动/实时记录,所以我不知道这些墓碑来自哪里?

此表具有收集列,并且在插入收集列时有单元格逻辑删除。在显示的警告中,收集单元的墓碑是否算作墓碑单元?

进行了一次小型测试,以查看收集的墓碑是否被视为墓碑,但事实并非如此。所以想知道我上面的查询中的那些墓碑来自哪里。

CREATE TABLE tbl (
    col1 text,
    col2 text,
    c1 int,
    col3 map<text, text>,
    PRIMARY KEY (col1, col2)
) WITH CLUSTERING ORDER BY (col2 ASC)

cassandra@cqlsh:dev_test> insert into tbl (col1 , col2 , c1, col3 ) values('3','3',3,{'key':'value'});
cassandra@cqlsh:dev_test> select * from tbl where col1 = '3';
 col1 | col2 | c1 | col3
----------------+----------+----+------------------
              3 |        3 |  3 | {'key': 'value'}
(1 rows)

Tracing session: 4c2a1894-3151-11e9-838d-29ed5fcf59ee
 activity                                                                                 | timestamp                  | source        | source_elapsed | client
------------------------------------------------------------------------------------------+----------------------------+---------------+----------------+-----------
                                                                       Execute CQL3 query | 2019-02-15 18:41:25.145000 | 10.216.1.1 |              0 | 127.0.0.1
                  Parsing select * from tbl where col1 = '3'; [CoreThread-3]              | 2019-02-15 18:41:25.145000 | 10.216.1.1 |            177 | 127.0.0.1
                                                       Preparing statement [CoreThread-3] | 2019-02-15 18:41:25.145001 | 10.216.1.1 |            295 | 127.0.0.1
                                        Reading data from [/10.216.1.1] [CoreThread-3]    | 2019-02-15 18:41:25.146000 | 10.216.1.1 |            491 | 127.0.0.1
                                Executing single-partition query on tbl [CoreThread-2]    | 2019-02-15 18:41:25.146000 | 10.216.1.1 |            770 | 127.0.0.1
                                              Acquiring sstable references [CoreThread-2] | 2019-02-15 18:41:25.146000 | 10.216.1.1 |            897 | 127.0.0.1
 Skipped 0/1 non-slice-intersecting sstables, included 0 due to tombstones [CoreThread-2] | 2019-02-15 18:41:25.146000 | 10.216.1.1 |           1096 | 127.0.0.1
                                 Merged data from memtables and 1 sstables [CoreThread-2] | 2019-02-15 18:41:25.146000 | 10.216.1.1 |           1235 | 127.0.0.1
                                    Read 1 live rows and 0 tombstone cells [CoreThread-2] | 2019-02-15 18:41:25.146000 | 10.216.1.1 |           1317 | 127.0.0.1
                                                                         Request complete | 2019-02-15 18:41:25.146529 | 10.216.1.1 |           1529 | 127.0.0.1
[root@localhost tbl-8aaa6bc1315011e991e523330936276b]# sstabledump aa-1-bti-Data.db 
[
  {
    "partition" : {
      "key" : [ "3" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 41,
        "clustering" : [ "3" ],
        "liveness_info" : { "tstamp" : "2019-02-15T18:36:16.838103Z" },
        "cells" : [
          { "name" : "c1", "value" : 3 },
          { "name" : "col3", "deletion_info" : { "marked_deleted" : "2019-02-15T18:36:16.838102Z", "local_delete_time" : "2019-02-15T18:36:17Z" } },
          { "name" : "col3", "path" : [ "key" ], "value" : "value" }
        ]
      }
    ]
  }```

1 个答案:

答案 0 :(得分:0)

如果您使用相同的主键插入集合数据(地图/列表/集合),Cassandra将不知道先前的数据是否存在,而只是插入一个逻辑删除以防止与先前版本意外合并。如果更新完整集合而不是对集合进行更新操作,也会发生相同的情况。您可以在以下博客文章(12)中找到更多信息。

如果您不需要对集合进行部分更新,那么最好使用冻结的集合:

  • 如果您更新/替换它们,则不会为其生成墓碑
  • 它们可以更有效地保存在磁盘上并从磁盘上读取。
相关问题