Skip to content

Commit

Permalink
add delete threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeymq authored Aug 4, 2017
1 parent 96ed4d8 commit a4dd50e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/main/java/net/lvsq/jgossip/core/GossipManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,17 @@ private void checkStatus() {
HeartbeatState state = endpoints.get(k);
long now = System.currentTimeMillis();
long duration = now - state.getHeartbeatTime();
LOGGER.info("check : " + k.toString() + " state : " + state.toString() + " duration : " + duration + " convictedTime : " + convictedTime());
//TODO: delete the service from deadmembers which outage for a long time
if (duration > convictedTime() && (isAlive(k) || getLiveMembers().contains(k))) {
LOGGER.info("down ~~");
down(k);
long convictedTime = convictedTime();
LOGGER.info("check : " + k.toString() + " state : " + state.toString() + " duration : " + duration + " convictedTime : " + convictedTime);
if (duration > convictedTime) {
if (duration > (getSettings().getDeleteThreshold() * getSettings().getGossipInterval())) {
clearMember(k);
} else if (isAlive(k) || getLiveMembers().contains(k)) {
LOGGER.info("down ~~");
down(k);
}
}
if (duration <= convictedTime() && (isDiscoverable(k) || getDeadMembers().contains(k))) {
if (duration <= convictedTime && (isDiscoverable(k) || getDeadMembers().contains(k))) {
LOGGER.info("up ~~");
up(k);
}
Expand Down Expand Up @@ -386,6 +390,16 @@ private void fireGossipEvent(GossipMember member, GossipState state) {
}
}

private void clearMember(GossipMember member) {
rwlock.writeLock().lock();
try {
deadMembers.remove(member);
endpointMembers.remove(member);
} finally {
rwlock.writeLock().unlock();
}
}

public void down(GossipMember member) {
rwlock.writeLock().lock();
try {
Expand All @@ -407,7 +421,7 @@ private void up(GossipMember member) {
if (!liveMembers.contains(member)) {
liveMembers.add(member);
}
if(deadMembers.contains(member)){
if (deadMembers.contains(member)) {
deadMembers.remove(member);
fireGossipEvent(member, GossipState.UP);
}
Expand Down

0 comments on commit a4dd50e

Please sign in to comment.