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 cfae999 Print runtime mode of proxy in the startup log (#15149) cfae999 is described below commit cfae9992985efc1983e287f7be36b0f9112b3d73 Author: Haoran Meng <menghaora...@gmail.com> AuthorDate: Fri Jan 28 18:08:13 2022 +0800 Print runtime mode of proxy in the startup log (#15149) --- .../prometheus/collector/ProxyInfoCollectorTest.java | 2 +- .../service/PrometheusPluginBootServiceTest.java | 2 +- .../keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java | 14 +++++++------- .../keygen/SnowflakeKeyGenerateAlgorithmTest.java | 4 ++-- .../shardingsphere/infra/instance/InstanceContext.java | 5 ++++- .../mode/manager/cluster/ClusterContextManagerBuilder.java | 2 +- .../mode/manager/memory/MemoryContextManagerBuilder.java | 2 +- .../standalone/StandaloneContextManagerBuilder.java | 2 +- .../shardingsphere/proxy/frontend/ShardingSphereProxy.java | 2 +- .../adapter/impl/ShardingSphereProxyContainer.java | 2 +- 10 files changed, 20 insertions(+), 17 deletions(-) diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java index 5f3d388..ca2790e 100644 --- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java +++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java @@ -36,7 +36,7 @@ public final class ProxyInfoCollectorTest { @Test public void assertCollect() { ProxyContext.getInstance().getContextManager().init(mock(MetaDataContexts.class), mock(TransactionContexts.class), new InstanceContext(new ComputeNodeInstance(), - new MemoryWorkerIdGenerator())); + new MemoryWorkerIdGenerator(), "Memory")); ProxyInfoCollector proxyInfoCollector = new ProxyInfoCollector(); List<Collector.MetricFamilySamples> metricFamilySamples = proxyInfoCollector.collect(); assertFalse(metricFamilySamples.isEmpty()); diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java index f0e51dd..28d05db 100644 --- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java +++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java @@ -45,7 +45,7 @@ public final class PrometheusPluginBootServiceTest { @Test public void assertStart() { ProxyContext.getInstance().getContextManager().init(mock(MetaDataContexts.class), mock(TransactionContexts.class), new InstanceContext(new ComputeNodeInstance(), - new MemoryWorkerIdGenerator())); + new MemoryWorkerIdGenerator(), "Memory")); Properties props = new Properties(); props.setProperty("JVM_INFORMATION_COLLECTOR_ENABLED", "true"); PluginConfiguration configuration = new PluginConfiguration("localhost", 8090, "", props); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java index 6248095..531a930 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java @@ -15,9 +15,6 @@ package org.apache.shardingsphere.sharding.algorithm.keygen; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - import me.ahoo.cosid.converter.Radix62IdConverter; import me.ahoo.cosid.snowflake.MillisecondSnowflakeId; import me.ahoo.cosid.snowflake.MillisecondSnowflakeIdStateParser; @@ -31,6 +28,9 @@ import org.junit.Test; import java.util.Properties; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + public final class CosIdSnowflakeKeyGenerateAlgorithmTest { private static final long FIXTURE_WORKER_ID = 0; @@ -46,7 +46,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest { public void assertGenerateKey() { CosIdSnowflakeKeyGenerateAlgorithm cosIdSnowflakeKeyGenerateAlgorithm = new CosIdSnowflakeKeyGenerateAlgorithm(); Properties properties = new Properties(); - cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID))); + cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID), "Memory")); cosIdSnowflakeKeyGenerateAlgorithm.setProps(properties); cosIdSnowflakeKeyGenerateAlgorithm.init(); long firstActualKey = (Long) cosIdSnowflakeKeyGenerateAlgorithm.generateKey(); @@ -64,7 +64,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest { CosIdSnowflakeKeyGenerateAlgorithm cosIdSnowflakeKeyGenerateAlgorithm = new CosIdSnowflakeKeyGenerateAlgorithm(); Properties properties = new Properties(); properties.setProperty(CosIdSnowflakeKeyGenerateAlgorithm.AS_STRING_KEY, "true"); - cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID))); + cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID), "Memory")); cosIdSnowflakeKeyGenerateAlgorithm.setProps(properties); cosIdSnowflakeKeyGenerateAlgorithm.init(); Comparable<?> actualKey = cosIdSnowflakeKeyGenerateAlgorithm.generateKey(); @@ -90,7 +90,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest { public void assertGenerateKeyWhenNegative() { CosIdSnowflakeKeyGenerateAlgorithm cosIdSnowflakeKeyGenerateAlgorithm = new CosIdSnowflakeKeyGenerateAlgorithm(); Properties properties = new Properties(); - cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(-1))); + cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(-1), "Memory")); cosIdSnowflakeKeyGenerateAlgorithm.setProps(properties); cosIdSnowflakeKeyGenerateAlgorithm.init(); cosIdSnowflakeKeyGenerateAlgorithm.generateKey(); @@ -100,7 +100,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest { public void assertGenerateKeyWhenGreaterThen1023() { CosIdSnowflakeKeyGenerateAlgorithm cosIdSnowflakeKeyGenerateAlgorithm = new CosIdSnowflakeKeyGenerateAlgorithm(); Properties properties = new Properties(); - cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(1024))); + cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(1024), "Memory")); cosIdSnowflakeKeyGenerateAlgorithm.setProps(properties); cosIdSnowflakeKeyGenerateAlgorithm.init(); cosIdSnowflakeKeyGenerateAlgorithm.generateKey(); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java index 7ddef0e..b146847 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java @@ -175,7 +175,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest { @Test(expected = IllegalArgumentException.class) public void assertSetWorkerIdFailureWhenNegative() { - keyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(-1L))); + keyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(-1L), "Memory")); keyGenerateAlgorithm.init(); keyGenerateAlgorithm.generateKey(); clearInstanceContext(); @@ -192,7 +192,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest { @Test(expected = IllegalArgumentException.class) public void assertSetWorkerIdFailureWhenOutOfRange() { - keyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(Long.MIN_VALUE))); + keyGenerateAlgorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(Long.MIN_VALUE), "Memory")); keyGenerateAlgorithm.init(); keyGenerateAlgorithm.generateKey(); clearInstanceContext(); diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java index dba029d..7c8715d 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java @@ -38,10 +38,13 @@ public final class InstanceContext { private final WorkerIdGenerator workerIdGenerator; - public InstanceContext(final ComputeNodeInstance instance, final WorkerIdGenerator workerIdGenerator) { + private final String modeType; + + public InstanceContext(final ComputeNodeInstance instance, final WorkerIdGenerator workerIdGenerator, final String modeType) { this.instance = instance; switchInstanceState(instance.getStatus()); this.workerIdGenerator = workerIdGenerator; + this.modeType = modeType; } /** diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java index 3558131..c3c94f4 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java @@ -112,7 +112,7 @@ public final class ClusterContextManagerBuilder implements ContextManagerBuilder metaDataContexts = new MetaDataContextsBuilder(schemaConfigs, metaDataPersistService.getGlobalRuleService().load(), schemas, rules, loadedProps).build(metaDataPersistService); transactionContexts = new TransactionContextsBuilder(metaDataContexts.getMetaDataMap(), metaDataContexts.getGlobalRuleMetaData().getRules()).build(); instanceContext = new InstanceContext(metaDataPersistService.getComputeNodePersistService().loadComputeNodeInstance( - parameter.getInstanceDefinition()), new ClusterWorkerIdGenerator(repository, metaDataPersistService, parameter.getInstanceDefinition())); + parameter.getInstanceDefinition()), new ClusterWorkerIdGenerator(repository, metaDataPersistService, parameter.getInstanceDefinition()), getType()); } private ClusterPersistRepository createClusterPersistRepository(final ClusterPersistRepositoryConfiguration config) { diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java index afe77e8..f01cb20 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java @@ -70,7 +70,7 @@ public final class MemoryContextManagerBuilder implements ContextManagerBuilder ComputeNodeInstance instance = new ComputeNodeInstance(); instance.setInstanceDefinition(parameter.getInstanceDefinition()); instance.setLabels(parameter.getLabels()); - return new InstanceContext(instance, new MemoryWorkerIdGenerator()); + return new InstanceContext(instance, new MemoryWorkerIdGenerator(), getType()); } private void buildSpecialRules(final ContextManager contextManager) { diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java index 1ec5b7f..6c03c60 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java @@ -88,7 +88,7 @@ public final class StandaloneContextManagerBuilder implements ContextManagerBuil TransactionContexts transactionContexts = new TransactionContextsBuilder(metaDataContexts.getMetaDataMap(), metaDataContexts.getGlobalRuleMetaData().getRules()).build(); ContextManager result = new ContextManager(); result.init(metaDataContexts, transactionContexts, new InstanceContext(metaDataPersistService.getComputeNodePersistService().loadComputeNodeInstance(parameter.getInstanceDefinition()), - new StandaloneWorkerIdGenerator())); + new StandaloneWorkerIdGenerator(), getType())); buildSpecialRules(result); return result; } diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java index 55f46c2..57e3cef 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java +++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java @@ -74,7 +74,7 @@ public final class ShardingSphereProxy { } private void accept(final ChannelFuture future) throws InterruptedException { - log.info("ShardingSphere-Proxy start success"); + log.info("ShardingSphere-Proxy {} mode started successfully", ProxyContext.getInstance().getContextManager().getInstanceContext().getModeType()); future.channel().closeFuture().sync(); } diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/container/adapter/impl/ShardingSphereProxyContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/container/adapter/impl/ShardingSphereProxyContainer.java index d939738..d3a3858 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/container/adapter/impl/ShardingSphereProxyContainer.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/container/adapter/impl/ShardingSphereProxyContainer.java @@ -88,7 +88,7 @@ public final class ShardingSphereProxyContainer extends ShardingSphereAdapterCon @Override protected void configure() { withConfMapping("/docker/" + getParameterizedArray().getScenario() + "/" + getParameterizedArray().getDatabaseType().getName().toLowerCase() + "/proxy/conf"); - setWaitStrategy(new LogMessageWaitStrategy().withRegEx(".*ShardingSphere-Proxy start success.*")); + setWaitStrategy(new LogMessageWaitStrategy().withRegEx(".*ShardingSphere-Proxy .* mode started successfully.*")); super.configure(); }