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/06/21 14:53:52 UTC

svn commit: r1137985 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/dictionary/ engine/org/apache/derby/impl/db/ engine/org/apache/derby/impl/sql/catalog/ storeless/org/apache/derby/impl/storeless/ testing/org/apache/derbyTesting/func...

Author: rhillegas
Date: Tue Jun 21 12:53:51 2011
New Revision: 1137985

URL: http://svn.apache.org/viewvc?rev=1137985&view=rev
Log:
DERBY-4437: Reclaim unused sequence/identity values on orderly shutdown.

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/db/BasicDatabase.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.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/SequenceGeneratorTest.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=1137985&r1=1137984&r2=1137985&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 Tue Jun 21 12:53:51 2011
@@ -217,6 +217,13 @@ public interface DataDictionary
 	public void clearCaches() throws StandardException;
 
 	/**
+	 * Clear all of the sequence number generators.
+	 *
+	 * @exception StandardException Standard Derby error policy
+	 */
+	public void clearSequenceCaches() throws StandardException;
+
+	/**
 	 * Inform this DataDictionary that we are about to start reading it.  This
 	 * means using the various get methods in the DataDictionary.
 	 * Generally, this is done during query compilation.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java?rev=1137985&r1=1137984&r2=1137985&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java Tue Jun 21 12:53:51 2011
@@ -241,6 +241,14 @@ public class BasicDatabase implements Mo
     }
 
 	public void stop() {
+        try {
+            // on orderly shutdown, try not to leak unused numbers from the sequence generators.
+            dd.clearSequenceCaches();
+        }
+        catch (Throwable t)
+        {
+            t.printStackTrace(Monitor.getStream().getPrintWriter());
+        }
 		active = false;
 	}
 

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=1137985&r1=1137984&r2=1137985&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 Tue Jun 21 12:53:51 2011
@@ -8833,11 +8833,7 @@ public final class	DataDictionaryImpl
 		OIDTdCache.cleanAll();
 		OIDTdCache.ageOut();
 
-		sequenceGeneratorCache.cleanAll();
-		sequenceGeneratorCache.ageOut();
-
-		idGeneratorCache.cleanAll();
-		idGeneratorCache.ageOut();
+        clearSequenceCaches();
 
 		if (spsNameCache != null)
 		{
@@ -8849,6 +8845,19 @@ public final class	DataDictionaryImpl
 		}
 	}
 
+    /**
+       Flush sequence caches to disk so that we don't leak unused, pre-allocated numbers.
+    */
+    public void    clearSequenceCaches() throws StandardException
+    {
+		sequenceGeneratorCache.cleanAll();
+		sequenceGeneratorCache.ageOut();
+
+		idGeneratorCache.cleanAll();
+		idGeneratorCache.ageOut();
+    }
+    
+
 	/**
 		Add the required entries to the data dictionary for a System table.
 	*/

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=1137985&r1=1137984&r2=1137985&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 Tue Jun 21 12:53:51 2011
@@ -79,6 +79,11 @@ public class EmptyDictionary implements 
 
 	}
 
+	public void clearSequenceCaches() throws StandardException {
+		// TODO Auto-generated method stub
+
+	}
+
 	public int startReading(LanguageConnectionContext lcc)
 			throws StandardException {
 		// TODO Auto-generated method stub

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=1137985&r1=1137984&r2=1137985&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 Tue Jun 21 12:53:51 2011
@@ -417,13 +417,11 @@ public class SequenceGeneratorTest  exte
 
         getTestConfiguration().shutdownDatabase();
         conn = openUserConnection( TEST_DBO );
-        seq_04_value = (int) seq_04_upperBound;
         seq_04_upperBound = seq_04_value + ALLOCATION_COUNT;
         vetBumping( conn, TEST_DBO, "SEQ_04", seq_04_value++, seq_04_upperBound );
 
         getTestConfiguration().shutdownDatabase();
         conn = openUserConnection( TEST_DBO );
-        seq_04_value = (int) seq_04_upperBound;
         seq_04_upperBound = seq_04_value + ALLOCATION_COUNT;
         vetBumping( conn, TEST_DBO, "SEQ_04", seq_04_value++, seq_04_upperBound );
     }