Skip to content

Commit

Permalink
optimize fuzzy watch of config&naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiyue1102 committed Jan 9, 2025
1 parent 17bd04e commit b4d3b23
Show file tree
Hide file tree
Showing 107 changed files with 6,642 additions and 3,667 deletions.
76 changes: 60 additions & 16 deletions api/src/main/java/com/alibaba/nacos/api/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ public class Constants {

public static final Integer CLUSTER_GRPC_PORT_DEFAULT_OFFSET = 1001;

public static final String NAMESPACE_ID_SPLITTER = ">>";

public static final String DATA_ID_SPLITTER = "@@";

/**
* second.
*/
Expand Down Expand Up @@ -212,8 +208,6 @@ public class Constants {

public static final String ALL_PATTERN = "*";

public static final String FUZZY_LISTEN_PATTERN_WILDCARD = "*";

public static final String COLON = ":";

public static final String LINE_BREAK = "\n";
Expand All @@ -237,16 +231,6 @@ public class Constants {

public static final int DEFAULT_REDO_THREAD_COUNT = 1;

public static class ConfigChangeType {

public static final String ADD_CONFIG = "ADD_CONFIG";

public static final String DELETE_CONFIG = "DELETE_CONFIG";

public static final String FINISH_LISTEN_INIT = "FINISH_LISTEN_INIT";

public static final String LISTEN_INIT = "LISTEN_INIT";
}
public static final String APP_CONN_LABELS_KEY = "nacos.app.conn.labels";

public static final String DOT = ".";
Expand Down Expand Up @@ -292,6 +276,66 @@ public static class Naming {
public static final String CMDB_CONTEXT_TYPE = "CMDB";
}

public static final String FUZZY_WATCH_PATTERN_SPLITTER = ">>";

/**
* fuzzy watch sync type of watch init notify.
*/
public static final String FUZZY_WATCH_INIT_NOTIFY = "FUZZY_WATCH_INIT_NOTIFY";

/**
* fuzzy watch sync type of watch init notify finish.
*/
public static final String FINISH_FUZZY_WATCH_INIT_NOTIFY = "FINISH_FUZZY_WATCH_INIT_NOTIFY";

/**
* fuzzy watch sync type of watch diff sync notify.
*/
public static final String FUZZY_WATCH_DIFF_SYNC_NOTIFY = "FUZZY_WATCH_DIFF_SYNC_NOTIFY";

/**
* fuzzy watch sync type of watch resource changed.
*/
public static final String FUZZY_WATCH_RESOURCE_CHANGED = "FUZZY_WATCH_RESOURCE_CHANGED";

/**
* watch type of watch.
*/
public static final String WATCH_TYPE_WATCH = "WATCH";

/**
* watch type of cancel watch.
*/
public static final String WATCH_TYPE_CANCEL_WATCH = "CANCEL_WATCH";

/**
* The constants in config fuzzy watch changed type directory.
*/
public static class ConfigChangedType {

public static final String ADD_CONFIG = "ADD_CONFIG";

public static final String DELETE_CONFIG = "DELETE_CONFIG";

public static final String CONFIG_CHANGED = "CONFIG_CHANGED";

}

/**
* The constants in naming fuzzy watch changed type directory.
*/
public static class ServiceChangedType {

public static final String ADD_SERVICE = "ADD_SERVICE";

public static final String DELETE_SERVICE = "DELETE_SERVICE";

public static final String INSTANCE_CHANGED = "INSTANCE_CHANGED";

public static final String HEART_BEAT = "HEART_BEAT";

}

/**
* The constants in remote directory.
*/
Expand Down
167 changes: 87 additions & 80 deletions api/src/main/java/com/alibaba/nacos/api/config/ConfigService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
package com.alibaba.nacos.api.config;

import com.alibaba.nacos.api.config.filter.IConfigFilter;
import com.alibaba.nacos.api.config.listener.AbstractFuzzyListenListener;
import com.alibaba.nacos.api.config.listener.FuzzyWatchEventWatcher;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;

import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import java.util.Set;
import java.util.concurrent.Future;

/**
* Config Service Interface.
Expand Down Expand Up @@ -63,8 +63,8 @@ String getConfigAndSignListener(String dataId, String group, long timeoutMs, Lis
/**
* Add a listener to the configuration, after the server modified the configuration, the client will use the
* incoming listener callback. Recommended asynchronous processing, the application can implement the getExecutor
* method in the ManagerListener, provide a thread pool of execution. If not provided, use the main thread callback,
* May block other configurations or be blocked by other configurations.
* method in the ManagerListener, provide a thread pool of execution. If not provided, use the main thread callback, May
* block other configurations or be blocked by other configurations.
*
* @param dataId dataId
* @param group group
Expand All @@ -73,78 +73,6 @@ String getConfigAndSignListener(String dataId, String group, long timeoutMs, Lis
*/
void addListener(String dataId, String group, Listener listener) throws NacosException;

/**
* Add a fuzzy listener to the configuration. After the server modifies the configuration matching the specified
* fixed group name, the client will utilize the incoming fuzzy listener callback. Fuzzy listeners allow for
* pattern-based subscription to configurations, where the fixed group name represents the group and dataId patterns
* specified for subscription.
*
* @param fixedGroupName The fixed group name representing the group and dataId patterns to subscribe to.
* @param listener The fuzzy listener to be added.
* @throws NacosException NacosException
*/
void addFuzzyListener(String fixedGroupName, AbstractFuzzyListenListener listener) throws NacosException;

/**
* Add a fuzzy listener to the configuration. After the server modifies the configuration matching the specified
* dataId pattern and fixed group name, the client will utilize the incoming fuzzy listener callback. Fuzzy
* listeners allow for pattern-based subscription to configurations.
*
* @param dataIdPattern The pattern to match dataIds for subscription.
* @param fixedGroupName The fixed group name representing the group and dataId patterns to subscribe to.
* @param listener The fuzzy listener to be added.
* @throws NacosException NacosException
*/
void addFuzzyListener(String dataIdPattern, String fixedGroupName, AbstractFuzzyListenListener listener)
throws NacosException;

/**
* Add a fuzzy listener to the configuration and retrieve all configs that match the specified fixed group name.
* Fuzzy listeners allow for pattern-based subscription to configs, where the fixed group name represents the group
* and dataId patterns specified for subscription.
*
* @param fixedGroupName The fixed group name representing the group and dataId patterns to subscribe to.
* @param listener The fuzzy listener to be added.
* @return CompletableFuture containing collection of configs that match the specified fixed group name.
* @throws NacosException NacosException
*/
CompletableFuture<Collection<String>> addFuzzyListenerAndGetConfigs(String fixedGroupName,
AbstractFuzzyListenListener listener) throws NacosException;

/**
* Add a fuzzy listener to the configuration and retrieve all configs that match the specified dataId pattern and
* fixed group name. Fuzzy listeners allow for pattern-based subscription to configs.
*
* @param dataIdPattern The pattern to match dataIds for subscription.
* @param fixedGroupName The fixed group name representing the group and dataId patterns to subscribe to.
* @param listener The fuzzy listener to be added.
* @return CompletableFuture containing collection of configs that match the specified dataId pattern and fixed
* group name.
* @throws NacosException NacosException
*/
CompletableFuture<Collection<String>> addFuzzyListenerAndGetConfigs(String dataIdPattern, String fixedGroupName,
AbstractFuzzyListenListener listener) throws NacosException;

/**
* Cancel fuzzy listen and remove the event listener for a specified fixed group name.
*
* @param fixedGroupName The fixed group name for fuzzy watch.
* @param listener The event listener to be removed.
* @throws NacosException If an error occurs during the cancellation process.
*/
void cancelFuzzyListen(String fixedGroupName, AbstractFuzzyListenListener listener) throws NacosException;

/**
* Cancel fuzzy listen and remove the event listener for a specified service name pattern and fixed group name.
*
* @param dataIdPatter The pattern to match dataId for fuzzy watch.
* @param fixedGroupName The fixed group name for fuzzy watch.
* @param listener The event listener to be removed.
* @throws NacosException If an error occurs during the cancellation process.
*/
void cancelFuzzyListen(String dataIdPatter, String fixedGroupName, AbstractFuzzyListenListener listener)
throws NacosException;

/**
* Publish config.
*
Expand Down Expand Up @@ -220,10 +148,10 @@ boolean publishConfigCas(String dataId, String group, String content, String cas
* @return whether health
*/
String getServerStatus();

/**
* add config filter. It is recommended to use {@link com.alibaba.nacos.api.config.filter.AbstractConfigFilter} to
* expand the filter.
* add config filter.
* It is recommended to use {@link com.alibaba.nacos.api.config.filter.AbstractConfigFilter} to expand the filter.
*
* @param configFilter filter
* @since 2.3.0
Expand All @@ -236,4 +164,83 @@ boolean publishConfigCas(String dataId, String group, String content, String cas
* @throws NacosException exception.
*/
void shutDown() throws NacosException;

/**
* Add a fuzzy listener to the configuration. After the server modifies the configuration matching the specified
* fixed group name, the client will utilize the incoming fuzzy listener callback. Fuzzy listeners allow for
* pattern-based subscription to configurations, where the fixed group name represents the group and dataId patterns
* specified for subscription.
*
* @param fixedGroupName The fixed group name representing the group and dataId patterns to subscribe to.
* @param watcher The fuzzy watcher to be added.
* @throws NacosException NacosException
* @since 3.0
*/
void fuzzyWatch(String fixedGroupName, FuzzyWatchEventWatcher watcher) throws NacosException;

/**
* Add a fuzzy listener to the configuration. After the server modifies the configuration matching the specified
* dataId pattern and fixed group name, the client will utilize the incoming fuzzy listener callback. Fuzzy
* listeners allow for pattern-based subscription to configurations.
*
* @param dataIdPattern The pattern to match dataIds for subscription.
* @param fixedGroupName The fixed group name representing the group and dataId patterns to subscribe to.
* @param watcher The fuzzy listener to be added.
* @throws NacosException NacosException
* @since 3.0
*/
void fuzzyWatch(String dataIdPattern, String fixedGroupName, FuzzyWatchEventWatcher watcher)
throws NacosException;

/**
* Add a fuzzy listener to the configuration and retrieve all configs that match the specified fixed group name.
* Fuzzy listeners allow for pattern-based subscription to configs, where the fixed group name represents the group
* and dataId patterns specified for subscription.
*
* @param fixedGroupName The fixed group name representing the group and dataId patterns to subscribe to.
* @param watcher The fuzzy watcher to be added.
* @return CompletableFuture containing collection of configs that match the specified fixed group name.
* @throws NacosException NacosException
* @since 3.0
*/
Future<Set<String>> fuzzyWatchWithGroupKeys(String fixedGroupName,
FuzzyWatchEventWatcher watcher) throws NacosException;

/**
* Add a fuzzy listener to the configuration and retrieve all configs that match the specified dataId pattern and
* fixed group name. Fuzzy listeners allow for pattern-based subscription to configs.
*
* @param dataIdPattern The pattern to match dataIds for subscription.
* @param fixedGroupName The fixed group name representing the group and dataId patterns to subscribe to.
* @param watcher The fuzzy watcher to be added.
* @return CompletableFuture containing collection of configs that match the specified dataId pattern and fixed
* group name.
* @throws NacosException NacosException
* @since 3.0
*/
Future<Set<String>> fuzzyWatchWithGroupKeys(String dataIdPattern, String fixedGroupName,
FuzzyWatchEventWatcher watcher) throws NacosException;

/**
* Cancel fuzzy listen and remove the event listener for a specified fixed group name.
*
* @param fixedGroupName The fixed group name for fuzzy watch.
* @param watcher The event watcher to be removed.
* @throws NacosException If an error occurs during the cancellation process.
* @since 3.0
*/
void cancelFuzzyWatch(String fixedGroupName, FuzzyWatchEventWatcher watcher) throws NacosException;

/**
* Cancel fuzzy listen and remove the event listener for a specified service name pattern and fixed group name.
*
* @param dataIdPattern The pattern to match dataId for fuzzy watch.
* @param fixedGroupName The fixed group name for fuzzy watch.
* @param watcher The event listener to be removed.
* @throws NacosException If an error occurs during the cancellation process.
* @since 3.0
*/
void cancelFuzzyWatch(String dataIdPattern, String fixedGroupName, FuzzyWatchEventWatcher watcher)
throws NacosException;

}
Loading

0 comments on commit b4d3b23

Please sign in to comment.