搬运君又来搬运优质 Discussions 啦,发起者来源于 GitHub zjcnb
zjcnb:
当我测试使用高可用性 MGR 时。效果不好,我执行读或写操作,它总是选择主数据源。我看到源代码找到了
@RequiredArgsConstructor
public final class DatabaseDiscoveryDataSourceRouter {
private final DatabaseDiscoveryDataSourceRule rule;
/**
* Route.
*
* @return data source name
*/
public String route() {
return rule.getPrimaryDataSourceName();
}
}
然后,我尝试将高可用性 MGR 与 ReadWriteRules 结合使用。它运行良好,我的配置是:
schemaName: database_discovery_db
dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:13308/demo_primary_ds?serverTimezone=UTC&useSSL=false
username: root
password:
connectionTimeoutMilliseconds: 3000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds_1:
url: jdbc:mysql://127.0.0.1:13309/demo_primary_ds?serverTimezone=UTC&useSSL=false
username: root
password:
connectionTimeoutMilliseconds: 3000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds_2:
url: jdbc:mysql://127.0.0.1:13308/demo_primary_ds?serverTimezone=UTC&useSSL=false
username: root
password:
connectionTimeoutMilliseconds: 3000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
rules:
- !READWRITE_SPLITTING
dataSources:
rd_rs:
autoAwareDataSourceName: pr_ds
- !DB_DISCOVERY
dataSources:
pr_ds:
dataSourceNames:
- ds_0
- ds_1
- ds_2
discoveryTypeName: mgr
discoveryTypes:
mgr:
type: MGR
props:
groupName: b13df29e-90b6-11e8-8d1b-525400fc3996
zkServerLists: 'localhost:2181'
keepAliveCron: '0/50 * * * * ?'
通过我们知道 MGR 哪一个是主要的数据源(writeDataSourceName)和其他从数据源(readDataSourceNames),那么,我想- !READWRITE_SPLITTING
和- !DB_DISCOVERY
应该合并,并让 DB_DISCOVERY 是 READWRITE 的增强版本
strongduanmu:
@zjcnb 我喜欢这个建议,因为 DatabaseDiscovery
看起来与其他建议不同DistributedRule
,例如ReadWriteSplitting
和 Shadow
。它没有路由功能。看起来更像是 ReadWriteSplitting
now 的一个实现,区别于传统的主从架构。
为了中文开发者更好的查阅,讨论已经翻译成中文
详情链接点击 这里