db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r745485 - in /db/derby/code/branches/10.4/java: engine/org/apache/derby/impl/store/access/btree/BTreeController.java testing/org/apache/derbyTesting/functionTests/tests/lang/NullableUniqueConstraintTest.java
Date Wed, 18 Feb 2009 12:03:38 GMT
Author: kahatlen
Date: Wed Feb 18 12:03:38 2009
New Revision: 745485

URL: http://svn.apache.org/viewvc?rev=745485&view=rev
Log:
DERBY-4027: An attempt was made to access an out of range slot on a page

Merged fix from trunk (revision 744984).

Modified:
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/access/btree/BTreeController.java
    db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullableUniqueConstraintTest.java

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/access/btree/BTreeController.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/access/btree/BTreeController.java?rev=745485&r1=745484&r2=745485&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/access/btree/BTreeController.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/access/btree/BTreeController.java
Wed Feb 18 12:03:38 2009
@@ -392,6 +392,11 @@
                     if (newLeaf)
                         oldLeaf.release();
                     newLeaf = true;
+                    // DERBY-4027: We have moved to the previous page and need
+                    // to recheck that the slot number is valid (it won't be
+                    // if the page we moved to is empty). Restart from the top
+                    // of the loop body to get the slot number rechecked.
+                    continue;
                 } catch (WaitError we) {
                     throw StandardException.plainWrapException(we);
                 }
@@ -450,6 +455,11 @@
                     return NO_MATCH;
                 //point slot to the first record of new leaf
                 slot = 1;
+                // DERBY-4027: We have moved to the next page and need
+                // to recheck that the slot number is valid (it won't be
+                // if the page we moved to is empty). Restart from the top
+                // of the loop body to get the slot number rechecked.
+                continue;
             }
             rh = leaf.page.fetchFromSlot(null, slot, rows, null, true);
             if (rh != null) {

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullableUniqueConstraintTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullableUniqueConstraintTest.java?rev=745485&r1=745484&r2=745485&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullableUniqueConstraintTest.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullableUniqueConstraintTest.java
Wed Feb 18 12:03:38 2009
@@ -456,6 +456,33 @@
                 stmt.executeUpdate("update constraintest set " +
                 "val1 = val2, val2 = val1"));
     }
+
+    /**
+     * Test that repeatedly performing multi-row inserts and deletes spanning
+     * multiple pages works correctly with nullable unique constraint. This
+     * used to cause <tt>ERROR XSDA1: An attempt was made to access an out of
+     * range slot on a page</tt> (DERBY-4027).
+     */
+    public void testMixedInsertDelete() throws SQLException {
+        createStatement().execute(
+                "alter table constraintest add constraint uc unique (val1)");
+        PreparedStatement insert = prepareStatement(
+                "insert into constraintest(val1) values ?");
+        PreparedStatement delete = prepareStatement(
+                "delete from constraintest");
+        // The error happened most frequently in the second iteration, but
+        // it didn't always, so we repeat it ten times to increase the
+        // likelihood of triggering the bug.
+        for (int i = 0; i < 10; i++) {
+            for (int j = 0; j < 1000; j++) {
+                insert.setInt(1, j);
+                insert.addBatch();
+            }
+            insert.executeBatch();
+            assertEquals(1000, delete.executeUpdate());
+        }
+    }
+
     public static void main(String [] args) {
         TestResult tr = new TestResult();
         Test t = suite();



Mime
View raw message