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 2013/04/10 21:01:22 UTC

svn commit: r1466623 - in /db/derby/code/branches/10.10: ./ java/engine/org/apache/derby/iapi/sql/dictionary/ java/engine/org/apache/derby/impl/sql/catalog/ java/engine/org/apache/derby/impl/sql/execute/ java/storeless/org/apache/derby/impl/storeless/ ...

Author: rhillegas
Date: Wed Apr 10 19:01:22 2013
New Revision: 1466623

URL: http://svn.apache.org/r1466623
Log:
DERBY-6137: Port 1466481 and 1466522 from trunk to 10.10 branch.

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

Propchange: db/derby/code/branches/10.10/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1466481,1466522

Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java?rev=1466623&r1=1466622&r2=1466623&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java Wed Apr 10 19:01:22 2013
@@ -215,6 +215,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/branches/10.10/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=1466623&r1=1466622&r2=1466623&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java Wed Apr 10 19:01:22 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");
@@ -10493,7 +10505,19 @@ public final class	DataDictionaryImpl
                     ( schemaName + "." + sequenceName) );
         }
         
-        return ((SequenceUpdater) sequenceGeneratorCache.find( uuid )).peekAtCurrentValue();
+        SequenceUpdater sequenceUpdater = null;
+
+        try {
+            sequenceUpdater = (SequenceUpdater) sequenceGeneratorCache.find( uuid );
+            return sequenceUpdater.peekAtCurrentValue();
+        }
+        finally
+        {
+            if ( sequenceUpdater != null )
+            {
+                sequenceGeneratorCache.release( sequenceUpdater );
+            }
+        }
     }
     
     public RowLocation getRowLocationTemplate(LanguageConnectionContext lcc,

Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java?rev=1466623&r1=1466622&r2=1466623&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java Wed Apr 10 19:01:22 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/branches/10.10/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java?rev=1466623&r1=1466622&r2=1466623&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java (original)
+++ db/derby/code/branches/10.10/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java Wed Apr 10 19:01:22 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/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java?rev=1466623&r1=1466622&r2=1466623&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java Wed Apr 10 19:01:22 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" );
+    }
 }