From f1b9b4b8ce718f683114d3ba8ee02e712c12d00b Mon Sep 17 00:00:00 2001 From: Yevgeny Khodorkovsky Date: Wed, 12 Feb 2014 10:04:41 -0800 Subject: [PATCH] Switch Manager should ignore redundant updates - Redundant node and node connector updates (such as in the case of cluster switchover) should not be notified to apps/listeners, to avoid expensive tasks Change-Id: Ia541bdcba6b53170c7a6c29e2c35f1b7b8104d60 Signed-off-by: Yevgeny Khodorkovsky --- .../switchmanager/internal/SwitchManager.java | 63 ++++++++++++------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java index 19f45e63c5..615bb4df83 100644 --- a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java +++ b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java @@ -1004,7 +1004,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa } } - boolean proactiveForwarding = false; + boolean forwardingModeChanged = false; + // copy node properties from config if (nodeConfigList != null) { String nodeId = node.toString(); @@ -1014,7 +1015,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa propMap.putAll(nodeProperties); if (nodeProperties.get(ForwardingMode.name) != null) { ForwardingMode mode = (ForwardingMode) nodeProperties.get(ForwardingMode.name); - proactiveForwarding = mode.isProactive(); + forwardingModeChanged = mode.isProactive(); } } } @@ -1023,28 +1024,35 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa Property defaultMode = new ForwardingMode(ForwardingMode.REACTIVE_FORWARDING); propMap.put(ForwardingMode.name, defaultMode); } - boolean result = false; - if (propMapCurr == null) { - if (nodeProps.putIfAbsent(node, propMap) == null) { - result = true; - } + + boolean propsAdded = false; + // Attempt initial add + if (nodeProps.putIfAbsent(node, propMap) == null) { + propsAdded = true; + + /* Notify listeners only for initial node addition + * to avoid expensive tasks triggered by redundant notifications + */ + notifyNode(node, UpdateType.ADDED, propMap); } else { - result = nodeProps.replace(node, propMapCurr, propMap); + + propsAdded = nodeProps.replace(node, propMapCurr, propMap); + + // check whether forwarding mode changed + if (propMapCurr.get(ForwardingMode.name) != null) { + ForwardingMode mode = (ForwardingMode) propMapCurr.get(ForwardingMode.name); + forwardingModeChanged ^= mode.isProactive(); + } } - if (!result) { - log.debug("Cluster conflict: Conflict while adding the node properties. Node: {} Properties: {}", - node.getID(), props); + if (!propsAdded) { + log.debug("Cluster conflict while adding node {}. Overwriting with latest props: {}", node.getID(), props); addNodeProps(node, propMap); } - // check if span ports are configed + // check if span ports are configured addSpanPorts(node); - - // notify node listeners - notifyNode(node, UpdateType.ADDED, propMap); - // notify proactive mode forwarding - if (proactiveForwarding) { + if (forwardingModeChanged) { notifyModeChange(node, true); } } @@ -1054,7 +1062,12 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa if (nodeProps == null) { return; } - nodeProps.remove(node); + + if (nodeProps.remove(node) == null) { + log.debug("Received redundant node REMOVED udate for {}. Skipping..", node); + return; + } + nodeConnectorNames.remove(node); Set removeNodeConnectorSet = new HashSet(); for (Map.Entry> entry : nodeConnectorProps.entrySet()) { @@ -1149,6 +1162,13 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa switch (type) { case ADDED: + // Skip redundant ADDED update (e.g. cluster switch-over) + if (nodeConnectorProps.containsKey(nodeConnector)) { + log.debug("Redundant nodeconnector ADDED for {}, props {} for container {}", + nodeConnector, props, containerName); + update = false; + } + if (props != null) { for (Property prop : props) { addNodeConnectorProp(nodeConnector, prop); @@ -1158,6 +1178,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa addNodeConnectorProp(nodeConnector, null); } + addSpanPort(nodeConnector); break; case CHANGED: @@ -2026,9 +2047,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa // only add if span is configured on this nodeConnector for (SpanConfig conf : getSpanConfigList(nodeConnector.getNode())) { if (conf.getPortArrayList().contains(nodeConnector)) { - List ncLists = new ArrayList(); - ncLists.add(nodeConnector); - addSpanPorts(nodeConnector.getNode(), ncLists); + List ncList = new ArrayList(); + ncList.add(nodeConnector); + addSpanPorts(nodeConnector.getNode(), ncList); return; } } -- 2.36.6