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 mi...@apache.org on 2007/05/22 19:34:06 UTC

svn commit: r540657 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/store/access/heap/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/store/

Author: mikem
Date: Tue May 22 10:34:04 2007
New Revision: 540657

URL: http://svn.apache.org/viewvc?view=rev&rev=540657
Log:
DERBY-2549
contributed by Mayuresh Nirhali

Fix null pointer when running inplace compress.  Change code to correctly
handle when more than 100 rows are moved from a single page.  The new code
returns to the caller after processing the 100 rows, and the next trip 
through the loop picks up the scan where it left off on that same page.
Test case was added to existing test.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapCompressScan.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/OnlineCompressTest.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineCompressTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapCompressScan.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapCompressScan.java?view=diff&rev=540657&r1=540656&r2=540657
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapCompressScan.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapCompressScan.java Tue May 22 10:34:04 2007
@@ -102,6 +102,12 @@
         int                     ret_row_count           = 0;
         DataValueDescriptor[]   fetch_row               = null;
 
+        // only fetch maximum number of rows per "group" as the size of
+        // the array.  If more than one group is available on page, just
+        // leave the scan on the page and the next group will come from
+        // this page also.
+        int                     max_rowcnt = row_array.length;
+
         if (SanityManager.DEBUG)
         {
             SanityManager.ASSERT(row_array != null);
@@ -175,6 +181,7 @@
 			while ((scan_position.current_slot + 1) < 
                     scan_position.current_page.recordCount())
 			{
+
                 // Allocate a new row to read the row into.
                 if (fetch_row == null)
                 {
@@ -191,6 +198,7 @@
 
                 // move scan current position forward.
                 scan_position.positionAtNextSlot();
+                int restart_slot = scan_position.current_slot;
 
                 this.stat_numrows_visited++;
 
@@ -226,7 +234,7 @@
                             new_handle) == 1)
                     {
                         // raw store moved the row, so bump the row count but 
-                        // postion the scan at previous slot, so next trip
+                        // position the scan at previous slot, so next trip
                         // through loop will pick up correct row.
                         // The subsequent rows will have been moved forward
                         // to take place of moved row.
@@ -244,6 +252,24 @@
                         fetch_row = null;
 
                     }
+                }
+
+                // Derby-2549. If ret_row_count reaches the limit of the buffer,
+                // then return the maximum number and come back into the same 
+                // method to fetch the remaining rows. In this block we ensure
+                // that the scan_position is appropriate.
+                if (ret_row_count >= max_rowcnt)
+                {
+                    // filled group buffer, exit fetch loop and return to caller
+
+                    // save current scan position by record handle.
+                    scan_position.current_rh =
+                        scan_position.current_page.getRecordHandleAtSlot(
+                            restart_slot);
+
+                    scan_position.unlatch();
+
+                    return(ret_row_count);
                 }
 			}
 

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=540657&r1=540656&r2=540657
==============================================================================
--- 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 Tue May 22 10:34:04 2007
@@ -83,3 +83,6 @@
 Executing test: delete all rows case succeeded.
 Executing test: end simple deleteAllRows,104000 row test.
 Ending test: test6
+Beginning test: test7
+Executing test: delete rows case succeeded.
+Ending test: test7

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=540657&r1=540656&r2=540657
==============================================================================
--- 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 Tue May 22 10:34:04 2007
@@ -1407,7 +1407,7 @@
         // delete all the rows.
         ret_before = getSpaceInfo(conn, "APP", table_name, true);
         executeQuery(conn, "delete from " + table_name, true);
-	conn.commit();
+        conn.commit();
 
         if (verbose)
             testProgress("deleted all rows, now calling compress.");
@@ -1436,6 +1436,63 @@
         endTest(conn, test_name);
     }
 
+    /**
+     * Test 7 - Online compress test for fetching more rows than buffer limit.
+     * <p>
+     * For smaller row size, if number of rows per page is more than max buffer
+     * size, then check if the remaining rows are also fetched for Compress 
+     * Operation
+     * <p>
+     **/
+    private void test7(
+    Connection  conn,
+    String      test_name,
+    String      table_name)
+        throws SQLException 
+    {
+        beginTest(conn, test_name);
+
+        Statement s = conn.createStatement();
+
+        s.execute("create table " + table_name + "(keycol int)");
+        s.close();
+        PreparedStatement insert_stmt = 
+            conn.prepareStatement("insert into " + table_name + " values(?)");
+        try
+        {
+            for (int i = 0; i < 1200; i++)
+            {
+                insert_stmt.setInt(1, i);
+
+                insert_stmt.execute();
+            }
+        }
+        catch (SQLException sqle)
+        {
+            System.out.println(
+                "Exception while trying to insert a row");
+            throw sqle;
+        }
+        conn.commit();
+
+        // delete the front rows leaving the last 200.  Post commit may reclaim
+        // space on pages where all rows are deleted.  
+        executeQuery(
+            conn, "delete from " + table_name + " where keycol < 1000", true);
+
+        conn.commit();
+
+        if (verbose)
+            testProgress("deleted first 1000 rows, now calling compress.");
+
+        callCompress(conn, "APP", table_name, true, true, true, true);
+
+        testProgress("delete rows case succeeded.");
+
+        executeQuery(conn, "drop table " + table_name, true);
+
+        endTest(conn, test_name);
+    }
 
     public void testList(Connection conn)
         throws SQLException
@@ -1445,7 +1502,8 @@
         test3(conn, "test3", "TEST3");
         // test4(conn, "test4", "TEST4");
         test5(conn, "test5", "TEST5");
-	test6(conn, "test6", "TEST6");
+        test6(conn, "test6", "TEST6");
+        test7(conn, "test7", "TEST7");
     }
 
     public static void main(String[] argv)