db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r806139 - in /db/derby/code/branches/10.4: ./ java/engine/org/apache/derby/impl/store/access/btree/BTreeController.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullableUniqueConstraintTest.java
Date Thu, 20 Aug 2009 12:17:04 GMT
Author: kahatlen
Date: Thu Aug 20 12:17:03 2009
New Revision: 806139

URL: http://svn.apache.org/viewvc?rev=806139&view=rev
Log:
DERBY-4081: BTreeController.comparePreviousRecord() may fail to release latch on left-most
leaf

Merged fix from trunk (revision 805696).

Modified:
    db/derby/code/branches/10.4/   (props changed)
    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

Propchange: db/derby/code/branches/10.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 20 12:17:03 2009
@@ -1 +1 @@
-/db/derby/code/trunk:788436
+/db/derby/code/trunk:788436,805696

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=806139&r1=806138&r2=806139&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
Thu Aug 20 12:17:03 2009
@@ -384,14 +384,15 @@
                     //slot is pointing before the first slot
                     //get left sibiling
                     leaf = (LeafControlRow) leaf.getLeftSibling(this);
+                    if (newLeaf) {
+                        oldLeaf.release();
+                    }
+                    newLeaf = true;
                     //no left sibiling
                     if (leaf == null)
                         return NO_MATCH;
                     //set the slot to last slot number
                     slot = leaf.page.recordCount() - 1;
-                    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

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=806139&r1=806138&r2=806139&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
Thu Aug 20 12:17:03 2009
@@ -531,6 +531,33 @@
                 "update constraintest set val1 = '2' where val1 = '3'");
     }
 
+    /**
+     * Test that we can insert and delete the same value multiple times in a
+     * nullable unique index. This used to cause a livelock before DERBY-4081
+     * because the duplicate check on insert sometimes didn't release all
+     * latches.
+     */
+    public void testInsertDeleteContinuouslySameValue() throws SQLException {
+        // Must disable auto-commit for reliable reproduction, otherwise the
+        // post-commit worker thread will remove deleted index rows.
+        setAutoCommit(false);
+
+        Statement s = createStatement();
+        s.execute("create table d4081(x int unique)");
+
+        // The loop below did not get past the 372nd iteration before
+        // DERBY-4081 was fixed. Try 500 iterations now.
+        PreparedStatement ins = prepareStatement("insert into d4081 values 0");
+        PreparedStatement del = prepareStatement("delete from d4081");
+        for (int i = 0; i < 500; i++) {
+            ins.execute();
+            del.execute();
+        }
+
+        // Verify that the table is empty after the last delete operation.
+        assertTableRowCount("D4081", 0);
+    }
+
     public static void main(String [] args) {
         TestResult tr = new TestResult();
         Test t = suite();



Mime
View raw message