Charles Chan
Committed by Charles Chan

Bugfix: store entry is not removed properly after device disconnected

Change-Id: I4c967a1d98208b5d3eee0e7b00dfd4ed2fddde01
......@@ -57,13 +57,11 @@ import org.onosproject.store.serializers.KryoNamespaces;
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 @@ public class McastHandler {
* @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();
}
}
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();
}
}
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);
mcastRoleStore.entrySet().stream()
.filter(entry -> entry.getKey().deviceId().equals(deviceId))
.forEach(entry -> {
mcastRoleStore.remove(entry.getKey());
});
log.debug("{} is removed from mcastRoleStore", deviceId);
}
/**
......
......@@ -44,12 +44,9 @@ import org.onosproject.store.serializers.KryoNamespaces;
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 @@ public class XConnectHandler {
* @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);
}
/**
......