bug 7599 improve perf of ucast mcas 27/51427/5
authorK.V Suneelu Verma <k.v.suneelu.verma@ericsson.com>
Sun, 5 Feb 2017 09:05:08 +0000 (14:35 +0530)
committerK.V Suneelu Verma <k.v.suneelu.verma@ericsson.com>
Wed, 15 Mar 2017 05:17:08 +0000 (10:47 +0530)
for ucast macs update do not read operational state again
get the relevant data from local device info.
This avoids reading the whole node possibly from the other cluster node
for processing a single ucast mac update.

Change-Id: I14eb4419a208a7d38cb665d1ac94b0c41c18bcfe
Signed-off-by: K.V Suneelu Verma <k.v.suneelu.verma@ericsson.com>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDeviceInfo.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/HwvtepOperationalState.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/TransactCommandAggregator.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/UcastMacsRemoteRemoveCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/UcastMacsRemoteUpdateCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepMacEntriesRemoveCommand.java

index 0c8fec7f99069037afe8c7469390b1d109431b40..3a0cc5ae8dd7d4db15d563195589c465ad916754 100644 (file)
@@ -189,8 +189,15 @@ public class HwvtepDeviceInfo {
 
     public void markKeyAsInTransit(Class<? extends Identifiable> cls, InstanceIdentifier key) {
         LOG.debug("Marking device data as intransit {}", key);
+        DeviceData deviceData = getDeviceOpData(cls, key);
+        UUID uuid = null;
+        Object data = null;
+        if (deviceData != null) {
+            uuid = deviceData.getUuid();
+            data = deviceData.getData();
+        }
         HwvtepSouthboundUtil.updateData(opKeyVsData, cls, key,
-                new DeviceData(key, null, null, DeviceDataStatus.IN_TRANSIT));
+                new DeviceData(key, uuid, data, DeviceDataStatus.IN_TRANSIT));
     }
 
     public void updateDeviceOpData(Class<? extends Identifiable> cls, InstanceIdentifier key, UUID uuid, Object data) {
index fbaae846b9189739e514bf15835dd31ec6a3d1a8..a74fdd52274f4bd34d60bdc18242d65b945661a5 100644 (file)
@@ -77,13 +77,42 @@ public class HwvtepOperationalState {
             Pair<Map<Class<? extends Identifiable>, List<Identifiable>>,
                     Map<Class<? extends Identifiable>, List<Identifiable>>>> modifiedData = new HashMap<>();
     private boolean inReconciliation = false;
+    private final DataBroker db;
+    private final Collection<DataTreeModification<Node>> changes;
 
     public HwvtepOperationalState(DataBroker db, HwvtepConnectionInstance connectionInstance,
                                   Collection<DataTreeModification<Node>> changes) {
         this.connectionInstance = connectionInstance;
         this.deviceInfo = connectionInstance.getDeviceInfo();
+        this.db = db;
+        this.changes = changes;
+        this.transaction = db.newReadWriteTransaction();
+    }
+
+    public HwvtepOperationalState(HwvtepConnectionInstance connectionInstance) {
+        this.connectionInstance = connectionInstance;
+        this.deviceInfo = connectionInstance.getDeviceInfo();
+        this.db = connectionInstance.getDataBroker();
+        this.changes = null;
+        transaction = connectionInstance.getDataBroker().newReadWriteTransaction();
+        Optional<Node> readNode = HwvtepSouthboundUtil.readNode(transaction,
+                connectionInstance.getInstanceIdentifier());
+        if (readNode.isPresent()) {
+            operationalNodes.put(connectionInstance.getInstanceIdentifier(), readNode.get());
+        }
+    }
+
+    public void readOperationalNodes() {
+        if (inReconciliation) {
+            return;
+        }
+        if (changes == null) {
+            LOG.warn("Could not read operational nodes for {} as changes is",
+                    connectionInstance.getNodeId().getValue());
+            return;
+        }
         Map<InstanceIdentifier<Node>, Node> nodeCreateOrUpdate =
-            TransactUtils.extractCreatedOrUpdatedOrRemoved(changes, Node.class);
+                TransactUtils.extractCreatedOrUpdatedOrRemoved(changes, Node.class);
         if (nodeCreateOrUpdate != null) {
             transaction = db.newReadWriteTransaction();
             for (Entry<InstanceIdentifier<Node>, Node> entry: nodeCreateOrUpdate.entrySet()) {
@@ -118,16 +147,6 @@ public class HwvtepOperationalState {
         }
     }
 
-    public HwvtepOperationalState(HwvtepConnectionInstance connectionInstance) {
-        this.connectionInstance = connectionInstance;
-        this.deviceInfo = connectionInstance.getDeviceInfo();
-        transaction = connectionInstance.getDataBroker().newReadWriteTransaction();
-        Optional<Node> readNode = HwvtepSouthboundUtil.readNode(transaction, connectionInstance.getInstanceIdentifier());
-        if (readNode.isPresent()) {
-            operationalNodes.put(connectionInstance.getInstanceIdentifier(), readNode.get());
-        }
-    }
-
     public Optional<Node> getGlobalNode(InstanceIdentifier<?> iid) {
         InstanceIdentifier<Node> nodeIid = iid.firstIdentifierOf(Node.class);
         return Optional.fromNullable(operationalNodes.get(nodeIid));
index 0e07f3dac2b0cd261939263abdd48230a3381e93..6c5cf06194f326b34f387f804388a218a2f6fc66 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.Identifiable;
@@ -85,6 +86,7 @@ public class TransactCommandAggregator implements TransactCommand {
     }
 
     private void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
+        boolean readOperationalNodes = false;
         for (DataTreeModification<Node> change : changes) {
             final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
             final DataObjectModification<Node> mod = change.getRootNode();
@@ -93,9 +95,21 @@ public class TransactCommandAggregator implements TransactCommand {
             extractDataChanged(key, mod, updatedData, deletedData);
             modifiedData.put(key, Pair.of(updatedData, deletedData));
             operationalState.setModifiedData(modifiedData);
+            if (!isMacOnlyUpdate(updatedData, deletedData)) {
+                readOperationalNodes = true;
+            }
+        }
+        if (readOperationalNodes) {
+            operationalState.readOperationalNodes();
         }
     }
 
+    private boolean isMacOnlyUpdate(final Map<Class<? extends Identifiable>, List<Identifiable>> updatedData,
+                                    final Map<Class<? extends Identifiable>, List<Identifiable>> deletedData) {
+        return (updatedData.containsKey(RemoteUcastMacs.class) && updatedData.size() == 1)
+                || (deletedData.containsKey(RemoteUcastMacs.class) && deletedData.size() == 1);
+    }
+
     private void extractDataChanged(final InstanceIdentifier<Node> key,
                                     final DataObjectModification<Node> mod,
                                     final Map<Class<? extends Identifiable>, List<Identifiable>> updatedData,
index 3883fed200f48d2fd6b158ccf182e15c92bc7008..7a5f07dfe6f36089ddd3efdbcc840a57e6aee148 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016 China Telecom Beijing Research Institute and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 China Telecom Beijing Research Institute and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -16,6 +16,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
@@ -53,14 +54,16 @@ public class UcastMacsRemoteRemoveCommand extends AbstractTransactCommand<Remote
             InstanceIdentifier<Node> instanceIdentifier, List<RemoteUcastMacs> macList) {
         for (RemoteUcastMacs mac: macList) {
             LOG.debug("Removing remoteUcastMacs, mac address: {}", mac.getMacEntryKey().getValue());
-            Optional<RemoteUcastMacs> operationalMacOptional =
-                    getOperationalState().getRemoteUcastMacs(instanceIdentifier, mac.getKey());
+            InstanceIdentifier<RemoteUcastMacs> macIid = instanceIdentifier.augmentation(HwvtepGlobalAugmentation.class).
+                    child(RemoteUcastMacs.class, mac.getKey());
+            HwvtepDeviceInfo.DeviceData deviceData =
+                    getOperationalState().getDeviceInfo().getDeviceOpData(RemoteUcastMacs.class, macIid);
             UcastMacsRemote ucastMacsRemote = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
                     UcastMacsRemote.class, null);
-            if (operationalMacOptional.isPresent() && operationalMacOptional.get().getMacEntryUuid() != null) {
+            if (deviceData != null && deviceData.getUuid() != null) {
                 //when mac entry is deleted, its referenced locators are deleted automatically.
                 //locators in config DS is not deleted and need to be removed explicitly by user.
-                UUID macEntryUUID = new UUID(operationalMacOptional.get().getMacEntryUuid().getValue());
+                UUID macEntryUUID = deviceData.getUuid();
                 ucastMacsRemote.getUuidColumn().setData(macEntryUUID);
                 transaction.add(op.delete(ucastMacsRemote.getSchema()).
                         where(ucastMacsRemote.getUuidColumn().getSchema().opEqual(macEntryUUID)).build());
@@ -69,8 +72,6 @@ public class UcastMacsRemoteRemoveCommand extends AbstractTransactCommand<Remote
                 LOG.warn("Unable to delete remoteUcastMacs {} because it was not found in the operational store",
                         mac.getMacEntryKey().getValue());
             }
-            InstanceIdentifier<RemoteUcastMacs> macIid = instanceIdentifier.augmentation(HwvtepGlobalAugmentation.class).
-                    child(RemoteUcastMacs.class, mac.getKey());
             updateCurrentTxDeleteData(RemoteUcastMacs.class, macIid, mac);
         }
     }
index b4de21c848d9167433a09f1ac6799d062131b29a..b6b336fb745bd974153bc0c1936a767d657d7d4a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016 China Telecom Beijing Research Institute and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 China Telecom Beijing Research Institute and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -14,6 +14,7 @@ import com.google.common.collect.Lists;
 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
 
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
@@ -92,19 +93,20 @@ public class UcastMacsRemoteUpdateCommand extends AbstractTransactCommand<Remote
                                    InstanceIdentifier macKey,
                                    Object... extraData) {
             LOG.debug("Creating remoteUcastMacs, mac address: {}", remoteUcastMac.getMacEntryKey().getValue());
-            Optional<RemoteUcastMacs> operationalMacOptional =
-                    getOperationalState().getRemoteUcastMacs(instanceIdentifier, remoteUcastMac.getKey());
+            HwvtepDeviceInfo.DeviceData deviceData =
+                    getOperationalState().getDeviceInfo().getDeviceOpData(RemoteUcastMacs.class, macKey);
+
             UcastMacsRemote ucastMacsRemote = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), UcastMacsRemote.class);
             setIpAddress(ucastMacsRemote, remoteUcastMac);
             setLocator(transaction, ucastMacsRemote, remoteUcastMac);
             setLogicalSwitch(ucastMacsRemote, remoteUcastMac);
-            if (!operationalMacOptional.isPresent()) {
-                setMac(ucastMacsRemote, remoteUcastMac, operationalMacOptional);
+            if (deviceData == null) {
+                setMac(ucastMacsRemote, remoteUcastMac);
                 LOG.trace("doDeviceTransaction: creating RemotUcastMac entry: {}", ucastMacsRemote);
                 transaction.add(op.insert(ucastMacsRemote));
                 transaction.add(op.comment("UcastMacRemote: Creating " + remoteUcastMac.getMacEntryKey().getValue()));
-            } else if (operationalMacOptional.get().getMacEntryUuid() != null) {
-                UUID macEntryUUID = new UUID(operationalMacOptional.get().getMacEntryUuid().getValue());
+            } else if (deviceData.getUuid() != null) {
+                UUID macEntryUUID = deviceData.getUuid();
                 UcastMacsRemote extraMac = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
                                 UcastMacsRemote.class, null);
                 extraMac.getUuidColumn().setData(macEntryUUID);
@@ -122,13 +124,12 @@ public class UcastMacsRemoteUpdateCommand extends AbstractTransactCommand<Remote
     private void setLogicalSwitch(UcastMacsRemote ucastMacsRemote, RemoteUcastMacs inputMac) {
         if (inputMac.getLogicalSwitchRef() != null) {
             @SuppressWarnings("unchecked")
-            InstanceIdentifier<LogicalSwitches> lswitchIid = (InstanceIdentifier<LogicalSwitches>) inputMac.getLogicalSwitchRef().getValue();
-            Optional<LogicalSwitches> operationalSwitchOptional =
-                    getOperationalState().getLogicalSwitches(lswitchIid);
-            if (operationalSwitchOptional.isPresent()) {
-                Uuid logicalSwitchUuid = operationalSwitchOptional.get().getLogicalSwitchUuid();
-                UUID logicalSwitchUUID = new UUID(logicalSwitchUuid.getValue());
-                ucastMacsRemote.setLogicalSwitch(logicalSwitchUUID);
+            InstanceIdentifier<LogicalSwitches> lswitchIid =
+                    (InstanceIdentifier<LogicalSwitches>) inputMac.getLogicalSwitchRef().getValue();
+            HwvtepDeviceInfo.DeviceData deviceData = getOperationalState().getDeviceInfo().getDeviceOpData(
+                    LogicalSwitches.class, lswitchIid);
+            if (deviceData != null && deviceData.getUuid() != null) {
+                ucastMacsRemote.setLogicalSwitch(deviceData.getUuid());
             } else {
                 ucastMacsRemote.setLogicalSwitch(TransactUtils.getLogicalSwitchUUID(lswitchIid));
             }
@@ -142,12 +143,10 @@ public class UcastMacsRemoteUpdateCommand extends AbstractTransactCommand<Remote
             @SuppressWarnings("unchecked")
             InstanceIdentifier<TerminationPoint> iid = (InstanceIdentifier<TerminationPoint>) inputMac.getLocatorRef().getValue();
             //try to find locator in operational DS
-            Optional<HwvtepPhysicalLocatorAugmentation> operationalLocatorOptional =
-                    getOperationalState().getPhysicalLocatorAugmentation(iid);
-            if (operationalLocatorOptional.isPresent()) {
+            HwvtepDeviceInfo.DeviceData deviceData = getOperationalState().getDeviceInfo().getDeviceOpData(TerminationPoint.class, iid);
+            if (deviceData != null) {
                 //if exist, get uuid
-                HwvtepPhysicalLocatorAugmentation locatorAugmentation = operationalLocatorOptional.get();
-                locatorUuid = new UUID(locatorAugmentation.getPhysicalLocatorUuid().getValue());
+                locatorUuid = deviceData.getUuid();
             } else {
                 locatorUuid = getOperationalState().getUUIDFromCurrentTx(TerminationPoint.class, iid);
                 if (locatorUuid == null) {
@@ -168,12 +167,9 @@ public class UcastMacsRemoteUpdateCommand extends AbstractTransactCommand<Remote
         }
     }
 
-    private void setMac(UcastMacsRemote ucastMacsRemote, RemoteUcastMacs inputMac,
-            Optional<RemoteUcastMacs> inputSwitchOptional) {
+    private void setMac(UcastMacsRemote ucastMacsRemote, RemoteUcastMacs inputMac) {
         if (inputMac.getMacEntryKey() != null) {
             ucastMacsRemote.setMac(inputMac.getMacEntryKey().getValue());
-        } else if (inputSwitchOptional.isPresent() && inputSwitchOptional.get().getMacEntryKey() != null) {
-            ucastMacsRemote.setMac(inputSwitchOptional.get().getMacEntryKey().getValue());
         }
     }
 
index 3bee2c2dfd524c172447a58cc8b92782120b10d4..db392d5cf8b0f09284ac3b8bb0f4dbf0b49de063 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -84,7 +84,7 @@ public class HwvtepMacEntriesRemoveCommand extends AbstractTransactionCommand {
                                     new RemoteUcastMacsKey(getLogicalSwitchRef(rum.getLogicalSwitchColumn().getData()),
                                                     getMacAddress(rum.getMac())));
                 transaction.delete(LogicalDatastoreType.OPERATIONAL, rumId);
-                getOvsdbConnectionInstance().getDeviceInfo().clearDeviceOpData(RemoteMcastMacs.class, rumId);
+                getOvsdbConnectionInstance().getDeviceInfo().clearDeviceOpData(RemoteUcastMacs.class, rumId);
             } else {
                 LOG.debug("Failed to delete UcastMacRemote entry {}", rum.getUuid());
             }