Add cursor lookup fast-path 72/46372/2
authorRobert Varga <rovarga@cisco.com>
Tue, 20 Sep 2016 15:39:19 +0000 (17:39 +0200)
committerRobert Varga <nite@hq.sk>
Mon, 3 Oct 2016 13:49:39 +0000 (13:49 +0000)
Users will typically select one of the subtrees to create
cursor on, hence add a fast path which will perform a simple
lookup.

Change-Id: Ied0710a765edf8cdd4ebd7f2712f310f82f35b1a
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit 2ff021b039e02cfc74661383a2a204992b4ef200)

dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTreeWriteTransaction.java
dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InmemoryDOMDataTreeShardWriteTransaction.java

index 53feef2dc4aa6a87c69734eaba1ce011aca8acf4..90060597f94fb62906adecefd6942f34f8f1fa77 100644 (file)
@@ -68,10 +68,14 @@ final class ShardedDOMDataTreeWriteTransaction implements DOMDataTreeCursorAware
     }
 
     private DOMDataTreeShardWriteTransaction lookup(final DOMDataTreeIdentifier prefix) {
+        final DOMDataTreeShardWriteTransaction fast = transactions.get(prefix);
+        if (fast != null) {
+            return fast;
+        }
+
+        LOG.debug("Prefix {} not found in available subtrees {}, fallback to slow path", prefix, transactions.keySet());
         for (final Entry<DOMDataTreeIdentifier, DOMDataTreeShardWriteTransaction> e : transactions.entrySet()) {
             if (e.getKey().contains(prefix)) {
-                Preconditions.checkArgument(!producer.isDelegatedToChild(prefix),
-                    "Path %s is delegated to child producer.", prefix);
                 return e.getValue();
             }
         }
@@ -107,6 +111,8 @@ final class ShardedDOMDataTreeWriteTransaction implements DOMDataTreeCursorAware
     public synchronized DOMDataTreeWriteCursor createCursor(final DOMDataTreeIdentifier prefix) {
         Preconditions.checkState(!closed, "Transaction is closed already");
         Preconditions.checkState(openCursor == null, "There is still a cursor open");
+        Preconditions.checkArgument(!producer.isDelegatedToChild(prefix), "Path %s is delegated to child producer.",
+            prefix);
 
         final DOMDataTreeShardWriteTransaction lookup = lookup(prefix);
         Preconditions.checkArgument(lookup != null, "Path %s is not accessible from transaction %s", prefix, this);
index e0dbe985a76902c81745ee0eae92fba7a5f49109..a476069a58060de9848578dfdbdfb984c5c4c845 100644 (file)
@@ -232,8 +232,8 @@ class InmemoryDOMDataTreeShardWriteTransaction implements DOMDataTreeShardWriteT
     public DOMDataTreeWriteCursor createCursor(final DOMDataTreeIdentifier prefix) {
         Preconditions.checkState(!finished, "Transaction is finished/closed already.");
         Preconditions.checkState(cursor == null, "Previous cursor wasn't closed");
-        final DOMDataTreeWriteCursor ret = getCursor();
         final YangInstanceIdentifier relativePath = toRelative(prefix.getRootIdentifier());
+        final DOMDataTreeWriteCursor ret = getCursor();
         ret.enter(relativePath.getPathArguments());
         return ret;
     }