Cassandra 文档

版本

您正在查看预发布版本的文档。

sstabledump

将给定 SSTable 的内容以 JSON 格式转储到标准输出。

您必须提供一个 sstable。

在执行此工具之前,必须停止 Cassandra,否则会导致意外结果。注意:该脚本不会验证 Cassandra 是否已停止。

用法

sstabledump <options> <sstable 文件路径>

-d

每行一个 CQL 行的内部表示

-e

仅枚举分区键

-k <arg>

分区键

-x <arg>

排除的分区键

-t

打印原始时间戳而不是 iso8601 日期字符串

-l

将每行输出为单独的 JSON 对象

如有必要,请先使用 sstableutil 找出表使用的 sstable。

转储整个表

在没有任何选项的情况下转储整个表。

示例

sstabledump /var/lib/cassandra/data/keyspace/eventlog-65c429e08c5a11e8939edf4f403979ef/mc-1-big-Data.db > eventlog_dump_2018Jul26

cat eventlog_dump_2018Jul26
[
  {
    "partition" : {
      "key" : [ "3578d7de-c60d-4599-aefb-3f22a07b2bc6" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 61,
        "liveness_info" : { "tstamp" : "2018-07-20T20:23:08.378711Z" },
        "cells" : [
          { "name" : "event", "value" : "party" },
          { "name" : "insertedtimestamp", "value" : "2018-07-20 20:23:08.384Z" },
          { "name" : "source", "value" : "asdf" }
        ]
      }
    ]
  },
  {
    "partition" : {
      "key" : [ "d18250c0-84fc-4d40-b957-4248dc9d790e" ],
      "position" : 62
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 123,
        "liveness_info" : { "tstamp" : "2018-07-20T20:23:07.783522Z" },
        "cells" : [
          { "name" : "event", "value" : "party" },
          { "name" : "insertedtimestamp", "value" : "2018-07-20 20:23:07.789Z" },
          { "name" : "source", "value" : "asdf" }
        ]
      }
    ]
  },
  {
    "partition" : {
      "key" : [ "cf188983-d85b-48d6-9365-25005289beb2" ],
      "position" : 124
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 182,
        "liveness_info" : { "tstamp" : "2018-07-20T20:22:27.028809Z" },
        "cells" : [
          { "name" : "event", "value" : "party" },
          { "name" : "insertedtimestamp", "value" : "2018-07-20 20:22:27.055Z" },
          { "name" : "source", "value" : "asdf" }
        ]
      }
    ]
  }
]

以更易于管理的格式转储表

使用 -l 选项将每行转储为单独的 JSON 对象。这将使大型数据集的输出更容易操作。参考:issues.apache.org/jira/browse/CASSANDRA-13848

示例

sstabledump /var/lib/cassandra/data/keyspace/eventlog-65c429e08c5a11e8939edf4f403979ef/mc-1-big-Data.db -l > eventlog_dump_2018Jul26_justlines

cat eventlog_dump_2018Jul26_justlines
[
  {
    "partition" : {
      "key" : [ "3578d7de-c60d-4599-aefb-3f22a07b2bc6" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 61,
        "liveness_info" : { "tstamp" : "2018-07-20T20:23:08.378711Z" },
        "cells" : [
          { "name" : "event", "value" : "party" },
          { "name" : "insertedtimestamp", "value" : "2018-07-20 20:23:08.384Z" },
          { "name" : "source", "value" : "asdf" }
        ]
      }
    ]
  },
  {
    "partition" : {
      "key" : [ "d18250c0-84fc-4d40-b957-4248dc9d790e" ],
      "position" : 62
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 123,
        "liveness_info" : { "tstamp" : "2018-07-20T20:23:07.783522Z" },
        "cells" : [
          { "name" : "event", "value" : "party" },
          { "name" : "insertedtimestamp", "value" : "2018-07-20 20:23:07.789Z" },
          { "name" : "source", "value" : "asdf" }
        ]
      }
    ]
  },
  {
    "partition" : {
      "key" : [ "cf188983-d85b-48d6-9365-25005289beb2" ],
      "position" : 124
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 182,
        "liveness_info" : { "tstamp" : "2018-07-20T20:22:27.028809Z" },
        "cells" : [
          { "name" : "event", "value" : "party" },
          { "name" : "insertedtimestamp", "value" : "2018-07-20 20:22:27.055Z" },
          { "name" : "source", "value" : "asdf" }
        ]
      }
    ]
  }

仅转储键

使用 -e 选项仅转储键。

示例

sstabledump /var/lib/cassandra/data/keyspace/eventlog-65c429e08c5a11e8939edf4f403979ef/mc-1-big-Data.db -e > eventlog_dump_2018Jul26_justkeys

cat eventlog_dump_2018Jul26b
[ [ "3578d7de-c60d-4599-aefb-3f22a07b2bc6" ], [ "d18250c0-84fc-4d40-b957-4248dc9d790e" ], [ "cf188983-d85b-48d6-9365-25005289beb2" ]

转储单个键的行

使用 -k 选项转储单个键。

示例

sstabledump /var/lib/cassandra/data/keyspace/eventlog-65c429e08c5a11e8939edf4f403979ef/mc-1-big-Data.db -k 3578d7de-c60d-4599-aefb-3f22a07b2bc6 > eventlog_dump_2018Jul26_singlekey

cat eventlog_dump_2018Jul26_singlekey
[
  {
    "partition" : {
      "key" : [ "3578d7de-c60d-4599-aefb-3f22a07b2bc6" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 61,
        "liveness_info" : { "tstamp" : "2018-07-20T20:23:08.378711Z" },
        "cells" : [
          { "name" : "event", "value" : "party" },
          { "name" : "insertedtimestamp", "value" : "2018-07-20 20:23:08.384Z" },
          { "name" : "source", "value" : "asdf" }
        ]
      }
    ]
  }

在行转储中排除一个或多个键

转储表,但排除使用 -x 选项排除的行。可以使用多个键。

示例

sstabledump /var/lib/cassandra/data/keyspace/eventlog-65c429e08c5a11e8939edf4f403979ef/mc-1-big-Data.db -x 3578d7de-c60d-4599-aefb-3f22a07b2bc6 d18250c0-84fc-4d40-b957-4248dc9d790e  > eventlog_dump_2018Jul26_excludekeys

cat eventlog_dump_2018Jul26_excludekeys
[
  {
    "partition" : {
      "key" : [ "cf188983-d85b-48d6-9365-25005289beb2" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 182,
        "liveness_info" : { "tstamp" : "2018-07-20T20:22:27.028809Z" },
        "cells" : [
          { "name" : "event", "value" : "party" },
          { "name" : "insertedtimestamp", "value" : "2018-07-20 20:22:27.055Z" },
          { "name" : "source", "value" : "asdf" }
        ]
      }
    ]
  }

显示原始时间戳

默认情况下,日期以 iso8601 日期格式显示。使用 -t 选项将以原始时间戳转储数据。

示例

sstabledump /var/lib/cassandra/data/keyspace/eventlog-65c429e08c5a11e8939edf4f403979ef/mc-1-big-Data.db -t -k cf188983-d85b-48d6-9365-25005289beb2 > eventlog_dump_2018Jul26_times

cat eventlog_dump_2018Jul26_times
[
  {
    "partition" : {
      "key" : [ "cf188983-d85b-48d6-9365-25005289beb2" ],
      "position" : 124
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 182,
        "liveness_info" : { "tstamp" : "1532118147028809" },
        "cells" : [
          { "name" : "event", "value" : "party" },
          { "name" : "insertedtimestamp", "value" : "2018-07-20 20:22:27.055Z" },
          { "name" : "source", "value" : "asdf" }
        ]
      }
    ]
  }

在输出中显示内部结构

以反映内部结构的格式转储表。

示例

sstabledump /var/lib/cassandra/data/keyspace/eventlog-65c429e08c5a11e8939edf4f403979ef/mc-1-big-Data.db -d > eventlog_dump_2018Jul26_d

cat eventlog_dump_2018Jul26_d
[3578d7de-c60d-4599-aefb-3f22a07b2bc6]@0 Row[info=[ts=1532118188378711] ]:  | [event=party ts=1532118188378711], [insertedtimestamp=2018-07-20 20:23Z ts=1532118188378711], [source=asdf ts=1532118188378711]
[d18250c0-84fc-4d40-b957-4248dc9d790e]@62 Row[info=[ts=1532118187783522] ]:  | [event=party ts=1532118187783522], [insertedtimestamp=2018-07-20 20:23Z ts=1532118187783522], [source=asdf ts=1532118187783522]
[cf188983-d85b-48d6-9365-25005289beb2]@124 Row[info=[ts=1532118147028809] ]:  | [event=party ts=1532118147028809], [insertedtimestamp=2018-07-20 20:22Z ts=1532118147028809], [source=asdf ts=1532118147028809]