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 km...@apache.org on 2009/02/12 21:16:33 UTC

svn commit: r743864 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/impl/store/raw/data/ testing/org/apache/derbyTesting/functionTests/tests/store/ testing/org/apache/derbyTesting/junit/

Author: kmarsden
Date: Thu Feb 12 20:16:33 2009
New Revision: 743864

URL: http://svn.apache.org/viewvc?rev=743864&view=rev
Log:
DERBY-4050 Multithreaded clob update causes growth in table that does not get reclaimed

merge 743799 from 10.4


Added:
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/store/ClobReclamationTest.java
      - copied unchanged from r743799, db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/store/ClobReclamationTest.java
Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/store/raw/data/ReclaimSpaceHelper.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/store/raw/data/ReclaimSpaceHelper.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/store/raw/data/ReclaimSpaceHelper.java?rev=743864&r1=743863&r2=743864&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/store/raw/data/ReclaimSpaceHelper.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/store/raw/data/ReclaimSpaceHelper.java Thu Feb 12 20:16:33 2009
@@ -259,9 +259,28 @@
             }
 
 			if (work.incrAttempts() < 3) // retry this for serveral times
+            {
 				return Serviceable.REQUEUE;
+            }
 			else
+            {
+                // If code gets here, the space will be lost forever, and
+                // can only be reclaimed by a full offline compress of the
+                // table/index.
+
+                if (SanityManager.DEBUG)
+                {
+                    if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace))
+                    {
+                        SanityManager.DEBUG(
+                            DaemonService.DaemonTrace, 
+                            "  gave up after 3 tries to get container lock " + 
+                            work);
+                    }
+                }
+
 				return Serviceable.DONE;
+            }
 		}	
 
 		// At this point, container is opened with IX lock.
@@ -281,8 +300,8 @@
 			return Serviceable.DONE;
 		}
 
-		// We are reclaiming row space or long column.  First get an xlock on the
-		// head row piece.
+		// We are reclaiming row space or long column.  
+		// First get an xlock on the head row piece.
 		RecordHandle headRecord = work.getHeadRowHandle();
 
 		if (!container_rlock.lockRecordForWrite(
@@ -291,9 +310,27 @@
 			// cannot get the row lock, retry
 			tran.abort();
 			if (work.incrAttempts() < 3)
+            {
 				return Serviceable.REQUEUE;
+            }
 			else
+            {
+                // If code gets here, the space will be lost forever, and
+                // can only be reclaimed by a full offline compress of the
+                // table/index.
+
+                if (SanityManager.DEBUG)
+                {
+                    if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace))
+                    {
+                        SanityManager.DEBUG(
+                            DaemonService.DaemonTrace, 
+                            "  gave up after 3 tries to get row lock " + 
+                            work);
+                    }
+                }
 				return Serviceable.DONE;
+            }
 		}
 
 		// The exclusive lock on the head row has been gotten.
@@ -332,19 +369,33 @@
 			// operation.  
 			// 
 			long headPageId = ((PageKey)headRecord.getPageId()).getPageNumber();
+			//DERBY-4050 - we wait for the page so we don't have to retry.
+			// prior to the 4050 fix, we called getPageNoWait and just 
+			// retried 3 times.  This left unreclaimed space if we were 
+			// not successful after three tries.
 			StoredPage headRowPage = 
-				(StoredPage)containerHdl.getPageNoWait(headPageId);
-
+				(StoredPage)containerHdl.getPage(headPageId);
 			if (headRowPage == null)
 			{
-				// Cannot get page no wait, try again later.
+				// It is not clear why headRowPage would be null,
+				// but logging the failure in case it happens.
+				// If code gets here, the space will be lost forever, and
+				// can only be reclaimed by a full offline compress of the
+				// table/index.
+
+				if (SanityManager.DEBUG)
+				{
+					if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace))
+					{
+						SanityManager.DEBUG(
+								DaemonService.DaemonTrace, 
+								"gave up because hadRowPage was null" + 
+								work);
+					}
+				}
 				tran.abort();
-				if (work.incrAttempts() < 3)
-					return Serviceable.REQUEUE;
-				else
-					return Serviceable.DONE;
+				return Serviceable.DONE;
 			}
-
 			try
 			{
 				headRowPage.removeOrphanedColumnChain(work, containerHdl);

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java?rev=743864&r1=743863&r2=743864&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java Thu Feb 12 20:16:33 2009
@@ -56,6 +56,7 @@
         suite.addTest(Derby3625Test.suite());
         suite.addTest(PositionedStoreStreamTest.suite());
         suite.addTest(OfflineBackupTest.suite());
+        suite.addTest(ClobReclamationTest.suite());
         // Encryption only supported for Derby in J2SE/J2EE environments.
         // J2ME (JSR169) does not support encryption.
         if (JDBC.vmSupportsJDBC3()) {

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java?rev=743864&r1=743863&r2=743864&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java Thu Feb 12 20:16:33 2009
@@ -36,6 +36,7 @@
 	
 	protected Properties newValues;
 	private Properties oldValues;
+	private boolean staticProperties;
 	
 	/**
 	 * Create a test decorator that sets and restores the passed
@@ -45,14 +46,31 @@
 	 * @param newValues properties to be set
 	 */
 	public SystemPropertyTestSetup(Test test,
-			Properties newValues)
+			Properties newValues,
+			boolean staticProperties)
 	{
 		super(test);
 		this.newValues = newValues;
 		this.oldValues = new Properties();
+		this.staticProperties = staticProperties;
 	}
 
 	/**
+	 * Create a test decorator that sets and restores 
+	 * System properties.  Do not shutdown engine after
+	 * setting properties
+	 * @param test
+	 * @param newValues
+	 */
+	public SystemPropertyTestSetup(Test test,
+			Properties newValues)
+	{
+		super(test);
+		this.newValues = newValues;
+		this.oldValues = new Properties();
+		this.staticProperties = false;
+	}
+	/**
 	 * For each property store the current value and
 	 * replace it with the new value, unless there is no change.
 	 */
@@ -60,6 +78,9 @@
     throws java.lang.Exception
     {
     	setProperties(newValues);
+    	// shutdown engine so static properties take effect
+    	if (staticProperties)
+    		TestConfiguration.getCurrent().shutdownEngine();
     }
 
     /**
@@ -78,6 +99,9 @@
        	}
     	// and then reset nay old values
     	setProperties(oldValues);
+    	// shutdown engine to restore any static properties
+    	if (staticProperties)
+    		TestConfiguration.getCurrent().shutdownEngine();
         newValues = null;
         oldValues = null;
     }