3

我有从另一个 cassandara 数据文件夹复制的所有键空间和表,如何在我的 cassandara 节点中恢复它。

我没有通常需要恢复的快照。

4

2 回答 2

3

您可以使用 Cassandra Bulk Loader 来完成此操作。

假设打包安装(使用默认数据和 bin 位置),请从您的一个节点尝试此操作:

$ sstableloader -d hostname1,hostname2 /var/lib/cassandra/data/yourKeyspaceName/tableName/

查看Bulk Loader 上的文档以获取更多详细信息。

于 2015-03-26T19:07:34.113 回答
2

你可以这样做,但是:

  1. 您需要知道要恢复的所有表的架构。如果您不知道这一点,请使用 sstable2json(下面的示例,但这可能很棘手,需要了解 sstable2json 的格式)

  2. 您将必须启动一个新节点,使用从 1 派生的模式创建键空间及其表,然后使用 Aaron (BryceAtNetwork23) 的文档中描述的 BulkLoader。

使用 sstable2json 检索模式(离线进程)的示例,此示例假设您的键空间名称为test并且表名为example1

sstable2json /var/lib/cassandra/data/test/example1-55639910d46a11e4b4335dbb0aaeeb24/test-example1-ka-1-Data.db

// output:
WARN  10:25:34 JNA link failure, one or more native method will be unavailable.
[
{"key": "7d700500-d46b-11e4-b433-5dbb0aaeeb24",    <-- key = bytes of what is in the PRIMARY KEY()
 "cells": [["coolguy:","",1427451885901681],       <-- cql3 row marker (empty cell that tells us table was created using cql3)
           ["coolguy:age","29",1427451885901681],  <-- age
           ["coolguy:email:_","coolguy:email:!",1427451885901680,"t",1427451885],        <-- collection cell marker 
           ["coolguy:email:6367406d61696c2e6e6574","",1427451885901681],                 <-- first entry in collection 
           ["coolguy:email:636f6f6c677579383540676d61696c2e636f6d","",1427451885901681], <-- second entry in collection
           ["coolguy:password","xQajKe2fa?af",1427451885901681]]},                       <-- another text field for password
{"key": "52641f40-d46b-11e4-b433-5dbb0aaeeb24",
 "cells": [["lyubent:","",1427451813663728],
           ["lyubent:age","109",1427451813663728],
           ["lyubent:email:_","lyubent:email:!",1427451813663727,"t",1427451813],
           ["lyubent:email:66616b65406162762e6267","",1427451813663728],
           ["lyubent:email:66616b6540676d61696c2e636f6d","",1427451813663728],
           ["lyubent:password","password",1427451813663728]]}
]

以上相当于:

CREATE TABLE test.example1 (
    id timeuuid,
    username text,
    age int,
    email set<text>,
    password text,
    PRIMARY KEY (id, username)
) WITH CLUSTERING ORDER BY (username ASC)
// the below are settings that you have no way of knowing,
// unless you are hardcore enough to start digging through
// system tables with the debug tool, but this is beyond
// the scope of the question.
    AND bloom_filter_fp_chance = 0.01
    AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
    AND comment = ''
    AND compaction = {'min_threshold': '4', 'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32'}
    AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    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 = '99.0PERCENTILE';

您可以清楚地看到,用户名和密码在翻译中丢失了,因为它们是密钥,但是您可以根据所有单元格在上述两个条目中预先附加的部分:这些例子是coolguy:和lyubent:。继续进行此操作,您知道它们的密钥由 PRIMARY KEY(某事?,用户名文本)组成。如果你幸运的话,你的主键会很简单,从中调试模式也很简单,如果不把它贴在这里,我们会看看我们能走多远。

于 2015-03-27T10:34:00.690 回答