db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1441923 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/upgradeTests/ functionTests/tests/upgradeTests/helpers/ junit/
Date Sun, 03 Feb 2013 14:56:40 GMT
Author: kristwaa
Date: Sun Feb  3 14:56:40 2013
New Revision: 1441923

URL: http://svn.apache.org/viewvc?rev=1441923&view=rev
Log:
DERBY-6064: Failures in upgradeTests.Changes10_9 related to index cardinality statistics

Added logic to adjust asserts based on the version of the old database.
The fix affecting the tests is in the released 10.8.3-version of Derby, and
the fix has been backported to older branches back to 10.3.

Patch file: derby-6064-1a-istat_upgrade_test_fixes.diff

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_9.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeChange.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/helpers/DisposableIndexStatistics.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyVersion.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_9.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_9.java?rev=1441923&r1=1441922&r2=1441923&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_9.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_9.java
Sun Feb  3 14:56:40 2013
@@ -886,6 +886,10 @@ public class Changes10_9 extends Upgrade
         // Helper object to obtain information about index statistics.
         IndexStatsUtil stats = new IndexStatsUtil(openDefaultConnection());
         Statement s = createStatement();
+        // The expected initial number of statistics entries in TEST_TAB_2.
+        final int expected =
+                DisposableIndexStatistics.hasDerby5681Bug(getOldVersion()) ?
+                    2 : 1;
         
         switch (getPhase())
         {
@@ -926,7 +930,7 @@ public class Changes10_9 extends Upgrade
                     "DROP CONSTRAINT TEST_TAB_2_FK_1");
             //Dropping the foreign key constraint does not remove it's 
             // statistics row because of DERBY-5681.
-            stats.assertTableStats("TEST_TAB_2",2);
+            stats.assertTableStats("TEST_TAB_2", expected);
             assertStatementError("42Y03", s,
             "CALL SYSCS_UTIL.SYSCS_DROP_STATISTICS('APP','TEST_TAB_2', null)");
             break;
@@ -938,7 +942,7 @@ public class Changes10_9 extends Upgrade
             break;
 
         case PH_HARD_UPGRADE:
-            stats.assertTableStats("TEST_TAB_2",2);
+            stats.assertTableStats("TEST_TAB_2", expected);
             s.execute("CALL SYSCS_UTIL.SYSCS_DROP_STATISTICS('APP','TEST_TAB_2', null)");
             stats.assertNoStatsTable("TEST_TAB_2");
             s.execute("CALL SYSCS_UTIL.SYSCS_UPDATE_STATISTICS('APP','TEST_TAB_2', null)");
@@ -987,8 +991,8 @@ public class Changes10_9 extends Upgrade
         final String TBL = "ISTAT_DISPOSABLE_STATS";
         String updateStatsSQL = "call syscs_util.syscs_update_statistics(" +
                 "'APP', ?, null)";
-        DisposableIndexStatistics dis =
-                new DisposableIndexStatistics(getConnection(), TBL);
+        DisposableIndexStatistics dis = new DisposableIndexStatistics(
+                getOldVersion(), getConnection(), TBL);
 
         switch (getPhase()) {
             // create with old version
@@ -998,8 +1002,7 @@ public class Changes10_9 extends Upgrade
                 // We expect that the maximum number of statistics have been
                 // created here, since we're using an older version of Derby
                 // that contained a bug and lacked the latest optimizations.
-                dis.assertStatsCount(
-                        DisposableIndexStatistics.getNumTotalPossibleStats());
+                dis.assertStatsCount(false);
                 break;
             }
             // boot with new version and soft-upgrade
@@ -1012,22 +1015,19 @@ public class Changes10_9 extends Upgrade
                     ps.setString(1, tables[i]);
                     ps.executeUpdate();
                 }
-                dis.assertStatsCount(
-                        DisposableIndexStatistics.getNumTotalPossibleStats());
+                dis.assertStatsCount(false);
                 break;
             }
             // soft-downgrade: boot with old version after soft-upgrade
             case PH_POST_SOFT_UPGRADE:
             {
-                dis.assertStatsCount(
-                        DisposableIndexStatistics.getNumTotalPossibleStats());
+                dis.assertStatsCount(false);
                 break;
             }
             // boot with new version and hard-upgrade
             case PH_HARD_UPGRADE:
             {
-                dis.assertStatsCount(
-                        DisposableIndexStatistics.getNumTotalPossibleStats());
+                dis.assertStatsCount(false);
                 PreparedStatement ps = prepareStatement(updateStatsSQL);
                 String[] tables = dis.getTableNames();
                 for (int i=0; i < tables.length; i++) {
@@ -1037,9 +1037,7 @@ public class Changes10_9 extends Upgrade
                 // Confirm that we disposed of the statistics that were added
                 // due to a bug or simply not needed by Derby.
                 try {
-                    dis.assertStatsCount(
-                        DisposableIndexStatistics.getNumTotalPossibleStats() -
-                        DisposableIndexStatistics.getNumDisposableStats());
+                    dis.assertStatsCount(true);
                 } finally {
                     for (int i=0; i < tables.length; i++) {
                         dropTable(tables[i]);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeChange.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeChange.java?rev=1441923&r1=1441922&r2=1441923&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeChange.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeChange.java
Sun Feb  3 14:56:40 2013
@@ -21,6 +21,7 @@ limitations under the License.
 package org.apache.derbyTesting.functionTests.tests.upgradeTests;
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.DerbyVersion;
 
 /**
  * Abstract class to provide support for test fixtures for
@@ -95,6 +96,16 @@ abstract class UpgradeChange extends Bas
     }
     
     /**
+     * Returns a {@code DerbyVersion} object describing the old version.
+     *
+     * @return A version object.
+     */
+    final DerbyVersion getOldVersion() {
+        return new DerbyVersion(
+                getOldMajor(), getOldMinor(), getOldFixPack(), getOldPoint());
+    }
+
+    /**
      * Get the major number of the old version being upgraded
      * from.
      */

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/helpers/DisposableIndexStatistics.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/helpers/DisposableIndexStatistics.java?rev=1441923&r1=1441922&r2=1441923&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/helpers/DisposableIndexStatistics.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/helpers/DisposableIndexStatistics.java
Sun Feb  3 14:56:40 2013
@@ -30,6 +30,7 @@ import java.util.List;
 
 import junit.framework.Assert;
 
+import org.apache.derbyTesting.junit.DerbyVersion;
 import org.apache.derbyTesting.junit.IndexStatsUtil;
 
 /**
@@ -48,6 +49,7 @@ public class DisposableIndexStatistics {
      */
     private static final int ROW_COUNT = 2000;
 
+    private final DerbyVersion oldVersion;
     private final Connection con;
     private final String tbl;
     private final String fktbl;
@@ -59,7 +61,10 @@ public class DisposableIndexStatistics {
      * @param con connection
      * @param tableName base table name
      */
-    public DisposableIndexStatistics(Connection con, String tableName) {
+    public DisposableIndexStatistics(DerbyVersion oldVersion,
+                                     Connection con,
+                                     String tableName) {
+        this.oldVersion = oldVersion;
         this.con = con;
         this.tbl = tableName;
         this.fktbl = tableName + "_FK";
@@ -137,12 +142,21 @@ public class DisposableIndexStatistics {
         stmt.executeUpdate("alter table " + tbl + " drop constraint " +
                 "fk_on_pk");
         // Derby failed to drop the statistics when the constraint got dropped.
-        Assert.assertTrue(stats.getStatsTable(tbl).length == preFkAddition +1);
+        // DERBY-5681: Originally fixed in 10.9, but has now been backported
+        //      all the way back to 10.3.
+        int tableStatsCount = stats.getStatsTable(tbl).length;
+        if (hasDerby5681Bug(oldVersion)) {
+            Assert.assertEquals(preFkAddition +1, tableStatsCount);
+        } else {
+            Assert.assertEquals(preFkAddition, tableStatsCount);
+        }
 
-        // Do an assert, but since we may be run with both old and new
-        // releases allow for two cases.
-        Assert.assertEquals(
-                getNumTotalPossibleStats(), getAllRelevantStats(null));
+        // Several valid states here, use a relaxed range check.
+        int max = getNumTotalPossibleStats();
+        int min = max - getNumDisposableStats();
+        int cur = getAllRelevantStats(null);
+        Assert.assertTrue("cur=" + cur + ", min=" + min, cur >= min);
+        Assert.assertTrue("cur=" + cur + ", max=" + max, cur <= max);
     }
 
     private void insertData(Connection con)
@@ -190,9 +204,24 @@ public class DisposableIndexStatistics {
         return new String[] {tbl, fktbl, pktbl};
     }
 
-    /** Asserts the number of statistics entries for all relevant tables. */
-    public void assertStatsCount(int expected)
+    /**
+     * Asserts the number of statistics entries for all relevant tables.
+     *
+     * @param disposedOf tells if the disposable statistics entries are
+     *      expected to have been removed at this point
+     */
+    public void assertStatsCount(boolean disposedOf)
             throws SQLException {
+        int expected = getNumTotalPossibleStats();
+        // Adjust expected count if the disposable stats should be gone.
+        if (disposedOf) {
+            expected -= getNumDisposableStats();
+        } else if (!hasDerby5681Bug(oldVersion)) {
+            // Here we correct for the orphaned statistics entry, but not for
+            // entires that are considered extraneous by newer releases (for
+            // instance statistics for single column unique indexes).
+            expected--;
+        }
         ArrayList entries = new ArrayList();
         int found = getAllRelevantStats(entries);
         if (found != expected) {
@@ -253,4 +282,36 @@ public class DisposableIndexStatistics {
     public static int getNumDisposableStats() {
         return 3;
     }
+
+    /**
+     * Tells if the old version is affected by the DERBY-5681 bug.
+     * <p>
+     * The bug is that Derby fails to drop a statistics entry for a foreign key
+     * constraint, leaving an orphaned and outdated entry behind.
+     *
+     * @param oldVersion the old derbyVersion used in the test
+     * @return {@code true} if the old version has the bug.
+     */
+    public static boolean hasDerby5681Bug(DerbyVersion oldVersion) {
+        if (oldVersion.atLeast(DerbyVersion._10_9)) {
+            return false;
+        }
+
+        // Here we have to check the versions within each branch back to 10.5
+        // (the test isn't run for older versions).
+        if (oldVersion.atMajorMinor(10, 8)) {
+            return !oldVersion.greaterThan(DerbyVersion._10_8_2_2);
+        }
+        if (oldVersion.atMajorMinor(10, 7)) {
+            return !oldVersion.greaterThan(DerbyVersion._10_7_1_1);
+        }
+        if (oldVersion.atMajorMinor(10, 6)) {
+            return !oldVersion.greaterThan(DerbyVersion._10_6_2_1);
+        }
+        if (oldVersion.atMajorMinor(10, 5)) {
+            return !oldVersion.greaterThan(DerbyVersion._10_5_3_0);
+        }
+        throw new IllegalStateException(
+                "didn't expect to get here, old version is " + oldVersion);
+    }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyVersion.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyVersion.java?rev=1441923&r1=1441922&r2=1441923&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyVersion.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyVersion.java Sun Feb
 3 14:56:40 2013
@@ -40,6 +40,7 @@ public class DerbyVersion
     public static final DerbyVersion _10_6     = new DerbyVersion(10,6,0,0);
     public static final DerbyVersion _10_7     = new DerbyVersion(10,7,0,0);
     public static final DerbyVersion _10_8     = new DerbyVersion(10,8,0,0);
+    public static final DerbyVersion _10_9     = new DerbyVersion(10,9,0,0);
 
     // A list of all known official Derby releases.
 
@@ -77,6 +78,10 @@ public class DerbyVersion
     public static final DerbyVersion _10_8_1_2 = new DerbyVersion(10,8,1,2);
     /** 10.8.2.2 (October 24, 2011/ SVN 1181258) */
     public static final DerbyVersion _10_8_2_2 = new DerbyVersion(10,8,2,2);
+    /** 10.8.3.0 (November 16, 2012/ SVN 1405108) */
+    public static final DerbyVersion _10_8_3_0 = new DerbyVersion(10,8,3,0);
+    /** 10.9.1.0 (June 25, 2012/ SVN 1344872) */
+    public static final DerbyVersion _10_9_1_0 = new DerbyVersion(10,9,1,0);
 
     private final int major;
     private final int minor;



Mime
View raw message