Simplify anti-entropy code
Change-Id: I6568b1cc7c67e12c5a81ec9f8680f6461813ddce
diff --git a/core/api/src/main/java/org/onosproject/store/Timestamp.java b/core/api/src/main/java/org/onosproject/store/Timestamp.java
index 67c01b1..44aed95 100644
--- a/core/api/src/main/java/org/onosproject/store/Timestamp.java
+++ b/core/api/src/main/java/org/onosproject/store/Timestamp.java
@@ -15,6 +15,8 @@
*/
package org.onosproject.store;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* Opaque version structure.
* <p>
@@ -28,4 +30,14 @@
@Override
public abstract boolean equals(Object obj);
+
+ /**
+ * Tests if this timestamp is newer than the specified timestamp.
+ *
+ * @param other timestamp to compare against
+ * @return true if this instance is newer
+ */
+ public default boolean isNewerThan(Timestamp other) {
+ return this.compareTo(checkNotNull(other)) > 0;
+ }
}
diff --git a/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java b/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
index f16bd06..f8e19c0 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
@@ -1170,7 +1170,8 @@
Timestamped<DeviceDescription> lProvDevice = lDeviceDescs.getDeviceDesc();
Timestamp advDevTimestamp = devAds.get(devFragId);
- if (advDevTimestamp == null || lProvDevice.isNewer(advDevTimestamp)) {
+ if (advDevTimestamp == null || lProvDevice.isNewerThan(
+ advDevTimestamp)) {
// remote does not have it or outdated, suggest
notifyPeer(sender, new InternalDeviceEvent(provId, deviceId, lProvDevice));
} else if (!lProvDevice.timestamp().equals(advDevTimestamp)) {
@@ -1188,7 +1189,8 @@
final PortFragmentId portFragId = new PortFragmentId(deviceId, provId, num);
Timestamp advPortTimestamp = portAds.get(portFragId);
- if (advPortTimestamp == null || lPort.isNewer(advPortTimestamp)) {
+ if (advPortTimestamp == null || lPort.isNewerThan(
+ advPortTimestamp)) {
// remote does not have it or outdated, suggest
notifyPeer(sender, new InternalPortStatusEvent(provId, deviceId, lPort));
} else if (!lPort.timestamp().equals(advPortTimestamp)) {
diff --git a/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java b/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java
index fe8f1a8..d0e6733 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java
@@ -262,7 +262,7 @@
private boolean putInternal(K key, V value, Timestamp timestamp) {
Timestamp removed = removedItems.get(key);
- if (removed != null && removed.compareTo(timestamp) > 0) {
+ if (removed != null && removed.isNewerThan(timestamp)) {
log.debug("ecmap - removed was newer {}", value);
return false;
}
@@ -270,7 +270,7 @@
boolean success;
synchronized (this) {
Timestamped<V> existing = items.get(key);
- if (existing != null && existing.isNewer(timestamp)) {
+ if (existing != null && existing.isNewerThan(timestamp)) {
log.debug("ecmap - existing was newer {}", value);
success = false;
} else {
@@ -305,7 +305,7 @@
private boolean removeInternal(K key, Timestamp timestamp) {
Timestamped<V> value = items.get(key);
if (value != null) {
- if (value.isNewer(timestamp)) {
+ if (value.isNewerThan(timestamp)) {
return false;
} else {
items.remove(key, value);
@@ -315,7 +315,7 @@
Timestamp removedTimestamp = removedItems.get(key);
if (removedTimestamp == null) {
return removedItems.putIfAbsent(key, timestamp) == null;
- } else if (timestamp.compareTo(removedTimestamp) > 0) {
+ } else if (timestamp.isNewerThan(removedTimestamp)) {
return removedItems.replace(key, removedTimestamp, timestamp);
} else {
return false;
@@ -614,7 +614,7 @@
remoteTimestamp = ad.tombstones().get(key);
}
if (remoteTimestamp == null || localValue
- .isNewer(remoteTimestamp)) {
+ .isNewerThan(remoteTimestamp)) {
// local value is more recent, push to sender
updatesToSend
.add(new PutEntry<>(key, localValue.value(),
@@ -623,7 +623,7 @@
Timestamp remoteDeadTimestamp = ad.tombstones().get(key);
if (remoteDeadTimestamp != null &&
- remoteDeadTimestamp.compareTo(localValue.timestamp()) > 0) {
+ remoteDeadTimestamp.isNewerThan(localValue.timestamp())) {
// sender has a more recent remove
if (removeInternal(key, remoteDeadTimestamp)) {
externalEvents.add(new EventuallyConsistentMapEvent<>(
@@ -664,7 +664,7 @@
Timestamp remoteLiveTimestamp = ad.timestamps().get(key);
if (remoteLiveTimestamp != null
- && localDeadTimestamp.compareTo(remoteLiveTimestamp) > 0) {
+ && localDeadTimestamp.isNewerThan(remoteLiveTimestamp)) {
// sender has zombie, push remove
removesToSend
.add(new RemoveEntry<>(key, localDeadTimestamp));
@@ -702,18 +702,19 @@
Timestamped<V> local = items.get(key);
Timestamp localDead = removedItems.get(key);
- if (local != null
- && remoteDeadTimestamp.compareTo(local.timestamp()) > 0) {
- // remove our version
+ if (local != null && remoteDeadTimestamp.isNewerThan(
+ local.timestamp())) {
+ // If the remote has a more recent tombstone than either our local
+ // value, then do a remove with their timestamp
if (removeInternal(key, remoteDeadTimestamp)) {
externalEvents.add(new EventuallyConsistentMapEvent<>(
EventuallyConsistentMapEvent.Type.REMOVE, key, null));
}
- } else if (localDead != null &&
- remoteDeadTimestamp.compareTo(localDead) > 0) {
- // If we both had the item as removed, but their timestamp is
- // newer, update ours to the newer value
- removedItems.put(key, remoteDeadTimestamp);
+ } else if (localDead != null && remoteDeadTimestamp.isNewerThan(
+ localDead)) {
+ // If the remote has a more recent tombstone than us, update ours
+ // to their timestamp
+ removeInternal(key, remoteDeadTimestamp);
}
}
diff --git a/core/store/dist/src/main/java/org/onosproject/store/host/impl/GossipHostStore.java b/core/store/dist/src/main/java/org/onosproject/store/host/impl/GossipHostStore.java
index c65dc79..74236c3 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/host/impl/GossipHostStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/host/impl/GossipHostStore.java
@@ -235,7 +235,7 @@
private boolean isHostRemoved(HostId hostId, Timestamp timestamp) {
Timestamped<Host> removedInfo = removedHosts.get(hostId);
if (removedInfo != null) {
- if (removedInfo.isNewer(timestamp)) {
+ if (removedInfo.isNewerThan(timestamp)) {
return true;
}
removedHosts.remove(hostId, removedInfo);
diff --git a/core/store/dist/src/main/java/org/onosproject/store/impl/Timestamped.java b/core/store/dist/src/main/java/org/onosproject/store/impl/Timestamped.java
index 5b158a0..12dd565 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/impl/Timestamped.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/impl/Timestamped.java
@@ -15,13 +15,12 @@
*/
package org.onosproject.store.impl;
-import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.base.MoreObjects;
+import org.onosproject.store.Timestamp;
import java.util.Objects;
-import org.onosproject.store.Timestamp;
-
-import com.google.common.base.MoreObjects;
+import static com.google.common.base.Preconditions.checkNotNull;
/**
* Wrapper class to store Timestamped value.
@@ -69,17 +68,17 @@
* @return true if this instance is newer.
*/
public boolean isNewer(Timestamped<T> other) {
- return isNewer(checkNotNull(other).timestamp());
+ return isNewerThan(checkNotNull(other).timestamp());
}
/**
* Tests if this timestamp is newer than the specified timestamp.
+ *
* @param other timestamp to compare against
* @return true if this instance is newer
*/
- //TODO put this in Timestamp
- public boolean isNewer(Timestamp other) {
- return this.timestamp.compareTo(checkNotNull(other)) > 0;
+ public boolean isNewerThan(Timestamp other) {
+ return timestamp.isNewerThan(other);
}
@Override
diff --git a/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java b/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java
index 54c35ec..013b20c 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java
@@ -360,7 +360,7 @@
// only if this request is more recent.
Timestamp linkRemovedTimestamp = removedLinks.get(key);
if (linkRemovedTimestamp != null) {
- if (linkDescription.isNewer(linkRemovedTimestamp)) {
+ if (linkDescription.isNewerThan(linkRemovedTimestamp)) {
removedLinks.remove(key);
} else {
log.trace("Link {} was already removed ignoring.", key);
@@ -762,7 +762,7 @@
remoteTimestamp = ad.linkTombstones().get(key);
}
if (remoteTimestamp == null ||
- pDesc.isNewer(remoteTimestamp)) {
+ pDesc.isNewerThan(remoteTimestamp)) {
// I have more recent link description. update peer.
notifyPeer(sender, new InternalLinkEvent(providerId, pDesc));
} else {
@@ -776,7 +776,7 @@
// search local latest along the way
if (localLatest == null ||
- pDesc.isNewer(localLatest)) {
+ pDesc.isNewerThan(localLatest)) {
localLatest = pDesc.timestamp();
}
}