Compress removals into a single transaction 78/5278/2
authorRobert Varga <rovarga@cisco.com>
Wed, 12 Feb 2014 02:34:26 +0000 (03:34 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 13 Feb 2014 05:14:23 +0000 (05:14 +0000)
When node removal occurs, do not cascade into multiple transactions, but
trigger only a single one.

Change-Id: Ic9994e6a801953efdf83a707be3b821f9a93b35b
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateHandler.java

index 941a8f8..acf182a 100644 (file)
@@ -36,39 +36,33 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Following are two main responsibilities of the class
- * 1) Listen for the create changes in config data store for tree nodes (Flow,Group,Meter,Queue) 
+ * 1) Listen for the create changes in config data store for tree nodes (Flow,Group,Meter,Queue)
  * and send statistics request to the switch to fetch the statistics
- * 
+ *
  * 2)Listen for the remove changes in config data store for tree nodes (Flow,Group,Meter,Queue)
  * and remove the relative statistics data from operational data store.
- * 
+ *
  * @author avishnoi@in.ibm.com
  *
  */
 public class StatisticsUpdateHandler implements DataChangeListener {
 
-    public final static Logger suhLogger = LoggerFactory.getLogger(StatisticsUpdateHandler.class);
-
+    private static final Logger suhLogger = LoggerFactory.getLogger(StatisticsUpdateHandler.class);
     private final StatisticsProvider statisticsManager;
-    
-    public StatisticsUpdateHandler(final StatisticsProvider manager){
 
+    public StatisticsUpdateHandler(final StatisticsProvider manager){
         this.statisticsManager = manager;
     }
-    
-    public StatisticsProvider getStatisticsManager(){
-        return statisticsManager;
-    }
 
     @SuppressWarnings("unchecked")
     @Override
     public void onDataChanged(DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
-        
+
         Map<InstanceIdentifier<?>, DataObject> nodeAdditions = change.getCreatedOperationalData();
         for (InstanceIdentifier<? extends DataObject> dataObjectInstance : nodeAdditions.keySet()) {
             DataObject dataObject = nodeAdditions.get(dataObjectInstance);
             if(dataObject instanceof Node){
-                
+
                 Node node = (Node) dataObject;
                 if(node.getAugmentation(FlowCapableNode.class) != null){
                     this.statisticsManager.sendStatisticsRequestsToNode(node);
@@ -114,56 +108,50 @@ public class StatisticsUpdateHandler implements DataChangeListener {
                 }
             }
         }
-            
+
+        DataModificationTransaction it = this.statisticsManager.startChange();
         Set<InstanceIdentifier<? extends DataObject>> removals = change.getRemovedConfigurationData();
         for (InstanceIdentifier<? extends DataObject> dataObjectInstance : removals) {
             DataObject dataObject = change.getOriginalConfigurationData().get(dataObjectInstance);
-            
+
             if(dataObject instanceof Flow){
                 InstanceIdentifier<Flow> flowII = (InstanceIdentifier<Flow>)dataObjectInstance;
-                InstanceIdentifier<?> flowAugmentation = 
+                InstanceIdentifier<?> flowAugmentation =
                         InstanceIdentifier.builder(flowII).augmentation(FlowStatisticsData.class).toInstance();
-                removeAugmentedOperationalData(flowAugmentation);
+                it.removeOperationalData(flowAugmentation);
             }
             if(dataObject instanceof Meter){
                 InstanceIdentifier<Meter> meterII = (InstanceIdentifier<Meter>)dataObjectInstance;
-                
-                InstanceIdentifier<?> nodeMeterConfigStatsAugmentation = 
+
+                InstanceIdentifier<?> nodeMeterConfigStatsAugmentation =
                         InstanceIdentifier.builder(meterII).augmentation(NodeMeterConfigStats.class).toInstance();
-                removeAugmentedOperationalData(nodeMeterConfigStatsAugmentation);
+                it.removeOperationalData(nodeMeterConfigStatsAugmentation);
 
-                InstanceIdentifier<?> nodeMeterStatisticsAugmentation = 
+                InstanceIdentifier<?> nodeMeterStatisticsAugmentation =
                         InstanceIdentifier.builder(meterII).augmentation(NodeMeterStatistics.class).toInstance();
-                removeAugmentedOperationalData(nodeMeterStatisticsAugmentation);
+                it.removeOperationalData(nodeMeterStatisticsAugmentation);
             }
-            
+
             if(dataObject instanceof Group){
                 InstanceIdentifier<Group> groupII = (InstanceIdentifier<Group>)dataObjectInstance;
-                
-                InstanceIdentifier<?> nodeGroupDescStatsAugmentation = 
+
+                InstanceIdentifier<?> nodeGroupDescStatsAugmentation =
                         InstanceIdentifier.builder(groupII).augmentation(NodeGroupDescStats.class).toInstance();
-                removeAugmentedOperationalData(nodeGroupDescStatsAugmentation);
+                it.removeOperationalData(nodeGroupDescStatsAugmentation);
 
-                InstanceIdentifier<?> nodeGroupStatisticsAugmentation = 
+                InstanceIdentifier<?> nodeGroupStatisticsAugmentation =
                         InstanceIdentifier.builder(groupII).augmentation(NodeGroupStatistics.class).toInstance();
-                removeAugmentedOperationalData(nodeGroupStatisticsAugmentation);
+                it.removeOperationalData(nodeGroupStatisticsAugmentation);
             }
-            
+
             if(dataObject instanceof Queue){
                 InstanceIdentifier<Queue> queueII = (InstanceIdentifier<Queue>)dataObjectInstance;
-                
-                InstanceIdentifier<?> nodeConnectorQueueStatisticsDataAugmentation = 
+
+                InstanceIdentifier<?> nodeConnectorQueueStatisticsDataAugmentation =
                         InstanceIdentifier.builder(queueII).augmentation(FlowCapableNodeConnectorQueueStatisticsData.class).toInstance();
-                removeAugmentedOperationalData(nodeConnectorQueueStatisticsDataAugmentation);
+                it.removeOperationalData(nodeConnectorQueueStatisticsDataAugmentation);
             }
         }
-    }
-    
-    private void removeAugmentedOperationalData(InstanceIdentifier<? extends DataObject> dataObjectInstance ){
-        if(dataObjectInstance != null){
-            DataModificationTransaction it = this.statisticsManager.startChange();
-            it.removeOperationalData(dataObjectInstance);
-            it.commit();
-        }
+        it.commit();
     }
 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.