【问题标题】:Restore not restoring data all the time恢复不是一直恢复数据
【发布时间】:2016-10-19 17:01:23
【问题描述】:

我在容器中安装了 cassandra 3.7 并由 kubernetes 管理 我创建了一个复制因子为 3 的键空间 cathy1

在 node1 上的 cassandra 容器内,我创建了一个键空间 cathy1,如下所示:

CREATE KEYSPACE cathy1  WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3};

CREATE TABLE cathy1.employees(emp_id int PRIMARY KEY,emp_name text);
INSERT INTO cathy1.employees(emp_id,emp_name) VALUES (1,'cathy');
INSERT INTO cathy1.employees(emp_id,emp_name) VALUES (2,'jon');

所以每个节点都拥有 100% 的数据

我在每个节点上运行cqlsh -f list_tables

 emp_id | emp_name
--------+----------
      1 |    cathy 
      2 |      jon 
(2 rows)

我在节点 2 上运行:

nodetool snapshot -t mycathy1-node2 cathy1

我在cassandra/data/cathy1/employees* /snapshots 下看到一个目录mycathy1-node2,其中包含以下内容:

-rw-r--r--  1 root root   32 Oct 18 20:27 manifest.json
-rw-r--r--  2 root root   43 Oct 18 20:22 mb-12-big-CompressionInfo.db 
-rw-r--r--  2 root root   96 Oct 18 20:22 mb-12-big-Data.db
-rw-r--r--  2 root root    9 Oct 18 20:22 mb-12-big-Digest.crc32 
-rw-r--r--  2 root root   16 Oct 18 20:22 mb-12-big-Filter.db 
-rw-r--r--  2 root root   32 Oct 18 20:22 mb-12-big-Index.db 
-rw-r--r--  2 root root 4610 Oct 18 20:23 mb-12-big-Statistics.db 
-rw-r--r--  2 root root   56 Oct 18 20:22 mb-12-big-Summary.db 
-rw-r--r--  2 root root   92 Oct 18 20:22 mb-12-big-TOC.txt 

然后我截断表格

cqlsh -e "truncate cathy1.employees"

此时在任何节点上都没有cassandra/data/cathy1/employees* 下的文件
仅保留快照目录

我在每个节点上运行cqlsh -f list_tables

 emp_id | emp_name 
--------+---------- 
(0 rows) 

我在节点 2 上运行修复:

nodetool repair cathy1 

成功完成
然后仍然在节点 2

cd cassandra/data/employees* 
cp ./snapshots/mycathy1-node2/* . 

-rw-r--r--  1 root root   32 Oct 18 20:34 manifest.json 
-rw-r--r--  1 root root   43 Oct 18 20:34 mb-12-big-CompressionInfo.db  
-rw-r--r--  1 root root   96 Oct 18 20:34 mb-12-big-Data.db 
-rw-r--r--  1 root root    9 Oct 18 20:34 mb-12-big-Digest.crc32 
-rw-r--r--  1 root root   16 Oct 18 20:34 mb-12-big-Filter.db 
-rw-r--r--  1 root root   32 Oct 18 20:34 mb-12-big-Index.db 
-rw-r--r--  1 root root 4610 Oct 18 20:34 mb-12-big-Statistics.db 
-rw-r--r--  1 root root   56 Oct 18 20:34 mb-12-big-Summary.db 
-rw-r--r--  1 root root   92 Oct 18 20:34 mb-12-big-TOC.txt 
drwxr-xr-x 16 root root 4096 Oct 18 20:29 snapshots 

然后我运行nodetool refresh employees
我在每个节点上运行 cqlsh -f list_tables

 emp_id | emp_name
--------+----------
(0 rows)

我跑nodetool repair cathy1

仍然没有可见的数据!!!!!!

    Pending Flushes: 0 <br>
            Table: employees <br>
            Space used (live): 4954 <br>
            Space used (total): 4954 <br>
            Space used by snapshots (total): 59873 <br>
            Off heap memory used (total): 32 <br>
            SSTable Compression Ratio: 0.75 <br>
            **Number of keys (estimate): 4** <br>

即使统计数据显示表 cathy1.employees 中有 4 个键

nodetool flush cathy1

使用 cqlsh 仍然没有可见的数据

这是为什么呢?

【问题讨论】:

    标签: cassandra restore


    【解决方案1】:

    您需要在复制快照文件的目录中运行 sstableloader

    sstableloader -d <node_ip> -u cassandra -pw cassandra <directory_location>
    

    注意:如果您的当前目录是您复制快照文件的目录,那么您不需要在字段 directory_location 中放置任何内容。

    有关 sstableloader 的更多详细信息:https://docs.datastax.com/en/cassandra/2.0/cassandra/tools/toolsBulkloader_t.html

    【讨论】:

    • 为什么需要运行 sstableloader?文档说 nodetool refresh 也是如此。
    • 为什么我在 cfstats 中看到员工表的键,但选择 * 显示没有数据?
    • 要备份数据和恢复您可以使用多种方法。您也可以在不拍摄任何快照的情况下备份和恢复数据(COPY TO CSV 和 COPY FROM CSV)。对我来说,我在 sstableloader 的帮助下使用快照成功地备份和恢复了我的数据。它工作正常。
    猜你喜欢
    • 2011-01-27
    • 2011-09-24
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-15
    • 2016-12-30
    相关资源
    最近更新 更多