Add transaction level traces 58/72658/2
authorStephen Kitt <skitt@redhat.com>
Mon, 4 Jun 2018 13:31:15 +0000 (15:31 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 29 Jun 2018 12:09:23 +0000 (12:09 +0000)
This adds traces giving information on the locations from which
transactions are created and committed. It also traces the transaction
identifier, with the intent of making it possible to match up
transaction traces with error messages.

Change-Id: Id82a79e8e430665f6fb5433ed7bab858044eacbe
Signed-off-by: Stephen Kitt <skitt@redhat.com>
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/java/org/opendaylight/controller/md/sal/trace/dom/impl/AbstractTracingWriteTransaction.java

index 3d98b79..553cbfb 100644 (file)
@@ -13,6 +13,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
+import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.mdsal.common.api.CommitInfo;
@@ -28,6 +29,7 @@ abstract class AbstractTracingWriteTransaction implements DOMDataWriteTransactio
     AbstractTracingWriteTransaction(DOMDataWriteTransaction delegate, TracingBroker tracingBroker) {
         this.delegate = Objects.requireNonNull(delegate);
         this.tracingBroker = Objects.requireNonNull(tracingBroker);
+        recordOp(null, null, "instantiate", null);
     }
 
     private void recordOp(LogicalDatastoreType store, YangInstanceIdentifier yiid, String method,
@@ -44,14 +46,22 @@ abstract class AbstractTracingWriteTransaction implements DOMDataWriteTransactio
             }
         } else {
             StringBuilder sb = new StringBuilder();
-            sb.append("Method \"").append(method);
-            sb.append("\" to ").append(store);
-            sb.append(" at ").append(tracingBroker.toPathString(yiid)).append('.');
-            sb.append(" Data: ");
-            if (node != null) {
-                sb.append(node.getValue());
-            } else {
-                sb.append("null");
+            sb.append("Method \"").append(method).append('"');
+            if (store != null) {
+                sb.append(" to ").append(store);
+            }
+            if (yiid != null) {
+                sb.append(" at ").append(tracingBroker.toPathString(yiid));
+            }
+            sb.append('.');
+            if (yiid != null) {
+                // If we don’t have an id, we don’t expect data either
+                sb.append(" Data: ");
+                if (node != null) {
+                    sb.append(node.getValue());
+                } else {
+                    sb.append("null");
+                }
             }
             sb.append(" Stack:").append(tracingBroker.getStackSummary());
             synchronized (this) {
@@ -62,7 +72,10 @@ abstract class AbstractTracingWriteTransaction implements DOMDataWriteTransactio
 
     private synchronized void logOps() {
         synchronized (this) {
-            logs.forEach(log -> TracingBroker.LOG.warn(log));
+            if (TracingBroker.LOG.isWarnEnabled()) {
+                TracingBroker.LOG.warn("Transaction {} contains the following operations:", getIdentifier());
+                logs.forEach(TracingBroker.LOG::warn);
+            }
             logs.clear();
         }
     }
@@ -84,8 +97,7 @@ abstract class AbstractTracingWriteTransaction implements DOMDataWriteTransactio
         synchronized (this) {
             logs.clear();
         }
-        boolean result = delegate.cancel();
-        return result;
+        return delegate.cancel();
     }
 
     @Override
@@ -96,11 +108,13 @@ abstract class AbstractTracingWriteTransaction implements DOMDataWriteTransactio
 
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
+        recordOp(null, null, "commit", null);
         logOps();
         return delegate.commit();
     }
 
     @Override
+    @Nonnull
     public Object getIdentifier() {
         return delegate.getIdentifier();
     }

©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.