Skip to content

Commit

Permalink
Fix address server mode cannot be obtained application.properties And…
Browse files Browse the repository at this point in the history
… synchronize the properties value(alibaba#3509)
  • Loading branch information
qm0123 committed Aug 4, 2020
1 parent df4b006 commit 95ad77d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 46 deletions.
8 changes: 7 additions & 1 deletion console/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ server.port=8848


#*************** Config Module Related Configurations ***************#
### If user MySQL as datasource:
### If use MySQL as datasource:
# spring.datasource.platform=mysql

### Count of DB:
Expand Down Expand Up @@ -154,6 +154,12 @@ nacos.istio.mcp.server.enabled=false
## for AddressServerMemberLookup
# Maximum number of retries to query the address server upon initialization
# nacos.core.address-server.retry=5
## Server domain name address of [address-server] mode
# address.server.domain=jmenv.tbsite.net
## Server port of [address-server] mode
# address.server.port=8080
## Request address of [address-server] mode
# address.server.url=/nacos/serverlist

#*************** JRaft Related Configurations ***************#

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,30 @@
* @author <a href="mailto:[email protected]">liaochuntao</a>
*/
public class AddressServerMemberLookup extends AbstractMemberLookup {

private final GenericType<RestResult<String>> genericType = new GenericType<RestResult<String>>() {
};

public String domainName;

public String addressPort;

public String addressUrl;

public String envIdUrl;

public String addressServerUrl;

private volatile boolean isAddressServerHealth = true;

private int addressServerFailCount = 0;

private int maxFailCount = 12;

private NSyncHttpClient syncHttpClient = HttpClientManager.getSyncHttpClient();

private volatile boolean shutdown = false;

@Override
public void start() throws NacosException {
if (start.compareAndSet(false, true)) {
Expand All @@ -75,28 +75,33 @@ public void start() throws NacosException {
run();
}
}

private void initAddressSys() {
String envDomainName = System.getenv("address_server_domain");
if (StringUtils.isBlank(envDomainName)) {
domainName = System.getProperty("address.server.domain", "jmenv.tbsite.net");
domainName = ApplicationUtils.getProperty("address.server.domain", "jmenv.tbsite.net");
} else {
domainName = envDomainName;
}
String envAddressPort = System.getenv("address_server_port");
if (StringUtils.isBlank(envAddressPort)) {
addressPort = System.getProperty("address.server.port", "8080");
addressPort = ApplicationUtils.getProperty("address.server.port", "8080");
} else {
addressPort = envAddressPort;
}
addressUrl = System.getProperty("address.server.url", ApplicationUtils.getContextPath() + "/" + "serverlist");
String envAddressUrl = System.getenv("address_server_url");
if (StringUtils.isBlank(envAddressUrl)) {
addressUrl = ApplicationUtils.getProperty("address.server.url", ApplicationUtils.getContextPath() + "/" + "serverlist");
} else {
addressUrl = envAddressUrl;
}
addressServerUrl = "http://" + domainName + ":" + addressPort + addressUrl;
envIdUrl = "http://" + domainName + ":" + addressPort + "/env";

Loggers.CORE.info("ServerListService address-server port:" + addressPort);
Loggers.CORE.info("ADDRESS_SERVER_URL:" + addressServerUrl);
}

@SuppressWarnings("PMD.UndefineMagicConstantRule")
private void run() throws NacosException {
// With the address server, you need to perform a synchronous member node pull at startup
Expand All @@ -117,15 +122,15 @@ private void run() throws NacosException {
if (!success) {
throw new NacosException(NacosException.SERVER_ERROR, ex);
}

GlobalExecutor.scheduleByCommon(new AddressServerSyncTask(), 5_000L);
}

@Override
public void destroy() throws NacosException {
shutdown = true;
}

@Override
public Map<String, Object> info() {
Map<String, Object> info = new HashMap<>(4);
Expand All @@ -135,7 +140,7 @@ public Map<String, Object> info() {
info.put("addressServerFailCount", addressServerFailCount);
return info;
}

private void syncFromAddressUrl() throws Exception {
RestResult<String> result = syncHttpClient
.get(addressServerUrl, Header.EMPTY, Query.EMPTY, genericType.getType());
Expand All @@ -158,9 +163,9 @@ private void syncFromAddressUrl() throws Exception {
Loggers.CLUSTER.error("[serverlist] failed to get serverlist, error code {}", result.getCode());
}
}

class AddressServerSyncTask implements Runnable {

@Override
public void run() {
if (shutdown) {
Expand Down
21 changes: 11 additions & 10 deletions distribution/conf/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ server.port=8848

### Connect URL of DB:
# db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
# db.user=nacos
# db.password=nacos
# db.user=root
# db.password=1017


#*************** Naming Module Related Configurations ***************#
Expand Down Expand Up @@ -98,7 +98,7 @@ management.metrics.export.influx.enabled=false
server.tomcat.accesslog.enabled=true

### The access log pattern:
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i

### The directory of access log:
server.tomcat.basedir=
Expand Down Expand Up @@ -148,29 +148,30 @@ nacos.istio.mcp.server.enabled=false

### MemberLookup
### Addressing pattern category, If set, the priority is highest
# nacos.core.member.lookup.type=[file,address-server,discovery]
# nacos.core.member.lookup.type=[file,address-server]
## Set the cluster list with a configuration file or command-line argument
# nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
## for DiscoveryMemberLookup
# If you want to use cluster node self-discovery, turn this parameter on
# nacos.member.discovery=false
## for AddressServerMemberLookup
# Maximum number of retries to query the address server upon initialization
# nacos.core.address-server.retry=5
## Server domain name address of [address-server] mode
# address.server.domain=jmenv.tbsite.net
## Server port of [address-server] mode
# address.server.port=8080
## Request address of [address-server] mode
# address.server.url=/nacos/serverlist

#*************** JRaft Related Configurations ***************#

### Sets the Raft cluster election timeout, default value is 5 second
# nacos.core.protocol.raft.data.election_timeout_ms=5000
### Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute
# nacos.core.protocol.raft.data.snapshot_interval_secs=30
### Requested retries, default value is 1
# nacos.core.protocol.raft.data.request_failoverRetries=1
### raft internal worker threads
# nacos.core.protocol.raft.data.core_thread_num=8
### Number of threads required for raft business request processing
# nacos.core.protocol.raft.data.cli_service_thread_num=4
### raft linear read strategy, defaults to index
### raft linear read strategy. Safe linear reads are used by default, that is, the Leader tenure is confirmed by heartbeat
# nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe
### rpc request timeout, default 5 seconds
# nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000
23 changes: 12 additions & 11 deletions distribution/conf/application.properties.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ server.port=8848


#*************** Config Module Related Configurations ***************#
### If user MySQL as datasource:
### If use MySQL as datasource:
# spring.datasource.platform=mysql

### Count of DB:
# db.num=1

### Connect URL of DB:
# db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
# db.user=nacos
# db.password=nacos
# db.user=root
# db.password=1017


#*************** Naming Module Related Configurations ***************#
Expand Down Expand Up @@ -98,7 +98,7 @@ management.metrics.export.influx.enabled=false
server.tomcat.accesslog.enabled=true

### The access log pattern:
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i

### The directory of access log:
server.tomcat.basedir=
Expand Down Expand Up @@ -148,29 +148,30 @@ nacos.istio.mcp.server.enabled=false

### MemberLookup
### Addressing pattern category, If set, the priority is highest
# nacos.core.member.lookup.type=[file,address-server,discovery]
# nacos.core.member.lookup.type=[file,address-server]
## Set the cluster list with a configuration file or command-line argument
# nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
## for DiscoveryMemberLookup
# If you want to use cluster node self-discovery, turn this parameter on
# nacos.member.discovery=false
## for AddressServerMemberLookup
# Maximum number of retries to query the address server upon initialization
# nacos.core.address-server.retry=5
## Server domain name address of [address-server] mode
# address.server.domain=jmenv.tbsite.net
## Server port of [address-server] mode
# address.server.port=8080
## Request address of [address-server] mode
# address.server.url=/nacos/serverlist

#*************** JRaft Related Configurations ***************#

### Sets the Raft cluster election timeout, default value is 5 second
# nacos.core.protocol.raft.data.election_timeout_ms=5000
### Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute
# nacos.core.protocol.raft.data.snapshot_interval_secs=30
### Requested retries, default value is 1
# nacos.core.protocol.raft.data.request_failoverRetries=1
### raft internal worker threads
# nacos.core.protocol.raft.data.core_thread_num=8
### Number of threads required for raft business request processing
# nacos.core.protocol.raft.data.cli_service_thread_num=4
### raft linear read strategy, defaults to index
### raft linear read strategy. Safe linear reads are used by default, that is, the Leader tenure is confirmed by heartbeat
# nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe
### rpc request timeout, default 5 seconds
# nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000

0 comments on commit 95ad77d

Please sign in to comment.