db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sure...@apache.org
Subject svn commit: r484797 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/services/io/ engine/org/apache/derby/iapi/store/raw/ engine/org/apache/derby/iapi/store/raw/xact/ engine/org/apache/derby/impl/store/raw/data/ engine/org/apache/derby/impl...
Date Fri, 08 Dec 2006 21:42:16 GMT
Author: suresht
Date: Fri Dec  8 13:42:14 2006
New Revision: 484797

URL: http://svn.apache.org/viewvc?view=rev&rev=484797
Log:
DERBY-606 : SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE fails on (very) large tables

Patch Contributed by Mayuresh Nirhali.

Problem was when Allocated Extent associated with last allocated page is being
compressed, All the pages are found to be free, thus new_highest_page is set to
'-1'. Now, when the CompressSpaceOperation is being logged
CompressedNumber.writeInt method is called with value -1. This method is
written to throw exception if the value is less than Zero, hence the 
IOException occurs. 

This patch addresses the problem  by modifying compress 
log record to write the new Highest Page as an uncompressed number, 
if the database is created/hard-upgrade to 10.3. A new Compress Log 
Record Class is created that will read/write new_highest_page in compressed 
format as before 10.3. Old version of compress log Operation is used on 
recovery, if  the log record needs to be replayed on upgrade 
from old-version of the database and also on soft-upgrade to 10.3. 

Test cases for this bug are  added to the existing OnlineCompressTest.java
test and to the upgrade test .



Added:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/CompressSpacePageOperation10_2.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/xact/RawTransaction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/AllocPage.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/CompressSpacePageOperation.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/LoggableAllocActions.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/Xact.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/OnlineCompressTest.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/Upgrade_10_1_10_3.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineCompressTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeTester.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
Fri Dec  8 13:42:14 2006
@@ -515,7 +515,7 @@
         /* 451 */   "org.apache.derby.catalog.types.RoutineAliasInfo",
 		/* 452 */   null,
 		/* 453 */   "org.apache.derby.impl.store.raw.log.ChecksumOperation",
-		/* 454 */   "org.apache.derby.impl.store.raw.data.CompressSpacePageOperation",
+		/* 454 */   "org.apache.derby.impl.store.raw.data.CompressSpacePageOperation10_2",
 		/* 455 */   "org.apache.derby.catalog.types.SynonymAliasInfo",
         /* 456 */   "org.apache.derby.iapi.types.DTSClassInfo", //InstanceGetter, XML_TYPE_ID
         /* 457 */   "org.apache.derby.catalog.types.TypesImplInstanceGetter", // XML_TYPE_ID_IMPL
@@ -526,5 +526,6 @@
         /* 462 */   "org.apache.derby.impl.sql.catalog.CoreDDFinderClassInfo",
         /* 463 */   "org.apache.derby.impl.sql.catalog.CoreDDFinderClassInfo",
         /* 464 */   "org.apache.derby.iapi.types.SqlXmlUtil",        
+	/* 465 */   "org.apache.derby.impl.store.raw.data.CompressSpacePageOperation",
 };
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
Fri Dec  8 13:42:14 2006
@@ -1728,10 +1728,14 @@
         public static final int LOGOP_CHECKSUM =
                 (MIN_ID_2 + 453);
 
-		/* org.apache.derby.impl.store.raw.data.CompressSpacePageOperation */
-        public static final int LOGOP_COMPRESS_SPACE =
+		/* org.apache.derby.impl.store.raw.data.CompressSpacePageOperation10_2 */
+        public static final int LOGOP_COMPRESS10_2_SPACE =
                 (MIN_ID_2 + 454);
 
+	/* org.apache.derby.impl.store.raw.data.CompressSpacePageOperation */
+        public static final int LOGOP_COMPRESS_SPACE =
+                (MIN_ID_2 + 465);
+
    		/* org.apache.derby.impl.store.raw.data.EncryptContainerOperation */
         public static final int LOGOP_ENCRYPT_CONTAINER =
                 (MIN_ID_2 + 459);
@@ -1859,7 +1863,7 @@
          * Make sure this is updated when a new module is added
          */
         public static final int MAX_ID_2 =
-                (MIN_ID_2 + 464);
+                (MIN_ID_2 + 465);
 
         // DO NOT USE 4 BYTE IDS ANYMORE
         static public final int MAX_ID_4 =

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java Fri
Dec  8 13:42:14 2006
@@ -105,6 +105,9 @@
     /** Derby Store Minor Version (2) **/
 	public static final int DERBY_STORE_MINOR_VERSION_2    = 2;
 
+	/** Derby Store Minor Version (3) **/
+	public static final int DERBY_STORE_MINOR_VERSION_3    = 3;
+
 	/** Derby 10 Store Major version */
 	public static final int DERBY_STORE_MAJOR_VERSION_10   = 10;
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/xact/RawTransaction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/xact/RawTransaction.java?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/xact/RawTransaction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/xact/RawTransaction.java
Fri Dec  8 13:42:14 2006
@@ -32,6 +32,7 @@
 import org.apache.derby.iapi.store.raw.Transaction;
 import org.apache.derby.iapi.store.raw.GlobalTransactionId;
 import org.apache.derby.iapi.store.raw.log.LogInstant;
+import org.apache.derby.iapi.store.raw.log.LogFactory;
 import org.apache.derby.iapi.store.raw.data.RawContainerHandle;
 import org.apache.derby.iapi.error.StandardException;
 
@@ -83,6 +84,11 @@
 		Get the data factory to be used during this transaction.
 	*/
 	public abstract DataFactory getDataFactory();
+
+	/**	
+		Get the log factory to be used during this transaction.
+	*/
+	public abstract LogFactory getLogFactory();
 
 	/**
 		Get cache statistics for the specified cache

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/AllocPage.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/AllocPage.java?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/AllocPage.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/AllocPage.java Fri
Dec  8 13:42:14 2006
@@ -909,7 +909,9 @@
         {
 			SanityManager.ASSERT(isLatched(), "page is not latched");
             SanityManager.ASSERT(isLast(), "compress on non last alloc page.");
-            SanityManager.ASSERT(new_highest_page >= 0, "negative new high page.");
+	    //Derby-606. newHighestPage = -1, is a valid case as it means that 
+	    //all the pages in this extent can be compressed.
+            SanityManager.ASSERT(new_highest_page >= -1, "negative new high page.");
         }
 
 		logAction(instant);

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/CompressSpacePageOperation.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/CompressSpacePageOperation.java?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/CompressSpacePageOperation.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/CompressSpacePageOperation.java
Fri Dec  8 13:42:14 2006
@@ -50,7 +50,7 @@
 
 **/
 
-public final class CompressSpacePageOperation extends PhysicalPageOperation
+public class CompressSpacePageOperation extends PhysicalPageOperation
 {
     /**************************************************************************
      * Fields of the class
@@ -100,8 +100,11 @@
 	public void writeExternal(ObjectOutput out) throws IOException 
 	{
 		super.writeExternal(out);
-		CompressedNumber.writeInt(out, newHighestPage);
-		CompressedNumber.writeInt(out, num_pages_truncated);
+		if( !(this instanceof CompressSpacePageOperation10_2) )
+		{
+			out.writeInt(newHighestPage);
+			CompressedNumber.writeInt(out, num_pages_truncated);
+		}
 	}
 
 	/**
@@ -112,8 +115,11 @@
 		 throws IOException, ClassNotFoundException
 	{
 		super.readExternal(in);
-		newHighestPage      = CompressedNumber.readInt(in);
-		num_pages_truncated = CompressedNumber.readInt(in);
+		if( !(this instanceof CompressSpacePageOperation10_2) )
+		{
+			newHighestPage      = in.readInt();
+			num_pages_truncated = CompressedNumber.readInt(in);
+		}
 	}
 
 	/**

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/CompressSpacePageOperation10_2.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/CompressSpacePageOperation10_2.java?view=auto&rev=484797
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/CompressSpacePageOperation10_2.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/CompressSpacePageOperation10_2.java
Fri Dec  8 13:42:14 2006
@@ -0,0 +1,94 @@
+/*
+
+   Derby - Class org.apache.derby.impl.store.raw.data.CompressSpacePageOperation10_2
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.impl.store.raw.data;
+
+import org.apache.derby.impl.store.raw.data.CompressSpacePageOperation;
+import org.apache.derby.impl.store.raw.data.BasePage;
+
+import org.apache.derby.iapi.services.io.FormatIdUtil;
+import org.apache.derby.iapi.services.io.StoredFormatIds;
+
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.services.io.CompressedNumber;
+
+import java.io.OutputStream;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+import org.apache.derby.iapi.services.sanity.SanityManager;
+
+/**
+ * This class overrides the CompressSpacePageOperation class to write
+ * CompressSpaceOperation Log Records that do not support negative values
+ * for new_highest_page. No other changes are added to the superclass behavior.
+ * This class ensures backword compatibility for Soft upgrades. 
+ */
+public final class CompressSpacePageOperation10_2 extends CompressSpacePageOperation {
+    
+	/**************************************************************************
+	* Constructors for This class:
+	**************************************************************************
+	*/
+	public CompressSpacePageOperation10_2(
+		AllocPage   allocPage, 
+		int         highest_page, 
+		int         num_truncated)
+			throws StandardException
+	{
+		super(allocPage, highest_page, num_truncated);
+	}
+
+	// no-arg constructor, required by Formatable 
+	public CompressSpacePageOperation10_2() { super(); }
+
+	/**************************************************************************
+	* Public Methods of Formatable interface.
+	**************************************************************************
+	*/
+
+	public void writeExternal(ObjectOutput out) throws IOException 
+	{
+		super.writeExternal(out);
+		CompressedNumber.writeInt(out, newHighestPage);
+		CompressedNumber.writeInt(out, num_pages_truncated);
+	}
+
+	/**
+		@exception IOException error reading from log stream
+		@exception ClassNotFoundException cannot read object from input
+	*/
+	public void readExternal(ObjectInput in)
+		 throws IOException, ClassNotFoundException
+	{
+		super.readExternal(in);
+		newHighestPage      = CompressedNumber.readInt(in);
+		num_pages_truncated = CompressedNumber.readInt(in);
+	}
+
+	/**
+		Return my format identifier.
+	*/
+	public int getTypeFormatId() {
+		return StoredFormatIds.LOGOP_COMPRESS10_2_SPACE;
+	}
+
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/CompressSpacePageOperation10_2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/LoggableAllocActions.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/LoggableAllocActions.java?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/LoggableAllocActions.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/LoggableAllocActions.java
Fri Dec  8 13:42:14 2006
@@ -24,6 +24,7 @@
 import org.apache.derby.impl.store.raw.data.AllocationActions;
 import org.apache.derby.impl.store.raw.data.BasePage;
 
+import org.apache.derby.iapi.store.raw.RawStoreFactory;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.services.io.FormatIdUtil;
 
@@ -119,10 +120,23 @@
     int             num_pages_truncated)
         throws StandardException
     {
-		Loggable lop = 
-            new CompressSpacePageOperation(
-                (AllocPage)allocPage, new_highest_page, num_pages_truncated);
-        allocPage.preDirty();
+	Loggable lop = null;
+	
+	// Derby-606. As part of the fix for Derby-606, negative values can be written to
+	// CompressSpace operation Log Records. In order for this fix to be backword 
+	// compatible, we make sure that the implementation behaves the old way in soft
+	// upgrade mode, here. This is achieved by passing null to feature argument.
+	if( t.getLogFactory().checkVersion(RawStoreFactory.DERBY_STORE_MAJOR_VERSION_10,
+					RawStoreFactory.DERBY_STORE_MINOR_VERSION_3,
+					null) )
+	{
+		lop = new CompressSpacePageOperation(
+				(AllocPage)allocPage, new_highest_page, num_pages_truncated);
+	} else {
+		lop = new CompressSpacePageOperation10_2(
+				(AllocPage)allocPage, new_highest_page, num_pages_truncated);
+	}
+	allocPage.preDirty();
 
         t.logAndDo(lop);
     }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/Xact.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/Xact.java?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/Xact.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/Xact.java Fri Dec
 8 13:42:14 2006
@@ -308,6 +308,15 @@
 	public final DataFactory getDataFactory() {
 		return dataFactory;
 	}
+	
+	/**
+	 * JIRA-606. As a part of this fix, it was required that
+	 * LogFactory.checkVersion method to be exposed for any possible Version 
+	 * checks in the Transaction processing module.  
+	 */
+	public final LogFactory getLogFactory() {
+		return logFactory;
+	}
 
 	/**
 		Get cache statistics for the specified cache

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/OnlineCompressTest.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/OnlineCompressTest.out?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/OnlineCompressTest.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/OnlineCompressTest.out
Fri Dec  8 13:42:14 2006
@@ -78,3 +78,8 @@
 Executing test: begin test5: 10000 row test.
 Executing test: end test5: 10000 row test.
 Ending test: test5
+Beginning test: test6
+Executing test: no delete case complete.
+Executing test: delete all rows case succeeded.
+Executing test: end simple deleteAllRows,104000 row test.
+Ending test: test6

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/Upgrade_10_1_10_3.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/Upgrade_10_1_10_3.out?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/Upgrade_10_1_10_3.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/Upgrade_10_1_10_3.out
Fri Dec  8 13:42:14 2006
@@ -12,6 +12,7 @@
 complete caseCompilationSchema - passed true
 Test grant/revoke, Phase: CREATE; derby.database.sqlAuthorization=false
 complete caseGrantRevoke - passed true
+complete caseNegValueSupportedLogRecord - passed true
 Test metadata starting
 Union Result -- precision: 10 scale: 2 display size: 13 type name: DECIMAL
 dec(10,2) -- precision: 10 scale: 2 display size: 13 type name: DECIMAL
@@ -281,6 +282,7 @@
 ,SYS,SYSVIEWS,SYSTEM TABLE,
 ,SYSIBM,SYSDUMMY1,SYSTEM TABLE,
 ,APP,ALLTYPES,TABLE,
+,APP,CASE606,TABLE,
 ,APP,CT1,TABLE,
 ,APP,GR_TAB,TABLE,
 ,APP,INFLIGHT,TABLE,
@@ -297,6 +299,7 @@
 getTables() with TABLE_TYPE in ('VIEW','TABLE') :
 TABLE_CAT[VARCHAR],TABLE_SCHEM[VARCHAR],TABLE_NAME[VARCHAR],TABLE_TYPE[VARCHAR],REMARKS[VARCHAR]
 ,APP,ALLTYPES,TABLE,
+,APP,CASE606,TABLE,
 ,APP,CT1,TABLE,
 ,APP,GR_TAB,TABLE,
 ,APP,INFLIGHT,TABLE,
@@ -724,6 +727,7 @@
 complete caseCompilationSchema - passed true
 Test grant/revoke, Phase: SOFT UPGRADE; derby.database.sqlAuthorization=false
 complete caseGrantRevoke - passed true
+complete caseNegValueSupportedLogRecord - passed true
 Test metadata starting
 Union Result -- precision: 10 scale: 2 display size: 13 type name: DECIMAL
 dec(10,2) -- precision: 10 scale: 2 display size: 12 type name: DECIMAL
@@ -1079,6 +1083,7 @@
 ,SYS,SYSVIEWS,SYSTEM TABLE,,null,null,null,null,null
 ,SYSIBM,SYSDUMMY1,SYSTEM TABLE,,null,null,null,null,null
 ,APP,ALLTYPES,TABLE,,null,null,null,null,null
+,APP,CASE606,TABLE,,null,null,null,null,null
 ,APP,CT1,TABLE,,null,null,null,null,null
 ,APP,GR_TAB,TABLE,,null,null,null,null,null
 ,APP,INFLIGHT,TABLE,,null,null,null,null,null
@@ -1095,6 +1100,7 @@
 getTables() with TABLE_TYPE in ('VIEW','TABLE') :
 TABLE_CAT[VARCHAR],TABLE_SCHEM[VARCHAR],TABLE_NAME[VARCHAR],TABLE_TYPE[VARCHAR],REMARKS[VARCHAR],TYPE_CAT[VARCHAR],TYPE_SCHEM[VARCHAR],TYPE_NAME[VARCHAR],SELF_REFERENCING_COL_NAME[VARCHAR],REF_GENERATION[VARCHAR]
 ,APP,ALLTYPES,TABLE,,null,null,null,null,null
+,APP,CASE606,TABLE,,null,null,null,null,null
 ,APP,CT1,TABLE,,null,null,null,null,null
 ,APP,GR_TAB,TABLE,,null,null,null,null,null
 ,APP,INFLIGHT,TABLE,,null,null,null,null,null
@@ -1478,6 +1484,7 @@
 complete caseCompilationSchema - passed true
 Test grant/revoke, Phase: POST SOFT UPGRADE; derby.database.sqlAuthorization=false
 complete caseGrantRevoke - passed true
+complete caseNegValueSupportedLogRecord - passed true
 Test metadata starting
 Union Result -- precision: 10 scale: 2 display size: 13 type name: DECIMAL
 dec(10,2) -- precision: 10 scale: 2 display size: 13 type name: DECIMAL
@@ -1747,6 +1754,7 @@
 ,SYS,SYSVIEWS,SYSTEM TABLE,
 ,SYSIBM,SYSDUMMY1,SYSTEM TABLE,
 ,APP,ALLTYPES,TABLE,
+,APP,CASE606,TABLE,
 ,APP,CT1,TABLE,
 ,APP,GR_TAB,TABLE,
 ,APP,INFLIGHT,TABLE,
@@ -1763,6 +1771,7 @@
 getTables() with TABLE_TYPE in ('VIEW','TABLE') :
 TABLE_CAT[VARCHAR],TABLE_SCHEM[VARCHAR],TABLE_NAME[VARCHAR],TABLE_TYPE[VARCHAR],REMARKS[VARCHAR]
 ,APP,ALLTYPES,TABLE,
+,APP,CASE606,TABLE,
 ,APP,CT1,TABLE,
 ,APP,GR_TAB,TABLE,
 ,APP,INFLIGHT,TABLE,
@@ -2189,6 +2198,7 @@
 complete caseCompilationSchema - passed true
 Test grant/revoke, Phase: UPGRADE; derby.database.sqlAuthorization=false
 complete caseGrantRevoke - passed true
+complete caseNegValueSupportedLogRecord - passed true
 Expected exception during shutdown: Database 'wombat' shutdown.
 Test grant/revoke, Phase: UPGRADE; derby.database.sqlAuthorization=true
 complete caseGrantRevoke - passed true
@@ -2572,6 +2582,7 @@
 ,SYS,SYSVIEWS,SYSTEM TABLE,,null,null,null,null,null
 ,SYSIBM,SYSDUMMY1,SYSTEM TABLE,,null,null,null,null,null
 ,APP,ALLTYPES,TABLE,,null,null,null,null,null
+,APP,CASE606,TABLE,,null,null,null,null,null
 ,APP,CT1,TABLE,,null,null,null,null,null
 ,APP,GR_TAB,TABLE,,null,null,null,null,null
 ,APP,INFLIGHT,TABLE,,null,null,null,null,null
@@ -2588,6 +2599,7 @@
 getTables() with TABLE_TYPE in ('VIEW','TABLE') :
 TABLE_CAT[VARCHAR],TABLE_SCHEM[VARCHAR],TABLE_NAME[VARCHAR],TABLE_TYPE[VARCHAR],REMARKS[VARCHAR],TYPE_CAT[VARCHAR],TYPE_SCHEM[VARCHAR],TYPE_NAME[VARCHAR],SELF_REFERENCING_COL_NAME[VARCHAR],REF_GENERATION[VARCHAR]
 ,APP,ALLTYPES,TABLE,,null,null,null,null,null
+,APP,CASE606,TABLE,,null,null,null,null,null
 ,APP,CT1,TABLE,,null,null,null,null,null
 ,APP,GR_TAB,TABLE,,null,null,null,null,null
 ,APP,INFLIGHT,TABLE,,null,null,null,null,null

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineCompressTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineCompressTest.java?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineCompressTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineCompressTest.java
Fri Dec  8 13:42:14 2006
@@ -170,6 +170,147 @@
     }
 
     /**
+     * Create and load a table with large columns.
+     * <p>
+     * If create_table is set creates a test data table with indexes.
+     * Loads num_rows into the table.  This table defaults to 32k page size.
+     * <p>
+     *
+     *
+     * @param conn          Connection to use for sql execution.
+     * @param create_table  If true, create new table - otherwise load into
+     *                      existing table.
+     * @param tblname       table to use.
+     * @param num_rows      number of rows to add to the table.
+     * @param start_value   Starting number from which num_rows are inserted
+     * @exception  StandardException  Standard exception policy.
+     **/
+    protected void createAndLoadLargeTable(
+    Connection  conn,
+    boolean     create_table,
+    String      tblname,
+    int         num_rows,
+    int         start_value)
+        throws SQLException
+    {
+        if (create_table)
+        {
+            Statement s = conn.createStatement();
+
+	    // Derby-606. Note that this table is currently only used by Test6.
+	    // Test6 needs data be to spread over 2 AllocExtents
+	    // and this table schema is chosen so that the required scenario
+	    // is exposed in minimum test execution time.
+            s.execute(
+                "create table " + tblname + 
+                    "(keycol int, indcol1 int, indcol2 int, data1 char(24), data2 char(24),
data3 char(24)," +
+			    "data4 char(24), data5 char(24), data6 char(24), data7 char(24), data8 char(24),"
+ 
+			    "data9 char(24), data10 char(24), inddec1 decimal(8), indcol3 int, indcol4 int, data11
varchar(50))");
+            s.close();
+        }
+
+        PreparedStatement insert_stmt = 
+            conn.prepareStatement(
+                "insert into " + tblname + " values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?)");
+
+        char[]  data1_data = new char[24];
+        char[]  data2_data = new char[24];
+        char[]  data3_data = new char[24];
+        char[]  data4_data = new char[24];
+        char[]  data5_data = new char[24];
+        char[]  data6_data = new char[24];
+        char[]  data7_data = new char[24];
+        char[]  data8_data = new char[24];
+        char[]  data9_data = new char[24];
+        char[]  data10_data = new char[24];
+        char[]  data11_data = new char[50];
+
+        for (int i = 0; i < data1_data.length; i++) 
+	{
+            data1_data[i] = 'a';
+            data2_data[i] = 'b';
+            data3_data[i] = 'c';
+            data4_data[i] = 'd';
+            data5_data[i] = 'e';
+            data6_data[i] = 'f';
+            data7_data[i] = 'g';
+            data8_data[i] = 'h';
+            data9_data[i] = 'i';
+            data10_data[i] = 'j';
+	}
+	for( int i=0; i < data11_data.length; i++) 
+	{
+	    data11_data[i] = 'z';
+        }
+
+        String  data1_str = new String(data1_data);
+        String  data2_str = new String(data2_data);
+        String  data3_str = new String(data3_data);
+        String  data4_str = new String(data4_data);
+        String  data5_str = new String(data5_data);
+        String  data6_str = new String(data6_data);
+        String  data7_str = new String(data7_data);
+        String  data8_str = new String(data8_data);
+        String  data9_str = new String(data9_data);
+        String  data10_str = new String(data10_data);
+        String  data11_str = new String(data11_data);
+
+        int row_count = 0;
+        try
+        {
+            for (int i = start_value; row_count < num_rows; row_count++, i++)
+            {
+                insert_stmt.setInt(1, i);               // keycol
+                insert_stmt.setInt(2, i * 10);          // indcol1
+                insert_stmt.setInt(3, i * 100);         // indcol2
+                insert_stmt.setString(4, data1_str);    // data1_data
+                insert_stmt.setString(5, data2_str);    // data2_data
+                insert_stmt.setString(6, data3_str);    // data3_data
+                insert_stmt.setString(7, data4_str);    // data4_data
+                insert_stmt.setString(8, data5_str);    // data5_data
+                insert_stmt.setString(9, data6_str);    // data6_data
+                insert_stmt.setString(10, data7_str);    // data7_data
+                insert_stmt.setString(11, data8_str);    // data8_data
+                insert_stmt.setString(12, data9_str);    // data9_data
+                insert_stmt.setString(13, data10_str);    // data10_data
+                insert_stmt.setInt(14, i * 20);          // indcol3
+                insert_stmt.setInt(15, i * 200);         // indcol4
+		insert_stmt.setInt(16, i * 50);
+                insert_stmt.setString(17, data11_str);    // data11_data
+
+                insert_stmt.execute();
+            }
+        }
+        catch (SQLException sqle)
+        {
+            System.out.println(
+                "Exception while trying to insert row number: " + row_count);
+            throw sqle;
+        }
+
+        if (create_table)
+        {
+            Statement s = conn.createStatement();
+
+            s.execute(
+                "create index " + tblname + "_idx_keycol on " + tblname +
+                    "(keycol)");
+            s.execute(
+                "create index " + tblname + "_idx_indcol1 on " + tblname +
+                    "(indcol1)");
+            s.execute(
+                "create index " + tblname + "_idx_indcol2 on " + tblname +
+                    "(indcol2)");
+            s.execute(
+                "create unique index " + tblname + "_idx_indcol3 on " + tblname +
+                    "(indcol3)");
+            s.close();
+        }
+
+        conn.commit();
+    }
+
+    /**
      * Create and load a table with long columns and long rows.
      * <p>
      * If create_table is set creates a test data table with indexes.
@@ -1219,6 +1360,82 @@
         endTest(conn, test_name);
     }
 
+    /**
+     * Test 6 - Online compress test for table that spans more than 1 AllocExtent.
+     * <p>
+     * Create dataset with Data spread over more than 1 AllcExtent and then:
+     * delete enough rows so that the last AllocExtent is empty.
+     * Try OnlineCompress with Purge, Defragment and Truncate
+     * <p>
+     * run test with at least 103000 rows.
+     *
+     **/
+    private void test6(
+    Connection  conn,
+    String      test_name,
+    String      table_name)
+        throws SQLException 
+    {
+        beginTest(conn, test_name);
+
+        int[] noRows = {104000};
+
+        for (int i = 0; i < noRows.length; i++)
+        {
+            // first create new table and run the tests.
+            createAndLoadLargeTable(conn, true, table_name, noRows[i], 0);
+
+        if (verbose)
+            testProgress("Calling compress.");
+
+        // compress with no deletes should not affect size
+        int[] ret_before = getSpaceInfo(conn, "APP", table_name, true);
+        callCompress(conn, "APP", table_name, true, true, true, true);
+        int[] ret_after  = getSpaceInfo(conn, "APP", table_name, true);
+
+        if (ret_after[SPACE_INFO_NUM_ALLOC] != ret_before[SPACE_INFO_NUM_ALLOC])
+        {
+            log_wrong_count(
+                "Expected no alloc page change.", 
+                table_name, noRows[i], 
+                ret_before[SPACE_INFO_NUM_ALLOC], 
+                ret_after[SPACE_INFO_NUM_ALLOC],
+                ret_before, ret_after);
+        }
+
+        testProgress("no delete case complete.");
+
+        // delete all the rows.
+        ret_before = getSpaceInfo(conn, "APP", table_name, true);
+        executeQuery(conn, "delete from " + table_name, true);
+	conn.commit();
+
+        if (verbose)
+            testProgress("deleted all rows, now calling compress.");
+
+        callCompress(conn, "APP", table_name, true, true, true, true);
+        ret_after  = getSpaceInfo(conn, "APP", table_name, true);
+
+        // An empty table has 2 pages, one allocation page and the 1st page
+        // which will have a system row in it.  The space vti only reports
+        // a count of the user pages so the count is 1.
+        if (ret_after[SPACE_INFO_NUM_ALLOC] != 1)
+        {
+            log_wrong_count(
+                "Expected all pages to be truncated.",
+                table_name, noRows[i], 1, ret_after[SPACE_INFO_NUM_ALLOC],
+                ret_before, ret_after);
+        }
+
+        testProgress("delete all rows case succeeded.");
+
+        testProgress("end simple deleteAllRows," + noRows[i] + " row test.");
+
+            executeQuery(conn, "drop table " + table_name, true);
+        }
+
+        endTest(conn, test_name);
+    }
 
 
     public void testList(Connection conn)
@@ -1229,6 +1446,7 @@
         test3(conn, "test3", "TEST3");
         // test4(conn, "test4", "TEST4");
         test5(conn, "test5", "TEST5");
+	test6(conn, "test6", "TEST6");
     }
 
     public static void main(String[] argv) 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeTester.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeTester.java?view=diff&rev=484797&r1=484796&r2=484797
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeTester.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeTester.java
Fri Dec  8 13:42:14 2006
@@ -78,7 +78,12 @@
     <LI> Grant/Revoke tests
     </UL>
 	
-	
+    <BR>
+	10.3 Upgrade tests
+ 
+	<UL>
+	<LI> Log Record Format change to support negative value (DERBY-606)
+	</UL>
 	
  */
 public class UpgradeTester {
@@ -369,7 +374,8 @@
 			passed = caseCompilationSchema(phase, conn) && passed;
             passed = caseGrantRevoke(conn, phase, classLoader, false) && passed;
             // Test grant/revoke feature with sql authorization
-            if(phase == PH_HARD_UPGRADE) {
+			passed = caseNegValueSupportedLogRecord(conn, phase) && passed;
+		if(phase == PH_HARD_UPGRADE) {
             	setSQLAuthorization(conn, true);
             	conn = restartDatabase(classLoader);
             	passed = caseGrantRevoke(conn, phase, classLoader, true) && passed;
@@ -1001,7 +1007,121 @@
     	
     	return passed;
     }
-    
+     
+	/**
+	 * In 10.3: We will write a LogRecord with a different format 
+	 * that can also write negative values.
+	 * 
+	 * Verify here that a 10.2 Database does not malfunction from this and
+	 * 10.2 Databases will work with the old LogRecord format.
+	 */
+	private boolean caseNegValueSupportedLogRecord(Connection conn, int phase)
+		throws SQLException
+	{
+		boolean passed;
+		switch(phase) {
+		case PH_CREATE: {
+			// This case is derived from OnlineCompressTest.test6.
+			passed = false;
+			Statement s = conn.createStatement();
+			s.execute("create table case606(keycol int, indcol1 int,"+
+			    "indcol2 int, data1 char(24), data2 char(24), data3 char(24)," +
+			    "data4 char(24), data5 char(24), data6 char(24),"+
+			    "data7 char(24), data8 char(24), data9 char(24)," + 
+			    "data10 char(24), inddec1 decimal(8), indcol3 int,"+
+			    "indcol4 int, data11 varchar(50))");
+			passed = true;
+			break;
+		}
+		case PH_SOFT_UPGRADE:
+			passed = false;
+			// Ensure that the old Log Record format is written
+			// by Newer release without throwing any exceptions.
+			checkDataToCase606(conn, 0, 2000);
+			passed = true;
+			break;
+		case PH_POST_SOFT_UPGRADE: {
+			// We are now back to Old release
+			passed = false;
+			checkDataToCase606(conn, 0, 1000);
+			passed = true;
+			break;
+		}
+		case PH_HARD_UPGRADE:
+			// Create the Derby606 bug scenario and test that
+			// the error does not occur in Hard Upgrade
+			checkDataToCase606(conn, 0, 94000);
+			// passed If no exception thrown.
+			passed = true;
+			break;
+		default:
+			passed = false;
+			break;
+		}
+		System.out.println("complete caseNegValueSupportedLogRecord - passed " + passed);
+		return passed;
+	}
+
+	private void checkDataToCase606(Connection conn, int start_value, int end_value)
+		throws SQLException {
+		Statement s = conn.createStatement();
+		PreparedStatement insert_stmt = conn.prepareStatement(
+			"insert into case606 values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+		char[] data_dt = new char[24];
+		char[] data_dt2 = new char[50];
+		for( int i=0; i < data_dt.length; i++)
+			data_dt[i] = 'a';
+		for( int i=0; i < data_dt2.length; i++)
+			data_dt2[i] = 'z';
+		String data1_str = new String(data_dt);
+		String data2_str = new String(data_dt2);
+		try
+		{
+		    for (int i = start_value; i < end_value; i++)
+		    {
+			insert_stmt.setInt(1, i);               // keycol
+			insert_stmt.setInt(2, i * 10);          // indcol1
+			insert_stmt.setInt(3, i * 100);         // indcol2
+			insert_stmt.setString(4, data1_str);    // data1_data
+			insert_stmt.setString(5, data1_str);    // data2_data
+			insert_stmt.setString(6, data1_str);    // data3_data
+			insert_stmt.setString(7, data1_str);    // data4_data
+			insert_stmt.setString(8, data1_str);    // data5_data
+			insert_stmt.setString(9, data1_str);    // data6_data
+			insert_stmt.setString(10, data1_str);    // data7_data
+			insert_stmt.setString(11, data1_str);    // data8_data
+			insert_stmt.setString(12, data1_str);    // data9_data
+			insert_stmt.setString(13, data1_str);    // data10_data
+			insert_stmt.setInt(14, i * 20);          // indcol3
+			insert_stmt.setInt(15, i * 200);         // indcol4
+			insert_stmt.setInt(16, i * 50);
+			insert_stmt.setString(17, data2_str);    // data11_data
+
+			insert_stmt.execute();
+		    }
+		    conn.commit();
+
+		    s.execute("delete from case606 where case606.keycol > 10000");
+		    conn.commit();
+		}
+		catch (SQLException sqle)
+		{
+		    System.out.println(
+			"Exception while trying to update the database!");
+		    throw sqle;
+		}
+
+		try {
+			s.execute("call SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE('APP','CASE606',1,1,1)");
+			conn.commit();
+		}
+		catch (SQLException sqle)
+		{
+			System.out.println("Exception while CompressSpace Operation!");
+			throw sqle;
+		}
+	}
+   
     /**
      * Set derby.database.sqlAuthorization as a database property.
      * 



Mime
View raw message