Skip to content

Commit

Permalink
Merge pull request #9335 from alibaba/develop
Browse files Browse the repository at this point in the history
Upgrade to 2.1.2
  • Loading branch information
KomachiSion authored Oct 17, 2022
2 parents 41859be + 0834641 commit 2eb7f73
Show file tree
Hide file tree
Showing 221 changed files with 34,517 additions and 2,369 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
pull_request:
branches: [ develop, v1.x-develop ]

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
unix:
runs-on: ${{ matrix.os }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
pull_request:
branches: [ develop, v1.x-develop ]

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
unix:
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@

## 0.2.1-release(Sept 28, 2018)

* FIx deregister last instance failed error.
* Fix deregister last instance failed error.
* Fix url pattern error.
* Fully integrate with and seamlessly support Spring framework, Spring Boot and Spring Cloud
* Separate nacos-api from nacos client implementation
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ For more details, see [quick-start.](https://nacos.io/en-us/docs/quick-start.htm

You can view the full documentation from the [Nacos website](https://nacos.io/en-us/docs/what-is-nacos.html).

You can also read this online eBook from the [NACOS ARCHITECTURE & PRINCIPLES](https://www.yuque.com/nacos/ebook/kbyo6n).

All the latest and long-term notice can also be found here from [Github notice issue](https://github.com/alibaba/nacos/labels/notice).

## Contributing
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class PropertyKeyConst {

public static final String NAMING_PUSH_EMPTY_PROTECTION = "namingPushEmptyProtection";

public static final String NAMING_ASYNC_QUERY_SUBSCRIBE_SERVICE = "namingAsyncQuerySubscribeService";

public static final String PUSH_RECEIVER_UDP_PORT = "push.receiver.udp.port";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,18 @@

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

import com.alibaba.nacos.api.remote.response.Response;

/**
* batch instance response.
*
* @author <a href="mailto:[email protected]">chenhao26</a>
*/
public class BatchInstanceResponse extends Response {

private String type;
public class BatchInstanceResponse extends InstanceResponse {

public BatchInstanceResponse() {
super();
}

public BatchInstanceResponse(String type) {
this.type = type;
}

public void setType(String type) {
this.type = type;
super(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ public void setType(String type) {
this.type = type;
}

public String getType() {
return type;
}
}
166 changes: 134 additions & 32 deletions client/pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public void shutdown() throws NacosException {
String className = this.getClass().getName();
LOGGER.info("{} do shutdown begin", className);
ConfigHttpClientManager.getInstance().shutdown();
serverListMgr.shutdown();
LOGGER.info("{} do shutdown stop", className);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public class CacheData {
*/
private volatile boolean isSyncWithServer = false;

/**
* if is cache data is discard,need to remove.
*/
private volatile boolean isDiscard = false;

private String type;

public boolean isInitializing() {
Expand Down Expand Up @@ -402,6 +407,14 @@ public void setSyncWithServer(boolean syncWithServer) {
isSyncWithServer = syncWithServer;
}

public boolean isDiscard() {
return isDiscard;
}

public void setDiscard(boolean discard) {
isDiscard = discard;
}

public CacheData(ConfigFilterChainManager configFilterChainManager, String name, String dataId, String group) {
this(configFilterChainManager, name, dataId, group, TenantUtil.getUserTenantForAcm());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ public class ClientWorker implements Closeable {
private int taskPenaltyTime;

private boolean enableRemoteSyncConfig = false;

private static final int MIN_THREAD_NUM = 2;

private static final int THREAD_MULTIPLE = 1;

/**
* Add listeners for data.
*
Expand All @@ -146,6 +146,7 @@ public void addListeners(String dataId, String group, List<? extends Listener> l
for (Listener listener : listeners) {
cache.addListener(listener);
}
cache.setDiscard(false);
cache.setSyncWithServer(false);
agent.notifyListenConfig();

Expand All @@ -169,6 +170,7 @@ public void addTenantListeners(String dataId, String group, List<? extends Liste
for (Listener listener : listeners) {
cache.addListener(listener);
}
cache.setDiscard(false);
cache.setSyncWithServer(false);
agent.notifyListenConfig();
}
Expand Down Expand Up @@ -196,6 +198,7 @@ public void addTenantListenersWithContent(String dataId, String group, String co
for (Listener listener : listeners) {
cache.addListener(listener);
}
cache.setDiscard(false);
cache.setSyncWithServer(false);
agent.notifyListenConfig();
}
Expand All @@ -217,6 +220,7 @@ public void removeListener(String dataId, String group, Listener listener) {
cache.removeListener(listener);
if (cache.getListeners().isEmpty()) {
cache.setSyncWithServer(false);
cache.setDiscard(true);
agent.removeCache(dataId, group);
}
}
Expand All @@ -240,6 +244,7 @@ public void removeTenantListener(String dataId, String group, Listener listener)
cache.removeListener(listener);
if (cache.getListeners().isEmpty()) {
cache.setSyncWithServer(false);
cache.setDiscard(true);
agent.removeCache(dataId, group);
}
}
Expand Down Expand Up @@ -425,8 +430,8 @@ public ClientWorker(final ConfigFilterChainManager configFilterChainManager, Ser
}

private void refreshContentAndCheck(String groupKey, boolean notify) {
if (cacheMap.get() != null && cacheMap.get().containsKey(groupKey)) {
CacheData cache = cacheMap.get().get(groupKey);
CacheData cache = cacheMap.get().get(groupKey);
if (cache != null) {
refreshContentAndCheck(cache, notify);
}
}
Expand Down Expand Up @@ -696,7 +701,7 @@ public void startInternal() {
continue;
}
executeConfigListen();
} catch (Exception e) {
} catch (Throwable e) {
LOGGER.error("[ rpc listen execute ] [rpc listen] exception", e);
}
}
Expand Down Expand Up @@ -733,7 +738,7 @@ public void executeConfigListen() {
}
}

if (!CollectionUtils.isEmpty(cache.getListeners())) {
if (!cache.isDiscard()) {
//get listen config
if (!cache.isUseLocalConfigInfo()) {
List<CacheData> cacheDatas = listenCachesMap.get(String.valueOf(cache.getTaskId()));
Expand All @@ -744,7 +749,7 @@ public void executeConfigListen() {
cacheDatas.add(cache);

}
} else if (CollectionUtils.isEmpty(cache.getListeners())) {
} else if (cache.isDiscard()) {

if (!cache.isUseLocalConfigInfo()) {
List<CacheData> cacheDatas = removeListenCachesMap.get(String.valueOf(cache.getTaskId()));
Expand Down Expand Up @@ -779,7 +784,7 @@ public void executeConfigListen() {
RpcClient rpcClient = ensureRpcClient(taskId);
ConfigChangeBatchListenResponse configChangeBatchListenResponse = (ConfigChangeBatchListenResponse) requestProxy(
rpcClient, configChangeListenRequest);
if (configChangeBatchListenResponse != null && configChangeBatchListenResponse.isSuccess()) {
if (configChangeBatchListenResponse.isSuccess()) {

Set<String> changeKeys = new HashSet<>();
//handle changed keys,notify listener
Expand Down Expand Up @@ -807,8 +812,8 @@ public void executeConfigListen() {
if (!cacheData.getListeners().isEmpty()) {

Long previousTimesStamp = timestampMap.get(groupKey);
if (previousTimesStamp != null && !cacheData.getLastModifiedTs().compareAndSet(previousTimesStamp,
System.currentTimeMillis())) {
if (previousTimesStamp != null && !cacheData.getLastModifiedTs()
.compareAndSet(previousTimesStamp, System.currentTimeMillis())) {
continue;
}
cacheData.setSyncWithServer(true);
Expand Down Expand Up @@ -844,7 +849,7 @@ public void executeConfigListen() {
if (removeSuccess) {
for (CacheData cacheData : removeListenCaches) {
synchronized (cacheData) {
if (cacheData.getListeners().isEmpty()) {
if (cacheData.isDiscard()) {
ClientWorker.this
.removeCache(cacheData.dataId, cacheData.group, cacheData.tenant);
}
Expand Down Expand Up @@ -979,8 +984,8 @@ public ConfigResponse queryConfig(String dataId, String group, String tenant, lo
LOGGER.error("[{}] [sub-server-error] dataId={}, group={}, tenant={}, code={}", this.getName(), dataId,
group, tenant, response);
throw new NacosException(response.getErrorCode(),
"http error, code=" + response.getErrorCode() + ",msg=" + response.getMessage() + ",dataId=" + dataId + ",group=" + group
+ ",tenant=" + tenant);
"http error, code=" + response.getErrorCode() + ",msg=" + response.getMessage() + ",dataId="
+ dataId + ",group=" + group + ",tenant=" + tenant);

}
}
Expand Down Expand Up @@ -1012,20 +1017,20 @@ private RequestResource resourceBuild(Request request) {
if (request instanceof ConfigQueryRequest) {
String tenant = ((ConfigQueryRequest) request).getTenant();
String group = ((ConfigQueryRequest) request).getGroup();
String dataId = ((ConfigQueryRequest) request).getGroup();
String dataId = ((ConfigQueryRequest) request).getDataId();
return buildResource(tenant, group, dataId);
}
if (request instanceof ConfigPublishRequest) {
String tenant = ((ConfigPublishRequest) request).getTenant();
String group = ((ConfigPublishRequest) request).getGroup();
String dataId = ((ConfigPublishRequest) request).getGroup();
String dataId = ((ConfigPublishRequest) request).getDataId();
return buildResource(tenant, group, dataId);
}

if (request instanceof ConfigRemoveRequest) {
String tenant = ((ConfigRemoveRequest) request).getTenant();
String group = ((ConfigRemoveRequest) request).getGroup();
String dataId = ((ConfigRemoveRequest) request).getGroup();
String dataId = ((ConfigRemoveRequest) request).getDataId();
return buildResource(tenant, group, dataId);
}
return RequestResource.configBuilder().build();
Expand Down Expand Up @@ -1059,7 +1064,7 @@ public boolean publishConfig(String dataId, String group, String tenant, String
}
} catch (Exception e) {
LOGGER.warn("[{}] [publish-single] error, dataId={}, group={}, tenant={}, code={}, msg={}",
this.getName(), dataId, group, tenant, "unkonw", e.getMessage());
this.getName(), dataId, group, tenant, "unknown", e.getMessage());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,24 @@ public ServerListManager(Properties properties) throws NacosException {
}

private String initServerName(Properties properties) {
String serverName = "";
String serverName;
//1.user define server name.
if (properties != null && properties.containsKey(PropertyKeyConst.SERVER_NAME)) {
serverName = properties.get(PropertyKeyConst.SERVER_NAME).toString();
} else {
// if fix url,use fix url join string.
if (isFixed) {
serverName = FIXED_NAME + "-" + (StringUtils.isNotBlank(namespace) ? (StringUtils.trim(namespace) + "-")
: "") + getFixedNameSuffix(serverUrls.toArray(new String[serverUrls.size()]));
: "") + getFixedNameSuffix(serverUrls.toArray(new String[0]));
} else {
//if use endpoint , use endpoint ,content path ,serverlist name
serverName = CUSTOM_NAME + "-" + String
.join("_", endpoint, String.valueOf(endpointPort), contentPath, serverListName) + (
StringUtils.isNotBlank(namespace) ? ("_" + StringUtils.trim(namespace)) : "");
}
}
serverName.replaceAll("\\/", "_");
serverName.replaceAll("\\:", "_");
serverName = serverName.replaceAll("\\/", "_");
serverName = serverName.replaceAll("\\:", "_");

return serverName;
}
Expand All @@ -254,8 +254,8 @@ private void initAddressServerUrl(Properties properties) {
ContextPathUtil.normalizeContextPath(this.contentPath), this.serverListName));
boolean hasQueryString = false;
if (StringUtils.isNotBlank(namespace)) {
addressServerUrlTem.append("?namespace=" + namespace);
hasQueryString = false;
addressServerUrlTem.append("?namespace=").append(namespace);
hasQueryString = true;
}
if (properties != null && properties.containsKey(PropertyKeyConst.ENDPOINT_QUERY_PARAMS)) {
addressServerUrlTem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class SysEnv {

public static final String JM_SNAPSHOT_PATH = "JM.SNAPSHOT.PATH";

public static final String NACOS_ENVS_SEARCH = "nacos.envs.search";
public static final String NACOS_ENV_FIRST = "nacos.env.first";

}

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

package com.alibaba.nacos.client.env;

import java.util.Properties;

abstract class AbstractPropertySource {

/**
Expand All @@ -31,4 +33,17 @@ abstract class AbstractPropertySource {
*/
abstract String getProperty(String key);

/**
* Tests if the specified object is a key in this propertySource.
* @param key key – possible key
* @return true if and only if the specified object is a key in this propertySource, false otherwise.
*/
abstract boolean containsKey(String key);

/**
* to properties.
* @return properties
*/
abstract Properties asProperties();

}
Loading

0 comments on commit 2eb7f73

Please sign in to comment.