Minimize storeNode() locking 69/100669/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Apr 2022 12:19:24 +0000 (14:19 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Apr 2022 12:28:19 +0000 (14:28 +0200)
Locking only covers transaction interactions, callbacks should be
invoked without the lock being held.

JIRA: BGPCEP-1005
Change-Id: I21ca6ae62ba1936e8c8109fc6e09d733cc054ad0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyNodeState.java

index 97a99071331fed6240b225f6670d991f5e4a8693..e1fd9765133e3677db9018ca51626abff85a05ad 100644 (file)
@@ -187,14 +187,18 @@ final class TopologyNodeState implements TransactionChainListener {
         }, MoreExecutors.directExecutor());
     }
 
-    synchronized void storeNode(final InstanceIdentifier<Node1> topologyAugment, final Node1 ta,
-            final PCEPSession session) {
+    void storeNode(final InstanceIdentifier<Node1> topologyAugment, final Node1 ta, final PCEPSession session) {
         LOG.trace("Peer data {} set to {}", topologyAugment, ta);
-        final WriteTransaction trans = chain.newWriteOnlyTransaction();
-        trans.put(LogicalDatastoreType.OPERATIONAL, topologyAugment, ta);
 
-        // All set, commit the modifications
-        trans.commit().addCallback(new FutureCallback<CommitInfo>() {
+        final FluentFuture<? extends CommitInfo> future;
+        synchronized (this) {
+            final WriteTransaction trans = chain.newWriteOnlyTransaction();
+            trans.put(LogicalDatastoreType.OPERATIONAL, topologyAugment, ta);
+            // All set, commit the modifications
+            future = trans.commit();
+        }
+
+        future.addCallback(new FutureCallback<CommitInfo>() {
             @Override
             public void onSuccess(final CommitInfo result) {
                 LOG.trace("Node stored {} for session {} updated successfully", topologyAugment, session);