db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1596619 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java testing/org/apache/derbyTesting/functionTests/tests/lang/IdentitySequenceTest.java
Date Wed, 21 May 2014 16:54:56 GMT
Author: rhillegas
Date: Wed May 21 16:54:55 2014
New Revision: 1596619

URL: http://svn.apache.org/r1596619
Log:
DERBY-6542: Raise LockTimeout when there is too much contention on an identity column; commit
derby-6542-03-aa-lockTimeoutForIdentityContention.diff.

Modified:
    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/IdentitySequenceTest.java

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=1596619&r1=1596618&r2=1596619&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 May 21 16:54:55 2014
@@ -37,6 +37,7 @@ import org.apache.derby.iapi.services.pr
 import org.apache.derby.shared.common.sanity.SanityManager;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 import org.apache.derby.iapi.sql.dictionary.BulkInsertCounter;
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
 import org.apache.derby.iapi.sql.dictionary.SequenceDescriptor;
 import org.apache.derby.iapi.store.access.AccessFactory;
 import org.apache.derby.iapi.store.access.TransactionController;
@@ -176,10 +177,18 @@ public abstract class SequenceUpdater im
      * and identities. See DERBY-5426.
      * </p>
      */
-    protected   StandardException   tooMuchContentionException()
+    private   StandardException   tooMuchContentionException()
     {
-        return StandardException.newException
-            ( SQLState.LANG_TOO_MUCH_CONTENTION_ON_SEQUENCE, _sequenceGenerator.getName()
);
+        // If the sequence lives in the SYS schema, then it is used to back an identity column.
+        if ( SchemaDescriptor.STD_SYSTEM_SCHEMA_NAME.equals( _sequenceGenerator.getSchemaName()
) )
+        {
+            return StandardException.newException( SQLState.LOCK_TIMEOUT );
+        }
+        else
+        {
+            return StandardException.newException
+                ( SQLState.LANG_TOO_MUCH_CONTENTION_ON_SEQUENCE, _sequenceGenerator.getName()
);
+        }
     }
     
     ///////////////////////////////////////////////////////////////////////////////////

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/IdentitySequenceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/IdentitySequenceTest.java?rev=1596619&r1=1596618&r2=1596619&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/IdentitySequenceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/IdentitySequenceTest.java
Wed May 21 16:54:55 2014
@@ -338,6 +338,44 @@ public class IdentitySequenceTest extend
              );
     }
 
+    /**
+     * <p>
+     * Test that too much contention on an identity column raises a LOCK_TIMEOUT.
+     * </p>
+     */
+    public  void    test_003_identityTimeout()
+        throws Exception
+    {
+        Connection  conn = getConnection();
+
+        goodStatement( conn, "call syscs_util.syscs_set_database_property( 'derby.locks.waitTimeout',
'1' )" );
+        goodStatement( conn, "create table t_timeout( a int generated always as identity,
b int )" );
+        conn.setAutoCommit( false );
+
+        try {
+            PreparedStatement   ps = chattyPrepare( conn, "select count(*) from sys.syssequences
with rs\n" );
+            getScalarInteger( ps );
+            expectExecutionError( conn, LOCK_TIMEOUT, "insert into t_timeout( b ) values
( 1 )" );
+        }
+        finally
+        {
+            conn.setAutoCommit( true );
+            goodStatement( conn, "call syscs_util.syscs_set_database_property( 'derby.locks.waitTimeout',
'60' )" );
+        }
+    }
+    /** Get a scalar integer result from a query */
+    private int getScalarInteger( PreparedStatement ps ) throws Exception
+    {
+        ResultSet rs = ps.executeQuery();
+        rs.next();
+        int retval = rs.getInt( 1 );
+
+        rs.close();
+        ps.close();
+
+        return retval;
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS



Mime
View raw message