Bugfix: store entry is not removed properly after device disconnected
Change-Id: I4c967a1d98208b5d3eee0e7b00dfd4ed2fddde01
diff --git a/src/main/java/org/onosproject/segmentrouting/McastHandler.java b/src/main/java/org/onosproject/segmentrouting/McastHandler.java
index 6d5666a..6f42cf6 100644
--- a/src/main/java/org/onosproject/segmentrouting/McastHandler.java
+++ b/src/main/java/org/onosproject/segmentrouting/McastHandler.java
@@ -57,13 +57,11 @@
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
-import org.onosproject.store.service.Versioned;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -518,27 +516,22 @@
* @param deviceId device ID
*/
public void removeDevice(DeviceId deviceId) {
- Iterator<Map.Entry<McastStoreKey, Versioned<NextObjective>>> itNextObj =
- mcastNextObjStore.entrySet().iterator();
- while (itNextObj.hasNext()) {
- Map.Entry<McastStoreKey, Versioned<NextObjective>> entry = itNextObj.next();
- if (entry.getKey().deviceId().equals(deviceId)) {
- ConnectPoint source = getSource(entry.getKey().mcastIp());
- removeGroupFromDevice(entry.getKey().deviceId(), entry.getKey().mcastIp(),
- assignedVlan(deviceId.equals(source.deviceId()) ? source : null));
- itNextObj.remove();
- }
- }
+ mcastNextObjStore.entrySet().stream()
+ .filter(entry -> entry.getKey().deviceId().equals(deviceId))
+ .forEach(entry -> {
+ ConnectPoint source = getSource(entry.getKey().mcastIp());
+ removeGroupFromDevice(entry.getKey().deviceId(), entry.getKey().mcastIp(),
+ assignedVlan(deviceId.equals(source.deviceId()) ? source : null));
+ mcastNextObjStore.remove(entry.getKey());
+ });
+ log.debug("{} is removed from mcastNextObjStore", deviceId);
- Iterator<Map.Entry<McastStoreKey, Versioned<McastRole>>> itRole =
- mcastRoleStore.entrySet().iterator();
- while (itRole.hasNext()) {
- Map.Entry<McastStoreKey, Versioned<McastRole>> entry = itRole.next();
- if (entry.getKey().deviceId().equals(deviceId)) {
- itRole.remove();
- }
- }
-
+ mcastRoleStore.entrySet().stream()
+ .filter(entry -> entry.getKey().deviceId().equals(deviceId))
+ .forEach(entry -> {
+ mcastRoleStore.remove(entry.getKey());
+ });
+ log.debug("{} is removed from mcastRoleStore", deviceId);
}
/**
diff --git a/src/main/java/org/onosproject/segmentrouting/XConnectHandler.java b/src/main/java/org/onosproject/segmentrouting/XConnectHandler.java
index 0adf7eb..c3f737f 100644
--- a/src/main/java/org/onosproject/segmentrouting/XConnectHandler.java
+++ b/src/main/java/org/onosproject/segmentrouting/XConnectHandler.java
@@ -44,12 +44,9 @@
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
-import org.onosproject.store.service.Versioned;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Iterator;
-import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@@ -398,14 +395,12 @@
* @param deviceId device ID
*/
protected void removeDevice(DeviceId deviceId) {
- Iterator<Map.Entry<XConnectStoreKey, Versioned<NextObjective>>> itNextObj =
- xConnectNextObjStore.entrySet().iterator();
- while (itNextObj.hasNext()) {
- Map.Entry<XConnectStoreKey, Versioned<NextObjective>> entry = itNextObj.next();
- if (entry.getKey().deviceId().equals(deviceId)) {
- itNextObj.remove();
- }
- }
+ xConnectNextObjStore.entrySet().stream()
+ .filter(entry -> entry.getKey().deviceId().equals(deviceId))
+ .forEach(entry -> {
+ xConnectNextObjStore.remove(entry.getKey());
+ });
+ log.debug("{} is removed from xConnectNextObjStore", deviceId);
}
/**