Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第四期 作业五:基于MySQL Replication Connection 实现通用同区域优先以及 Zone 多活架构 #38

Open
mercyblitz opened this issue Mar 1, 2024 · 2 comments

Comments

@mercyblitz
Copy link
Owner

要求:

  • 参考 ReplicationConnectionProxy 实现,结合 Availability Zones Locator API 实现
@Kurok1
Copy link
Contributor

Kurok1 commented Mar 6, 2024

Kurok1/microsphere-multiactive@f9a716b

数据库定义(classpath:/META-INF/microsphere-database-zone.properties)

microsphere.multiple.jdbc.defaultZone=localhost:33306,localhost:13306
microsphere.multiple.jdbc.AZone=localhost:3306

jdbcUrl定义
jdbc:mysql:replication://localhost:33306,localhost:13306,localhost:3306/test?ha.loadBalanceStrategy=io.microsphere.multiple.active.zone.jdbc.mysql.ZonePreferenceBalanceStrategy

@walklown
Copy link
Contributor

walklown commented Mar 8, 2024

可直接使用 ReplicationConnectionProxy 多主多从策略,将同区域MySQL实例配置为SOURCE,其他区域MySQL实例配置为REPLICA),配置方式如下:
jdbc:mysql:replication://root:root123456@(host=localhost,port=3309,type=SOURCE),root:root123456@(host=localhost,port=3310,type=SOURCE),root:root123456@(host=localhost,port=3311,type=REPLICA),root:root123456@(host=localhost,port=3312,type=REPLICA)/my_schema?ha.loadBalanceStrategy=random
参考代码:com.mysql.cj.conf.ConnectionUrlParser
配置效果:
image

优点:无入侵,完全使用MySQL驱动原生实现和配置;可在实现多区域多活、同区域优先的前提下,支持LoadBalance策略。
缺点:功能仅限于多区域多活、同区域优先,如果需要指定区域优先级等定制策略,还是需要自定义扩展。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants