db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1466481 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/dictionary/ engine/org/apache/derby/impl/sql/catalog/ engine/org/apache/derby/impl/sql/execute/ storeless/org/apache/derby/impl/storeless/ testing/org/apache/derbyTes...
Date Wed, 10 Apr 2013 13:30:38 GMT
Author: rhillegas
Date: Wed Apr 10 13:30:37 2013
New Revision: 1466481

URL: http://svn.apache.org/r1466481
Log:
DERBY-6137: Don't clear the sequence cache during most DDL write operations.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java
    db/derby/code/trunk/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java?rev=1466481&r1=1466480&r2=1466481&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
Wed Apr 10 13:30:37 2013
@@ -218,6 +218,13 @@ public interface DataDictionary
 	public static final int DDL_MODE = 1;
 
 	/**
+	 * Clear the DataDictionary caches, including the sequence caches if requested..
+	 *
+	 * @exception StandardException Standard Derby error policy
+	 */
+	public void clearCaches( boolean clearSequenceCaches ) throws StandardException;
+
+	/**
 	 * Clear all of the DataDictionary caches.
 	 *
 	 * @exception StandardException Standard Derby error policy

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=1466481&r1=1466480&r2=1466481&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
Wed Apr 10 13:30:37 2013
@@ -1310,8 +1310,10 @@ public final class	DataDictionaryImpl
 						/* Switch the caching mode to DDL */
 						setCacheMode(DataDictionary.DDL_MODE);
 	
-						/* Clear out all the caches */
-						clearCaches();
+						// Until we implement ALTER SEQUENCE, there should be no need
+                        // to clear the sequence cache. Always clearing the sequence cache
+                        // here gives rise to DERBY-6137.
+						clearCaches( false );
 					}
 		
 					/* Keep track of the number of DDL users */
@@ -9122,11 +9124,21 @@ public final class	DataDictionaryImpl
 	 */
 	public void clearCaches() throws StandardException
 	{
+        clearCaches( true );
+    }
+    
+	/**
+	 * Clear the DataDictionary caches, including the sequence caches if requested..
+	 *
+	 * @exception StandardException Standard Derby error policy
+	 */
+	public void clearCaches( boolean clearSequenceCaches ) throws StandardException
+	{
 		nameTdCache.cleanAll();
 		nameTdCache.ageOut();
 		OIDTdCache.cleanAll();
 		OIDTdCache.ageOut();
-        clearSequenceCaches();
+        if ( clearSequenceCaches ) { clearSequenceCaches(); }
 		if (spsNameCache != null)
 		{
 			//System.out.println("CLEARING SPS CACHE");

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java?rev=1466481&r1=1466480&r2=1466481&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java
Wed Apr 10 13:30:37 2013
@@ -91,6 +91,7 @@ class DropSequenceConstantAction extends
         ** the transaction.
         */
         dd.startWriting(lcc);
+        dd.clearSequenceCaches();
 
         SequenceDescriptor sequenceDescriptor = dd.getSequenceDescriptor(schemaDescriptor,
sequenceName);
 
@@ -101,6 +102,5 @@ class DropSequenceConstantAction extends
         }
 
         sequenceDescriptor.drop(lcc);
-
     }
 }

Modified: db/derby/code/trunk/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java?rev=1466481&r1=1466480&r2=1466481&view=diff
==============================================================================
--- db/derby/code/trunk/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java
(original)
+++ db/derby/code/trunk/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java
Wed Apr 10 13:30:37 2013
@@ -78,6 +78,8 @@ import org.apache.derby.iapi.types.RowLo
  */
 public class EmptyDictionary implements DataDictionary, ModuleSupportable {
 
+	public void clearCaches( boolean clearSequenceCaches ) {}
+    
 	public void clearCaches() throws StandardException {
 		// Auto-generated method stub
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java?rev=1466481&r1=1466480&r2=1466481&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java
Wed Apr 10 13:30:37 2013
@@ -556,4 +556,82 @@ public class SequenceTest extends Genera
         goodStatement( conn, "create table t_5254( cycle int, minvalue int, maxvalue int
)" );
         goodStatement( conn, "drop table t_5254" );
     }
+    
+    /**
+     * Verify that trigger recompilation doesn't choke trying to create
+     * two nested writable transactions.
+     */
+    public void test_16_6137() throws Exception
+    {
+        Connection conn = openUserConnection( TEST_DBO );
+
+        goodStatement( conn, "call syscs_util.syscs_set_database_property( 'derby.language.sequence.preallocator',
'2' )" );
+        goodStatement( conn, "create table t_6137( rateID int generated always as identity
primary key, amount decimal( 5,2 ) )" );
+        goodStatement( conn, "create table t_history_6137( changeID int primary key, amount
decimal( 5,2 ) )" );
+        goodStatement( conn, "create sequence seq_6137 start with 1" );
+        goodStatement
+            (
+             conn,
+             "create trigger trg_t_6137_hist_del\n" +
+             "after delete on t_6137\n" +
+             "referencing old row as old\n" +
+             "for each row\n" +
+             " insert into t_history_6137 ( changeID, amount ) values (( next value for seq_6137
), old.amount )\n"
+             );
+        goodStatement( conn, "insert into t_6137( amount ) values ( 30.04 ), ( 60.04 ), (
90.04 )" );
+
+        // invalidate the stored statements so that the trigger will have to be recompiled
+        goodStatement( conn, "call syscs_util.syscs_invalidate_stored_statements()" );
+
+        // put the sequence in the cache
+        assertResults
+            (
+             conn,
+             "values next value for seq_6137",
+             new String[][]
+             {
+                 { "1" },
+             },
+             true
+             );
+
+        // verify that the trigger recompiles and fires correctly
+        goodStatement( conn, "delete from t_6137 where rateID = 1" );
+        goodStatement( conn, "delete from t_6137 where rateID = 2" );
+        assertResults
+            (
+             conn,
+             "select * from t_history_6137 order by changeID",
+             new String[][]
+             {
+                 { "2", "30.04" },
+                 { "3", "60.04" },
+             },
+             true
+             );
+
+        // verify current value of sequence
+        String  peekAtSequence = "values syscs_util.syscs_peek_at_sequence('" + TEST_DBO
+ "', 'SEQ_6137')";
+        assertResults
+            (
+             conn,
+             peekAtSequence,
+             new String[][]
+             {
+                 { "4" },
+             },
+             true
+             );
+
+        // tidy up
+        goodStatement( conn, "drop trigger trg_t_6137_hist_del" );
+        goodStatement( conn, "drop table t_history_6137" );
+        goodStatement( conn, "drop table t_6137" );
+        goodStatement( conn, "drop sequence seq_6137 restrict" );
+        goodStatement( conn, "call syscs_util.syscs_set_database_property( 'derby.language.sequence.preallocator',
null )" );
+
+        // verify that the uncleared cache does not leave a phantom sequence hanging around
+        expectExecutionError( conn, MISSING_OBJECT, peekAtSequence );
+        expectCompilationError( conn, OBJECT_DOES_NOT_EXIST, "values next value for seq_6137"
);
+    }
 }



Mime
View raw message