分布式数据库中间件Mycat2(虚拟数据库类)
源码地址
https://github.com/MyCATApache/Mycat2
https://gitee.com/MycatOne/Mycat2
如果觉得可以请给个star
官网
http://www.mycat.org.cn/
http://mycatone.top/
分享就是获得!
从零开始写分布式数据库中间件并不难。把下面技术了学习一下就可以。
熟悉词法分析,语法分析,编译器,解释器,查询编译器的基本原理。
了解查询优化器的基本原理。
了解执行器的基本原理。
熟悉MySQL的网络通讯协议。
熟悉网络编程。
熟悉高可用与负载均衡的实现原理。
熟悉数据库事务基本原理。
了解虚拟数据库,分布式数据库中间件。
具体技术:
JAVA NIO,Vertx(Netty),Apache Calcite,Alibaba Druid,MySQL网络通讯协议,MySQL系统表,MySQL高可用,分布式事务,Apache Arrow,Spark,Linq4j,Rxjava,分库分表
Software introduction
Mycat2 is a distributed relational database (middleware) developed by the Mycat community. It supports distributed SQL queries, is compatible with the MySQL communication protocol, supports a variety of back-end databases with Java ecology, and improves data query processing capabilities through data fragmentation.
软件介绍
Mycat2是Mycat社区开发的一款分布式关系型数据库(中间件)。它支持分布式SQL查询,兼容MySQL通信协议,以Java生态支持多种后端数据库,通过数据分片提高数据查询处理能力。
Features
1. Open source code
Learning middleware technology, database technology, and code is a must.
2. Distributed query engine compatible with MySQL syntax
• Compatible with MySQL syntax.
• Compatible with MySQL value types.
• Use an optimizer based on rule optimization and cost.
• Independent physical execution engine.
3. Custom function algorithm development
• Sharding algorithm, serial number algorithm, load balancing algorithm, etc. can all be customized to load.
• The query engine can run away from the network framework.
4. Customize the process
Self-developed DSL manipulates the physical query plan.
Support SQL forwarding and cache result set.
产品特点
1.代码开源
2.兼容MySQL语法的分布式查询引擎
- 兼容MySQL语法。
- 兼容MySQL值类型。
- 使用基于规则优化与代价的优化器。
-
3.自定义功能算法开发
分片算法,序列号算法,负载均衡算法等都可自定义加载。
- 查询引擎可脱离网络框架运行。
4.自定义处理过程
自研DSL操纵物理查询计划。
支持SQL转发,缓存结果集。
Product functions for DBA/O&M
Instance operation
• Distinguish between non-updatable configuration and hot-updatable configuration
• The database/logical table is dynamically created, rebuilt, and deleted statements to change the configuration
• Support file configuration, middleware management configuration
• To a certain extent, it is compatible with common table creation and DDL statements to delete tables, and supports fragmented table creation statements
• Supports global tables, ordinary tables, and fragmented tables. ER tables are not supported. Just configure the ER tables into fragmented tables. The optimizer will analyze the table relationship between the tables. In particular, if in the case of single database sharded tables, You need to use the join push of the global table, or you need to configure the ordinary table as a global table.
• Starting from 1.15, MySQL XA transactions are supported. The principle is the same as the PolarDB-X cloud-native distributed database. The transaction log table will create the mycat.xa_log table on the storage node when Mycat2 starts. It records the transactions that have entered the commit node. The recorded distributed transactions are to be committed, and transactions that are not in the XA PREPARE phase of this table are to be rolled back.
• Temporarily no data migration/expansion components (to be integrated)
Data management
Custom rules on the configuration allow any sub-database, sub-table, sub-database and sub-table
Read and write separation
Monitoring and management
Grafana monitoring template and monitoring terminal
面向DBA/运维的产品功能
实例操作
- 区分不可更新配置/可热更新配置
- 数据库/逻辑表动态创建,重建,删除语句来更改配置
- 支持文件配置,中间件管理配置
- 一定程度上兼容常见的建表,删除表的DDL语句,支持分片表建表语句
- 支持全局表,普通表,分片表,不支持ER表,把ER表配置成分片表即可,优化器会分析表之间的表关系.特别地,如果在单库分表情况下,需要使用全局表的join下推,还是需要把普通表配置成全局表的.
- 1.15开始支持MySQL XA事务,原理与PolarDB-X 云原生分布式数据库一致,事务日志表会在Mycat2启动时候在存储节点上建立mycat.xa_log表,它记录已经进入commit节点事务,在此表有记录的分布式事务都是要提交的,而不在此表的XA PREPARE阶段事务是要回滚的.
-
数据管理
监控管理
面向开发的产品功能
分布式查询引擎
SQL参数化并支持简单的查询计划缓存
- EXPLAIN输出查询计划
- 基于规则的优化下推逻辑算子
- 基于代价的优化选择物理算子
- 支持UDF并兼容多数MySQL中的SQL函数
- 兼容MySQL的类型转换系统
- 支持多语句
不支持不能消除关联的关联子查询(已经支持)- 平台兼容性问题,如Java与C之间有难以工程兼顾的问题,比如少数MySQL函数不支持
- 不支持CEP
- 自动加载MySQL系统表免配置
-
简单SQL引擎(用于insert,delete,update)
支持参数化的批量插入
-
计算执行引擎
基于代码生成执行的表达式运行时
基于解释器模型的表达式运行时(待开发)- 实现对应查询引擎的MySQL中的SQL函数
- 并行拉取数据源
纯JDBC模式完整支持多语句,Proxy能自动检测多语句冲突报错MySQL协议网络层
仅支持mysql_native_password 原生网络协议
- 后端支持jdbc或者mysql_native_password 原生网络协议
- Proxy模式可任意透传响应文本结果集并响应多语句
- 不支持加密协议
- 不支持压缩协议
不支持透传预处理语句(涉及预处理句柄管理待完善或者说意义不大)
事务框架
支持单个本地事务和多个本地事务
- 支持基于Proxy的事务
理论上基于JDBC的事务框架的多线程事务框架容易支持JTA方案的分布式事务方案由于性能太差被移除没有准备支持分布式事务,请通过架构层面解决这个问题-
高可用与集群
基于轮训心跳的集群管理
- 集群管理可被禁用
- 策略模式的心跳类