You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2011/09/22 20:10:42 UTC

svn commit: r1174297 - in /db/derby/code/branches/10.8/java/engine/org/apache/derby: impl/sql/catalog/SequenceUpdater.java loc/messages.xml

Author: rhillegas
Date: Thu Sep 22 18:10:40 2011
New Revision: 1174297

URL: http://svn.apache.org/viewvc?rev=1174297&view=rev
Log:
DERBY-5426: Port 1174290 from trunk to 10.8 branch.

Modified:
    db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java?rev=1174297&r1=1174296&r2=1174297&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java Thu Sep 22 18:10:40 2011
@@ -155,7 +155,7 @@ public abstract class SequenceUpdater im
     
     ///////////////////////////////////////////////////////////////////////////////////
     //
-    // ABSTRACT BEHAVIOR TO BE IMPLEMENTED BY CHILDREN
+    // ABSTRACT OR OVERRIDABLE BEHAVIOR TO BE IMPLEMENTED BY CHILDREN
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
@@ -187,6 +187,19 @@ public abstract class SequenceUpdater im
      */
     abstract protected boolean updateCurrentValueOnDisk( TransactionController tc, Long oldValue, Long newValue, boolean wait ) throws StandardException;
     
+    /**
+     * <p>
+     * Create an exception to state that there is too much contention on the generator.
+     * For backward compatibility reasons, different messages are needed by sequences
+     * and identities. See DERBY-5426.
+     * </p>
+     */
+    protected   StandardException   tooMuchContentionException()
+    {
+        return StandardException.newException
+            ( SQLState.LANG_TOO_MUCH_CONTENTION_ON_SEQUENCE, _sequenceGenerator.getName() );
+    }
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // Cacheable BEHAVIOR
@@ -322,10 +335,10 @@ public abstract class SequenceUpdater im
         ( 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
+        // We try to get a sequence number. We try until we've exceeded the lock timeout
+        // in case we find ourselves in a race with another session which is draining numbers from
         // the same sequence generator.
         //
         while ( true )
@@ -377,18 +390,16 @@ public abstract class SequenceUpdater im
                 ( (System.currentTimeMillis() - startTime.longValue()) > _lockTimeoutInMillis )
                 )
             {
-                break;
+                //
+                // If we get here, then we exhausted our retry attempts. This might be a sign
+                // that we need to increase the number of sequence numbers which we
+                // allocate. There's an opportunity for Derby to tune itself here.
+                //
+                throw tooMuchContentionException();
             }
             
         } // end of retry loop
 
-        //
-        // If we get here, then we exhausted our retry attempts. This might be a sign
-        // that we need to increase the number of sequence numbers which we
-        // allocate. There's an opportunity for Derby to tune itself here.
-        //
-        throw StandardException.newException
-            ( SQLState.LANG_TOO_MUCH_CONTENTION_ON_SEQUENCE, _sequenceGenerator.getName() );
     }
 
     /**
@@ -595,6 +606,17 @@ public abstract class SequenceUpdater im
         {
             return _dd.updateCurrentIdentityValue( tc, _sequenceRowLocation, wait, oldValue, newValue );
         }
+
+        /**
+         * Wrap the "too much contention" exception in a "lock timeout" exception in
+         * order to preserve the old error behavior of identity columns. See DERBY-5426.
+         */
+        protected   StandardException   tooMuchContentionException()
+        {
+            StandardException   tooMuchContention = super.tooMuchContentionException();
+
+            return StandardException.newException( SQLState.LOCK_TIMEOUT, tooMuchContention );
+        }
     }
 
     /**

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml?rev=1174297&r1=1174296&r2=1174297&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml Thu Sep 22 18:10:40 2011
@@ -3435,7 +3435,7 @@ Guide.
 
             <msg>
                 <name>X0Y84.S</name>
-                <text>Too much contention on sequence {0}.</text>
+                <text>Too much contention on sequence {0}. To avoid this error, try adjusting derby.locks.waitTimeout and/or derby.language.sequence.preallocator. See the Derby Reference Manual for more information on these properties.</text>
                 <arg>sequenceName</arg>
             </msg>