This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 f2d069c78d2 Refactor watchSessionConnection method via
InstanceContextAware (#20799)
f2d069c78d2 is described below
commit f2d069c78d216544a637805fa82f3eecb032da4d
Author: gin <[email protected]>
AuthorDate: Mon Sep 5 19:28:59 2022 +0800
Refactor watchSessionConnection method via InstanceContextAware (#20799)
---
.../keygen/SnowflakeKeyGenerateAlgorithm.java | 4 +--
.../shardingsphere/sharding/rule/ShardingRule.java | 14 +++++-----
.../keygen/SnowflakeKeyGenerateAlgorithmTest.java | 30 +++++++++++-----------
.../keygen/CosIdSnowflakeKeyGenerateAlgorithm.java | 4 +--
.../InstanceContextAware.java} | 8 +++---
.../fixture/FixtureClusterPersistRepository.java | 5 ----
.../cluster/ClusterContextManagerBuilder.java | 6 ++++-
.../fixture/ClusterPersistRepositoryFixture.java | 5 ----
...ProcessListClusterPersistRepositoryFixture.java | 5 ----
.../cluster/ClusterPersistRepository.java | 8 ------
.../repository/cluster/etcd/EtcdRepository.java | 6 -----
.../zookeeper/CuratorZookeeperRepository.java | 5 ++--
.../fixture/ClusterPersistRepositoryFixture.java | 5 ----
.../fixture/TestClusterPersistRepository.java | 5 ----
14 files changed, 37 insertions(+), 73 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithm.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithm.java
index bb02bdab934..12e2f250204 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithm.java
@@ -21,7 +21,7 @@ import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.config.algorithm.InstanceAwareAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContextAware;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
@@ -39,7 +39,7 @@ import java.util.Properties;
* 12 bits auto increment offset in one mills
* </pre>
*/
-public final class SnowflakeKeyGenerateAlgorithm implements
KeyGenerateAlgorithm, InstanceAwareAlgorithm {
+public final class SnowflakeKeyGenerateAlgorithm implements
KeyGenerateAlgorithm, InstanceContextAware {
public static final long EPOCH;
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index 76276802aca..3c247477da4 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -22,7 +22,7 @@ import com.google.common.base.Splitter;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.config.algorithm.InstanceAwareAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContextAware;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.datanode.DataNode;
@@ -135,9 +135,9 @@ public final class ShardingRule implements DatabaseRule,
DataNodeContainedRule,
Preconditions.checkArgument(isValidBindingTableConfiguration(tableRules, new
BindingTableCheckedConfiguration(this.dataSourceNames, shardingAlgorithms,
config.getBindingTableGroups(),
broadcastTables, defaultDatabaseShardingStrategyConfig,
defaultTableShardingStrategyConfig, defaultShardingColumn)),
"Invalid binding table configuration in
ShardingRuleConfiguration.");
- keyGenerators.values().stream().filter(each -> each instanceof
InstanceAwareAlgorithm).forEach(each -> ((InstanceAwareAlgorithm)
each).setInstanceContext(instanceContext));
- if (defaultKeyGenerateAlgorithm instanceof InstanceAwareAlgorithm) {
- ((InstanceAwareAlgorithm)
defaultKeyGenerateAlgorithm).setInstanceContext(instanceContext);
+ keyGenerators.values().stream().filter(each -> each instanceof
InstanceContextAware).forEach(each -> ((InstanceContextAware)
each).setInstanceContext(instanceContext));
+ if (defaultKeyGenerateAlgorithm instanceof InstanceContextAware) {
+ ((InstanceContextAware)
defaultKeyGenerateAlgorithm).setInstanceContext(instanceContext);
}
}
@@ -162,9 +162,9 @@ public final class ShardingRule implements DatabaseRule,
DataNodeContainedRule,
Preconditions.checkArgument(isValidBindingTableConfiguration(tableRules, new
BindingTableCheckedConfiguration(this.dataSourceNames, shardingAlgorithms,
config.getBindingTableGroups(),
broadcastTables, defaultDatabaseShardingStrategyConfig,
defaultTableShardingStrategyConfig, defaultShardingColumn)),
"Invalid binding table configuration in
ShardingRuleConfiguration.");
- keyGenerators.values().stream().filter(each -> each instanceof
InstanceAwareAlgorithm).forEach(each -> ((InstanceAwareAlgorithm)
each).setInstanceContext(instanceContext));
- if (defaultKeyGenerateAlgorithm instanceof InstanceAwareAlgorithm) {
- ((InstanceAwareAlgorithm)
defaultKeyGenerateAlgorithm).setInstanceContext(instanceContext);
+ keyGenerators.values().stream().filter(each -> each instanceof
InstanceContextAware).forEach(each -> ((InstanceContextAware)
each).setInstanceContext(instanceContext));
+ if (defaultKeyGenerateAlgorithm instanceof InstanceContextAware) {
+ ((InstanceContextAware)
defaultKeyGenerateAlgorithm).setInstanceContext(instanceContext);
}
}
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 f32b0f72b52..cf74b827800 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
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.sharding.algorithm.keygen;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.algorithm.InstanceAwareAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContextAware;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.schedule.ScheduleContext;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
@@ -71,8 +71,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
ExecutorService executor = Executors.newFixedThreadPool(threadNumber);
int taskNumber = threadNumber * 4;
KeyGenerateAlgorithm algorithm =
KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE",
new Properties()));
- if (algorithm instanceof InstanceAwareAlgorithm) {
- ((InstanceAwareAlgorithm) algorithm).setInstanceContext(INSTANCE);
+ if (algorithm instanceof InstanceContextAware) {
+ ((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
Set<Comparable<?>> actual = new HashSet<>(taskNumber, 1);
for (int i = 0; i < taskNumber; i++) {
@@ -85,8 +85,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
public void assertGenerateKeyWithSingleThread() {
SnowflakeKeyGenerateAlgorithm.setTimeService(new FixedTimeService(1));
KeyGenerateAlgorithm algorithm =
KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE",
new Properties()));
- if (algorithm instanceof InstanceAwareAlgorithm) {
- ((InstanceAwareAlgorithm) algorithm).setInstanceContext(INSTANCE);
+ if (algorithm instanceof InstanceContextAware) {
+ ((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
List<Comparable<?>> expected = Arrays.asList(0L, 4194305L, 4194306L,
8388608L, 8388609L, 12582913L, 12582914L, 16777216L, 16777217L, 20971521L);
List<Comparable<?>> actual = new ArrayList<>(DEFAULT_KEY_AMOUNT);
@@ -102,8 +102,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
Properties props = new Properties();
props.setProperty("max-vibration-offset", "3");
KeyGenerateAlgorithm algorithm =
KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE",
props));
- if (algorithm instanceof InstanceAwareAlgorithm) {
- ((InstanceAwareAlgorithm) algorithm).setInstanceContext(INSTANCE);
+ if (algorithm instanceof InstanceContextAware) {
+ ((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
assertThat(algorithm.generateKey(), is(0L));
assertThat(algorithm.generateKey(), is(1L));
@@ -118,8 +118,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
SnowflakeKeyGenerateAlgorithm.setTimeService(new TimeService());
props.setProperty("max-vibration-offset", String.valueOf(3));
KeyGenerateAlgorithm algorithm =
KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE",
props));
- if (algorithm instanceof InstanceAwareAlgorithm) {
- ((InstanceAwareAlgorithm) algorithm).setInstanceContext(INSTANCE);
+ if (algorithm instanceof InstanceContextAware) {
+ ((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
String actualGenerateKey0 =
Long.toBinaryString(Long.parseLong(algorithm.generateKey().toString()));
assertThat(Integer.parseInt(actualGenerateKey0.substring(actualGenerateKey0.length()
- 3), 2), is(0));
@@ -142,8 +142,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
TimeService timeService = new FixedTimeService(1);
SnowflakeKeyGenerateAlgorithm.setTimeService(timeService);
KeyGenerateAlgorithm algorithm =
KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE",
new Properties()));
- if (algorithm instanceof InstanceAwareAlgorithm) {
- ((InstanceAwareAlgorithm) algorithm).setInstanceContext(INSTANCE);
+ if (algorithm instanceof InstanceContextAware) {
+ ((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
setLastMilliseconds(algorithm, timeService.getCurrentMillis() + 2);
List<Comparable<?>> expected = Arrays.asList(4194304L, 8388609L,
8388610L, 12582912L, 12582913L, 16777217L, 16777218L, 20971520L, 20971521L,
25165825L);
@@ -161,8 +161,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
Properties props = new Properties();
props.setProperty("max-tolerate-time-difference-milliseconds",
String.valueOf(0));
KeyGenerateAlgorithm algorithm =
KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE",
props));
- if (algorithm instanceof InstanceAwareAlgorithm) {
- ((InstanceAwareAlgorithm) algorithm).setInstanceContext(INSTANCE);
+ if (algorithm instanceof InstanceContextAware) {
+ ((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
setLastMilliseconds(algorithm, timeService.getCurrentMillis() + 2);
List<Comparable<?>> actual = new ArrayList<>(DEFAULT_KEY_AMOUNT);
@@ -177,8 +177,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
TimeService timeService = new FixedTimeService(2);
SnowflakeKeyGenerateAlgorithm.setTimeService(timeService);
KeyGenerateAlgorithm algorithm =
KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE",
new Properties()));
- if (algorithm instanceof InstanceAwareAlgorithm) {
- ((InstanceAwareAlgorithm) algorithm).setInstanceContext(INSTANCE);
+ if (algorithm instanceof InstanceContextAware) {
+ ((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
setLastMilliseconds(algorithm, timeService.getCurrentMillis());
setSequence(algorithm, (1 << DEFAULT_SEQUENCE_BITS) - 1);
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
index 6f7bb3c0ecb..5aff3810e35 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
@@ -24,7 +24,7 @@ import me.ahoo.cosid.snowflake.ClockSyncSnowflakeId;
import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
import me.ahoo.cosid.snowflake.SnowflakeId;
import me.ahoo.cosid.snowflake.StringSnowflakeId;
-import org.apache.shardingsphere.infra.config.algorithm.InstanceAwareAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContextAware;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
@@ -35,7 +35,7 @@ import java.util.Properties;
/**
* CosId snowflake key generate algorithm.
*/
-public final class CosIdSnowflakeKeyGenerateAlgorithm implements
KeyGenerateAlgorithm, InstanceAwareAlgorithm {
+public final class CosIdSnowflakeKeyGenerateAlgorithm implements
KeyGenerateAlgorithm, InstanceContextAware {
public static final long DEFAULT_EPOCH;
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/InstanceAwareAlgorithm.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContextAware.java
similarity index 83%
rename from
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/InstanceAwareAlgorithm.java
rename to
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContextAware.java
index 085ec7bc635..30b25f5e586 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/InstanceAwareAlgorithm.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContextAware.java
@@ -15,14 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.config.algorithm;
-
-import org.apache.shardingsphere.infra.instance.InstanceContext;
+package org.apache.shardingsphere.infra.instance;
/**
- * Instance aware algorithm.
+ * Instance context aware.
*/
-public interface InstanceAwareAlgorithm {
+public interface InstanceContextAware {
/**
* Set instance context.
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/fixture/FixtureClusterPersistRepository.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/fixture/FixtureClusterPersistRepository.java
index fb5476f4de6..8965a88b945 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/fixture/FixtureClusterPersistRepository.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/fixture/FixtureClusterPersistRepository.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.spring.namespace.fixture;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener;
@@ -69,10 +68,6 @@ public final class FixtureClusterPersistRepository
implements ClusterPersistRepo
public void watch(final String key, final DataChangedEventListener
listener) {
}
- @Override
- public void watchSessionConnection(final InstanceContext instanceContext) {
- }
-
@Override
public boolean persistLock(final String lockKey, final long timeoutMillis)
{
return false;
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 1bf6c2d4921..8ad645f4437 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
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.mode.manager.cluster;
+import org.apache.shardingsphere.infra.instance.InstanceContextAware;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -49,7 +50,10 @@ public final class ClusterContextManagerBuilder implements
ContextManagerBuilder
persistConfigurations(persistService, parameter);
RegistryCenter registryCenter = new RegistryCenter(repository, new
EventBusContext(), parameter.getInstanceMetaData(),
parameter.getDatabaseConfigs());
InstanceContext instanceContext = buildInstanceContext(registryCenter,
parameter);
- registryCenter.getRepository().watchSessionConnection(instanceContext);
+ ClusterPersistRepository persistRepository =
registryCenter.getRepository();
+ if (persistRepository instanceof InstanceContextAware) {
+ ((InstanceContextAware)
persistRepository).setInstanceContext(instanceContext);
+ }
MetaDataContexts metaDataContexts =
MetaDataContextsFactory.create(persistService, parameter, instanceContext);
persistMetaData(metaDataContexts);
ContextManager result = new ContextManager(metaDataContexts,
instanceContext);
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java
index 0777c77f740..60a4434143b 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator.fixture;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener;
@@ -61,10 +60,6 @@ public final class ClusterPersistRepositoryFixture
implements ClusterPersistRepo
public void watch(final String key, final DataChangedEventListener
listener) {
}
- @Override
- public void watchSessionConnection(final InstanceContext instanceContext) {
- }
-
@Override
public boolean persistLock(final String lockKey, final long timeoutMillis)
{
return false;
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFixture.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFix
[...]
index bdb4a351d74..397b22a33e4 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFixture.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFixture.java
@@ -17,7 +17,6 @@
package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener;
@@ -68,10 +67,6 @@ public final class
ProcessListClusterPersistRepositoryFixture implements Cluster
public void watch(final String key, final DataChangedEventListener
listener) {
}
- @Override
- public void watchSessionConnection(final InstanceContext instanceContext) {
- }
-
@Override
public boolean persistLock(final String lockKey, final long timeoutMillis)
{
return false;
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/ClusterPersistRepository.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/ClusterPer
[...]
index 4e69db74e0a..1c34f3ff762 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/ClusterPersistRepository.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/ClusterPersistRepository.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.mode.repository.cluster;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.mode.persist.PersistRepository;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener;
@@ -65,11 +64,4 @@ public interface ClusterPersistRepository extends
PersistRepository {
* @param listener data changed event listener
*/
void watch(String key, DataChangedEventListener listener);
-
- /**
- * Watch session connection.
- *
- * @param instanceContext instance context
- */
- void watchSessionConnection(InstanceContext instanceContext);
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-etcd/src/main/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepository.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mo
[...]
index 9b45e2fc5f7..2b1c0d09514 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-etcd/src/main/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepository.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-etcd/src/main/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepository.java
@@ -31,7 +31,6 @@ import io.etcd.jetcd.support.Observers;
import io.etcd.jetcd.watch.WatchEvent;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
import
org.apache.shardingsphere.mode.repository.cluster.etcd.lock.EtcdInternalLockHolder;
@@ -144,11 +143,6 @@ public final class EtcdRepository implements
ClusterPersistRepository {
}
}
- @Override
- public void watchSessionConnection(final InstanceContext instanceContext) {
- // TODO
- }
-
@Override
public boolean persistLock(final String lockKey, final long timeoutMillis)
{
return
etcdInternalLockHolder.getInternalLock(lockKey).tryLock(timeoutMillis);
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepository.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-prov
[...]
index eb42a456bf5..49b62d1b7ba 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepository.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepository.java
@@ -28,6 +28,7 @@ import
org.apache.curator.framework.recipes.cache.TreeCacheEvent;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.CloseableUtils;
import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.instance.InstanceContextAware;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryException;
@@ -56,7 +57,7 @@ import java.util.concurrent.TimeUnit;
/**
* Registry repository of ZooKeeper.
*/
-public final class CuratorZookeeperRepository implements
ClusterPersistRepository {
+public final class CuratorZookeeperRepository implements
ClusterPersistRepository, InstanceContextAware {
private final Map<String, CuratorCache> caches = new HashMap<>();
@@ -295,7 +296,7 @@ public final class CuratorZookeeperRepository implements
ClusterPersistRepositor
}
@Override
- public void watchSessionConnection(final InstanceContext instanceContext) {
+ public void setInstanceContext(final InstanceContext instanceContext) {
client.getConnectionStateListenable().addListener(new
SessionConnectionListener(instanceContext, this));
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java
index 0d44faed7e1..02f07bf1991 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.proxy.fixture;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener;
@@ -67,10 +66,6 @@ public final class ClusterPersistRepositoryFixture
implements ClusterPersistRepo
public void watch(final String key, final DataChangedEventListener
listener) {
}
- @Override
- public void watchSessionConnection(final InstanceContext instanceContext) {
- }
-
@Override
public boolean persistLock(final String lockKey, final long timeoutMillis)
{
return false;
diff --git
a/shardingsphere-test/shardingsphere-integration-driver-test/src/test/java/org/apache/shardingsphere/driver/fixture/TestClusterPersistRepository.java
b/shardingsphere-test/shardingsphere-integration-driver-test/src/test/java/org/apache/shardingsphere/driver/fixture/TestClusterPersistRepository.java
index a5d97d43415..09bb93cc64b 100644
---
a/shardingsphere-test/shardingsphere-integration-driver-test/src/test/java/org/apache/shardingsphere/driver/fixture/TestClusterPersistRepository.java
+++
b/shardingsphere-test/shardingsphere-integration-driver-test/src/test/java/org/apache/shardingsphere/driver/fixture/TestClusterPersistRepository.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.driver.fixture;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener;
@@ -69,10 +68,6 @@ public final class TestClusterPersistRepository implements
ClusterPersistReposit
public void watch(final String key, final DataChangedEventListener
listener) {
}
- @Override
- public void watchSessionConnection(final InstanceContext instanceContext) {
- }
-
@Override
public boolean persistLock(final String lockKey, final long timeoutMillis)
{
return false;