Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
34cbbeaf
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
34cbbeaf
编写于
11月 05, 2020
作者:
Z
Zhang Yonglun
提交者:
GitHub
11月 05, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#7318, add route switch (#8041)
上级
37651f3a
变更
24
隐藏空白更改
内联
并排
Showing
24 changed file
with
48 addition
and
18 deletion
+48
-18
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/src/main/java/org/apache/shardingsphere/ha/api/config/rule/HADataSourceRuleConfiguration.java
...ere/ha/api/config/rule/HADataSourceRuleConfiguration.java
+2
-0
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/HADataSourceRule.java
...a/org/apache/shardingsphere/ha/rule/HADataSourceRule.java
+3
-0
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/config/rule/YamlHADataSourceRuleConfiguration.java
...a/yaml/config/rule/YamlHADataSourceRuleConfiguration.java
+2
-0
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
...pper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
+3
-2
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleConfigurationYamlSwapper.java
...phere/ha/yaml/swapper/HARuleConfigurationYamlSwapper.java
+3
-2
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/HADataSourceRuleTest.java
...g/apache/shardingsphere/ha/rule/HADataSourceRuleTest.java
+5
-5
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/HARuleTest.java
...st/java/org/apache/shardingsphere/ha/rule/HARuleTest.java
+1
-1
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/biulder/AlgorithmProvidedHARuleBuilderTest.java
...e/ha/rule/biulder/AlgorithmProvidedHARuleBuilderTest.java
+1
-1
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/biulder/HARuleBuilderTest.java
...che/shardingsphere/ha/rule/biulder/HARuleBuilderTest.java
+1
-1
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapperTest.java
.../HARuleAlgorithmProviderConfigurationYamlSwapperTest.java
+1
-1
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleConfigurationYamlSwapperTest.java
...e/ha/yaml/swapper/HARuleConfigurationYamlSwapperTest.java
+2
-2
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/resources/yaml/ha-rule.yaml
...dingsphere-ha-common/src/test/resources/yaml/ha-rule.yaml
+2
-0
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/main/java/org/apache/shardingsphere/ha/route/engine/impl/HADataSourceRouter.java
...ardingsphere/ha/route/engine/impl/HADataSourceRouter.java
+1
-1
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/engine/HASQLRouterTest.java
...pache/shardingsphere/ha/route/engine/HASQLRouterTest.java
+1
-1
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/java/org/apache/shardingsphere/ha/spring/boot/HASpringBootStarterTest.java
...hardingsphere/ha/spring/boot/HASpringBootStarterTest.java
+1
-0
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/resources/application-ha.properties
...boot-starter/src/test/resources/application-ha.properties
+1
-0
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/parser/HARuleBeanDefinitionParser.java
...a/spring/namespace/parser/HARuleBeanDefinitionParser.java
+1
-0
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/tag/HARuleBeanDefinitionTag.java
...here/ha/spring/namespace/tag/HARuleBeanDefinitionTag.java
+2
-0
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/resources/META-INF/namespace/ha.xsd
...ng-namespace/src/main/resources/META-INF/namespace/ha.xsd
+1
-0
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/test/java/org/apache/shardingsphere/ha/spring/namespace/HASpringNamespaceTest.java
...dingsphere/ha/spring/namespace/HASpringNamespaceTest.java
+2
-0
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/test/resources/META-INF/spring/ha-application-context.xml
...test/resources/META-INF/spring/ha-application-context.xml
+1
-1
shardingsphere-jdbc/shardingsphere-jdbc-core/pom.xml
shardingsphere-jdbc/shardingsphere-jdbc-core/pom.xml
+5
-0
shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
+5
-0
shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-ha.yaml
...re-proxy-bootstrap/src/main/resources/conf/config-ha.yaml
+1
-0
未找到文件。
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/src/main/java/org/apache/shardingsphere/ha/api/config/rule/HADataSourceRuleConfiguration.java
浏览文件 @
34cbbeaf
...
...
@@ -36,4 +36,6 @@ public final class HADataSourceRuleConfiguration {
private
final
List
<
String
>
replicaDataSourceNames
;
private
final
String
loadBalancerName
;
private
final
Boolean
readWriteSplit
;
}
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/HADataSourceRule.java
浏览文件 @
34cbbeaf
...
...
@@ -46,6 +46,8 @@ public final class HADataSourceRule {
private
final
ReplicaLoadBalanceAlgorithm
loadBalancer
;
private
final
Boolean
readWriteSplit
;
@Getter
(
AccessLevel
.
NONE
)
private
final
Collection
<
String
>
disabledDataSourceNames
=
new
HashSet
<>();
...
...
@@ -55,6 +57,7 @@ public final class HADataSourceRule {
primaryDataSourceName
=
config
.
getPrimaryDataSourceName
();
replicaDataSourceNames
=
config
.
getReplicaDataSourceNames
();
this
.
loadBalancer
=
loadBalancer
;
this
.
readWriteSplit
=
config
.
getReadWriteSplit
();
}
private
void
checkConfiguration
(
final
HADataSourceRuleConfiguration
config
)
{
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/config/rule/YamlHADataSourceRuleConfiguration.java
浏览文件 @
34cbbeaf
...
...
@@ -40,5 +40,7 @@ public final class YamlHADataSourceRuleConfiguration implements YamlConfiguratio
private
String
loadBalancerName
;
private
Boolean
readWriteSplit
;
private
Properties
props
=
new
Properties
();
}
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
浏览文件 @
34cbbeaf
...
...
@@ -54,6 +54,7 @@ public final class HARuleAlgorithmProviderConfigurationYamlSwapper
result
.
setPrimaryDataSourceName
(
dataSourceRuleConfig
.
getPrimaryDataSourceName
());
result
.
setReplicaDataSourceNames
(
dataSourceRuleConfig
.
getReplicaDataSourceNames
());
result
.
setLoadBalancerName
(
dataSourceRuleConfig
.
getLoadBalancerName
());
result
.
setReadWriteSplit
(
dataSourceRuleConfig
.
getReadWriteSplit
());
return
result
;
}
...
...
@@ -69,8 +70,8 @@ public final class HARuleAlgorithmProviderConfigurationYamlSwapper
}
private
HADataSourceRuleConfiguration
swapToObject
(
final
String
name
,
final
YamlHADataSourceRuleConfiguration
yamlDataSourceRuleConfig
)
{
return
new
HADataSourceRuleConfiguration
(
name
,
yamlDataSourceRuleConfig
.
get
PrimaryDataSourceName
(),
yamlDataSourceRuleConfig
.
getReplicaDataSourceNames
(),
yamlDataSourceRuleConfig
.
getLoadBalancerName
());
return
new
HADataSourceRuleConfiguration
(
name
,
yamlDataSourceRuleConfig
.
getPrimaryDataSourceName
(),
yamlDataSourceRuleConfig
.
getReplicaDataSourceNames
(),
yamlDataSourceRuleConfig
.
get
LoadBalancerName
(),
yamlDataSourceRuleConfig
.
getReadWriteSplit
());
}
@Override
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleConfigurationYamlSwapper.java
浏览文件 @
34cbbeaf
...
...
@@ -58,6 +58,7 @@ public final class HARuleConfigurationYamlSwapper
result
.
setPrimaryDataSourceName
(
dataSourceRuleConfig
.
getPrimaryDataSourceName
());
result
.
setReplicaDataSourceNames
(
dataSourceRuleConfig
.
getReplicaDataSourceNames
());
result
.
setLoadBalancerName
(
dataSourceRuleConfig
.
getLoadBalancerName
());
result
.
setReadWriteSplit
(
dataSourceRuleConfig
.
getReadWriteSplit
());
return
result
;
}
...
...
@@ -75,8 +76,8 @@ public final class HARuleConfigurationYamlSwapper
}
private
HADataSourceRuleConfiguration
swapToObject
(
final
String
name
,
final
YamlHADataSourceRuleConfiguration
yamlDataSourceRuleConfig
)
{
return
new
HADataSourceRuleConfiguration
(
name
,
yamlDataSourceRuleConfig
.
get
PrimaryDataSourceName
(),
yamlDataSourceRuleConfig
.
getReplicaDataSourceNames
(),
yamlDataSourceRuleConfig
.
getLoadBalancerName
());
return
new
HADataSourceRuleConfiguration
(
name
,
yamlDataSourceRuleConfig
.
getPrimaryDataSourceName
(),
yamlDataSourceRuleConfig
.
getReplicaDataSourceNames
(),
yamlDataSourceRuleConfig
.
get
LoadBalancerName
(),
yamlDataSourceRuleConfig
.
getReadWriteSplit
());
}
@Override
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/HADataSourceRuleTest.java
浏览文件 @
34cbbeaf
...
...
@@ -34,26 +34,26 @@ import static org.junit.Assert.assertThat;
public
final
class
HADataSourceRuleTest
{
private
final
HADataSourceRule
haDataSourceRule
=
new
HADataSourceRule
(
new
HADataSourceRuleConfiguration
(
"test_pr"
,
"primary_ds"
,
Arrays
.
asList
(
"replica_ds_0"
,
"replica_ds_1"
),
"random"
),
new
RandomReplicaLoadBalanceAlgorithm
());
new
HADataSourceRuleConfiguration
(
"test_pr"
,
"primary_ds"
,
Arrays
.
asList
(
"replica_ds_0"
,
"replica_ds_1"
),
"random"
,
true
),
new
RandomReplicaLoadBalanceAlgorithm
());
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
assertNewHADataSourceRuleWithoutName
()
{
new
HADataSourceRule
(
new
HADataSourceRuleConfiguration
(
""
,
"primary_ds"
,
Collections
.
singletonList
(
"replica_ds"
),
null
),
new
RoundRobinReplicaLoadBalanceAlgorithm
());
new
HADataSourceRule
(
new
HADataSourceRuleConfiguration
(
""
,
"primary_ds"
,
Collections
.
singletonList
(
"replica_ds"
),
null
,
true
),
new
RoundRobinReplicaLoadBalanceAlgorithm
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
assertNewHADataSourceRuleWithoutPrimaryDataSourceName
()
{
new
HADataSourceRule
(
new
HADataSourceRuleConfiguration
(
"ds"
,
""
,
Collections
.
singletonList
(
"replica_ds"
),
null
),
new
RoundRobinReplicaLoadBalanceAlgorithm
());
new
HADataSourceRule
(
new
HADataSourceRuleConfiguration
(
"ds"
,
""
,
Collections
.
singletonList
(
"replica_ds"
),
null
,
true
),
new
RoundRobinReplicaLoadBalanceAlgorithm
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
assertNewHADataSourceRuleWithNullReplicaDataSourceName
()
{
new
HADataSourceRule
(
new
HADataSourceRuleConfiguration
(
"ds"
,
"primary_ds"
,
null
,
null
),
new
RoundRobinReplicaLoadBalanceAlgorithm
());
new
HADataSourceRule
(
new
HADataSourceRuleConfiguration
(
"ds"
,
"primary_ds"
,
null
,
null
,
true
),
new
RoundRobinReplicaLoadBalanceAlgorithm
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
assertNewHADataSourceRuleWithEmptyReplicaDataSourceName
()
{
new
HADataSourceRule
(
new
HADataSourceRuleConfiguration
(
"ds"
,
"primary_ds"
,
Collections
.
emptyList
(),
null
),
new
RoundRobinReplicaLoadBalanceAlgorithm
());
new
HADataSourceRule
(
new
HADataSourceRuleConfiguration
(
"ds"
,
"primary_ds"
,
Collections
.
emptyList
(),
null
,
true
),
new
RoundRobinReplicaLoadBalanceAlgorithm
());
}
@Test
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/HARuleTest.java
浏览文件 @
34cbbeaf
...
...
@@ -56,7 +56,7 @@ public final class HARuleTest {
private
HARule
createHARule
()
{
HADataSourceRuleConfiguration
config
=
new
HADataSourceRuleConfiguration
(
"test_pr"
,
"primary_ds"
,
Arrays
.
asList
(
"replica_ds_0"
,
"replica_ds_1"
),
"random"
);
new
HADataSourceRuleConfiguration
(
"test_pr"
,
"primary_ds"
,
Arrays
.
asList
(
"replica_ds_0"
,
"replica_ds_1"
),
"random"
,
true
);
return
new
HARule
(
new
HARuleConfiguration
(
Collections
.
singleton
(
config
),
ImmutableMap
.
of
(
"random"
,
new
ShardingSphereAlgorithmConfiguration
(
"RANDOM"
,
new
Properties
()))));
}
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/biulder/AlgorithmProvidedHARuleBuilderTest.java
浏览文件 @
34cbbeaf
...
...
@@ -43,7 +43,7 @@ public final class AlgorithmProvidedHARuleBuilderTest {
public
void
assertBuild
()
{
AlgorithmProvidedHARuleConfiguration
algorithmProvidedRuleConfig
=
mock
(
AlgorithmProvidedHARuleConfiguration
.
class
);
HADataSourceRuleConfiguration
ruleConfig
=
new
HADataSourceRuleConfiguration
(
"name"
,
"primaryDataSourceName"
,
Collections
.
singletonList
(
"name"
),
"loadBalancerName"
);
"name"
,
"primaryDataSourceName"
,
Collections
.
singletonList
(
"name"
),
"loadBalancerName"
,
true
);
when
(
algorithmProvidedRuleConfig
.
getDataSources
()).
thenReturn
(
Collections
.
singletonList
(
ruleConfig
));
ShardingSphereRuleBuilder
builder
=
OrderedSPIRegistry
.
getRegisteredServices
(
Collections
.
singletonList
(
algorithmProvidedRuleConfig
),
ShardingSphereRuleBuilder
.
class
).
get
(
algorithmProvidedRuleConfig
);
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/biulder/HARuleBuilderTest.java
浏览文件 @
34cbbeaf
...
...
@@ -43,7 +43,7 @@ public final class HARuleBuilderTest {
public
void
assertBuild
()
{
HARuleConfiguration
ruleConfig
=
mock
(
HARuleConfiguration
.
class
);
HADataSourceRuleConfiguration
dataSourceRuleConfig
=
new
HADataSourceRuleConfiguration
(
"name"
,
"primaryDataSourceName"
,
Collections
.
singletonList
(
"name"
),
"loadBalancerName"
);
"name"
,
"primaryDataSourceName"
,
Collections
.
singletonList
(
"name"
),
"loadBalancerName"
,
true
);
when
(
ruleConfig
.
getDataSources
()).
thenReturn
(
Collections
.
singletonList
(
dataSourceRuleConfig
));
ShardingSphereRuleBuilder
builder
=
OrderedSPIRegistry
.
getRegisteredServices
(
Collections
.
singletonList
(
ruleConfig
),
ShardingSphereRuleBuilder
.
class
).
get
(
ruleConfig
);
assertThat
(
builder
.
build
(
ruleConfig
,
Collections
.
emptyList
()),
instanceOf
(
HARule
.
class
));
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapperTest.java
浏览文件 @
34cbbeaf
...
...
@@ -85,7 +85,7 @@ public final class HARuleAlgorithmProviderConfigurationYamlSwapperTest {
private
YamlHARuleConfiguration
createYamlHARuleConfiguration
()
{
HADataSourceRuleConfiguration
ruleConfig
=
new
HADataSourceRuleConfiguration
(
"name"
,
"primaryDataSourceName"
,
Collections
.
singletonList
(
"replicaDataSourceName"
),
"loadBalancerName"
);
Collections
.
singletonList
(
"replicaDataSourceName"
),
"loadBalancerName"
,
true
);
return
swapper
.
swapToYamlConfiguration
(
new
AlgorithmProvidedHARuleConfiguration
(
Collections
.
singletonList
(
ruleConfig
),
ImmutableMap
.
of
(
"name"
,
new
RandomReplicaLoadBalanceAlgorithm
())));
}
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleConfigurationYamlSwapperTest.java
浏览文件 @
34cbbeaf
...
...
@@ -50,7 +50,7 @@ public final class HARuleConfigurationYamlSwapperTest {
@Test
public
void
assertSwapToYamlWithLoadBalanceAlgorithm
()
{
HADataSourceRuleConfiguration
dataSourceConfig
=
new
HADataSourceRuleConfiguration
(
"ds"
,
"primary"
,
Collections
.
singletonList
(
"replica"
),
"roundRobin"
);
new
HADataSourceRuleConfiguration
(
"ds"
,
"primary"
,
Collections
.
singletonList
(
"replica"
),
"roundRobin"
,
true
);
YamlHARuleConfiguration
actual
=
getHARuleConfigurationYamlSwapper
().
swapToYamlConfiguration
(
new
HARuleConfiguration
(
Collections
.
singleton
(
dataSourceConfig
),
ImmutableMap
.
of
(
"roundRobin"
,
new
ShardingSphereAlgorithmConfiguration
(
"ROUND_ROBIN"
,
new
Properties
()))));
assertThat
(
actual
.
getDataSources
().
get
(
"ds"
).
getName
(),
is
(
"ds"
));
...
...
@@ -61,7 +61,7 @@ public final class HARuleConfigurationYamlSwapperTest {
@Test
public
void
assertSwapToYamlWithoutLoadBalanceAlgorithm
()
{
HADataSourceRuleConfiguration
dataSourceConfig
=
new
HADataSourceRuleConfiguration
(
"ds"
,
"primary"
,
Collections
.
singletonList
(
"replica"
),
null
);
HADataSourceRuleConfiguration
dataSourceConfig
=
new
HADataSourceRuleConfiguration
(
"ds"
,
"primary"
,
Collections
.
singletonList
(
"replica"
),
null
,
true
);
YamlHARuleConfiguration
actual
=
getHARuleConfigurationYamlSwapper
().
swapToYamlConfiguration
(
new
HARuleConfiguration
(
Collections
.
singleton
(
dataSourceConfig
),
Collections
.
emptyMap
()));
assertThat
(
actual
.
getDataSources
().
get
(
"ds"
).
getName
(),
is
(
"ds"
));
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/resources/yaml/ha-rule.yaml
浏览文件 @
34cbbeaf
...
...
@@ -56,12 +56,14 @@ rules:
-
primary_ds_0_replica_0
-
primary_ds_0_replica_1
loadBalancerName
:
roundRobin
readWriteSplit
:
true
ds_1
:
primaryDataSourceName
:
primary_ds_1
replicaDataSourceNames
:
-
primary_ds_1_replica_0
-
primary_ds_1_replica_1
loadBalancerName
:
random
readWriteSplit
:
false
loadBalancers
:
roundRobin
:
type
:
ROUND_ROBIN
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/main/java/org/apache/shardingsphere/ha/route/engine/impl/HADataSourceRouter.java
浏览文件 @
34cbbeaf
...
...
@@ -39,7 +39,7 @@ public final class HADataSourceRouter {
* @return data source name
*/
public
String
route
(
final
SQLStatement
sqlStatement
)
{
if
(
isPrimaryRoute
(
sqlStatement
))
{
if
(
isPrimaryRoute
(
sqlStatement
)
||
!
rule
.
getReadWriteSplit
()
)
{
PrimaryVisitedManager
.
setPrimaryVisited
();
return
rule
.
getPrimaryDataSourceName
();
}
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/engine/HASQLRouterTest.java
浏览文件 @
34cbbeaf
...
...
@@ -80,7 +80,7 @@ public final class HASQLRouterTest {
@Before
public
void
setUp
()
{
rule
=
new
HARule
(
new
HARuleConfiguration
(
Collections
.
singleton
(
new
HADataSourceRuleConfiguration
(
DATASOURCE_NAME
,
PRIMARY_DATASOURCE
,
Collections
.
singletonList
(
REPLICA_DATASOURCE
),
null
)),
Collections
.
emptyMap
()));
new
HADataSourceRuleConfiguration
(
DATASOURCE_NAME
,
PRIMARY_DATASOURCE
,
Collections
.
singletonList
(
REPLICA_DATASOURCE
),
null
,
true
)),
Collections
.
emptyMap
()));
sqlRouter
=
(
HASQLRouter
)
OrderedSPIRegistry
.
getRegisteredServices
(
Collections
.
singleton
(
rule
),
SQLRouter
.
class
).
get
(
rule
);
}
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/java/org/apache/shardingsphere/ha/spring/boot/HASpringBootStarterTest.java
浏览文件 @
34cbbeaf
...
...
@@ -57,6 +57,7 @@ public class HASpringBootStarterTest {
assertThat
(
dataSourceRuleConfig
.
getName
(),
is
(
"pr_ds"
));
assertThat
(
dataSourceRuleConfig
.
getPrimaryDataSourceName
(),
is
(
"primary_ds"
));
assertThat
(
dataSourceRuleConfig
.
getLoadBalancerName
(),
is
(
"random"
));
assertTrue
(
dataSourceRuleConfig
.
getReadWriteSplit
());
assertThat
(
dataSourceRuleConfig
.
getReplicaDataSourceNames
().
size
(),
is
(
2
));
assertTrue
(
config
.
getDataSources
().
contains
(
dataSourceRuleConfig
));
assertThat
(
config
.
getLoadBalanceAlgorithms
().
size
(),
is
(
1
));
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/resources/application-ha.properties
浏览文件 @
34cbbeaf
...
...
@@ -20,3 +20,4 @@ spring.shardingsphere.rules.ha.load-balancers.random.type=RANDOM
spring.shardingsphere.rules.ha.data-sources.pr_ds.primary-data-source-name
=
primary_ds
spring.shardingsphere.rules.ha.data-sources.pr_ds.replica-data-source-names
=
replica_ds_0,replica_ds_1
spring.shardingsphere.rules.ha.data-sources.pr_ds.load-balancer-name
=
random
spring.shardingsphere.rules.ha.data-sources.pr_ds.read-write-split
=
true
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/parser/HARuleBeanDefinitionParser.java
浏览文件 @
34cbbeaf
...
...
@@ -63,6 +63,7 @@ public final class HARuleBeanDefinitionParser extends AbstractBeanDefinitionPars
factory
.
addConstructorArgValue
(
element
.
getAttribute
(
HARuleBeanDefinitionTag
.
PRIMARY_DATA_SOURCE_NAME_ATTRIBUTE
));
factory
.
addConstructorArgValue
(
parseReplicaDataSourcesRef
(
element
));
factory
.
addConstructorArgValue
(
element
.
getAttribute
(
HARuleBeanDefinitionTag
.
LOAD_BALANCE_ALGORITHM_REF_ATTRIBUTE
));
factory
.
addConstructorArgValue
(
element
.
getAttribute
(
HARuleBeanDefinitionTag
.
READ_WRITE_SPLIT_ATTRIBUTE
));
return
factory
.
getBeanDefinition
();
}
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/tag/HARuleBeanDefinitionTag.java
浏览文件 @
34cbbeaf
...
...
@@ -37,4 +37,6 @@ public final class HARuleBeanDefinitionTag {
public
static
final
String
REPLICA_DATA_SOURCE_NAMES_ATTRIBUTE
=
"replica-data-source-names"
;
public
static
final
String
LOAD_BALANCE_ALGORITHM_REF_ATTRIBUTE
=
"load-balance-algorithm-ref"
;
public
static
final
String
READ_WRITE_SPLIT_ATTRIBUTE
=
"read-write-split"
;
}
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/resources/META-INF/namespace/ha.xsd
浏览文件 @
34cbbeaf
...
...
@@ -38,6 +38,7 @@
<xsd:attribute
name=
"primary-data-source-name"
type=
"xsd:string"
use=
"required"
/>
<xsd:attribute
name=
"replica-data-source-names"
type=
"xsd:string"
use=
"required"
/>
<xsd:attribute
name=
"load-balance-algorithm-ref"
type=
"xsd:string"
/>
<xsd:attribute
name=
"read-write-split"
type=
"xsd:boolean"
/>
</xsd:complexType>
</xsd:element>
...
...
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/test/java/org/apache/shardingsphere/ha/spring/namespace/HASpringNamespaceTest.java
浏览文件 @
34cbbeaf
...
...
@@ -32,6 +32,7 @@ import java.util.Map;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@ContextConfiguration
(
locations
=
"classpath:META-INF/spring/ha-application-context.xml"
)
public
final
class
HASpringNamespaceTest
extends
AbstractJUnit4SpringContextTests
{
...
...
@@ -81,5 +82,6 @@ public final class HASpringNamespaceTest extends AbstractJUnit4SpringContextTest
assertThat
(
dataSourceRuleConfig
.
getPrimaryDataSourceName
(),
is
(
"primary_ds"
));
assertThat
(
dataSourceRuleConfig
.
getReplicaDataSourceNames
(),
is
(
Arrays
.
asList
(
"replica_ds_0"
,
"replica_ds_1"
)));
assertThat
(
dataSourceRuleConfig
.
getLoadBalancerName
(),
is
(
"randomLoadbalancer"
));
assertTrue
(
dataSourceRuleConfig
.
getReadWriteSplit
());
}
}
shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/test/resources/META-INF/spring/ha-application-context.xml
浏览文件 @
34cbbeaf
...
...
@@ -31,6 +31,6 @@
</ha:rule>
<ha:rule
id=
"randomRule"
>
<ha:data-source-rule
id=
"random_ds"
primary-data-source-name=
"primary_ds"
replica-data-source-names=
"replica_ds_0, replica_ds_1"
load-balance-algorithm-ref=
"randomLoadbalancer"
/>
<ha:data-source-rule
id=
"random_ds"
primary-data-source-name=
"primary_ds"
replica-data-source-names=
"replica_ds_0, replica_ds_1"
load-balance-algorithm-ref=
"randomLoadbalancer"
read-write-split=
"true"
/>
</ha:rule>
</beans>
shardingsphere-jdbc/shardingsphere-jdbc-core/pom.xml
浏览文件 @
34cbbeaf
...
...
@@ -72,6 +72,11 @@
<artifactId>
shardingsphere-replica-query-route
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
shardingsphere-ha-route
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
shardingsphere-sharding-rewrite
</artifactId>
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
浏览文件 @
34cbbeaf
...
...
@@ -77,6 +77,11 @@
<artifactId>
shardingsphere-replica-query-route
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
shardingsphere-ha-route
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
shardingsphere-sharding-rewrite
</artifactId>
...
...
shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-ha.yaml
浏览文件 @
34cbbeaf
...
...
@@ -87,3 +87,4 @@
# replicaDataSourceNames:
# - replica_ds_0
# - replica_ds_1
# readWriteSplit: false
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录