From 90c5a3b4e773bdefd115b7269a44fdee8420593e Mon Sep 17 00:00:00 2001 From: "K.V Suneelu Verma" Date: Tue, 7 Feb 2017 18:30:15 +0530 Subject: [PATCH] bug 7599 avoid mdsal read while processing the config update avoid mdsal read maintain the instance identifier vs connectionInstance map. Update the map upon GlobalUpdate. Clear the map upon node disconnect event. Use the map to identifiy the connectionInstance for the changed node. Change-Id: I8cbb505f0e56bdc0a3f5b46104a26aa02381ad6f Signed-off-by: K.V Suneelu Verma --- .../HwvtepConnectionInstance.java | 7 +++-- .../HwvtepConnectionManager.java | 30 +++++++++++++++++-- .../HwvtepDataChangeListener.java | 15 ++-------- .../HwvtepSouthboundUtil.java | 16 +++++++++- .../DataChangeListenerTestBase.java | 6 +++- 5 files changed, 56 insertions(+), 18 deletions(-) diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java index 1741042b7..c64d54803 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java @@ -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, @@ -69,9 +69,11 @@ public class HwvtepConnectionInstance { private HwvtepGlobalAugmentation initialCreatedData = null; private HwvtepDeviceInfo deviceInfo; private DataBroker dataBroker; + private final HwvtepConnectionManager hwvtepConnectionManager; - HwvtepConnectionInstance (ConnectionInfo key, OvsdbClient client, + HwvtepConnectionInstance (HwvtepConnectionManager hwvtepConnectionManager, ConnectionInfo key, OvsdbClient client, InstanceIdentifier iid, TransactionInvoker txInvoker, DataBroker dataBroker) { + this.hwvtepConnectionManager = hwvtepConnectionManager; this.connectionInfo = key; this.client = client; this.instanceIdentifier = iid; @@ -255,6 +257,7 @@ public class HwvtepConnectionInstance { public void setInstanceIdentifier(InstanceIdentifier iid) { this.instanceIdentifier = iid; + hwvtepConnectionManager.putConnectionInstance(instanceIdentifier, this); } public Entity getConnectedEntity() { diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java index 9ca92a88b..a371b8bc2 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 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, @@ -82,6 +82,8 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo private EntityOwnershipService entityOwnershipService; private HwvtepDeviceEntityOwnershipListener hwvtepDeviceEntityOwnershipListener; private final ReconciliationManager reconciliationManager; + private final Map, HwvtepConnectionInstance> nodeIidVsConnectionInstance = + new ConcurrentHashMap<>(); public HwvtepConnectionManager(DataBroker db, TransactionInvoker txInvoker, EntityOwnershipService entityOwnershipService) { @@ -151,6 +153,7 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo //Controller initiated connection can be terminated from switch side. //So cleanup the instance identifier cache. removeInstanceIdentifier(key); + removeConnectionInstance(hwvtepConnectionInstance.getInstanceIdentifier()); retryConnection(hwvtepConnectionInstance.getInstanceIdentifier(), hwvtepConnectionInstance.getHwvtepGlobalAugmentation(), ConnectionReconciliationTriggers.ON_DISCONNECT); @@ -213,7 +216,7 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo removeConnectionInstance(key); } - hwvtepConnectionInstance = new HwvtepConnectionInstance(key, externalClient, getInstanceIdentifier(key), + hwvtepConnectionInstance = new HwvtepConnectionInstance(this, key, externalClient, getInstanceIdentifier(key), txInvoker, db); hwvtepConnectionInstance.createTransactInvokers(); return hwvtepConnectionInstance; @@ -233,6 +236,18 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo return clients.get(connectionInfo); } + public HwvtepConnectionInstance getConnectionInstanceFromNodeIid(final InstanceIdentifier nodeIid) { + HwvtepConnectionInstance hwvtepConnectionInstance = nodeIidVsConnectionInstance.get(nodeIid); + if (hwvtepConnectionInstance != null) { + return hwvtepConnectionInstance; + } + InstanceIdentifier globalNodeIid = HwvtepSouthboundUtil.getGlobalNodeIid(nodeIid); + if (globalNodeIid != null) { + return nodeIidVsConnectionInstance.get(globalNodeIid); + } + return null; + } + public HwvtepConnectionInstance getConnectionInstance(Node node) { Preconditions.checkNotNull(node); HwvtepGlobalAugmentation hwvtepGlobal = node.getAugmentation(HwvtepGlobalAugmentation.class); @@ -543,6 +558,17 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo return entityConnectionMap.get(entity); } + void putConnectionInstance(final InstanceIdentifier nodeIid, + final HwvtepConnectionInstance connectionInstance) { + nodeIidVsConnectionInstance.put(nodeIid, connectionInstance); + } + + private void removeConnectionInstance(final InstanceIdentifier nodeIid) { + if (nodeIid != null) { + nodeIidVsConnectionInstance.remove(nodeIid); + } + } + private class HwvtepDeviceEntityOwnershipListener implements EntityOwnershipListener { private HwvtepConnectionManager hcm; private EntityOwnershipListenerRegistration listenerRegistration; diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDataChangeListener.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDataChangeListener.java index ec4e18ad4..af8fbb4fe 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDataChangeListener.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDataChangeListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 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, @@ -276,17 +276,8 @@ public class HwvtepDataChangeListener implements ClusteredDataTreeChangeListener final DataObjectModification mod = change.getRootNode(); //From original node to get connection instance Node node = mod.getDataBefore()!=null ? mod.getDataBefore() : mod.getDataAfter(); - HwvtepConnectionInstance connection = hcm.getConnectionInstance(node); - if(connection == null) { - //Let us try getting it from Operational DS - final ReadWriteTransaction transaction = db.newReadWriteTransaction(); - InstanceIdentifier connectionIid = HwvtepSouthboundMapper.createInstanceIdentifier(node.getNodeId()); - Optional optionalNode = HwvtepSouthboundUtil.readNode(transaction, connectionIid); - LOG.trace("Node in Operational DataStore for user node {} is {}", node, optionalNode); - if(optionalNode.isPresent()) { - connection = hcm.getConnectionInstance(optionalNode.get()); - } - } + HwvtepConnectionInstance connection = hcm.getConnectionInstanceFromNodeIid( + change.getRootPath().getRootIdentifier()); if (connection != null) { if (!result.containsKey(connection)) { List> tempChanges= new ArrayList>(); diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundUtil.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundUtil.java index 0a21cb73a..a5af62f14 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundUtil.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 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, @@ -24,7 +24,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs; 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.NodeId; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.Identifiable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -200,4 +203,15 @@ public class HwvtepSouthboundUtil { public static boolean isEmptyMap(Map map) { return map == null || map.isEmpty(); } + + public static InstanceIdentifier getGlobalNodeIid(final InstanceIdentifier physicalNodeIid) { + String nodeId = physicalNodeIid.firstKeyOf(Node.class).getNodeId().getValue(); + int physicalSwitchIndex = nodeId.indexOf(HwvtepSouthboundConstants.PSWITCH_URI_PREFIX); + if (physicalSwitchIndex > 0) { + nodeId = nodeId.substring(0, physicalSwitchIndex - 1); + } else { + return null; + } + return physicalNodeIid.firstIdentifierOf(Topology.class).child(Node.class , new NodeKey(new NodeId(nodeId))); + } } diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/DataChangeListenerTestBase.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/DataChangeListenerTestBase.java index 08875c74a..5da2e45f9 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/DataChangeListenerTestBase.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/DataChangeListenerTestBase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 2016, 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, @@ -148,10 +148,14 @@ public class DataChangeListenerTestBase extends AbstractDataBrokerTest { field(HwvtepConnectionManager.class, "txInvoker").set(hwvtepConnectionManager, transactionInvoker); field(HwvtepConnectionManager.class, "entityOwnershipService").set(hwvtepConnectionManager, entityOwnershipService); suppress(PowerMockito.method(HwvtepConnectionManager.class, "getConnectionInstance", HwvtepPhysicalSwitchAttributes.class)); + suppress(PowerMockito.method(HwvtepConnectionManager.class, "getConnectionInstanceFromNodeIid", + InstanceIdentifier.class)); when(hwvtepConnectionManager.getConnectionInstance(Mockito.any(HwvtepPhysicalSwitchAttributes.class))). thenReturn(connectionInstance); when(hwvtepConnectionManager.getConnectionInstance(Mockito.any(Node.class))). thenReturn(connectionInstance); + when(hwvtepConnectionManager.getConnectionInstanceFromNodeIid(Mockito.any(InstanceIdentifier.class))) + .thenReturn(connectionInstance); } void mockConnectionInstance() throws IllegalAccessException { -- 2.36.6