Cassandra 截断性能

Cassandra truncate performance

我最近听说,cassandra truncate 性能不佳而且是反模式的。但是,我不知道为什么?

所以,我有 2 个问题:

卡桑德拉版本:3.x

来自 cassandra 文档:

Note: TRUNCATE sends a JMX command to all nodes, telling them to delete SSTables that hold the data from the specified table. If any of these nodes is down or doesn't respond, the command fails and outputs a message like the following

因此,运行 truncate 将删除属于您的 cassandra table 的所有 sstable,这将非常快,但必须得到所有节点的确认。根据您的 cassandra.yml 这将在以下时间快照您的数据:

auto_snapshot (Default: true) Enable or disable whether a snapshot is taken of the data before keyspace truncation or dropping of tables. To prevent data loss, using the default setting is strongly advised. If you set to false, you will lose data on truncation or drop.

When creating or modifying tables, you enable or disable the key cache (partition key cache) or row cache for that table by setting the caching parameter. Other row and key cache tuning and configuration options are set at the global (node) level. Cassandra uses these settings to automatically distribute memory for each table on the node based on the overall workload and specific table usage. You can also configure the save periods for these caches globally.

针对您的问题:

  • upserts 会慢很多(当你的 table 中有重要数据时)
  • truncate 根本不写逻辑删除(相反,它会删除 all 上的 all nodes 用于截断的 table ss table秒)