#502 Fix error log print

This commit is contained in:
nkorange 2019-01-17 17:12:44 +08:00
parent 0e76f55a3f
commit cc1f6647b0
2 changed files with 20 additions and 0 deletions

View File

@ -16,6 +16,7 @@
package com.alibaba.nacos.naming.consistency.persistent.simpleraft; package com.alibaba.nacos.naming.consistency.persistent.simpleraft;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.naming.boot.RunningConfig;
import com.alibaba.nacos.naming.misc.HttpClient; import com.alibaba.nacos.naming.misc.HttpClient;
import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.misc.Loggers;
import com.alibaba.nacos.naming.misc.NetUtils; import com.alibaba.nacos.naming.misc.NetUtils;
@ -43,6 +44,8 @@ public class PeerSet {
private Set<String> sites = new HashSet<>(); private Set<String> sites = new HashSet<>();
private boolean ready = false;
public PeerSet() { public PeerSet() {
} }
@ -57,6 +60,10 @@ public class PeerSet {
return sites; return sites;
} }
public boolean isReady() {
return ready;
}
public void add(List<String> servers) { public void add(List<String> servers) {
for (String server : servers) { for (String server : servers) {
RaftPeer peer = new RaftPeer(); RaftPeer peer = new RaftPeer();
@ -71,6 +78,10 @@ public class PeerSet {
local.voteFor = NetUtils.localServer(); local.voteFor = NetUtils.localServer();
} }
if (RunningConfig.getServerPort() > 0) {
ready = true;
}
} }
public void remove(List<String> servers) { public void remove(List<String> servers) {

View File

@ -371,6 +371,11 @@ public class RaftCore {
@Override @Override
public void run() { public void run() {
try { try {
if (!peers.isReady()) {
return;
}
RaftPeer local = peers.local(); RaftPeer local = peers.local();
local.leaderDueMs -= GlobalExecutor.TICK_PERIOD_MS; local.leaderDueMs -= GlobalExecutor.TICK_PERIOD_MS;
if (local.leaderDueMs > 0) { if (local.leaderDueMs > 0) {
@ -470,6 +475,10 @@ public class RaftCore {
@Override @Override
public void run() { public void run() {
try { try {
if (!peers.isReady()) {
return;
}
RaftPeer local = peers.local(); RaftPeer local = peers.local();
local.heartbeatDueMs -= GlobalExecutor.TICK_PERIOD_MS; local.heartbeatDueMs -= GlobalExecutor.TICK_PERIOD_MS;
if (local.heartbeatDueMs > 0) { if (local.heartbeatDueMs > 0) {