Add ClientBackedTransaction allocation recording
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / ClientBackedTransactionChain.java
index db30372676c43057749ae11d157901eaa77978d3..36d1b5d575a3c01353112465a2fc41c78d670434 100644 (file)
@@ -35,24 +35,26 @@ final class ClientBackedTransactionChain implements DOMStoreTransactionChain {
     private final Map<AbstractClientHandle<?>, Boolean> openSnapshots = new WeakHashMap<>();
 
     private final ClientLocalHistory history;
+    private final boolean debugAllocation;
 
-    ClientBackedTransactionChain(final ClientLocalHistory history) {
+    ClientBackedTransactionChain(final ClientLocalHistory history, final boolean debugAllocation) {
         this.history = Preconditions.checkNotNull(history);
+        this.debugAllocation = debugAllocation;
     }
 
     @Override
     public DOMStoreReadTransaction newReadOnlyTransaction() {
-        return new ClientBackedReadTransaction(createSnapshot(), this);
+        return new ClientBackedReadTransaction(createSnapshot(), this, allocationContext());
     }
 
     @Override
     public DOMStoreReadWriteTransaction newReadWriteTransaction() {
-        return new ClientBackedReadWriteTransaction(createTransaction());
+        return new ClientBackedReadWriteTransaction(createTransaction(), allocationContext());
     }
 
     @Override
     public DOMStoreWriteTransaction newWriteOnlyTransaction() {
-        return new ClientBackedWriteTransaction(createTransaction());
+        return new ClientBackedWriteTransaction(createTransaction(), allocationContext());
     }
 
     @Override
@@ -86,6 +88,10 @@ final class ClientBackedTransactionChain implements DOMStoreTransactionChain {
         }
     }
 
+    private Throwable allocationContext() {
+        return debugAllocation ? new Throwable("allocated at") : null;
+    }
+
     private synchronized <T extends AbstractClientHandle<?>> T recordSnapshot(final T snapshot) {
         openSnapshots.put(snapshot, Boolean.TRUE);
         return snapshot;