This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 998788a #7318, add proxy yaml config file (#8037)
998788a is described below
commit 998788addd7f55b5f9f2df5d36cc8403676de1f1
Author: Zhang Yonglun <[email protected]>
AuthorDate: Thu Nov 5 18:59:57 2020 +0800
#7318, add proxy yaml config file (#8037)
* #7318, add config-ha.yaml
* #7318, add config-ha.yaml
* #7318, add config-ha.yaml
* #7318, fix ci
---
.../apache/shardingsphere/ha/constant/HAOrder.java | 4 +-
...eAlgorithmProviderConfigurationYamlSwapper.java | 2 +-
...orithmProviderConfigurationYamlSwapperTest.java | 2 +-
.../ha/route/engine/HASQLRouterTest.java | 23 ++++--
.../src/main/resources/conf/config-ha.yaml | 89 ++++++++++++++++++++++
.../shardingsphere-proxy-common/pom.xml | 5 ++
6 files changed, 114 insertions(+), 11 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/constant/HAOrder.java
b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/constant/HAOrder.java
index 53b99b0..a25036d 100644
---
a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/constant/HAOrder.java
+++
b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/constant/HAOrder.java
@@ -29,10 +29,10 @@ public final class HAOrder {
/**
* HA order.
*/
- public static final int ORDER = 10;
+ public static final int ORDER = 20;
/**
* Algorithm provider HA order.
*/
- public static final int ALGORITHM_PROVIDER_ORDER = 11;
+ public static final int ALGORITHM_PROVIDER_HA_ORDER = 21;
}
diff --git
a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
index de50901..15fb341 100644
---
a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
+++
b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
@@ -85,6 +85,6 @@ public final class
HARuleAlgorithmProviderConfigurationYamlSwapper
@Override
public int getOrder() {
- return HAOrder.ALGORITHM_PROVIDER_ORDER;
+ return HAOrder.ALGORITHM_PROVIDER_HA_ORDER;
}
}
diff --git
a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapperTest.java
b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapperTest.java
index afffaa1..78b36a0 100644
---
a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapperTest.java
+++
b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapperTest.java
@@ -80,7 +80,7 @@ public final class
HARuleAlgorithmProviderConfigurationYamlSwapperTest {
@Test
public void assertGetOrder() {
- assertThat(swapper.getOrder(), is(HAOrder.ALGORITHM_PROVIDER_ORDER));
+ assertThat(swapper.getOrder(),
is(HAOrder.ALGORITHM_PROVIDER_HA_ORDER));
}
private YamlHARuleConfiguration createYamlHARuleConfiguration() {
diff --git
a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/engine/HASQLRouterTest.java
b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/engine/HASQLRouterTest.java
index fd3e9fc..797f0d7 100644
---
a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/engine/HASQLRouterTest.java
+++
b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/engine/HASQLRouterTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.ha.route.engine;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.route.SQLRouter;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
@@ -50,6 +51,7 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -90,7 +92,8 @@ public final class HASQLRouterTest {
@Test
public void assertCreateRouteContextToPrimaryWithoutRouteUnits() {
LogicSQL logicSQL = new LogicSQL(mock(SQLStatementContext.class), "",
Collections.emptyList());
- ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule), Collections.emptyMap(),
mock(ShardingSphereSchema.class));
+ ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule),
+ mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
mock(ShardingSphereSchema.class));
RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData,
rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames =
actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATASOURCE));
@@ -100,7 +103,8 @@ public final class HASQLRouterTest {
public void assertDecorateRouteContextToPrimaryDataSource() {
RouteContext actual = mockRouteContext();
LogicSQL logicSQL = new LogicSQL(mock(SQLStatementContext.class), "",
Collections.emptyList());
- ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule), Collections.emptyMap(),
mock(ShardingSphereSchema.class));
+ ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule),
+ mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
mock(ShardingSphereSchema.class));
sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new
ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames =
actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(NONE_HA_DATASOURCE_NAME));
@@ -113,7 +117,8 @@ public final class HASQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.empty());
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "",
Collections.emptyList());
- ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule), Collections.emptyMap(),
mock(ShardingSphereSchema.class));
+ ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule),
+ mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
mock(ShardingSphereSchema.class));
RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData,
rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames =
actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(REPLICA_DATASOURCE));
@@ -126,7 +131,8 @@ public final class HASQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.empty());
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "",
Collections.emptyList());
- ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule), Collections.emptyMap(),
mock(ShardingSphereSchema.class));
+ ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule),
+ mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
mock(ShardingSphereSchema.class));
sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new
ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames =
actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(NONE_HA_DATASOURCE_NAME));
@@ -139,7 +145,8 @@ public final class HASQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.of(mock(LockSegment.class)));
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "",
Collections.emptyList());
- ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule), Collections.emptyMap(),
mock(ShardingSphereSchema.class));
+ ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule),
+ mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
mock(ShardingSphereSchema.class));
RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData,
rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames =
actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATASOURCE));
@@ -152,7 +159,8 @@ public final class HASQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.of(mock(LockSegment.class)));
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "",
Collections.emptyList());
- ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule), Collections.emptyMap(),
mock(ShardingSphereSchema.class));
+ ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule),
+ mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
mock(ShardingSphereSchema.class));
sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new
ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames =
actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(NONE_HA_DATASOURCE_NAME));
@@ -163,7 +171,8 @@ public final class HASQLRouterTest {
public void assertCreateRouteContextToPrimaryDataSource() {
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(InsertStatement.class));
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "",
Collections.emptyList());
- ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule), Collections.emptyMap(),
mock(ShardingSphereSchema.class));
+ ShardingSphereMetaData metaData = new
ShardingSphereMetaData("logic_schema", Collections.emptyList(),
Collections.singleton(rule),
+ mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
mock(ShardingSphereSchema.class));
RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData,
rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames =
actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATASOURCE));
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-ha.yaml
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-ha.yaml
new file mode 100644
index 0000000..38ce034
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-ha.yaml
@@ -0,0 +1,89 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######################################################################################################
+#
+# Here you can configure the rules for the proxy.
+# This example is configuration of HA rule.
+#
+######################################################################################################
+#
+#schemaName: ha_db
+#
+#dataSourceCommon:
+# username: postgres
+# password: postgres
+# connectionTimeoutMilliseconds: 30000
+# idleTimeoutMilliseconds: 60000
+# maxLifetimeMilliseconds: 1800000
+# maxPoolSize: 50
+# minPoolSize: 1
+# maintenanceIntervalMilliseconds: 30000
+#
+#dataSources:
+# primary_ds:
+# url:
jdbc:postgresql://127.0.0.1:5432/demo_primary_ds?serverTimezone=UTC&useSSL=false
+# replica_ds_0:
+# url:
jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_0?serverTimezone=UTC&useSSL=false
+# replica_ds_1:
+# url:
jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_1?serverTimezone=UTC&useSSL=false
+#
+#rules:
+#- !HA
+# dataSources:
+# pr_ds:
+# name: pr_ds
+# primaryDataSourceName: primary_ds
+# replicaDataSourceNames:
+# - replica_ds_0
+# - replica_ds_1
+
+######################################################################################################
+#
+# If you want to connect to MySQL, you should manually copy MySQL driver to
lib directory.
+#
+######################################################################################################
+
+#schemaName: ha_db
+#
+#dataSourceCommon:
+# username: root
+# password:
+# connectionTimeoutMilliseconds: 30000
+# idleTimeoutMilliseconds: 60000
+# maxLifetimeMilliseconds: 1800000
+# maxPoolSize: 50
+# minPoolSize: 1
+# maintenanceIntervalMilliseconds: 30000
+#
+#dataSources:
+# primary_ds:
+# url:
jdbc:mysql://127.0.0.1:3306/demo_primary_ds?serverTimezone=UTC&useSSL=false
+# replica_ds_0:
+# url:
jdbc:mysql://127.0.0.1:3306/demo_replica_ds_0?serverTimezone=UTC&useSSL=false
+# replica_ds_1:
+# url:
jdbc:mysql://127.0.0.1:3306/demo_replica_ds_1?serverTimezone=UTC&useSSL=false
+#
+#rules:
+#- !HA
+# dataSources:
+# pr_ds:
+# name: pr_ds
+# primaryDataSourceName: primary_ds
+# replicaDataSourceNames:
+# - replica_ds_0
+# - replica_ds_1
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
b/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
index e268c48..44e9d3f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
@@ -62,6 +62,11 @@
<artifactId>shardingsphere-encrypt-common</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-ha-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>com.zaxxer</groupId>