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

fuzzy watch optimize and test case coverage #13043

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author stone-98
* @date 2024/3/4
*/
public abstract class AbstractFuzzyWatchEventWatcher implements FuzzyWatchEventWatcher {
public abstract class AbstractFuzzyWatchEventWatcher implements FuzzyWatchEventWatcher, FuzzyWatchLoadWatcher {

/**
* Get executor for execute this receive.
Expand All @@ -35,4 +35,14 @@ public abstract class AbstractFuzzyWatchEventWatcher implements FuzzyWatchEventW
public Executor getExecutor() {
return null;
}

@Override
public void onPatternOverLimit() {
// do nothing default
}

@Override
public void onConfigReachUpLimit() {
// do nothing default
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 1999-2023 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.config.listener;

/**
* config fuzzy watch watcher that triggered when loader over limit.
* @author shiyiyue
*/
public interface FuzzyWatchLoadWatcher {

/**
* triggered when server pattern count over limit.
*/
void onPatternOverLimit();

/**
* triggered when pattern match config count over limit.
*/
void onConfigReachUpLimit();

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static ConfigFuzzyWatchSyncRequest buildSyncRequest(String syncType, Set<
}

/**
* Builds a final FuzzyListenNotifyDiffRequest with the specified group key pattern.
* Builds fuzzy watch init finish request.
*
* @param groupKeyPattern The pattern used to match group keys for the configurations
* @return A final FuzzyListenNotifyDiffRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public enum ErrorCode {

FUZZY_WATCH_PATTERN_OVER_LIMIT(50310, "fuzzy watch pattern over limit"),

FUZZY_WATCH_PATTERN_MATCH_GROUP_KEY_OVER_LIMIT(50311, "fuzzy watch pattern matched group key over limit");
FUZZY_WATCH_PATTERN_MATCH_COUNT_OVER_LIMIT(50311, "fuzzy watch pattern matched count over limit");

private final Integer code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@
*
* @author tanyongquan
*/
public abstract class AbstractFuzzyWatchEventWatcher implements FuzzyWatchEventWatcher {
public abstract class AbstractFuzzyWatchEventWatcher implements FuzzyWatchEventWatcher, FuzzyWatchLoadWatcher {

@Override
public Executor getExecutor() {
return null;
}

@Override
public void onPatternOverLimit() {
//do nothing default
}

@Override
public void onServiceReachUpLimit() {
//do nothing default
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 1999-2023 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.naming.listener;

/**
* naming fuzzy watch watcher that triggered when loader over limit.
* @author shiyiyue
*/
public interface FuzzyWatchLoadWatcher {

/**
* triggered when server pattern count over limit.
*/
void onPatternOverLimit();

/**
* triggered when pattern match service count over limit.
*/
void onServiceReachUpLimit();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.alibaba.nacos.api.naming.remote.request;

import static com.alibaba.nacos.api.common.Constants.FUZZY_WATCH_RESOURCE_CHANGED;

/**
* Nacos fuzzy watch notify service change request, use it when one of the services changes.
*
Expand All @@ -31,8 +33,8 @@ public NamingFuzzyWatchChangeNotifyRequest() {

}

public NamingFuzzyWatchChangeNotifyRequest(String serviceKey, String changedType, String syncType) {
super(syncType);
public NamingFuzzyWatchChangeNotifyRequest(String serviceKey, String changedType) {
super(FUZZY_WATCH_RESOURCE_CHANGED);
this.serviceKey = serviceKey;
this.changedType = changedType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

package com.alibaba.nacos.api.naming.remote.request;

import com.alibaba.nacos.api.common.Constants;

import java.util.HashSet;
import java.util.Set;

import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;

/**
* fuzzy watch sync request from Nacos server.
*
* @author shiyiyue
*/
public class NamingFuzzyWatchSyncRequest extends AbstractFuzzyWatchNotifyRequest {
Expand Down Expand Up @@ -69,10 +67,6 @@ public void setCurrentBatch(int currentBatch) {
this.currentBatch = currentBatch;
}

public static NamingFuzzyWatchSyncRequest buildInitNotifyFinishRequest(String pattern) {
return new NamingFuzzyWatchSyncRequest(pattern, Constants.FINISH_FUZZY_WATCH_INIT_NOTIFY, new HashSet<>(1));
}

/**
* byuld SyncNotifyRequest.
*
Expand Down
8 changes: 8 additions & 0 deletions bootstrap/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,11 @@ nacos.k8s.sync.enabled=false

### Sets the deployment type: 'merged' for joint deployment, 'server' for separate deployment server only, 'console' for separate deployment console only.
nacos.deployment.type=merged


#*************** Fuzzy Watch Configuration ***************#
nacos.config.fuzzy.watch.max.pattern.count=20
nacos.config.fuzzy.watch.max.pattern.match.config.count=500

nacos.naming.fuzzy.watch.max.pattern.count=20
nacos.naming.fuzzy.watch.max.pattern.match.service.count=500
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ClientFuzzyWatchNotifyRequestHandler(ConfigFuzzyWatchGroupKeyHolder confi
public Response requestReply(Request request, Connection connection) {
//fuzzy watch diff reconciliation sync
if (request instanceof ConfigFuzzyWatchSyncRequest) {
return configFuzzyWatchGroupKeyHolder.handleFuzzyWatchNotifyDiffRequest(
return configFuzzyWatchGroupKeyHolder.handleFuzzyWatchSyncNotifyRequest(
(ConfigFuzzyWatchSyncRequest) request);
}
//fuzzy watch changed notify for a single config. include config changed or config delete.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,16 @@ public class ClientWorker implements Closeable {

private ConfigFuzzyWatchGroupKeyHolder configFuzzyWatchGroupKeyHolder;

private Map<String, String> appLables = new HashMap<>();
private Map<String, String> appLabels = new HashMap<>();

private final ConfigFilterChainManager configFilterChainManager;

private final String uuid = UUID.randomUUID().toString();

private long timeout;

private long requestTimeout;

private final ConfigRpcTransportClient agent;

private int taskPenaltyTime;

private boolean enableRemoteSyncConfig = false;

private static final int MIN_THREAD_NUM = 2;
Expand Down Expand Up @@ -528,7 +524,7 @@ public ClientWorker(final ConfigFilterChainManager configFilterChainManager,
}

void initAppLabels(Properties properties) {
this.appLables = ConnLabelsUtils.addPrefixForEachKey(defaultLabelsCollectorManager.getLabels(properties),
this.appLabels = ConnLabelsUtils.addPrefixForEachKey(defaultLabelsCollectorManager.getLabels(properties),
APP_CONN_PREFIX);
}

Expand All @@ -546,12 +542,6 @@ private void init(NacosClientProperties properties) {

requestTimeout = ConvertUtils.toLong(properties.getProperty(PropertyKeyConst.CONFIG_REQUEST_TIMEOUT, "-1"));

timeout = Math.max(ConvertUtils.toInt(properties.getProperty(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT),
Constants.CONFIG_LONG_POLL_TIMEOUT), Constants.MIN_CONFIG_LONG_POLL_TIMEOUT);

taskPenaltyTime = ConvertUtils.toInt(properties.getProperty(PropertyKeyConst.CONFIG_RETRY_TIME),
Constants.CONFIG_RETRY_TIME);

this.enableRemoteSyncConfig = Boolean.parseBoolean(
properties.getProperty(PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG));
initAppLabels(properties.getProperties(SourceType.PROPERTIES));
Expand Down Expand Up @@ -663,8 +653,8 @@ public void shutdown() throws NacosException {
}
}

LOGGER.info("Shutdown executor {}", executor);
executor.shutdown();
LOGGER.info("Shutdown executor {}", agent.getExecutor());
agent.getExecutor().shutdown();
Map<String, CacheData> stringCacheDataMap = cacheMap.get();
for (Map.Entry<String, CacheData> entry : stringCacheDataMap.entrySet()) {
entry.getValue().setConsistentWithServer(false);
Expand Down Expand Up @@ -692,7 +682,7 @@ private Map<String, String> getLabels() {
labels.put(Constants.LOCATION_TAG, EnvUtil.getSelfLocationTag());
}

labels.putAll(appLables);
labels.putAll(appLabels);
return labels;
}

Expand Down Expand Up @@ -815,6 +805,7 @@ public Class<? extends Event> subscribeType() {

@Override
public void startInternal() {
ScheduledExecutorService executor = getExecutor();
executor.schedule(() -> {
while (!executor.isShutdown() && !executor.isTerminated()) {
try {
Expand Down
Loading