Bug 7373 - ConflictingModificationAppliedException: Node was 99/49399/2
authorAnil Vishnoi <vishnoianil@gmail.com>
Thu, 15 Dec 2016 01:49:17 +0000 (17:49 -0800)
committerSam Hague <shague@redhat.com>
Thu, 15 Dec 2016 15:53:17 +0000 (10:53 -0500)
created by other transaction

Ovsdb/Hwvtep plugin creates respective topology under network-topology/topology
and also they make a check if the parent node (network-topology) exist or not.
If not they create the root node. In a scenario where user loads both the
plugin together, their is a possibility that both the plugin can try to
create the network-topology as the same time and one of them will end up
with ConflictingModificationAppliedException. To resolve this scenario
this patch avoid the explcit create of the parent node, and uses the md-sal
PUT api that creates the missing parents. Although it's slow compared to
the other version of PUT api, but given that it's one time operation
at warm up time, it of not much concern.

Change-Id: I9171f17ceef43040d91e75e368ab4e6f59970c59
Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
Signed-off-by: Sam Hague <shague@redhat.com>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java

index d1a9d53b0f2f3c6aa619d704f234210bf82e485b..79f8a83f007a33988061195e9bb3ad6284c28134 100644 (file)
@@ -128,31 +128,13 @@ public class HwvtepSouthboundProvider implements AutoCloseable {
         InstanceIdentifier<Topology> path = InstanceIdentifier
                 .create(NetworkTopology.class)
                 .child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID));
-        initializeTopology(type);
         ReadWriteTransaction transaction = db.newReadWriteTransaction();
         CheckedFuture<Optional<Topology>, ReadFailedException> hwvtepTp = transaction.read(type, path);
         try {
             if (!hwvtepTp.get().isPresent()) {
                 TopologyBuilder tpb = new TopologyBuilder();
                 tpb.setTopologyId(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID);
-                transaction.put(type, path, tpb.build());
-                transaction.submit();
-            } else {
-                transaction.cancel();
-            }
-        } catch (Exception e) {
-            LOG.error("Error initializing hwvtep topology", e);
-        }
-    }
-
-    private void initializeTopology(LogicalDatastoreType type) {
-        ReadWriteTransaction transaction = db.newReadWriteTransaction();
-        InstanceIdentifier<NetworkTopology> path = InstanceIdentifier.create(NetworkTopology.class);
-        CheckedFuture<Optional<NetworkTopology>, ReadFailedException> topology = transaction.read(type,path);
-        try {
-            if (!topology.get().isPresent()) {
-                NetworkTopologyBuilder ntb = new NetworkTopologyBuilder();
-                transaction.put(type,path,ntb.build());
+                transaction.put(type, path, tpb.build(), true);
                 transaction.submit();
             } else {
                 transaction.cancel();
index 78eff8738b7c6025a4963d1bfcb6f80697119042..0756378e0d10967be466b1379bbc66cf44874f00 100644 (file)
@@ -28,7 +28,6 @@ import org.opendaylight.ovsdb.lib.OvsdbConnection;
 import org.opendaylight.ovsdb.southbound.transactions.md.TransactionInvoker;
 import org.opendaylight.ovsdb.southbound.transactions.md.TransactionInvokerImpl;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopologyBuilder;
 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.TopologyBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
@@ -115,31 +114,13 @@ public class SouthboundProvider implements AutoCloseable {
         InstanceIdentifier<Topology> path = InstanceIdentifier
                 .create(NetworkTopology.class)
                 .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID));
-        initializeTopology(type);
         ReadWriteTransaction transaction = db.newReadWriteTransaction();
         CheckedFuture<Optional<Topology>, ReadFailedException> ovsdbTp = transaction.read(type, path);
         try {
             if (!ovsdbTp.get().isPresent()) {
                 TopologyBuilder tpb = new TopologyBuilder();
                 tpb.setTopologyId(SouthboundConstants.OVSDB_TOPOLOGY_ID);
-                transaction.put(type, path, tpb.build());
-                transaction.submit();
-            } else {
-                transaction.cancel();
-            }
-        } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Error initializing ovsdb topology", e);
-        }
-    }
-
-    private void initializeTopology(LogicalDatastoreType type) {
-        ReadWriteTransaction transaction = db.newReadWriteTransaction();
-        InstanceIdentifier<NetworkTopology> path = InstanceIdentifier.create(NetworkTopology.class);
-        CheckedFuture<Optional<NetworkTopology>, ReadFailedException> topology = transaction.read(type,path);
-        try {
-            if (!topology.get().isPresent()) {
-                NetworkTopologyBuilder ntb = new NetworkTopologyBuilder();
-                transaction.put(type,path,ntb.build());
+                transaction.put(type, path, tpb.build(), true);
                 transaction.submit();
             } else {
                 transaction.cancel();