StarRocks 排查单副本表

文章目录

    • [StarRocks 排查单副本表](#StarRocks 排查单副本表)
      • [方式1 查询元数据,检查分区级的副本数](#方式1 查询元数据,检查分区级的副本数)
      • [方式2 SHOW PARTITIONS命令查看 ReplicationNum](#方式2 SHOW PARTITIONS命令查看 ReplicationNum)
      • 修改副本数命令

StarRocks 排查单副本表

方式1 查询元数据,检查分区级的副本数

sql 复制代码
# 方式一 查询元数据,检查分区级的副本数
with v_tmp1 as (
  select
    TABLE_ID, PARTITION_ID, tablet_id, count(*) as cnt
  from
    information_schema.be_tablets
  group by
    TABLE_ID, PARTITION_ID, tablet_id
  having
    count(*) = 1
) 
select /*+ set_var(query_timeout = 20) */
  distinct t1.TABLE_SCHEMA, t1.TABLE_NAME
from information_schema.tables_config t1 
join v_tmp1 t2 on t1.TABLE_ID = t2.TABLE_ID
;

方式2 SHOW PARTITIONS命令查看 ReplicationNum

shell 复制代码
# 方式二 遍历所有库表SHOW PARTITIONS命令查看 ReplicationNum
SHOW  PARTITIONS FROM [db_name.]table_name WHERE ReplicationNum = 1

修改副本数命令

shell 复制代码
# 修改副本数命令
# 修改表基本副本数
ALTER TABLE example_db.my_table SET ("default.replication_num" = "2");
# 单分区副本数
ALTER TABLE example_db.my_table SET ("replication_num" = "2");
# 历史分区副本数
ALTER TABLE example_db.my_table MODIFY PARTITION (*) SET("replication_num"="2");

遍历所有库表执行SHOW PARTITIONS命令

python 复制代码
import pymysql
import logging
logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
                    filemode='a',
                    filename='./sr.log'
                    )

ip = '10.xx'
port = 9030
user = 'xx'
passwd = 'xx'
database = 'information_schema'

class MysqlUtils(object):
    def __init__(self, ip, port, user, passwd, database):
        self.ip = ip
        self.port = port
        self.user = user
        self.passwd = passwd
        self.database = database
        self.conn = None
        self.cur = None
        try:
            self.conn = pymysql.connect(host=self.ip, user=self.user, passwd=self.passwd, port=self.port,
                                        charset='utf8', database=self.database)
        except Exception as e:
            logging.error("连接失败:{}".format(e))
        if self.conn:
            self.cur = self.conn.cursor()

    def close(self):
        if self.cur:
            self.cur.close()
        if self.conn:
            self.conn.close()

    def insert_data(self, sql, data):
        if self.cur:
            # cur = conn.cursor(pymysql.cursors.DictCursor)
            try:
                self.cur.executemany(sql, data)
            except pymysql.Error as e:
                logging.error("executemany执行失败:{}".format(e))
                self.conn.rollback()
                self.conn.close()
            self.conn.commit()


    def select_data(self,sql):
        if self.cur:
            self.cur.execute(sql)
            res = self.cur.fetchall()
            return res


def start():

    obj = MysqlUtils(ip, port, user, passwd, database)
    sql1 = "show databases;"
    dbs = obj.select_data(sql1)  # (('_statistics_',), ('ads_biz',))
    dbs = [d[0] for d in dbs if d[0] not in ('_statistics_','information_schema')]
	resu = list()
    for db in dbs:

        sql2 = "show tables from {}".format(db)
        tables = obj.select_data(sql2)
        tables = [t[0] for t in tables]
        # print(tables)

        for table in tables:
            # sql3 = "show create table `{}`.`{}`".format(db,table)
            # sql3 = """ ALTER TABLE `{}`.`{}` MODIFY PARTITION (*) SET("replication_num"="2"); """ .format(db,table)
            sql3 = "SHOW  PARTITIONS FROM `{}`.`{}` WHERE ReplicationNum = 1".format(db,table)
            logging.info(sql3)
            try:
                res = obj.select_data(sql3)  
            except Exception as e:
                logging.error(e)
            if res:
                resu.append(res)
    obj.close()
相关推荐
镜舟科技5 天前
数据仓库分层 4 层模型是什么?
starrocks·数据仓库·数据治理·bi·物化视图·bitmap 索引
胖胖胖胖胖虎5 天前
记一次 Starrocks be 内存异常宕机
starrocks
鸿乃江边鸟9 天前
Starrocks 物化视图的实现以及在刷新期间能否读数据
java·大数据·starrocks·sql
StarRocks_labs9 天前
StarRocks x Iceberg:云原生湖仓分析技术揭秘与最佳实践
大数据·starrocks·云原生·iceberg·物化视图
鸿乃江边鸟10 天前
Starrocks 怎么计算各个算子的统计信息
大数据·starrocks·sql
鸿乃江边鸟16 天前
Starrocks的CBO基石--统计信息的来源 StatisticAutoCollector
大数据·starrocks·sql
StarRocks_labs16 天前
StarRocks Community Monthly Newsletter (Apr)
数据库·starrocks·数据查询·routine load·stream load
StarRocks_labs21 天前
StarRocks MCP Server 开源发布:为 AI 应用提供强大分析中枢
数据库·starrocks·人工智能·开源·olap·mcp
鸿乃江边鸟21 天前
Starrocks的主键表涉及到的MOR Delete+Insert更新策略
大数据·starrocks·sql
StarRocks_labs23 天前
从InfluxDB到StarRocks:Grab实现Spark监控平台10倍性能提升
大数据·数据库·starrocks·分布式·spark·iris·物化视图