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 ka...@apache.org on 2012/12/07 14:06:28 UTC

svn commit: r1418296 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/dictionary/ engine/org/apache/derby/impl/sql/catalog/ testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/

Author: kahatlen
Date: Fri Dec  7 13:06:26 2012
New Revision: 1418296

URL: http://svn.apache.org/viewvc?rev=1418296&view=rev
Log:
DERBY-6003: Create row templates outside of the generated code

Upgrade test fix in preparation for the actual fix for this issue.

Improve SYSCS_INVALIDATE_STORED_STATEMENTS by making it null out the
plans in SYS.SYSSTATEMENTS. Previously, it only marked them as invalid.

Use the improved SYSCS_INVALIDATE_STORED_STATEMENTS to work around
problems in the upgrade tests when downgrading to a version that suffers
from DERBY-4835 or DERBY-5289. Remove the old workarounds for DERBY-4835,
DERBY-5105, DERBY-5263 and DERBY-5289, as they are now handled by the
centralized workaround that uses SYSCS_INVALIDATE_STORED_STATEMENTS.

This change is needed because later patches for this issue will change
the format of many stored plans, so more of the test cases need to work
around the downgrade bugs in some old versions.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java?rev=1418296&r1=1418295&r2=1418296&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java Fri Dec  7 13:06:26 2012
@@ -1011,6 +1011,7 @@ public class SPSDescriptor extends Tuple
 				if (valid == true)
 				{
 					valid = false;
+                    preparedStatement = null;
 					updateSYSSTATEMENTS(lcc, INVALIDATE, null);
 				}
 				dm.invalidateFor(this, dm.USER_RECOMPILE_REQUEST, lcc);

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=1418296&r1=1418295&r2=1418296&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 Fri Dec  7 13:06:26 2012
@@ -4429,6 +4429,7 @@ public final class	DataDictionaryImpl
 	 *
 	 * @param spsd	The descriptor to add
 	 * @param tc			The transaction controller
+     * @param recompile Whether to recompile or invalidate
 	 * @param updateParamDescriptors If true, will update the
 	 *						parameter descriptors in SYS.SYSCOLUMNS.
 	 * @param firstCompilation  true, if Statement is getting compiled for first
@@ -4472,7 +4473,12 @@ public final class	DataDictionaryImpl
 		}
 		else 
 		{
-			updCols = new int[]	{SYSSTATEMENTSRowFactory.SYSSTATEMENTS_VALID} ;
+            // This is an invalidation request. Update the VALID column (to
+            // false) and clear the plan stored in the CONSTANTSTATE column.
+            updCols = new int[] {
+                SYSSTATEMENTSRowFactory.SYSSTATEMENTS_VALID,
+                SYSSTATEMENTSRowFactory.SYSSTATEMENTS_CONSTANTSTATE,
+            };
 		}
 			
 		idOrderable = getIDValueAsCHAR(spsd.getUUID());

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java?rev=1418296&r1=1418295&r2=1418296&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java Fri Dec  7 13:06:26 2012
@@ -27,6 +27,7 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
 
+import org.apache.derby.catalog.SystemProcedures;
 import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -100,19 +101,7 @@ public class BasicSetup extends UpgradeC
             		"VALUES(20)");
             break;
         case PH_SOFT_UPGRADE:
-            s.executeUpdate("INSERT INTO Trigger_t1(max_size) "+
-    		"VALUES(20)");
-            break;
         case PH_POST_SOFT_UPGRADE:
-            // DERBY-5105: The post soft upgrade phase may fail with
-            // NoSuchMethodError if the old version suffers from DERBY-4835.
-            // Only execute this part of the test for versions that don't
-            // have this problem.
-            if (!oldSuffersFromDerby4835()) {
-                s.executeUpdate("INSERT INTO Trigger_t1(max_size) " +
-                                "VALUES(20)");
-            }
-            break;
         case PH_HARD_UPGRADE:
             s.executeUpdate("INSERT INTO Trigger_t1(max_size) "+
     		"VALUES(20)");
@@ -122,15 +111,6 @@ public class BasicSetup extends UpgradeC
     }
 
     /**
-     * Check if the old version from which we upgrade suffers from DERBY-4835.
-     */
-    private boolean oldSuffersFromDerby4835() {
-        // DERBY-4835 exists on 10.5 and 10.6 prior to 10.5.3.2 and 10.6.2.3.
-        return (oldAtLeast(10, 5) && oldLessThan(10, 5, 3, 2)) ||
-                (oldAtLeast(10, 6) && oldLessThan(10, 6, 2, 3));
-    }
-
-    /**
      * Simple test of the old version from the meta data.
      */
     public void testOldVersion() throws SQLException
@@ -285,7 +265,32 @@ public class BasicSetup extends UpgradeC
             break;
         }
     }  
-    
+
+    /**
+     * Test case that drops all trigger plans. Should be run at the end of
+     * soft upgrade if the old version suffers from DERBY-4835 or DERBY-5289.
+     * Otherwise, the database may fail to boot again with the old version.
+     */
+    public void dropAllTriggerPlans() throws Exception {
+        Statement s = createStatement();
+        s.execute("create procedure clear_sps_plans() language java "
+                + "parameter style java external name '"
+                + getClass().getName()
+                + ".clearSPSPlans'");
+        s.execute("call clear_sps_plans()");
+        s.execute("drop procedure clear_sps_plans");
+    }
+
+    /**
+     * Stored procedure that clears all SPS plans in the database. It does
+     * the same as SYSCS_UTIL.SYSCS_INVALIDATE_STORED_STATEMENTS, but we
+     * need to create our own procedure since the built-in procedure might
+     * not be available in soft upgrade.
+     */
+    public static void clearSPSPlans() throws SQLException {
+        SystemProcedures.SYSCS_INVALIDATE_STORED_STATEMENTS();
+    }
+
     /**
      * DERBY-5249 table created with primary and foreign key can't be dropped
      * Test currently disabled. Remove the x from the name to enable the 
@@ -1842,12 +1847,6 @@ public class BasicSetup extends UpgradeC
             return;
         }
 
-        if (getPhase() == PH_POST_SOFT_UPGRADE && oldSuffersFromDerby4835()) {
-            // DERBY-5263: Executing the trigger will fail after soft upgrade
-            // in all the versions that suffer from DERBY-4835. Skip the test.
-            return;
-        }
-
         Statement s = createStatement();
 
         if (getPhase() == PH_CREATE) {
@@ -1899,11 +1898,6 @@ public class BasicSetup extends UpgradeC
      * @throws SQLException
      */
     public void testDERBY5289TriggerUpgradeFormat() throws SQLException {
-        // if the old version suffers from DERBY-4835 we 
-        // cannot run this test because the database won't boot
-        // on soft upgrade and none of the fixtures will run.
-        if (oldSuffersFromDerby4835())
-            return;
         Statement s = createStatement();
         switch (getPhase())
         {
@@ -1924,21 +1918,7 @@ public class BasicSetup extends UpgradeC
                 assertDERBY5289ResultsAndDelete();
                 break;
             case PH_SOFT_UPGRADE:   
-                s.executeUpdate("insert into D5289TABLE1(COL1) values ('aaa')");
-                s.executeUpdate("insert into D5289TABLE2(COL2) values ('aaa')");
-                s.executeUpdate("UPDATE D5289TABLE1 SET COL1 = 'bbb'");
-                assertDERBY5289ResultsAndDelete();                
-                break;
             case PH_POST_SOFT_UPGRADE:
-                // If old version suffers from DERBY-5289, we can't run this part of the 
-                // DERBY-5289 won't go in until 10.8.2.0
-                if (! oldLessThan(10,8,2,0)) {
-                    s.executeUpdate("insert into D5289TABLE1(COL1) values ('aaa')");
-                    s.executeUpdate("insert into D5289TABLE2(COL2) values ('aaa') ");
-                    s.executeUpdate("UPDATE D5289TABLE1 SET COL1 = 'bbb'");
-                    assertDERBY5289ResultsAndDelete();
-                }
-                break;
             case PH_HARD_UPGRADE:
                 s.executeUpdate("insert into D5289TABLE1(COL1) values ('aaa')");
                 s.executeUpdate("insert into D5289TABLE2(COL2) values ('aaa') ");

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java?rev=1418296&r1=1418295&r2=1418296&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java Fri Dec  7 13:06:26 2012
@@ -230,9 +230,40 @@ class UpgradeRun extends UpgradeClassLoa
         {
             suite.addTest(new BasicSetup("noConnectionAfterHardUpgrade"));
         }
-                
+
+        if (phase == UpgradeChange.PH_SOFT_UPGRADE &&
+                suffersFromDerby4835or5289(version)) {
+            // If the old version suffers from DERBY-4835 or DERBY-5289,
+            // it may not be able to read the trigger plans after soft upgrade.
+            // Drop all trigger plans at the end of soft upgrade to prevent
+            // problems in the post soft upgrade phase.
+            suite.addTest(new BasicSetup("dropAllTriggerPlans"));
+        }
+
         return TestConfiguration.connectionDSDecorator(suite);
     }
+
+    /**
+     * Check if a version suffers from DERBY-4835 or DERBY-5289.
+     */
+    private static boolean suffersFromDerby4835or5289(int[] version) {
+        // DERBY-4835 affects the 10.5 and 10.6 branches, and was fixed in
+        // 10.5.3.2 and 10.6.2.3.
+        // DERBY-5289 affects the 10.5, 10.6, 10.7 and 10.8 branches, and was
+        // fixed in 10.5.3.1, 10.6.2.2, 10.7.1.4 and 10.8.2.2.
+        return
+                (lessThan(new int[] { 10, 5, 0, 0 }, version) &&
+                 lessThan(version, new int[] { 10, 5, 3, 2 }))
+            ||
+                (lessThan(new int[] { 10, 6, 0, 0 }, version) &&
+                 lessThan(version, new int[] { 10, 6, 2, 3 }))
+            ||
+                (lessThan(new int[] { 10, 7, 0, 0 }, version) &&
+                 lessThan(version, new int[] { 10, 7, 1, 4 }))
+            ||
+                (lessThan(new int[] { 10, 8, 0, 0 }, version) &&
+                 lessThan(version, new int[] { 10, 8, 2, 2 }));
+    }
     
     /**
      * Return true if and only if the left version is less than the