Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mysql index of init schema in admin module #5093

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fac5984
Merge pull request #1 from apache/master
bert82503 Aug 24, 2023
0298675
Add TABLE `api` index
bert82503 Aug 24, 2023
1207c66
Add TABLE `app_auth` key or index
bert82503 Aug 24, 2023
f9d3bbe
Add TABLE `auth_param` index
bert82503 Aug 24, 2023
fd5e0cd
Add TABLE `auth_path` index
bert82503 Aug 24, 2023
4bf822c
Add TABLE `data_permission` key or index
bert82503 Aug 24, 2023
f4ab1d2
Improve "selectDataIds" sql in data-permission-sqlmap.xml
bert82503 Aug 24, 2023
5d6c8d8
Add TABLE `detail` index
bert82503 Aug 24, 2023
d41fd7f
Add TABLE `meta_data` key or index
bert82503 Aug 24, 2023
46835d3
Add TABLE `mock_request_record` index
bert82503 Aug 26, 2023
8e77ec8
Add TABLE `operation_record_log` index
bert82503 Aug 26, 2023
9adb60a
Improve comment in SelectorQueryCondition,SearchCondition
bert82503 Aug 26, 2023
64a2176
Add TABLE `permission` index
bert82503 Aug 26, 2023
722ed02
Add TABLE `plugin` index
bert82503 Aug 26, 2023
4adaa4c
Add TABLE `resource` index
bert82503 Aug 26, 2023
8d405e0
Add TABLE `role` key
bert82503 Aug 26, 2023
4e1c32d
Add TABLE `rule` key
bert82503 Aug 26, 2023
bd8e883
Add TABLE `rule_condition` index
bert82503 Aug 26, 2023
de00612
Add TABLE `selector` key
bert82503 Aug 26, 2023
d6d3fd6
Rename plugin field to pluginIds in SelectorQueryCondition
bert82503 Aug 26, 2023
f7b5fa9
Add TABLE `selector_condition` index
bert82503 Aug 26, 2023
f3504a8
Add TABLE `user_role` index
bert82503 Aug 26, 2023
b4b9268
Add TABLE `tag` index
bert82503 Aug 26, 2023
5eeb26b
Add TABLE `tag_relation` index
bert82503 Aug 26, 2023
c3f906c
Add TABLE `discovery` index
bert82503 Aug 26, 2023
0a1bf85
Add TABLE `discovery_handler`,`discovery_rel` index
bert82503 Aug 26, 2023
ff9b561
Add TABLE `discovery_upstream` index
bert82503 Aug 26, 2023
c6e2d21
Add TABLE `proxy_selector`,`discovery_rel` index
bert82503 Aug 26, 2023
a84ba4b
Add TABLE `discovery_rel` index
bert82503 Aug 26, 2023
2eb1a13
Merge branch 'master' into feature/add_mysql_index_in_init_schema
bert82503 Aug 27, 2023
3acaa11
Merge branch 'master' into feature/add_mysql_index_in_init_schema
bert82503 Aug 28, 2023
44405fa
DataChangedListener-数据变更事件监听器
bert82503 May 10, 2024
0bf115a
Merge remote-tracking branch 'origin/feature/add_mysql_index_in_init_…
bert82503 May 10, 2024
1e7ed62
DataEventTypeEnum-数据事件类型
bert82503 May 10, 2024
6239388
ConfigGroupEnum-配置分组
bert82503 May 10, 2024
8b2c8ee
SyncDataServiceImpl.syncPluginData()-同步插件数据
bert82503 May 10, 2024
ad759cf
DataChangedEvent-数据变更事件
bert82503 May 10, 2024
fa7f64c
DataChangedEventDispatcher-数据变更事件的分发器
bert82503 May 10, 2024
276eab6
DataChangedListener-数据变更事件的监听器
bert82503 May 10, 2024
452ef36
RecordLogDataChangedAdapterListener-操作记录日志数据变更的适配监听器
bert82503 May 10, 2024
cf021c1
PluginData-插件数据,SelectorData-选择器数据,RuleData-规则数据
bert82503 May 10, 2024
9fdb26b
AbstractPathDataChangedListener-路径数据变更的监听器的抽象框架实现
bert82503 May 10, 2024
b036104
ZookeeperDataChangedListener-使用ZooKeeper发布数据变更
bert82503 May 10, 2024
e8bb4f7
EtcdDataDataChangedListener-使用etcd发布数据变更
bert82503 May 10, 2024
f9cd541
NacosDataChangedListener-使用nacos注册中心发布数据变更
bert82503 May 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 70 additions & 27 deletions db/init/mysql/schema.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@
@RestController
@RequestMapping("/plugin")
public class PluginController implements PagedController<PluginQueryCondition, PluginVO> {


/**
* 插件服务
*/
private final PluginService pluginService;


/**
* 同步数据服务
*/
private final SyncDataService syncDataService;

public PluginController(final PluginService pluginService, final SyncDataService syncDataService) {
Expand Down Expand Up @@ -208,6 +214,7 @@ public ShenyuAdminResult syncPluginAll() {

/**
* Sync plugin data.
* 同步插件数据
*
* @param id the id
* @return the mono
Expand All @@ -216,7 +223,8 @@ public ShenyuAdminResult syncPluginAll() {
public ShenyuAdminResult syncPluginData(@PathVariable("id")
@Existed(message = "plugin is not existed",
provider = PluginMapper.class) final String id) {
return ShenyuAdminResult.success(syncDataService.syncPluginData(id) ? ShenyuResultMessage.SYNC_SUCCESS : ShenyuResultMessage.SYNC_FAIL);
boolean syncResult = syncDataService.syncPluginData(id);
return ShenyuAdminResult.success(syncResult ? ShenyuResultMessage.SYNC_SUCCESS : ShenyuResultMessage.SYNC_FAIL);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public AdminResult<CommonPager<SelectorVO>> querySelectors(final String pluginId
@RequestParam @NotNull final Integer pageSize) {
final SelectorQueryCondition condition = new SelectorQueryCondition();
condition.setUserId(SessionUtil.visitor().getUserId());
condition.setPlugin(ListUtil.of(pluginId));
condition.setPluginIds(ListUtil.of(pluginId));
condition.setKeyword(name);
return searchAdaptor(new PageCondition<>(currentPage, pageSize, condition));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@

/**
* AbstractPathDataChangedListener.
* 路径数据变更的监听器的抽象框架实现
*/
public abstract class AbstractPathDataChangedListener implements DataChangedListener {

private static final Logger LOG = LoggerFactory.getLogger(AbstractPathDataChangedListener.class);

/**
* 规则同步对象锁
*/
private final Object ruleSyncObject = new Object();

/**
* 选择器同步对象锁
*/
private final Object selectorSyncObject = new Object();

@Override
Expand Down Expand Up @@ -116,28 +123,37 @@ public void onDiscoveryUpstreamChanged(final List<DiscoverySyncData> changed, fi

@Override
public void onSelectorChanged(final List<SelectorData> changed, final DataEventTypeEnum eventType) {
// 选择器数据的刷新事件
if (eventType == DataEventTypeEnum.REFRESH && !changed.isEmpty()) {
// 构建选择器的父路径("/shenyu/selector/${pluginName}")
String selectorParentPath = DefaultPathConstants.buildSelectorParentPath(changed.get(0).getPluginName());
// 递归地删除节点路径
deletePathRecursive(selectorParentPath);
}
// 变更的选择器数据遍历
for (SelectorData data : changed) {
// 选择器的真实路径("/shenyu/selector/${pluginName}/${selectorId}")
String selectorRealPath = DefaultPathConstants.buildSelectorRealPath(data.getPluginName(), data.getId());
// delete
if (eventType == DataEventTypeEnum.DELETE) {
deleteNode(selectorRealPath);
LOG.debug("[DataChangedListener] delete appKey {}", selectorRealPath);
continue;
}
//create or update
// create or update
synchronized (selectorSyncObject) {
createOrUpdate(selectorRealPath, data);
}
// 操作日志
LOG.debug("[DataChangedListener] change path {} with data {}", selectorRealPath, data);
}
}

@Override
public void onPluginChanged(final List<PluginData> changed, final DataEventTypeEnum eventType) {
// 变更的插件数据遍历
for (PluginData data : changed) {
// 构建插件路径("/shenyu/plugin/${pluginName}")
String pluginPath = DefaultPathConstants.buildPluginPath(data.getName());
// delete
if (eventType == DataEventTypeEnum.DELETE) {
Expand All @@ -149,28 +165,36 @@ public void onPluginChanged(final List<PluginData> changed, final DataEventTypeE
LOG.debug("[DataChangedListener] delete pluginPath {}", pluginPath);
continue;
}
//create or update
// create or update
createOrUpdate(pluginPath, data);
// 操作日志
LOG.debug("[DataChangedListener] change path {} with data {}", pluginPath, data);
}
}

@Override
public void onRuleChanged(final List<RuleData> changed, final DataEventTypeEnum eventType) {
// 规则数据的刷新事件
if (eventType == DataEventTypeEnum.REFRESH && !changed.isEmpty()) {
String selectorParentPath = DefaultPathConstants.buildRuleParentPath(changed.get(0).getPluginName());
deletePathRecursive(selectorParentPath);
// 构建规则的父路径("/shenyu/rule/${pluginName}")
String ruleParentPath = DefaultPathConstants.buildRuleParentPath(changed.get(0).getPluginName());
// 递归地删除节点路径
deletePathRecursive(ruleParentPath);
}
// 变更的规则数据遍历
for (RuleData data : changed) {
// 规则的真实路径("/shenyu/rule/${pluginName}/${selectorId-ruleId}")
String ruleRealPath = DefaultPathConstants.buildRulePath(data.getPluginName(), data.getSelectorId(), data.getId());
// delete
if (eventType == DataEventTypeEnum.DELETE) {
deleteNode(ruleRealPath);
continue;
}
//create or update
// create or update
synchronized (ruleSyncObject) {
createOrUpdate(ruleRealPath, data);
}
// 操作日志
LOG.debug("[DataChangedListener] change path {} with data {}", ruleRealPath, data);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

/**
* Data change event.
* 数据变更事件
*
* @see DataChangedEventDispatcher
* @since 2.0.0
Expand All @@ -35,8 +36,14 @@ public class DataChangedEvent extends ApplicationEvent {

private static final long serialVersionUID = 8397163004365988739L;

/**
* 数据事件类型
*/
private final DataEventTypeEnum eventType;

/**
* 配置分组
*/
private final ConfigGroupEnum groupKey;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@

/**
* Event forwarders, which forward the changed events to each ConfigEventListener.
* 数据变更事件的分发器
*/
@Component
public class DataChangedEventDispatcher implements ApplicationListener<DataChangedEvent>, InitializingBean {

/**
* 应用上下文
*/
private final ApplicationContext applicationContext;

/**
* 数据变更事件的监听器列表
*/
private List<DataChangedListener> listeners;

public DataChangedEventDispatcher(final ApplicationContext applicationContext) {
Expand All @@ -52,22 +59,28 @@ public DataChangedEventDispatcher(final ApplicationContext applicationContext) {
@Override
@SuppressWarnings("unchecked")
public void onApplicationEvent(final DataChangedEvent event) {
// 数据变更事件的监听器
for (DataChangedListener listener : listeners) {
switch (event.getGroupKey()) {
case APP_AUTH:
// 应用认证数据
listener.onAppAuthChanged((List<AppAuthData>) event.getSource(), event.getEventType());
break;
case PLUGIN:
// 插件数据变更
listener.onPluginChanged((List<PluginData>) event.getSource(), event.getEventType());
break;
case RULE:
// 规则数据变更
listener.onRuleChanged((List<RuleData>) event.getSource(), event.getEventType());
break;
case SELECTOR:
// 选择器数据变更
listener.onSelectorChanged((List<SelectorData>) event.getSource(), event.getEventType());
applicationContext.getBean(LoadServiceDocEntry.class).loadDocOnSelectorChanged((List<SelectorData>) event.getSource(), event.getEventType());
break;
case META_DATA:
// 元数据变更
listener.onMetaDataChanged((List<MetaData>) event.getSource(), event.getEventType());
break;
case PROXY_SELECTOR:
Expand All @@ -84,6 +97,7 @@ public void onApplicationEvent(final DataChangedEvent event) {

@Override
public void afterPropertiesSet() {
// 数据变更事件的监听器列表
Collection<DataChangedListener> listenerBeans = applicationContext.getBeansOfType(DataChangedListener.class).values();
this.listeners = Collections.unmodifiableList(new ArrayList<>(listenerBeans));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
/**
* Event listener, used to send notification of event changes,
* used to support HTTP, websocket, zookeeper and other event notifications.
* 数据变更事件的监听器
*/
public interface DataChangedListener {

/**
* invoke this method when AppAuth was received.
* 应用认证数据变更
*
* @param changed the changed
* @param eventType the event type
Expand All @@ -45,6 +47,7 @@ default void onAppAuthChanged(List<AppAuthData> changed, DataEventTypeEnum event

/**
* invoke this method when Plugin was received.
* 插件数据变更
*
* @param changed the changed
* @param eventType the event type
Expand All @@ -54,6 +57,7 @@ default void onPluginChanged(List<PluginData> changed, DataEventTypeEnum eventTy

/**
* invoke this method when Selector was received.
* 选择器数据变更
*
* @param changed the changed
* @param eventType the event type
Expand All @@ -63,6 +67,7 @@ default void onSelectorChanged(List<SelectorData> changed, DataEventTypeEnum eve

/**
* On meta data changed.
* 元数据变更
*
* @param changed the changed
* @param eventType the event type
Expand All @@ -73,6 +78,7 @@ default void onMetaDataChanged(List<MetaData> changed, DataEventTypeEnum eventTy

/**
* invoke this method when Rule was received.
* 规则数据变更
*
* @param changed the changed
* @param eventType the event type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@

/**
* RecordLogDataChangedAdapterListener.
* 操作记录日志数据变更的适配监听器
*/
@Component
public class RecordLogDataChangedAdapterListener implements DataChangedListener, ApplicationListener<AdminDataModelChangedEvent> {


/**
* 操作日志记录的数据访问对象
*/
private final OperationRecordLogMapper logMapper;

public RecordLogDataChangedAdapterListener(final OperationRecordLogMapper logMapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public Boolean exists(final String key) {
*/
public void put(final String key, final String value) {
try {
client.getKVClient().put(ByteSequence.from(key, StandardCharsets.UTF_8), ByteSequence.from(value, StandardCharsets.UTF_8)).get();
client.getKVClient()
.put(ByteSequence.from(key, StandardCharsets.UTF_8), ByteSequence.from(value, StandardCharsets.UTF_8))
.get();
} catch (Exception e) {
LOG.error("update value of node error.", e);
throw new ShenyuException(e.getMessage());
Expand All @@ -87,7 +89,8 @@ public void put(final String key, final String value) {
* @param key node name
*/
public void delete(final String key) {
client.getKVClient().delete(ByteSequence.from(key, StandardCharsets.UTF_8));
client.getKVClient()
.delete(ByteSequence.from(key, StandardCharsets.UTF_8));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@

/**
* EtcdDataDataChangedListener.
* 使用etcd注册中心发布数据变更
*/
public class EtcdDataDataChangedListener extends AbstractPathDataChangedListener {

/**
* etcd客户端
*/
private final EtcdClient etcdClient;

public EtcdDataDataChangedListener(final EtcdClient client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@

/**
* Use nacos to push data changes.
* 使用nacos注册中心发布数据变更
*/
public class NacosDataChangedListener extends AbstractNodeDataChangedListener {

private static final Logger LOG = LoggerFactory.getLogger(NacosDataChangedListener.class);

/**
* 配置服务
*/
private final ConfigService configService;

public NacosDataChangedListener(final ConfigService configService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@

/**
* Use zookeeper to push data changes.
* 使用ZooKeeper注册中心发布数据变更
*/
public class ZookeeperDataChangedListener extends AbstractPathDataChangedListener {

/**
* ZooKeeper客户端
*/
private final ZookeeperClient zkClient;

public ZookeeperDataChangedListener(final ZookeeperClient zkClient) {
Expand All @@ -34,19 +38,22 @@ public ZookeeperDataChangedListener(final ZookeeperClient zkClient) {

@Override
public void createOrUpdate(final String path, final Object data) {
// 创建持久化路径节点
zkClient.createOrUpdate(path, data, CreateMode.PERSISTENT);
}

@Override
public void deleteNode(final String path) {
if (zkClient.isExist(path)) {
// 删除路径节点
zkClient.delete(path);
}
}

@Override
public void deletePathRecursive(final String path) {
if (zkClient.isExist(path)) {
// 删除路径节点
zkClient.delete(path);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public interface DiscoveryHandlerMapper extends ExistProvider {
* @param proxySelectorId proxySelectorId
* @return DiscoveryHandlerDO
*/
DiscoveryHandlerDO selectByProxySelectorId(@Param("proxySelectorId") String proxySelectorId);
DiscoveryHandlerDO selectByProxySelectorId(
@Param("proxySelectorId") String proxySelectorId
);

/**
* DiscoveryHandlerDOList.
Expand All @@ -109,6 +111,8 @@ public interface DiscoveryHandlerMapper extends ExistProvider {
* @param discoveryId discoveryId
* @return DiscoveryHandlerDO list
*/
List<DiscoveryHandlerDO> selectByDiscoveryId(@Param("discoveryId")String discoveryId);
List<DiscoveryHandlerDO> selectByDiscoveryId(
@Param("discoveryId")String discoveryId
);

}
Loading