Skip to content

Commit

Permalink
#502 Fix error log print
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Jan 17, 2019
1 parent 0e76f55 commit cc1f664
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Expand Up @@ -16,6 +16,7 @@
package com.alibaba.nacos.naming.consistency.persistent.simpleraft;

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.Loggers;
import com.alibaba.nacos.naming.misc.NetUtils;
Expand Down Expand Up @@ -43,6 +44,8 @@ public class PeerSet {

private Set<String> sites = new HashSet<>();

private boolean ready = false;

public PeerSet() {
}

Expand All @@ -57,6 +60,10 @@ public Set<String> allSites() {
return sites;
}

public boolean isReady() {
return ready;
}

public void add(List<String> servers) {
for (String server : servers) {
RaftPeer peer = new RaftPeer();
Expand All @@ -71,6 +78,10 @@ public void add(List<String> servers) {
local.voteFor = NetUtils.localServer();

}

if (RunningConfig.getServerPort() > 0) {
ready = true;
}
}

public void remove(List<String> servers) {
Expand Down
Expand Up @@ -371,6 +371,11 @@ public class MasterElection implements Runnable {
@Override
public void run() {
try {

if (!peers.isReady()) {
return;
}

RaftPeer local = peers.local();
local.leaderDueMs -= GlobalExecutor.TICK_PERIOD_MS;
if (local.leaderDueMs > 0) {
Expand Down Expand Up @@ -470,6 +475,10 @@ public class HeartBeat implements Runnable {
@Override
public void run() {
try {
if (!peers.isReady()) {
return;
}

RaftPeer local = peers.local();
local.heartbeatDueMs -= GlobalExecutor.TICK_PERIOD_MS;
if (local.heartbeatDueMs > 0) {
Expand Down

0 comments on commit cc1f664

Please sign in to comment.