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 2011/03/29 11:24:22 UTC
svn commit: r1086527 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/execute/
testing/org/apache/derbyTesting/functionTests/tests/memory/
Author: kahatlen
Date: Tue Mar 29 09:24:22 2011
New Revision: 1086527
URL: http://svn.apache.org/viewvc?rev=1086527&view=rev
Log:
DERBY-3009: Out of memory error when creating a very large table
Clear the local state in AlterTableConstantAction after invocation so
that the memory held in the table descriptors can be freed.
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/Derby3009Test.java (with props)
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java?rev=1086527&r1=1086526&r2=1086527&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java Tue Mar 29 09:24:22 2011
@@ -262,6 +262,22 @@ class AlterTableConstantAction extends D
// INTERFACE METHODS
+ /**
+ * Run this constant action.
+ *
+ * @param activation the activation in which to run the action
+ * @throws StandardException if an error happens during execution
+ * of the action
+ */
+ public void executeConstantAction(Activation activation)
+ throws StandardException {
+ try {
+ executeConstantActionBody(activation);
+ } finally {
+ clearState();
+ }
+ }
+
/**
* This is the guts of the Execution-time logic for ALTER TABLE.
*
@@ -269,7 +285,7 @@ class AlterTableConstantAction extends D
*
* @exception StandardException Thrown on failure
*/
- public void executeConstantAction(Activation activation)
+ private void executeConstantActionBody(Activation activation)
throws StandardException {
// Save references to the main structures we need.
this.activation = activation;
@@ -617,6 +633,23 @@ class AlterTableConstantAction extends D
}
}
+ /**
+ * Clear the state of this constant action.
+ */
+ private void clearState() {
+ // DERBY-3009: executeConstantAction() stores some of its state in
+ // instance variables instead of local variables for convenience.
+ // These variables should be cleared after the execution of the
+ // constant action has completed, so that the objects they reference
+ // can be garbage collected.
+ td = null;
+ lcc = null;
+ dd = null;
+ dm = null;
+ tc = null;
+ activation = null;
+ }
+
/**
* Update statistics of either all the indexes on the table or only one
* specific index depending on what user has requested.
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/Derby3009Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/Derby3009Test.java?rev=1086527&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/Derby3009Test.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/Derby3009Test.java Tue Mar 29 09:24:22 2011
@@ -0,0 +1,71 @@
+/*
+ * Derby - Class org.apache.derbyTesting.functionTests.tests.memory.Derby3009Test
+ *
+ * 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.derbyTesting.functionTests.tests.memory;
+
+import java.sql.SQLException;
+import java.sql.Statement;
+import junit.framework.Test;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Regression test for DERBY-3009 which caused OutOfMemoryError when creating
+ * many foreign key constraints on a table. Run the test with 16 MB heap to
+ * expose the problem.
+ */
+public class Derby3009Test extends BaseJDBCTestCase {
+ public Derby3009Test(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ // The OOME happened in the engine, so run this test in embedded mode.
+ return new CleanDatabaseTestSetup(
+ TestConfiguration.embeddedSuite(Derby3009Test.class));
+ }
+
+ public void testTableWithManyForeignKeys() throws SQLException {
+ Statement s = createStatement();
+
+ // Create 50 tables with 50 columns each (plus primary key column).
+ final int tables = 50;
+ final int columns = 50;
+ for (int i = 1; i <= tables; i++) {
+ StringBuffer sql = new StringBuffer("create table d3009_t");
+ sql.append(i);
+ sql.append("(id int primary key");
+ for (int j = 1; j <= columns; j++) {
+ sql.append(", x").append(j).append(" int");
+ }
+ sql.append(")");
+ s.execute(sql.toString());
+ }
+
+ // Now add many foreign key constraints to table 50. Used to cause an
+ // OutOfMemoryError before DERBY-3009.
+ for (int i = 1; i <= tables; i++) {
+ s.execute("alter table d3009_t50 add constraint d3009_fk" + i +
+ " foreign key(x" + i + ") references d3009_t" + i);
+ }
+ }
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/Derby3009Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java?rev=1086527&r1=1086526&r2=1086527&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java Tue Mar 29 09:24:22 2011
@@ -40,6 +40,7 @@ public class _Suite extends BaseJDBCTest
suite.addTest(ClobMemTest.suite());
suite.addTest(MultiByteClobTest.suite());
suite.addTest(RolesDependencyTest.suite());
+ suite.addTest(Derby3009Test.suite());
return suite;
}
}