Skip to content

Commit 418dbb4

Browse files
authored
Refactor ClusterPersistRepository (#34992)
1 parent 886b409 commit 418dbb4

File tree

12 files changed

+31
-29
lines changed

12 files changed

+31
-29
lines changed

mode/spi/src/main/java/org/apache/shardingsphere/mode/spi/repository/PersistRepository.java

-9
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,6 @@ public interface PersistRepository extends TypedSPI, AutoCloseable {
6363
*/
6464
void persist(String key, String value);
6565

66-
/**
67-
* Persist ephemeral data.
68-
*
69-
* @param key key of data
70-
* @param value value of data
71-
*/
72-
default void persistEphemeral(String key, String value) {
73-
}
74-
7566
/**
7667
* Update data.
7768
*

mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/database/ClusterDatabaseListenerPersistCoordinator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
import lombok.RequiredArgsConstructor;
2121
import org.apache.shardingsphere.mode.node.path.engine.generator.NodePathGenerator;
2222
import org.apache.shardingsphere.mode.node.path.type.global.state.DatabaseListenerCoordinatorNodePath;
23-
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
23+
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
2424

2525
/**
2626
* Cluster database listener persist coordinator.
2727
*/
2828
@RequiredArgsConstructor
2929
public final class ClusterDatabaseListenerPersistCoordinator {
3030

31-
private final PersistRepository repository;
31+
private final ClusterPersistRepository repository;
3232

3333
/**
3434
* Persist database listener assisted state.

mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/facade/ClusterPersistServiceFacade.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.apache.shardingsphere.mode.manager.cluster.persist.service.ClusterProcessPersistService;
2626
import org.apache.shardingsphere.mode.metadata.manager.MetaDataContextManager;
2727
import org.apache.shardingsphere.mode.persist.mode.ModePersistServiceFacade;
28-
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
28+
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
2929

3030
/**
3131
* Cluster persist service facade.
@@ -42,7 +42,7 @@ public final class ClusterPersistServiceFacade implements ModePersistServiceFaca
4242
@Getter(AccessLevel.NONE)
4343
private final ComputeNodeInstance computeNodeInstance;
4444

45-
public ClusterPersistServiceFacade(final MetaDataContextManager metaDataContextManager, final PersistRepository repository) {
45+
public ClusterPersistServiceFacade(final MetaDataContextManager metaDataContextManager, final ClusterPersistRepository repository) {
4646
metaDataManagerPersistService = new ClusterMetaDataManagerPersistService(metaDataContextManager, repository);
4747
computeNodePersistService = new ClusterComputeNodePersistService(repository);
4848
processPersistService = new ClusterProcessPersistService(repository);

mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/facade/ClusterPersistServiceFacadeBuilder.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.shardingsphere.mode.metadata.manager.MetaDataContextManager;
2121
import org.apache.shardingsphere.mode.persist.mode.ModePersistServiceFacade;
2222
import org.apache.shardingsphere.mode.persist.mode.ModePersistServiceFacadeBuilder;
23+
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
2324
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
2425

2526
/**
@@ -29,7 +30,7 @@ public final class ClusterPersistServiceFacadeBuilder implements ModePersistServ
2930

3031
@Override
3132
public ModePersistServiceFacade build(final MetaDataContextManager metaDataContextManager, final PersistRepository repository) {
32-
return new ClusterPersistServiceFacade(metaDataContextManager, repository);
33+
return new ClusterPersistServiceFacade(metaDataContextManager, (ClusterPersistRepository) repository);
3334
}
3435

3536
@Override

mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterComputeNodePersistService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.apache.shardingsphere.mode.node.path.type.global.node.compute.status.StatusNodePath;
3636
import org.apache.shardingsphere.mode.node.path.type.global.node.compute.workerid.ComputeNodeWorkerIDNodePath;
3737
import org.apache.shardingsphere.mode.persist.service.ComputeNodePersistService;
38-
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
38+
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
3939

4040
import java.util.Arrays;
4141
import java.util.Collection;
@@ -52,7 +52,7 @@
5252
@Slf4j
5353
public final class ClusterComputeNodePersistService implements ComputeNodePersistService {
5454

55-
private final PersistRepository repository;
55+
private final ClusterPersistRepository repository;
5656

5757
/**
5858
* Register compute node online.

mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
3131
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
3232
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereView;
33-
import org.apache.shardingsphere.mode.manager.cluster.exception.ReloadMetaDataContextFailedException;
3433
import org.apache.shardingsphere.mode.exception.LoadTableMetaDataFailedException;
34+
import org.apache.shardingsphere.mode.manager.cluster.exception.ReloadMetaDataContextFailedException;
3535
import org.apache.shardingsphere.mode.manager.cluster.persist.coordinator.database.ClusterDatabaseListenerCoordinatorType;
3636
import org.apache.shardingsphere.mode.manager.cluster.persist.coordinator.database.ClusterDatabaseListenerPersistCoordinator;
3737
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -40,7 +40,7 @@
4040
import org.apache.shardingsphere.mode.metadata.persist.metadata.DatabaseMetaDataPersistFacade;
4141
import org.apache.shardingsphere.mode.metadata.refresher.metadata.util.TableRefreshUtils;
4242
import org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService;
43-
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
43+
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
4444
import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
4545
import org.apache.shardingsphere.single.rule.SingleRule;
4646

@@ -65,7 +65,7 @@ public final class ClusterMetaDataManagerPersistService implements MetaDataManag
6565

6666
private final ClusterDatabaseListenerPersistCoordinator clusterDatabaseListenerPersistCoordinator;
6767

68-
public ClusterMetaDataManagerPersistService(final MetaDataContextManager metaDataContextManager, final PersistRepository repository) {
68+
public ClusterMetaDataManagerPersistService(final MetaDataContextManager metaDataContextManager, final ClusterPersistRepository repository) {
6969
this.metaDataContextManager = metaDataContextManager;
7070
metaDataPersistFacade = metaDataContextManager.getMetaDataPersistFacade();
7171
clusterDatabaseListenerPersistCoordinator = new ClusterDatabaseListenerPersistCoordinator(repository);

mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/fixture/ClusterPersistRepositoryFixture.java

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public void persist(final String key, final String value) {
5757
public void update(final String key, final String value) {
5858
}
5959

60+
@Override
61+
public void persistEphemeral(final String key, final String value) {
62+
}
63+
6064
@Override
6165
public boolean persistExclusiveEphemeral(final String key, final String value) {
6266
return true;

mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/database/ClusterDatabaseListenerPersistCoordinatorTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.shardingsphere.mode.manager.cluster.persist.coordinator.database;
1919

20-
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
20+
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
2121
import org.junit.jupiter.api.Test;
2222
import org.junit.jupiter.api.extension.ExtendWith;
2323
import org.mockito.Answers;
@@ -30,7 +30,7 @@
3030
class ClusterDatabaseListenerPersistCoordinatorTest {
3131

3232
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
33-
private PersistRepository repository;
33+
private ClusterPersistRepository repository;
3434

3535
@Test
3636
void assertPersist() {

mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterComputeNodePersistServiceTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.apache.shardingsphere.infra.instance.yaml.YamlComputeNodeData;
2424
import org.apache.shardingsphere.infra.state.instance.InstanceState;
2525
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
26-
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
26+
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
2727
import org.junit.jupiter.api.BeforeEach;
2828
import org.junit.jupiter.api.Test;
2929
import org.junit.jupiter.api.extension.ExtendWith;
@@ -50,7 +50,7 @@ class ClusterComputeNodePersistServiceTest {
5050
private ClusterComputeNodePersistService computeNodePersistService;
5151

5252
@Mock
53-
private PersistRepository repository;
53+
private ClusterPersistRepository repository;
5454

5555
@BeforeEach
5656
void setUp() {

mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistServiceTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.apache.shardingsphere.mode.manager.cluster.persist.coordinator.database.ClusterDatabaseListenerPersistCoordinator;
2828
import org.apache.shardingsphere.mode.metadata.manager.MetaDataContextManager;
2929
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistFacade;
30-
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
30+
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
3131
import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
3232
import org.apache.shardingsphere.single.rule.SingleRule;
3333
import org.apache.shardingsphere.test.fixture.database.MockedDatabaseType;
@@ -68,7 +68,7 @@ class ClusterMetaDataManagerPersistServiceTest {
6868
@SneakyThrows(ReflectiveOperationException.class)
6969
@BeforeEach
7070
void setUp() {
71-
metaDataManagerPersistService = new ClusterMetaDataManagerPersistService(metaDataContextManager, mock(PersistRepository.class));
71+
metaDataManagerPersistService = new ClusterMetaDataManagerPersistService(metaDataContextManager, mock(ClusterPersistRepository.class));
7272
Plugins.getMemberAccessor().set(ClusterMetaDataManagerPersistService.class.getDeclaredField("metaDataPersistFacade"), metaDataManagerPersistService, metaDataPersistFacade);
7373
Plugins.getMemberAccessor().set(ClusterMetaDataManagerPersistService.class.getDeclaredField("clusterDatabaseListenerPersistCoordinator"),
7474
metaDataManagerPersistService, clusterDatabaseListenerPersistCoordinator);

mode/type/cluster/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/ClusterPersistRepository.java

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public interface ClusterPersistRepository extends PersistRepository {
3535
*/
3636
void init(ClusterPersistRepositoryConfiguration config, ComputeNodeInstanceContext computeNodeInstanceContext);
3737

38+
/**
39+
* Persist ephemeral data.
40+
*
41+
* @param key key of data
42+
* @param value value of data
43+
*/
44+
void persistEphemeral(String key, String value);
45+
3846
/**
3947
* Persist exclusive ephemeral data.
4048
*

proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/MetaDataImportExecutor.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyServerConfiguration;
2727
import org.apache.shardingsphere.proxy.backend.distsql.export.ExportedMetaData;
2828

29-
import java.sql.SQLException;
3029
import java.util.Collection;
3130
import java.util.LinkedList;
3231

@@ -51,15 +50,14 @@ public MetaDataImportExecutor(final ContextManager contextManager) {
5150
* Import cluster configurations.
5251
*
5352
* @param exportedMetaData exported metadata
54-
* @throws SQLException SQL exception
5553
*/
56-
public void importClusterConfigurations(final ExportedMetaData exportedMetaData) throws SQLException {
54+
public void importClusterConfigurations(final ExportedMetaData exportedMetaData) {
5755
Collection<YamlProxyDatabaseConfiguration> databaseConfigs = getYamlProxyDatabaseConfigurations(exportedMetaData);
5856
importServerConfiguration(exportedMetaData);
5957
importDatabaseConfigurations(databaseConfigs);
6058
}
6159

62-
private void importServerConfiguration(final ExportedMetaData exportedMetaData) throws SQLException {
60+
private void importServerConfiguration(final ExportedMetaData exportedMetaData) {
6361
YamlProxyServerConfiguration yamlServerConfig = YamlEngine.unmarshal(exportedMetaData.getRules() + System.lineSeparator() + exportedMetaData.getProps(), YamlProxyServerConfiguration.class);
6462
if (null == yamlServerConfig) {
6563
return;

0 commit comments

Comments
 (0)