Skip to content

Commit

Permalink
Remove usage of RegistryCenter (#31273)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored May 17, 2024
1 parent f1721ac commit c2514a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.shardingsphere.mode.manager.ContextManagerAware;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilder;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.RegistryCenter;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.GlobalLockPersistService;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.subscriber.ShardingSphereSchemaDataRegistrySubscriber;
Expand Down Expand Up @@ -65,17 +64,16 @@ public final class ClusterContextManagerBuilder implements ContextManagerBuilder
@Override
public ContextManager build(final ContextManagerBuilderParameter param, final EventBusContext eventBusContext) throws SQLException {
ClusterPersistRepository repository = getClusterPersistRepository((ClusterPersistRepositoryConfiguration) param.getModeConfiguration().getRepository());
RegistryCenter registryCenter = new RegistryCenter(eventBusContext, repository, param.getInstanceMetaData(), param.getDatabaseConfigs());
InstanceContext instanceContext = buildInstanceContext(repository, param, eventBusContext);
if (registryCenter.getRepository() instanceof InstanceContextAware) {
((InstanceContextAware) registryCenter.getRepository()).setInstanceContext(instanceContext);
if (repository instanceof InstanceContextAware) {
((InstanceContextAware) repository).setInstanceContext(instanceContext);
}
MetaDataPersistService metaDataPersistService = new MetaDataPersistService(repository);
MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(metaDataPersistService, param, instanceContext, new QualifiedDataSourceStatusService(repository).loadStatus());
ContextManager result = new ContextManager(metaDataContexts, instanceContext);
setContextManagerAware(result);
createSubscribers(eventBusContext, repository);
registerOnline(eventBusContext, instanceContext, registryCenter, param, result);
registerOnline(eventBusContext, instanceContext, repository, param, result);
setClusterState(repository, result);
return result;
}
Expand Down Expand Up @@ -111,16 +109,16 @@ private void createSubscribers(final EventBusContext eventBusContext, final Clus
}

private void registerOnline(final EventBusContext eventBusContext, final InstanceContext instanceContext,
final RegistryCenter registryCenter, final ContextManagerBuilderParameter param, final ContextManager contextManager) {
ComputeNodeStatusService computeNodeStatusService = new ComputeNodeStatusService(registryCenter.getRepository());
final ClusterPersistRepository repository, final ContextManagerBuilderParameter param, final ContextManager contextManager) {
ComputeNodeStatusService computeNodeStatusService = new ComputeNodeStatusService(repository);
computeNodeStatusService.registerOnline(instanceContext.getInstance().getMetaData());
computeNodeStatusService.persistInstanceLabels(instanceContext.getInstance().getCurrentInstanceId(), instanceContext.getInstance().getLabels());
computeNodeStatusService.persistInstanceState(instanceContext.getInstance().getCurrentInstanceId(), instanceContext.getInstance().getState());
new GovernanceWatcherFactory(registryCenter.getRepository(),
new GovernanceWatcherFactory(repository,
eventBusContext, param.getInstanceMetaData() instanceof JDBCInstanceMetaData ? param.getDatabaseConfigs().keySet() : Collections.emptyList()).watchListeners();
contextManager.getInstanceContext().getInstance().setLabels(param.getLabels());
contextManager.getInstanceContext().getAllClusterInstances().addAll(new ComputeNodeStatusService(registryCenter.getRepository()).loadAllComputeNodeInstances());
new ClusterEventSubscriberRegistry(contextManager, registryCenter).register();
contextManager.getInstanceContext().getAllClusterInstances().addAll(new ComputeNodeStatusService(repository).loadAllComputeNodeInstances());
new ClusterEventSubscriberRegistry(contextManager, repository).register();
}

private void setClusterState(final ClusterPersistRepository repository, final ContextManager contextManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber;

import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.RegistryCenter;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.subscriber.ProcessListChangedSubscriber;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import org.apache.shardingsphere.mode.subsciber.EventSubscriberRegistry;
import org.apache.shardingsphere.mode.subsciber.RuleItemChangedSubscriber;

Expand All @@ -28,15 +28,15 @@
*/
public final class ClusterEventSubscriberRegistry extends EventSubscriberRegistry {

public ClusterEventSubscriberRegistry(final ContextManager contextManager, final RegistryCenter registryCenter) {
public ClusterEventSubscriberRegistry(final ContextManager contextManager, final ClusterPersistRepository repository) {
super(contextManager,
new RuleItemChangedSubscriber(contextManager),
new ConfigurationChangedSubscriber(contextManager),
new ConfigurationChangedSubscriber(contextManager),
new ResourceMetaDataChangedSubscriber(contextManager),
new StateChangedSubscriber(contextManager, registryCenter.getRepository()),
new StateChangedSubscriber(contextManager, repository),
new DatabaseChangedSubscriber(contextManager),
new ProcessListChangedSubscriber(contextManager, registryCenter.getRepository()),
new ProcessListChangedSubscriber(contextManager, repository),
new CacheEvictedSubscriber());
}
}

0 comments on commit c2514a5

Please sign in to comment.