directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1378940 - /directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/OrCursor.java
Date Thu, 30 Aug 2012 13:44:15 GMT
Author: elecharny
Date: Thu Aug 30 13:44:15 2012
New Revision: 1378940

URL: http://svn.apache.org/viewvc?rev=1378940&view=rev
Log:
Added a prefetched candidate to avoid duplicate backend lookup. This speedup the tests by
a factor two when dealing with a complex filter using OR

Modified:
    directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/OrCursor.java

Modified: directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/OrCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/OrCursor.java?rev=1378940&r1=1378939&r2=1378940&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/OrCursor.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/OrCursor.java
Thu Aug 30 13:44:15 2012
@@ -52,6 +52,9 @@ public class OrCursor<V> extends Abstrac
     private final List<Set<String>> blacklists;
     private int cursorIndex = -1;
 
+    /** The candidate we have fetched in the next/previous call */
+    private IndexEntry<V, String> prefetched;
+
 
     // TODO - do same evaluator fail fast optimization that we do in AndCursor
     public OrCursor( List<Cursor<IndexEntry<V, String>>> cursors,
@@ -92,6 +95,7 @@ public class OrCursor<V> extends Abstrac
         cursorIndex = 0;
         cursors.get( cursorIndex ).beforeFirst();
         setAvailable( false );
+        prefetched = null;
     }
 
 
@@ -101,6 +105,7 @@ public class OrCursor<V> extends Abstrac
         cursorIndex = cursors.size() - 1;
         cursors.get( cursorIndex ).afterLast();
         setAvailable( false );
+        prefetched = null;
     }
 
 
@@ -155,12 +160,13 @@ public class OrCursor<V> extends Abstrac
         while ( cursors.get( cursorIndex ).previous() )
         {
             checkNotClosed( "previous()" );
-            IndexEntry<?, String> candidate = cursors.get( cursorIndex ).get();
+            IndexEntry<V, String> candidate = cursors.get( cursorIndex ).get();
 
             if ( !isBlackListed( candidate.getId() ) )
             {
                 blackListIfDuplicate( candidate );
 
+                prefetched = candidate;
                 return setAvailable( true );
             }
         }
@@ -174,17 +180,20 @@ public class OrCursor<V> extends Abstrac
             while ( cursors.get( cursorIndex ).previous() )
             {
                 checkNotClosed( "previous()" );
-                IndexEntry<?, String> candidate = cursors.get( cursorIndex ).get();
+                IndexEntry<V, String> candidate = cursors.get( cursorIndex ).get();
 
                 if ( !isBlackListed( candidate.getId() ) )
                 {
                     blackListIfDuplicate( candidate );
 
+                    prefetched = candidate;
                     return setAvailable( true );
                 }
             }
         }
 
+        prefetched = null;
+
         return setAvailable( false );
     }
 
@@ -194,12 +203,14 @@ public class OrCursor<V> extends Abstrac
         while ( cursors.get( cursorIndex ).next() )
         {
             checkNotClosed( "next()" );
-            IndexEntry<?, String> candidate = cursors.get( cursorIndex ).get();
+            IndexEntry<V, String> candidate = cursors.get( cursorIndex ).get();
 
             if ( !isBlackListed( candidate.getId() ) )
             {
                 blackListIfDuplicate( candidate );
 
+                prefetched = candidate;
+
                 return setAvailable( true );
             }
         }
@@ -213,16 +224,21 @@ public class OrCursor<V> extends Abstrac
             while ( cursors.get( cursorIndex ).next() )
             {
                 checkNotClosed( "previous()" );
-                IndexEntry<?, String> candidate = cursors.get( cursorIndex ).get();
+                IndexEntry<V, String> candidate = cursors.get( cursorIndex ).get();
+
                 if ( !isBlackListed( candidate.getId() ) )
                 {
                     blackListIfDuplicate( candidate );
 
+                    prefetched = candidate;
+
                     return setAvailable( true );
                 }
             }
         }
 
+        prefetched = null;
+
         return setAvailable( false );
     }
 
@@ -233,7 +249,7 @@ public class OrCursor<V> extends Abstrac
 
         if ( available() )
         {
-            return cursors.get( cursorIndex ).get();
+            return prefetched;
         }
 
         throw new InvalidCursorPositionException( I18n.err( I18n.ERR_708 ) );



Mime
View raw message