db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1550135 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/store/access/ iapi/store/raw/ impl/sql/execute/ impl/store/access/ impl/store/access/btree/index/ impl/store/access/heap/
Date Wed, 11 Dec 2013 13:39:53 GMT
Author: dag
Date: Wed Dec 11 13:39:52 2013
New Revision: 1550135

URL: http://svn.apache.org/r1550135
Log:
DERBY-6419 Make BTree scan honor OPENMODE_LOCK_NOWAIT for row locks

Patch derby-6419-1 introduces a mode to avoid waiting for row locks in
BTeee scans.  Using the debugger I can see that the current wait in
ConstraintCharactericsTest#testLocking, line 417 as of svn 1545394 is
no longer waiting with the patch, and stepping through the code in
IndexChanger I can see that the second next() which currently waits
returns immediately with an exception as desired.

Instead of overloading the current flag OPENMODE_LOCK_NOWAIT, I
introduced a new flag OPENMODE_LOCK_ROW_NOWAIT instead. The short
circuiting logic was added in B2IRowLocking3#LockRowOnPage: I had to
added an accessor to HeapController to get at the open_mode of the
base table's conglomerate; not sure if that's kosher or not. An
alternative could be to keep to flag in the B2IForwardScan object.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/TransactionController.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/ContainerHandle.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking3.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/Heap.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapController.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/TransactionController.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/TransactionController.java?rev=1550135&r1=1550134&r2=1550135&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/TransactionController.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/TransactionController.java
Wed Dec 11 13:39:52 2013
@@ -244,6 +244,15 @@ public interface TransactionController
     static final int OPENMODE_LOCK_NOWAIT           = 0x00000080;
 
     /**
+     * The row lock request will not wait.
+     * <p>
+     * The request to get the row lock (any row lock including intent or
+     * "real" row level lock), will not wait if it can't be granted. A
+     * lock timeout will be returned.
+     **/
+    static final int OPENMODE_LOCK_ROW_NOWAIT       = 0x00008000;
+
+    /**
      * Constants used for the countOpen() call.
      **/
     public static final int OPEN_CONGLOMERATE   = 0x01;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/ContainerHandle.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/ContainerHandle.java?rev=1550135&r1=1550134&r2=1550135&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/ContainerHandle.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/ContainerHandle.java Wed
Dec 11 13:39:52 2013
@@ -144,6 +144,7 @@ public interface ContainerHandle 
 	public static final int MODE_USE_UPDATE_LOCKS	   = 0x00001000; // external access
     public static final int MODE_SECONDARY_LOCKED      = 0x00002000; // external access
     public static final int MODE_BASEROW_INSERT_LOCKED = 0x00004000; // external access
+    public static final int MODE_LOCK_ROW_NOWAIT       = 0x00008000;
 
 	public static final int TEMPORARY_SEGMENT = -1;
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java?rev=1550135&r1=1550134&r2=1550135&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java Wed
Dec 11 13:39:52 2013
@@ -467,8 +467,7 @@ class IndexChanger
             ScanController idxScan = tc.openScan(
                     indexCID,
                     false,
-                    0, // FIXME: want NO_WAIT but not yet implemented
-                       // for row locks in BTRee scan
+                    TransactionController.OPENMODE_LOCK_ROW_NOWAIT,
                     TransactionController.MODE_RECORD,
                     TransactionController.ISOLATION_READ_COMMITTED_NOHOLDLOCK,
                     (FormatableBitSet)null, // retrieve all fields

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java?rev=1550135&r1=1550134&r2=1550135&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
Wed Dec 11 13:39:52 2013
@@ -438,6 +438,7 @@ public class RAMTransaction 
                       ContainerHandle.MODE_DROP_ON_COMMIT           |
                       ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY       |
                       ContainerHandle.MODE_LOCK_NOWAIT              |
+                      ContainerHandle.MODE_LOCK_ROW_NOWAIT          |
                       ContainerHandle.MODE_TRUNCATE_ON_ROLLBACK     |
                       ContainerHandle.MODE_FLUSH_ON_COMMIT          |
                       ContainerHandle.MODE_NO_ACTIONS_ON_COMMIT     |
@@ -498,6 +499,7 @@ public class RAMTransaction 
                    TransactionController.OPENMODE_USE_UPDATE_LOCKS |
                    TransactionController.OPENMODE_FOR_LOCK_ONLY |
                    TransactionController.OPENMODE_LOCK_NOWAIT |
+                   TransactionController.OPENMODE_LOCK_ROW_NOWAIT |
                    TransactionController.OPENMODE_SECONDARY_LOCKED)) != 0)
             {
                 SanityManager.THROWASSERT(

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking3.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking3.java?rev=1550135&r1=1550134&r2=1550135&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking3.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking3.java
Wed Dec 11 13:39:52 2013
@@ -24,6 +24,7 @@ package org.apache.derby.impl.store.acce
 import org.apache.derby.shared.common.sanity.SanityManager;
 
 import org.apache.derby.iapi.error.StandardException; 
+import org.apache.derby.iapi.reference.SQLState;
 
 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
 
@@ -45,6 +46,7 @@ import org.apache.derby.impl.store.acces
 import org.apache.derby.impl.store.access.btree.OpenBTree;
 import org.apache.derby.impl.store.access.btree.BTreeRowPosition;
 import org.apache.derby.impl.store.access.btree.WaitError;
+import org.apache.derby.impl.store.access.heap.HeapController;
 
 /**
 
@@ -296,6 +298,11 @@ class B2IRowLocking3 implements BTreeLoc
                 aux_leaf = null;
             }
 
+            if ((((HeapController)base_cc).getOpenConglomerate().getOpenMode() &
+                    TransactionManager.OPENMODE_LOCK_ROW_NOWAIT) != 0) {
+                throw StandardException.newException(SQLState.LOCK_TIMEOUT);
+            }
+
             base_cc.lockRow(
                 lock_row_loc, 
                 lock_operation,

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/Heap.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/Heap.java?rev=1550135&r1=1550134&r2=1550135&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/Heap.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/Heap.java Wed
Dec 11 13:39:52 2013
@@ -736,6 +736,15 @@ public class Heap 
     DynamicCompiledOpenConglomInfo  dynamic_info)
 		throws StandardException
 	{
+        if (SanityManager.DEBUG) {
+            if ((open_mode &
+                    TransactionController.OPENMODE_LOCK_ROW_NOWAIT) != 0) {
+                SanityManager.THROWASSERT(
+                    "Bad open mode to Heap#openScan:" +
+                    Integer.toHexString(open_mode));
+            }
+        }
+
         // Heap scans do not suppport start and stop scan positions (these
         // only make sense for ordered storage structures).
 		if (!RowUtil.isRowEmpty(startKeyValue)

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapController.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapController.java?rev=1550135&r1=1550134&r2=1550135&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapController.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapController.java
Wed Dec 11 13:39:52 2013
@@ -737,4 +737,7 @@ public class HeapController 
      * Public Methods of XXXX class:
      **************************************************************************
      */
+    public OpenConglomerate getOpenConglomerate() {
+        return open_conglom;
+    }
 }



Mime
View raw message