db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1075248 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/BTreeMaxScan.java
Date Mon, 28 Feb 2011 09:14:06 GMT
Author: kahatlen
Date: Mon Feb 28 09:14:05 2011
New Revision: 1075248

URL: http://svn.apache.org/viewvc?rev=1075248&view=rev
Log:
DERBY-642: SELECT MAX doesn't use indices optimally

In the case of a WaitError, wait until the latch on the left sibling
has been released before repositioning. If the repositioning happens
earlier, it will just hit the same WaitError and the work will be
wasted.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/BTreeMaxScan.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/BTreeMaxScan.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/BTreeMaxScan.java?rev=1075248&r1=1075247&r2=1075248&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/BTreeMaxScan.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/BTreeMaxScan.java
Mon Feb 28 09:14:05 2011
@@ -100,8 +100,11 @@ public class BTreeMaxScan extends BTreeS
             return true;
         } catch (WaitError we) {
             // We couldn't get the latch without waiting. Let's save the
-            // position and let the caller retry.
-            //
+            // position and let the caller retry. But first, let's save the
+            // page number of the left sibling so that we can try again to
+            // get the latch after we've saved the position.
+            long left = scan_position.current_leaf.getleftSiblingPageNumber();
+
             // If the page is empty, there is no position to save. Since
             // positionAtPreviousPage() skips empty pages mid-scan, we know
             // that an empty page seen here must be the rightmost leaf. In
@@ -117,6 +120,20 @@ public class BTreeMaxScan extends BTreeS
                 savePositionAndReleasePage();
             }
 
+            // There's no point in attempting to reposition too early, as we're
+            // likely to hit the same WaitError again (and again). So instead
+            // let's sleep here until the left sibling page has been released,
+            // and then return to let the caller reposition and retry.
+            Page leftPage = container.getPage(left);
+            if (leftPage != null) {
+                // Got the latch. Anything may have happened while we didn't
+                // hold any latches, so we don't know if we're still supposed
+                // to go to that page. Just release the latch and let the
+                // caller reposition to the right spot in the B-tree.
+                leftPage.unlatch();
+                leftPage = null;
+            }
+
             return false;
         }
     }



Mime
View raw message