ByteHouse 作为一款 MPP 架构的分布式数据库,为了实现数据的均衡存储和查询的均衡分发,每张表的定义必须在每个节点上都存在且一致。
本文将详细介绍在 ByteHouse 中,当表状态出现“缺损”和“冲突”时的解决步骤。
表状态反映了表在集群中的分布状态,具体描述如下:
您可以在 ByteHouse 控制台”数据管理 “页面,查看到库表的状态。
表缺损状态产生的原因,常见于建表时未带上“on cluster”语法,致使部分节点上未同步。
SELECT table_name, create_table_query, host_address from system.clusters as clusters left join ( SELECT name as table_name, create_table_query, host() AS node FROM cluster(<cluster_name>,system,tables) where database = '<table>' and (name = '<table_name>' or name = '<table_name_local>') ) as systable on clusters.host_address = systable.node;
例如,defalut库中,存在一张test表为缺损状态。
SELECT other_nodes.name as table_name, if(other_node_sql=first_node_sql,'same','diff') AS status, other_nodes.create_table_query AS other_node_sql, first_node.create_table_query AS first_node_sql, other_nodes.node FROM ( SELECT name, create_table_query, host() AS node FROM cluster('bytehouse_cluster_test', 'system', 'tables') WHERE database = '<db_name>' AND (name = '<table_name_local>' or name = '<table_name>') ) AS other_nodes LEFT JOIN ( SELECT name, create_table_query FROM system.tables WHERE database = '<db_name>' (name = '<table_name_local>' or name = '<table_name>') ) AS first_node ON other_nodes.name = first_node.name ORDER BY name;
如果有不一致,则:
SELECT name AS column_name, type AS column_type, host() AS node_name FROM cluster('bytehouse_cluster_test','system','columns') WHERE database = '<db_name>' AND (table = '<table_name>' or table = '<table_name_local>') ORDER BY column_name, node_name;
如果有不一致,则:
通过以上步骤,我们可以解决 ByteHouse 中表状态异常的问题,确保表在集群中的分布正常,从而提高数据库的性能和稳定性。