Skip to content
Snippets Groups Projects
Commit c9b36019 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[fix] Revert: store peer stats in second, no more in millis

parent 886b7342
No related branches found
No related tags found
No related merge requests found
Pipeline #4624 passed
...@@ -160,7 +160,8 @@ public class MemoryPeerDaoImpl implements PeerDao { ...@@ -160,7 +160,8 @@ public class MemoryPeerDaoImpl implements PeerDao {
@Override @Override
public void updatePeersAsDown(String currencyId, long minUpTimeInMs, Collection<String> endpointApis) { public void updatePeersAsDown(String currencyId, long minUpTimeInMs, Collection<String> endpointApis) {
long firstDownTimeInMs = System.currentTimeMillis(); long minUpTimeInS = Math.round(minUpTimeInMs / 1000);
long firstDownTimeInMs = Math.round(System.currentTimeMillis() / 1000);
getPeersByCurrencyId(currencyId).stream() getPeersByCurrencyId(currencyId).stream()
.filter(peer -> .filter(peer ->
...@@ -168,7 +169,7 @@ public class MemoryPeerDaoImpl implements PeerDao { ...@@ -168,7 +169,7 @@ public class MemoryPeerDaoImpl implements PeerDao {
&& peer.getStats().isReacheable() && peer.getStats().isReacheable()
&& ( && (
peer.getStats().getLastUpTime() == null peer.getStats().getLastUpTime() == null
|| peer.getStats().getLastUpTime() < minUpTimeInMs || peer.getStats().getLastUpTime() < minUpTimeInS
) )
&& (endpointApis == null || endpointApis.contains(peer.getApi())) && (endpointApis == null || endpointApis.contains(peer.getApi()))
) )
......
...@@ -197,8 +197,7 @@ public class Peer implements LocalEntity<String>, Serializable { ...@@ -197,8 +197,7 @@ public class Peer implements LocalEntity<String>, Serializable {
stats.setStatus(Peer.PeerStatus.UP); stats.setStatus(Peer.PeerStatus.UP);
// FIXME: Duniter 1.7 return lastUpTime in ms. Check if this a bug or not // FIXME: Duniter 1.7 return lastUpTime in ms. Check if this a bug or not
stats.setLastUpTime(System.currentTimeMillis()); stats.setLastUpTime((long)Math.round(System.currentTimeMillis() / 1000));
//stats.setLastUpTime((long)Math.round(System.currentTimeMillis() / 1000));
} }
else { else {
stats.setStatus(Peer.PeerStatus.DOWN); stats.setStatus(Peer.PeerStatus.DOWN);
...@@ -683,7 +682,7 @@ public class Peer implements LocalEntity<String>, Serializable { ...@@ -683,7 +682,7 @@ public class Peer implements LocalEntity<String>, Serializable {
} }
/** /**
* Last time the peer was UP (in millisecond) * Last time the peer was UP (in second)
* @return * @return
*/ */
public Long getLastUpTime() { public Long getLastUpTime() {
...@@ -695,7 +694,7 @@ public class Peer implements LocalEntity<String>, Serializable { ...@@ -695,7 +694,7 @@ public class Peer implements LocalEntity<String>, Serializable {
} }
/** /**
* First time the peer was DOWN (in millisecond) * First time the peer was DOWN (in second)
* @return * @return
*/ */
public Long getFirstDownTime() { public Long getFirstDownTime() {
......
...@@ -262,8 +262,7 @@ public final class Peers { ...@@ -262,8 +262,7 @@ public final class Peers {
stats.setStatus(Peer.PeerStatus.UP); stats.setStatus(Peer.PeerStatus.UP);
// FIXME: Duniter 1.7 return lastUpTime in ms. Check if this a bug or not // FIXME: Duniter 1.7 return lastUpTime in ms. Check if this a bug or not
stats.setLastUpTime(System.currentTimeMillis()); stats.setLastUpTime((long)Math.round(System.currentTimeMillis() / 1000));
//stats.setLastUpTime((long)Math.round(System.currentTimeMillis() / 1000));
} }
else { else {
stats.setStatus(Peer.PeerStatus.DOWN); stats.setStatus(Peer.PeerStatus.DOWN);
......
...@@ -192,8 +192,7 @@ public class PeerServiceImpl implements PeerService, InitializingBean { ...@@ -192,8 +192,7 @@ public class PeerServiceImpl implements PeerService, InitializingBean {
} }
// FIXME: Duniter 1.7 return lastUpTime in ms. Check if this a bug or not // FIXME: Duniter 1.7 return lastUpTime in ms. Check if this a bug or not
final long upTime = System.currentTimeMillis(); final long upTime = System.currentTimeMillis() / 1000;
//final long upTime = System.currentTimeMillis() / 1000;
peers.forEach(peer -> { peers.forEach(peer -> {
// On each UP peers: set last UP time // On each UP peers: set last UP time
...@@ -217,8 +216,8 @@ public class PeerServiceImpl implements PeerService, InitializingBean { ...@@ -217,8 +216,8 @@ public class PeerServiceImpl implements PeerService, InitializingBean {
int peerDownTimeoutMs = config.getPeerUpMaxAge(); int peerDownTimeoutMs = config.getPeerUpMaxAge();
// Mark old peers as DOWN // Mark old peers as DOWN
if (peerDownTimeoutMs >0) { if (peerDownTimeoutMs >0) {
long maxUpTimeInSec = Math.round((System.currentTimeMillis() - peerDownTimeoutMs*1000)); long maxUpTimeInMs = System.currentTimeMillis() - peerDownTimeoutMs;
updatePeersAsDown(currencyId, maxUpTimeInSec, filterApis); updatePeersAsDown(currencyId, maxUpTimeInMs, filterApis);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment