ClickHouse副本节点数据损坏恢复

参考链接:https://blog.csdn.net/qq_42082701/article/details/127771766

参考链接:https://kb.altinity.com/altinity-kb-setup-and-maintenance/suspiciously-many-broken-parts/

shell 复制代码
# 背景
	CK配置为1分片2副本

# 配置参数,这里我们将max_suspicious_broken_parts设置为0
<?xml version="1.0"?>
<yandex>
     <merge_tree>
         <max_suspicious_broken_parts>0</max_suspicious_broken_parts>
     </merge_tree>
</yandex>
	

# 创建表/clickhouse/tables/{shard}/test,{shard}在配置各个节点的配置文件中可能不同,这里不使用占位符
	create database test on cluster default;
	create table test.test on cluster default (A UInt32) ENGINE = ReplicatedMergeTree('/clickhouse/tables/shard0/test', '{replica}') order by A settings max_suspicious_broken_parts=0;
	insert into test.test select number from numbers(100000);
	

# 分离表并使数据损坏
	detach table test.test;

# 损坏数据,/var/lib/clickhouse/data/default/test/all_*** 使数据文件损坏:对 2 个或更多数据文件重复此操作。
I have no name!@clickhouse-0-0:/$ ls /var/lib/clickhouse/data/test/test/all_0_0_0
checksums.txt  columns.txt  count.txt  data.bin  data.mrk3  default_compression_codec.txt  primary.idx

I have no name!@clickhouse-0-0:/$ echo > /var/lib/clickhouse/data/test/test/all_0_0_0/data.mrk3
I have no name!@clickhouse-0-0:/$ echo > /var/lib/clickhouse/data/test/test/all_0_0_0/data.bin

# 附上表格
clickhouse-0-0.clickhouse-0.maas.svc.cluster.local :) attach table test.test;
ATTACH TABLE test.test
Query id: 6cc3e7d7-8439-4f04-bc6a-5231ffce3ecb
0 rows in set. Elapsed: 0.013 sec. 
Received exception from server (version 22.9.5):
Code: 231. DB::Exception: Received from localhost:9000. DB::Exception: Suspiciously many (1 parts, 308.00 B in total) broken parts to remove while maximum allowed broken parts count is 0. You can change the maximum value with merge tree setting 'max_suspicious_broken_parts' in <merge_tree> configuration section or in table settings in .sql file (don't forget to return setting back to default value). (TOO_MANY_UNEXPECTED_DATA_PARTS)
  • 方法一
shell 复制代码
# 设置force_restore_data标志,然后重启Clickhouse,
# 在 ClickHouse Keeper 中使用任意内容创建节点/path_to_table/replica_name/flags/force_restore_data,或运行命令来恢复所有复制表
# 启动时,服务器删除这些标志并开始恢复
I have no name!@clickhouse-0-0:/$ touch /var/lib/clickhouse/flags/force_restore_data

# 重启后,正常启动,不报错,查询数据是否从另外一个副本集中copy过来

# 异常数据被移到了detached目录
I have no name!@clickhouse-0-0:/$ ls /var/lib/clickhouse/data/test/test/detached/
broken-on-start_all_0_0_0
  • 方法二
shell 复制代码
# 如果可以接受数据丢失,可以将参数max_suspicious_broken_parts设置得大一些
<?xml version="1.0"?>
<yandex>
     <merge_tree>
         <max_suspicious_broken_parts>1000</max_suspicious_broken_parts>
     </merge_tree>
</yandex>
相关推荐
better_liang2 小时前
每日Java面试场景题知识点之-分布式事务处理
java·微服务·面试·springcloud·分布式事务
马克学长2 小时前
SSM青岛恒星科技学院机房管理系统0k0u9(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面
数据库·科技·ssm 框架·教育信息化·机房管理系统·青岛恒星科技学院
7***68433 小时前
Spring Boot 从 2.7.x 升级到 3.3注意事项
数据库·hive·spring boot
L***d6704 小时前
Spring Boot 各种事务操作实战(自动回滚、手动回滚、部分回滚)
java·数据库·spring boot
凌波粒4 小时前
Springboot基础教程(3)--自动装配原理/静态资源处理/欢迎页
java·spring boot·后端
java_logo4 小时前
MySQL Server Docker 容器化部署指南
linux·运维·数据库·docker·容器
likuolei4 小时前
XSL-FO 软件
java·开发语言·前端·数据库
凌波粒4 小时前
SpringBoot基础教程(2)--yaml/配置文件注入/数据校验/多环境配置
java·spring boot·后端·spring
p***95004 小时前
Springboot3 Mybatis-plus 3.5.9
数据库·oracle·mybatis
CS_浮鱼4 小时前
【MySQL】InnoDB存储引擎
数据库·mysql