Skip to content

Commit

Permalink
Use DataChangedEventHandler to instead of DispatchEventBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Dec 31, 2024
1 parent 5090f09 commit 56db830
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 282 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.handler.type;

import org.apache.shardingsphere.infra.instance.metadata.InstanceType;
import org.apache.shardingsphere.metadata.persist.node.DatabaseMetaDataNode;
import org.apache.shardingsphere.metadata.persist.node.StatesNode;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.handler.DataChangedEventHandler;
import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type.DatabaseMetaDataChangedListener;
import org.apache.shardingsphere.mode.metadata.refresher.ShardingSphereStatisticsRefreshEngine;
import org.apache.shardingsphere.mode.persist.service.unified.ListenerAssistedType;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;

import java.util.Arrays;
import java.util.Collection;

/**
* Listener assisted changed handler.
*/
public final class ListenerAssistedChangedHandler implements DataChangedEventHandler {

@Override
public String getSubscribedKey() {
return StatesNode.getListenerAssistedNodePath();
}

@Override
public Collection<Type> getSubscribedTypes() {
return Arrays.asList(Type.ADDED, Type.UPDATED);
}

@Override
public void handle(final ContextManager contextManager, final DataChangedEvent event) {
StatesNode.getDatabaseNameByListenerAssistedNodePath(event.getKey()).ifPresent(optional -> handle(contextManager, optional, ListenerAssistedType.valueOf(event.getValue())));
}

private static void handle(final ContextManager contextManager, final String databaseName, final ListenerAssistedType listenerAssistedType) {
ClusterPersistRepository repository = (ClusterPersistRepository) contextManager.getPersistServiceFacade().getRepository();
if (ListenerAssistedType.CREATE_DATABASE == listenerAssistedType) {
repository.watch(DatabaseMetaDataNode.getDatabaseNamePath(databaseName), new DatabaseMetaDataChangedListener(contextManager.getComputeNodeInstanceContext().getEventBusContext()));
contextManager.getMetaDataContextManager().getSchemaMetaDataManager().addDatabase(databaseName);
} else if (ListenerAssistedType.DROP_DATABASE == listenerAssistedType) {
repository.removeDataListener(DatabaseMetaDataNode.getDatabaseNamePath(databaseName));
contextManager.getMetaDataContextManager().getSchemaMetaDataManager().dropDatabase(databaseName);
}
contextManager.getPersistServiceFacade().getListenerAssistedPersistService().deleteDatabaseNameListenerAssisted(databaseName);
if (InstanceType.PROXY == contextManager.getComputeNodeInstanceContext().getInstance().getMetaData().getType()) {
new ShardingSphereStatisticsRefreshEngine(contextManager).asyncRefresh();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.CacheEvictedSubscriber;
import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.ComputeNodeStateSubscriber;
import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.DatabaseDataChangedSubscriber;
import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.ListenerAssistedSubscriber;
import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.MetaDataChangedSubscriber;
import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.ProcessListChangedSubscriber;
import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.RuleItemChangedSubscriber;
Expand All @@ -43,7 +42,6 @@ public final class ClusterDispatchEventSubscriberRegistry {
public ClusterDispatchEventSubscriberRegistry(final ContextManager contextManager) {
subscribers = Arrays.asList(new RuleItemChangedSubscriber(contextManager),
new MetaDataChangedSubscriber(contextManager),
new ListenerAssistedSubscriber(contextManager),
new DatabaseDataChangedSubscriber(contextManager),
new ProcessListChangedSubscriber(contextManager),
new CacheEvictedSubscriber(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.ComputeNodeStateDispatchEventBuilder
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.ShardingSphereDataDispatchEventBuilder
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.ListenerAssistedDispatchEventBuilder
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.ComputeNodeOnlineDispatchEventBuilder
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.ShowProcessListDispatchEventBuilder
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.KillProcessDispatchEventBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ org.apache.shardingsphere.mode.manager.cluster.event.dispatch.handler.type.Clust
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.handler.type.QualifiedDataSourceChangedHandler
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.handler.type.GlobalRuleChangedHandler
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.handler.type.PropertiesChangedHandler
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.handler.type.ListenerAssistedChangedHandler

This file was deleted.

Loading

0 comments on commit 56db830

Please sign in to comment.