在安装目录 /bin 和 tools/bin 目录中有很多工具可以直接处理一个 Cassandra 节点文件系统中的SSTable 数据文件。 这些文件的扩展名为 .db。
在正常情况下,你可能不需要经常使用这些工具,不过它们对于调试和更好地理解Cassandra的数据存储如何工作很有帮助。Cassandra不再本地主机上运行时,必须运行修改SSTable的工具(如 sstablelevelreset、sstablerepairedset、sstablesplit、sstableofflinerelevel)
sstabledump
以JSON格式将给定SSTable的内容转储到标准输出。 您必须提供一个sstable。 在执行此工具之前,必须停止Cassandra,否则将出现意外结果。注意:脚本不会验证Cassandra是否已停止。 -d CQL row per line internal representation -e Enumerate partition keys only -k <arg> Partition key -x <arg> Excluded partition key(s) -t Print raw timestamps instead of iso8601 date strings -l Output each row as a separate JSON object
sstableexpiredblockers
工具会找出阻止删除一个SSTable的阻塞SSTable,这个类会输出阻塞其他SSTable被删除的所有SSTable,是你能确定为什么给定的SSTable还在磁盘上。
如果表的sstables存在,但是没有任何表的数据比过期sstable中最新的逻辑碑旧,则脚本将不返回任何内容。
否则,脚本将返回过期的sstables,后面是被阻止的sstables的列表。
sstablelevelreset
工具将一组给定SSTable的级别重置为0,这就要求下一个合并操作中要合并这些SSTable。
如果设置了LeveledCompactionStrategy,则此脚本可用于在给定的一组sstables上将level重置为0。例如,如果要更改最小sstable大小,并因此使用此新配置重新启动压缩过程,则此选项非常有用。
请参阅http://cassandra.apache.org/doc/latest/operating/compaction.html#leveled compaction strategy,以了解如何在该压缩策略中使用级别。
在执行此工具之前,必须停止Cassandra,否则将出现意外结果。注意:脚本不会验证Cassandra是否已停止。
sstableloader
如果拓扑,令牌区间或副本因子有任何变化,就需要使用loader工具加载数据。
将目录<dir_path>中的sstables大容量加载到配置的集群。<dir_path>的父目录用作目标键空间/表名。例如,要将名为ma-1-big-Data.db的sstable加载到keyspace1/standard1中,您需要将文件ma-1-big-Data.db和ma-1-big-Index.db放在目录/path/to/keyspace1/standard1/中。该工具将创建新的sstables,并且不会清理复制的文件。
下面列出的几个选项并没有按预期工作,在这些情况下,针对特定的用例提到了解决方法。
为了避免在读取时压缩要加载的sstable文件,请将这些文件放置在数据目录之外的备用keyspace/table路径中。
参考:https://issues.apache.org/jira/browse/CASSANDRA-1278
在执行此工具之前,必须停止Cassandra,否则将出现意外结果。注意:脚本不会验证Cassandra是否已停止。
sstableutil
工具可以列出应指定表明的 SSTable 文件
sstablemetadata
将有关sstable的信息从相关的Statistics.db和Summary.db文件打印到标准输出。 参考:https://issues.apache.org/jira/browse/CASSANDRA-7159和https://issues.apache.org/jira/browse/CASSANDRA-10838 在执行此工具之前,必须停止Cassandra,否则将出现意外结果。注意:脚本不会验证Cassandra是否已停止。 SSTable prefix of the sstable filenames related to this sstable Partitioner partitioner type used to distribute data across nodes; defined in cassandra.yaml Bloom Filter FP precision of Bloom filter used in reads; defined in the table definition Minimum timestamp minimum timestamp of any entry in this sstable, in epoch microseconds Maximum timestamp maximum timestamp of any entry in this sstable, in epoch microseconds SSTable min local deletion time minimum timestamp of deletion date, based on TTL, in epoch seconds SSTable max local deletion time maximum timestamp of deletion date, based on TTL, in epoch seconds Compressor blank (-) by default; if not blank, indicates type of compression enabled on the table TTL min time-to-live in seconds; default 0 unless defined in the table definition TTL max time-to-live in seconds; default 0 unless defined in the table definition First token lowest token and related key found in the sstable summary Last token highest token and related key found in the sstable summary Estimated droppable tombstones ratio of tombstones to columns, using configured gc grace seconds if relevant SSTable level compaction level of this sstable, if leveled compaction (LCS) is used Repaired at the timestamp this sstable was marked as repaired via sstablerepairedset, in epoch milliseconds Replay positions covered the interval of time and commitlog positions related to this sstable totalColumnsSet number of cells in the table totalRows number of rows in the table Estimated tombstone drop times approximate number of rows that will expire, ordered by epoch seconds Count Row Size Cell Count two histograms in two columns; one represents distribution of Row Size and the other represents distribution of Cell Count Estimated cardinality an estimate of unique values, used for compaction EncodingStats* minTTL in epoch milliseconds EncodingStats* minLocalDeletionTime in epoch seconds EncodingStats* minTimestamp in epoch microseconds KeyType the type of partition key, useful in reading and writing data from/to storage; defined in the table definition ClusteringTypes the type of clustering key, useful in reading and writing data from/to storage; defined in the table definition StaticColumns a list of the shared columns in the table RegularColumns a list of non-static, non-key columns in the table
sstableofflinerelevel
当使用LeveledCompactionStrategy时,sstables可能会在最近引导的节点上停留在L0,并且压缩可能永远不会赶上。此工具用于将sstables提升到尽可能高的级别。 参考:https://issues.apache.org/jira/browse/CASSANDRA-8301 这样做的方式是:sstables按其最后一个标记存储。给定这样的原始级别(注意,[]表示令牌边界,而不是磁盘上的sstable大小;所有sstable都是相同的大小):
sstablerepairedset
在某些环境中,对于大数据量,修复可能需要很长时间。使用此工具可以在给定的一组sstables上设置repairedAt状态,以便在需要时只能在未修复的sstables上运行修复。 请注意,运行修复(例如,通过nodetool修复)不会设置此元数据的状态。只有通过此工具设置此元数据的状态才能执行此操作。 参考:https://issues.apache.org/jira/browse/CASSANDRA-5351 在执行此工具之前,必须停止Cassandra,否则将出现意外结果。注意:脚本不会验证Cassandra是否已停止。
sstablescrub
可以更有效地从SSTable文件删除已破坏的数据。如果这个工具删除了已破坏的行,就需要运行一个修复。
sstablesplit
工具用来将SSTable文件划分为不超过指定最大大小的多个SSTable。如果一个主合并生成大量的表,这会很有用。否则这些表可能很长时间都无法合并。
sstableupgrade
将给定表(或快照)中的sstables升级到当前版本的Cassandra。此过程通常在Cassandra版本升级后完成。此操作将重写指定表中的sstables,以匹配当前安装的Cassandra版本。sstableupgrade命令还可用于将sstables降级到以前的版本。
快照选项将只升级指定的快照。在尝试还原在比Cassandra当前运行的主版本旧的主版本中拍摄的快照之前,需要升级快照。这将替换给定快照中的文件,并断开到活动sstables的任何硬链接。
在执行此工具之前,必须停止Cassandra,否则将出现意外结果。注意:脚本不会验证Cassandra是否已停止。
sstableverify
检验对应table的SSTable文件,找出存在错误或数据破坏的文件。 检查s s table是否有错误或损坏,以查找所提供的表。 参考:https://issues.apache.org/jira/browse/CASSANDRA-5791 在执行此工具之前,必须停止Cassandra,否则将出现意外结果。注意:脚本不会验证Cassandra是否已停止。