You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/01/06 08:16:01 UTC
[shardingsphere] branch master updated: Add yaml scaling
configuration for proxy (#8911)
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 b1f04a3 Add yaml scaling configuration for proxy (#8911)
b1f04a3 is described below
commit b1f04a363bab7c7c4334893d5cd931b7b040c171
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Wed Jan 6 16:15:41 2021 +0800
Add yaml scaling configuration for proxy (#8911)
---
.../src/main/resources/conf/server.yaml | 4 ++++
.../core/yaml/config/YamlScalingConfiguration.java | 16 +++++-----------
.../initializer/impl/AbstractBootstrapInitializer.java | 11 +++++++++++
.../initializer/impl/GovernanceBootstrapInitializer.java | 12 ++++++++----
.../initializer/impl/StandardBootstrapInitializer.java | 7 ++++++-
.../src/main/resources/conf/server.yaml | 4 ++++
.../proxy/config/yaml/YamlProxyServerConfiguration.java | 3 +++
7 files changed, 41 insertions(+), 16 deletions(-)
diff --git a/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/conf/server.yaml b/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/conf/server.yaml
index 4a84d8a..663fb14 100644
--- a/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/conf/server.yaml
+++ b/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/conf/server.yaml
@@ -41,6 +41,10 @@
# password: sharding
# authorizedSchemas: sharding_db
+#scaling:
+# blockQueueSize: 10000
+# workerThread: 40
+
#props:
# max-connections-size-per-query: 1
# acceptor-size: 16 # The default value is available processors count * 2.
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlScalingConfiguration.java
similarity index 63%
copy from shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
copy to shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlScalingConfiguration.java
index b51bf23..fedd6c0 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlScalingConfiguration.java
@@ -15,26 +15,20 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.config.yaml;
+package org.apache.shardingsphere.governance.core.yaml.config;
import lombok.Getter;
import lombok.Setter;
-import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceConfiguration;
-import org.apache.shardingsphere.infra.auth.builtin.yaml.config.YamlAuthenticationConfiguration;
import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
-import java.util.Properties;
-
/**
- * Server configuration for YAML.
+ * Scaling configuration for Yaml.
*/
@Getter
@Setter
-public final class YamlProxyServerConfiguration implements YamlConfiguration {
-
- private YamlAuthenticationConfiguration authentication;
+public final class YamlScalingConfiguration implements YamlConfiguration {
- private YamlGovernanceConfiguration governance;
+ private int blockQueueSize;
- private Properties props = new Properties();
+ private int workerThread;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
index 76e6c30..2b2a293 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
@@ -31,6 +31,7 @@ import org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
import org.apache.shardingsphere.proxy.database.DatabaseServerInfo;
import org.apache.shardingsphere.proxy.frontend.ShardingSphereProxy;
import org.apache.shardingsphere.proxy.initializer.BootstrapInitializer;
+import org.apache.shardingsphere.scaling.core.config.ServerConfiguration;
import org.apache.shardingsphere.tracing.opentracing.OpenTracingTracer;
import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
@@ -115,6 +116,16 @@ public abstract class AbstractBootstrapInitializer implements BootstrapInitializ
}
}
+ protected Optional<ServerConfiguration> getScalingConfiguration(final YamlProxyConfiguration yamlConfig) {
+ if (null != yamlConfig.getServerConfiguration().getScaling()) {
+ ServerConfiguration result = new ServerConfiguration();
+ result.setBlockQueueSize(yamlConfig.getServerConfiguration().getScaling().getBlockQueueSize());
+ result.setWorkerThread(yamlConfig.getServerConfiguration().getScaling().getWorkerThread());
+ return Optional.of(result);
+ }
+ return Optional.empty();
+ }
+
protected abstract ProxyConfiguration getProxyConfiguration(YamlProxyConfiguration yamlConfig);
protected abstract MetaDataContexts decorateMetaDataContexts(MetaDataContexts metaDataContexts);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
index 5f9c42b..f87955b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
@@ -48,6 +48,7 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
@@ -137,9 +138,12 @@ public final class GovernanceBootstrapInitializer extends AbstractBootstrapIniti
@Override
protected void initScalingWorker(final YamlProxyConfiguration yamlConfig) {
- ServerConfiguration serverConfiguration = new ServerConfiguration();
- serverConfiguration.setDistributedScalingService(new GovernanceConfigurationYamlSwapper().swapToObject(yamlConfig.getServerConfiguration().getGovernance()));
- ScalingContext.getInstance().init(serverConfiguration);
- ScalingServiceHolder.getInstance().init(new DistributedScalingJobService());
+ Optional<ServerConfiguration> scalingConfigurationOptional = getScalingConfiguration(yamlConfig);
+ if (scalingConfigurationOptional.isPresent()) {
+ ServerConfiguration serverConfiguration = scalingConfigurationOptional.get();
+ serverConfiguration.setDistributedScalingService(new GovernanceConfigurationYamlSwapper().swapToObject(yamlConfig.getServerConfiguration().getGovernance()));
+ ScalingContext.getInstance().init(serverConfiguration);
+ ScalingServiceHolder.getInstance().init(new DistributedScalingJobService());
+ }
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
index 24bda7c..ace742c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
@@ -27,6 +27,8 @@ import org.apache.shardingsphere.scaling.core.config.ScalingContext;
import org.apache.shardingsphere.scaling.core.config.ServerConfiguration;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import java.util.Optional;
+
/**
* Standard bootstrap initializer.
*/
@@ -54,6 +56,9 @@ public final class StandardBootstrapInitializer extends AbstractBootstrapInitial
@Override
protected void initScalingWorker(final YamlProxyConfiguration yamlConfig) {
- ScalingContext.getInstance().init(new ServerConfiguration());
+ Optional<ServerConfiguration> scalingConfigurationOptional = getScalingConfiguration(yamlConfig);
+ if (scalingConfigurationOptional.isPresent()) {
+ ScalingContext.getInstance().init(scalingConfigurationOptional.get());
+ }
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
index 10ca789..3731ec2 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
@@ -41,6 +41,10 @@
# password: sharding
# authorizedSchemas: sharding_db
#
+#scaling:
+# blockQueueSize: 10000
+# workerThread: 40
+#
#props:
# max-connections-size-per-query: 1
# acceptor-size: 16 # The default value is available processors count * 2.
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
index b51bf23..d7c3f80 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.proxy.config.yaml;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceConfiguration;
+import org.apache.shardingsphere.governance.core.yaml.config.YamlScalingConfiguration;
import org.apache.shardingsphere.infra.auth.builtin.yaml.config.YamlAuthenticationConfiguration;
import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
@@ -36,5 +37,7 @@ public final class YamlProxyServerConfiguration implements YamlConfiguration {
private YamlGovernanceConfiguration governance;
+ private YamlScalingConfiguration scaling;
+
private Properties props = new Properties();
}