db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r921365 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/services/locks/ engine/org/apache/derby/impl/services/locks/ engine/org/apache/derby/impl/sql/catalog/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/or...
Date Wed, 10 Mar 2010 14:30:37 GMT
Author: rhillegas
Date: Wed Mar 10 14:30:37 2010
New Revision: 921365

URL: http://svn.apache.org/viewvc?rev=921365&view=rev
Log:
DERBY-4565: Loop till the lock wait timeout when attempting to allocate a block of sequence
numbers.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/locks/LockFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/AbstractPool.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/ConcurrentLockSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockTable.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SequenceGeneratorConcurrency.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/locks/LockFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/locks/LockFactory.java?rev=921365&r1=921364&r2=921365&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/locks/LockFactory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/locks/LockFactory.java
Wed Mar 10 14:30:37 2010
@@ -190,6 +190,12 @@ public interface LockFactory extends Pro
 							  Object group, Lockable ref, Object qualifier);
 
 	/**
+		Get the lock timeout in milliseconds. A negative number means that
+        there is no timeout.
+	*/
+	public int getWaitTimeout();
+
+	/**
 		Install a limit that is called when the size of the group exceeds
 		the required limit.
 		<BR>

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/AbstractPool.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/AbstractPool.java?rev=921365&r1=921364&r2=921365&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/AbstractPool.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/AbstractPool.java
Wed Mar 10 14:30:37 2010
@@ -323,6 +323,12 @@ abstract class AbstractPool implements L
 			group, ref, qualifier);
 	}
 
+	/**
+		Get the lock timeout in milliseconds. A negative number means that
+        there is no timeout.
+	*/
+	public int getWaitTimeout() { return lockTable.getWaitTimeout(); }
+
 	public void setLimit(CompatibilitySpace compatibilitySpace,
 						 Object group, int limit, Limit callback) {
 		((LockSpace) compatibilitySpace).setLimit(group, limit, callback);

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/ConcurrentLockSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/ConcurrentLockSet.java?rev=921365&r1=921364&r2=921365&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/ConcurrentLockSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/ConcurrentLockSet.java
Wed Mar 10 14:30:37 2010
@@ -886,6 +886,11 @@ forever:	for (;;) {
         waitTimeout = timeout;
     }
 	
+    /**
+     * Get the wait timeout in milliseconds.
+     */
+    public int getWaitTimeout() { return waitTimeout; }
+    
 	/*
 	** Non public methods
 	*/

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSet.java?rev=921365&r1=921364&r2=921365&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSet.java Wed
Mar 10 14:30:37 2010
@@ -665,6 +665,11 @@ forever:	for (;;) {
         waitTimeout = timeout;
     }
 	
+    /**
+     * Get the wait timeout in milliseconds.
+     */
+    public int getWaitTimeout() { return waitTimeout; }
+    
 	/*
 	** Non public methods
 	*/

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockTable.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockTable.java?rev=921365&r1=921364&r2=921365&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockTable.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockTable.java Wed
Mar 10 14:30:37 2010
@@ -136,6 +136,11 @@ interface LockTable {
     void setWaitTimeout(int timeout);
 
     /**
+     * Get the wait timeout in milliseconds.
+     */
+    int getWaitTimeout();
+
+    /**
      * Enable or disable tracing of deadlocks.
      *
      * @param flag <code>true</code> enables tracing, <code>false</code>

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java?rev=921365&r1=921364&r2=921365&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java
Wed Mar 10 14:30:37 2010
@@ -108,13 +108,6 @@ public abstract class SequenceUpdater im
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
-    //
-    // This is the number of times we attempt to get a sequence number in case we
-    // find ourselves in a race against another session which is draining numbers
-    // from the same sequence generator.
-    //
-    private static final int RETRY_COUNT = 3;
-
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // CONSTANT STATE
@@ -127,9 +120,12 @@ public abstract class SequenceUpdater im
     // This is the key used to lookup this generator in the cache.
     protected String _uuidString;
 
-    // This is the object which allocates ranges of sequence values */
+    // This is the object which allocates ranges of sequence values
     protected SequenceGenerator _sequenceGenerator;
 
+    // This is the lock timeout in milliseconds; a negative number means no timeout
+    private long _lockTimeoutInMillis;
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // CONSTRUCTOR
@@ -137,11 +133,16 @@ public abstract class SequenceUpdater im
     ///////////////////////////////////////////////////////////////////////////////////
 
     /** No-arg constructor to satisfy the Cacheable contract */
-    public SequenceUpdater() {}
+    public SequenceUpdater()
+    {
+        _lockTimeoutInMillis = getLockTimeout();
+    }
 
     /** Normal constructor */
     public SequenceUpdater( DataDictionaryImpl dd )
     {
+        this();
+        
         _dd = dd;
     }
     
@@ -289,12 +290,14 @@ public abstract class SequenceUpdater im
     public void getCurrentValueAndAdvance
         ( NumberDataValue returnValue ) throws StandardException
     {
+        Long startTime = null;
+        
         //
         // We try to get a sequence number. We try a couple times in case we find
         // ourselves in a race with another session which is draining numbers from
         // the same sequence generator.
         //
-        for ( int i = 0; i < RETRY_COUNT; i++ )
+        while ( true )
         {
             long[] cvaa = _sequenceGenerator.getCurrentValueAndAdvance();
             
@@ -331,7 +334,20 @@ public abstract class SequenceUpdater im
             // we or another session may have allocated more sequence numbers on disk. We
go back
             // in to try to grab one of those numbers.
             //
-
+            if ( startTime == null )
+            {
+                // get the system time only if we have to
+                startTime = new Long( System.currentTimeMillis() );
+                continue;
+            }
+            
+            if (
+                (_lockTimeoutInMillis >= 0L) &&
+                ( (System.currentTimeMillis() - startTime.longValue()) > _lockTimeoutInMillis
)
+                )
+            {
+                break;
+            }
             
         } // end of retry loop
 
@@ -376,11 +392,10 @@ public abstract class SequenceUpdater im
         TransactionController executionTransaction = getLCC().getTransactionExecute();
         TransactionController nestedTransaction = null;
 
-        // Try to get a nested transaction.
         try {
             nestedTransaction = executionTransaction.startNestedUserTransaction( false );
         } catch (StandardException se) {}
-
+        
         // First try to do the work in the nested transaction. Fail if we can't
         // get a lock immediately.
         if ( nestedTransaction != null )
@@ -398,9 +413,10 @@ public abstract class SequenceUpdater im
                 nestedTransaction.destroy();
             }
         }
-
+        
         // If we get here, we failed to do the work in the nested transaction.
         // Fall back on the execution transaction
+        
         return updateCurrentValueOnDisk( executionTransaction, oldValue, newValue, true );
     }
 
@@ -410,6 +426,12 @@ public abstract class SequenceUpdater im
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
+    /** Get the time we wait for a lock, in milliseconds--overridden by unit tests */
+    protected int getLockTimeout()
+    {
+        return getLCC().getTransactionExecute().getAccessManager().getLockFactory().getWaitTimeout();
+    }
+    
 	private static LanguageConnectionContext getLCC()
     {
 		return (LanguageConnectionContext) 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java?rev=921365&r1=921364&r2=921365&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java
Wed Mar 10 14:30:37 2010
@@ -654,6 +654,10 @@ public class SequenceGeneratorTest  exte
         {
             return updateCurrentValueOnDisk( null, oldValue, newValue, false );
         }
+        
+        // overridden to avoid a null pointer exception when we don't have a language context
+        protected int getLockTimeout() { return 1000; }
+    
     }
 
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SequenceGeneratorConcurrency.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SequenceGeneratorConcurrency.java?rev=921365&r1=921364&r2=921365&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SequenceGeneratorConcurrency.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SequenceGeneratorConcurrency.java
Wed Mar 10 14:30:37 2010
@@ -215,7 +215,7 @@ public class SequenceGeneratorConcurrenc
                     _psArray[ sequence ][ table ].executeUpdate();
                 }
             }
-            catch (SQLException t)
+            catch (Throwable t)
             {
                 debugPrint
                     (



Mime
View raw message