[ONOS-7332] Ensure DEVICE_ADDED events are not skipped after device creation on a non-master node
Change-Id: I9a6ee21833d89db16fab6b13bb946746e381d36c
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 f5c055a..5242fbb 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
@@ -303,7 +303,7 @@
DeviceDescription deviceDescription) {
NodeId localNode = clusterService.getLocalNode().id();
NodeId deviceNode = mastershipService.getMasterFor(deviceId);
- final boolean isMaster = localNode.equals(deviceNode);
+ boolean isMaster = localNode.equals(deviceNode);
// Process device update only if we're the master,
// otherwise signal the actual master.
@@ -311,9 +311,15 @@
// If this node is the master for the device, acquire a new timestamp. Otherwise,
// use a 0,0 or tombstone timestamp to create the device if it doesn't already exist.
- final Timestamp newTimestamp = isMaster
- ? deviceClockService.getTimestamp(deviceId)
- : removalRequest.getOrDefault(deviceId, DEFAULT_TIMESTAMP);
+ Timestamp newTimestamp;
+ try {
+ newTimestamp = isMaster
+ ? deviceClockService.getTimestamp(deviceId)
+ : removalRequest.getOrDefault(deviceId, DEFAULT_TIMESTAMP);
+ } catch (IllegalStateException e) {
+ newTimestamp = removalRequest.getOrDefault(deviceDescription, DEFAULT_TIMESTAMP);
+ isMaster = false;
+ }
final Timestamped<DeviceDescription> deltaDesc = new Timestamped<>(deviceDescription, newTimestamp);
final Timestamped<DeviceDescription> mergedDesc;
final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId);
@@ -331,8 +337,6 @@
log.debug("Notifying peers of a device update topology event for providerId: {} and deviceId: {}",
providerId, deviceId);
notifyPeers(new InternalDeviceEvent(providerId, deviceId, mergedDesc));
- } else {
- return null;
}
return deviceEvent;