Package org.apache.derby.iapi.store.access

Examples of org.apache.derby.iapi.store.access.ScanController


                ret_val = false;
            }
        }

        // index check - there should be no records left.
        ScanController empty_scan =
            tc.openScan(create_ret.index_conglomid, false,
                        0,
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE,
            (FormatableBitSet) null,
                        null, ScanController.NA,
                        null,
                        null, ScanController.NA);
        if (empty_scan.next())
      throw T_Fail.testFailMsg("t_005: there are still rows in table.");

        index_cc.checkConsistency();

        for (int i = 600; i >= 400; i -= 3)
        {
            ((SQLLongint)base_row[0]).setValue(1);
            ((SQLLongint)base_row[1]).setValue(i);

            base_cc.insertAndFetchLocation(base_row, rowloc);
            if (index_cc.insert(index_row.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");
        }

        index_cc.checkConsistency();

        tc.abort();

        // index check - there should be no records left.
        empty_scan =
            tc.openScan(create_ret.index_conglomid, false,
                        0,
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE,
            (FormatableBitSet) null,
                        null, ScanController.NA,
                        null,
                        null, ScanController.NA);
        if (empty_scan.next())
      throw T_Fail.testFailMsg("t_005: there are still rows in table.");


        REPORT("Ending t_005");
View Full Code Here


        index_cc.close();

        // open a new scan

        ScanController scan =
            tc.openScan(create_ret.index_conglomid, false,
                        0,
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE,
            (FormatableBitSet) null,
                        null, ScanController.NA,
                        null,
                        null, ScanController.NA);

        int numrows = 0;
        while (scan.next())
        {
            numrows++;

            scan.fetch(index_row_from_base_row.getRow());

            try
            {
                scan.fetchLocation(null);
                return(FAIL("t_006: scan.fetchLocation() succeeded"));
            }
            catch (StandardException e)
            {
            }

            try
            {
                RowLocation rowloc = scan.newRowLocationTemplate();
                return(FAIL("t_006: scan.newRowLocationTemplate() succeeded"));
            }
            catch (StandardException e)
            {
            }

            try
            {
                scan.replace(index_row_from_base_row.getRow(), (FormatableBitSet) null);
                return(FAIL("t_006: scan.replace() succeeded"));
            }
            catch (StandardException e)
            {
            }

        }

        // make sure that scan.next() continues to return false
        if (scan.next())
            return(FAIL("t_006: scan.next() returned true after false."));

        scan.close();

        if (numrows != 1)
        {
            return(FAIL("(t_scan) wrong number of rows. Expected " +
                   "1 row, but got " + numrows + "rows."));
View Full Code Here

        if (index_cc.insert(index_row.getRow()) != 0)
      throw T_Fail.testFailMsg("insert failed");

        // open a new scan

        ScanController scan =
            tc.openScan(create_ret.index_conglomid, false,
                        0,                       
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE,
            (FormatableBitSet) null,
                        null, ScanController.NA,
                        null,
                        null, ScanController.NA);

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(scan.next());

        scan.fetch(index_row.getRow());
        long key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 3);

        // insert 1
        ((SQLLongint)(index_row.getRow()[1])).setValue(1);
        base_cc.insertAndFetchLocation(base_row, row_loc);
        if (index_cc.insert(index_row.getRow()) != 0)
      throw T_Fail.testFailMsg("insert failed");

        // insert 2
        ((SQLLongint)(index_row.getRow()[1])).setValue(2);
        base_cc.insertAndFetchLocation(base_row, row_loc);
        if (index_cc.insert(index_row.getRow()) != 0)
      throw T_Fail.testFailMsg("insert failed");

        // current position should not have changed
        scan.fetch(index_row.getRow());
        key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 3);

        // next position should be 5
        if (SanityManager.DEBUG)
            SanityManager.ASSERT(scan.next());
        scan.fetch(index_row.getRow());
        key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 5);

        index_cc.close();
        scan.close();

        REPORT("Ending t_007");

        return(ret_val);
    }
View Full Code Here

      throw T_Fail.testFailMsg("insert failed");
        }

        // open a new scan

        ScanController scan =
            tc.openScan(create_ret.index_conglomid, false,
                        0,
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE,
            (FormatableBitSet) null,
                        null, ScanController.NA,
                        null,
                        null, ScanController.NA);

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(scan.next());

        scan.fetch(index_row.getRow());
        long key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 1000);

        // The following test works best if 5 rows fit on one page

        //for (int i = 1; i < 900; i++)
        for (int i = 0; i < 6; i++)
        {
            // insert i
            ((SQLLongint)base_row[1]).setValue(i);
            base_cc.insertAndFetchLocation(base_row, base_rowloc);

            if (index_cc.insert(index_row_from_base_row.getRow()) != 0)
            {
                throw T_Fail.testFailMsg("insert failed");
            }

            // About every 2nd split page, recheck the position
           
            if (i % 10 == 0)
            {
                // current position should not have changed
                scan.fetch(index_row.getRow());
                key = ((SQLLongint)(index_row.getRow()[1])).getLong();
                if (SanityManager.DEBUG)
                    SanityManager.ASSERT(key == 1000);
            }

        }

        // insert 3000
        ((SQLLongint)base_row[1]).setValue(3000);
        base_cc.insertAndFetchLocation(base_row, base_rowloc);
        if (index_cc.insert(index_row_from_base_row.getRow()) != 0)
        {
      throw T_Fail.testFailMsg("insert failed");
        }

        // current position should not have changed
        scan.fetch(index_row.getRow());
        key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 1000);

        // next position should be 3000
        if (SanityManager.DEBUG)
            SanityManager.ASSERT(scan.next());
        scan.fetch(index_row.getRow());
        key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 3000);

        index_cc.checkConsistency();

        index_cc.close();
        scan.close();

        REPORT("Ending t_008");

        return(ret_val);
    }
View Full Code Here

   * @exception  T_Fail  Throws T_Fail on any test failure.
     **/
    protected boolean t_009(TransactionController tc)
        throws StandardException, T_Fail
    {
        ScanController scan         = null;

        REPORT("Starting t_009");

        // NON-UNIQUE INDEX
        T_CreateConglomRet create_ret = new T_CreateConglomRet();
View Full Code Here

   * @exception  T_Fail  Throws T_Fail on any test failure.
     **/
    protected boolean t_013(TransactionController tc)
        throws StandardException, T_Fail
    {
        ScanController scan         = null;

        // SanityManager.DEBUG_SET("LockTrace");

        REPORT("Starting t_013");

        T_CreateConglomRet create_ret = new T_CreateConglomRet();

        // Create the btree so that it only allows 2 rows per page.
        createCongloms(tc, 2, true, false, 5, create_ret);

        // Open the base table
        ConglomerateController base_cc =
            tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Open the secondary index
    ConglomerateController index_cc = 
            tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Create an index row object for the "delete row"
    DataValueDescriptor[]         r1     = TemplateRow.newU8Row(2);
        T_SecondaryIndexRow     index_row1   = new T_SecondaryIndexRow();
        RowLocation             base_rowloc1 = base_cc.newRowLocationTemplate();

        index_row1.init(r1, base_rowloc1, 3);

        // Create another index row object for the other inserts.
    DataValueDescriptor[]         r2              =  TemplateRow.newU8Row(2);
        T_SecondaryIndexRow index_row2      = new T_SecondaryIndexRow();
        RowLocation         base_rowloc2    = base_cc.newRowLocationTemplate();

        index_row2.init(r2, base_rowloc2, 3);

        // Commit the create of the tables so that the following aborts don't
        // undo that work.
        tc.commit();

        // CASE 1:
        tc.commit();

        // Open the base table
        base_cc = tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        // Open the secondary index
        index_cc =  tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        ((SQLLongint)r1[0]).setValue(1);

        // insert row which will be deleted (key = 100, base_rowloc1):
        ((SQLLongint)r1[1]).setValue(100);
        base_cc.insertAndFetchLocation(r1, base_rowloc1);

        // Insert the row into the secondary index.
        if (index_cc.insert(index_row1.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");

        // insert enough rows so that the logical undo of the insert will
        // need to search the tree.  The tree has been set to split after
        // 5 rows are on a page, so 10 should be plenty.
        for (int i = 0; i < 10; i++)
        {
            ((SQLLongint)r2[1]).setValue(i);

            // Insert the row into the base table;remember its location.
            base_cc.insertAndFetchLocation(r2, base_rowloc2);

            // Insert the row into the secondary index.
            if (index_cc.insert(index_row2.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");
        }

        // delete row which was inserted (key = 100, base_rowloc1):
        if (!t_delete(tc, create_ret.index_conglomid,
                index_row1.getRow(), create_ret.index_template_row))
        {
            throw T_Fail.testFailMsg(
                "t_008: could not delete key.");
        }
        base_cc.delete(base_rowloc1);

        // insert enough rows so that the logical undo of the delete will
        // need to search the tree.  The tree has been set to split after
        // 5 rows are on a page, so 10 should be plenty.
        for (int i = 10; i < 20; i++)
        {
            ((SQLLongint)r2[1]).setValue(i);

            // Insert the row into the base table;remember its location.
            base_cc.insertAndFetchLocation(r2, base_rowloc2);

            // Insert the row into the secondary index.
            if (index_cc.insert(index_row2.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");
        }

        // insert row which will be deleted (key = 100, base_rowloc1):
        ((SQLLongint)r1[1]).setValue(100);
        base_cc.insertAndFetchLocation(r1, base_rowloc1);

        // Insert the row into the secondary index.
        if (index_cc.insert(index_row1.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");

        // insert enough rows so that the logical undo of the update field will
        // need to search the tree.  The tree has been set to split after
        // 5 rows are on a page, so 10 should be plenty.
        for (int i = 20; i < 30; i++)
        {
            ((SQLLongint)r2[1]).setValue(i);

            // Insert the row into the base table;remember its location.
            base_cc.insertAndFetchLocation(r2, base_rowloc2);

            // Insert the row into the secondary index.
            if (index_cc.insert(index_row2.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");
        }

        // RESOLVE (mikem) - check that the right row is at key 100.
       

        tc.abort();

        // index check - there should be no records left.
        ScanController empty_scan =
            tc.openScan(create_ret.index_conglomid, false,
                        0,
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE,
            (FormatableBitSet) null,
                        null, ScanController.NA,
                        null,
                        null, ScanController.NA);

        if (empty_scan.next())
            throw T_Fail.testFailMsg("t_002: there are still rows in table.");

        tc.commit();
        REPORT("Ending t_013");

View Full Code Here

   * @exception  T_Fail  Throws T_Fail on any test failure.
     **/
    protected boolean t_014(TransactionController tc)
        throws StandardException, T_Fail
    {
        ScanController scan         = null;

        // SanityManager.DEBUG_SET("LockTrace");

        REPORT("Starting t_014");

View Full Code Here

   * @exception  T_Fail  Throws T_Fail on any test failure.
     **/
    protected boolean t_015(TransactionController tc)
        throws StandardException, T_Fail
    {
        ScanController scan         = null;

        // SanityManager.DEBUG_SET("LockTrace");

        REPORT("Starting t_015");

        T_CreateConglomRet create_ret = new T_CreateConglomRet();

        // Create the btree so that it only allows 2 rows per page.
        createCongloms(tc, 2, false, false, 2, create_ret);

        // Open the base table
        ConglomerateController base_cc =
            tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Open the secondary index
    ConglomerateController index_cc = 
            tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        if (!(index_cc instanceof B2IController))
        {
      throw T_Fail.testFailMsg("openConglomerate returned wrong type");
        }

        index_cc.checkConsistency();

    // Create a row and insert into base table, remembering it's location.
    DataValueDescriptor[] r1           = TemplateRow.newU8Row(2);
        T_SecondaryIndexRow   index_row1   = new T_SecondaryIndexRow();
        RowLocation           base_rowloc1 = base_cc.newRowLocationTemplate();

        index_row1.init(r1, base_rowloc1, 3);

        // Commit the create of the tables so that the following aborts don't
        // undo that work.
        tc.commit();

        // Now load up the table with multiple pages of data.

        // Open the base table
        base_cc =
            tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        // Open the secondary index
        index_cc = 
            tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        // now insert enough rows to cause failure
        for (int i = 100; i > 0; i -= 2)
        {
            ((SQLLongint)r1[0]).setValue(2);
            ((SQLLongint)r1[1]).setValue(i);

            // Insert the row into the base table;remember its location.
            base_cc.insertAndFetchLocation(r1, base_rowloc1);

            // Insert the row into the secondary index.
            if (index_cc.insert(index_row1.getRow()) != 0)
            {
                throw T_Fail.testFailMsg("insert failed");
            }
        }

        // Now try simulated lock wait/latch release paths through the code.
        String[] latch_debug_strings = {
            "B2iRowLocking3_1_lockScanRow1",
            "B2iRowLocking3_2_lockScanRow1",
            "B2iRowLocking3_3_lockScanRow1",
            "BTreeScan_positionAtStartPosition1",
            "BTreeScan_positionAtNextPage1",
            // "BTreeScan_reposition1",
            "BTreeScan_fetchNextGroup1",
        };

        for (int errs = 0; errs < latch_debug_strings.length; errs++)
        {
            REPORT("Doing latch release tests: " + latch_debug_strings[errs]);

            // set the debug flag, which will cause a simulated lock wait
            // latch release path through the code.
            if (SanityManager.DEBUG)
                SanityManager.DEBUG_SET(latch_debug_strings[errs]);

            // Just scan the rows and make sure you see them all, mostly just
            // a test to make sure no errors are thrown by the latch release
            // code paths.
            scan = tc.openScan(create_ret.index_conglomid, false,
                    0,
                    TransactionController.MODE_RECORD,
                    TransactionController.ISOLATION_SERIALIZABLE,
                    (FormatableBitSet) null,
                    null, ScanController.NA,
                    null,
                    null, ScanController.NA);

            int row_count = 0;
            while (scan.next())
            {
                row_count++;
            }

            scan.close();

            if (row_count != 50)
                throw T_Fail.testFailMsg("wrong scan count = " + row_count);
        }

View Full Code Here

   * @exception  T_Fail  Throws T_Fail on any test failure.
     **/
    protected boolean t_016(TransactionController tc)
        throws StandardException, T_Fail
    {
        ScanController scan         = null;

        // SanityManager.DEBUG_SET("LockTrace");

        REPORT("Starting t_016");

        T_CreateConglomRet create_ret = new T_CreateConglomRet();

        // Create the btree so that it only allows 2 rows per page.
        createCongloms(tc, 2, false, false, 2, create_ret);

        // Open the base table
        ConglomerateController base_cc =
            tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Open the secondary index
    ConglomerateController index_cc = 
            tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        if (!(index_cc instanceof B2IController))
        {
      throw T_Fail.testFailMsg("openConglomerate returned wrong type");
        }

        index_cc.checkConsistency();

    // Create a row and insert into base table, remembering it's location.
    DataValueDescriptor[] r1            = TemplateRow.newU8Row(2);
        T_SecondaryIndexRow   index_row1    = new T_SecondaryIndexRow();
        RowLocation           base_rowloc1  = base_cc.newRowLocationTemplate();

        index_row1.init(r1, base_rowloc1, 3);

        // Commit the create of the tables so that the following aborts don't
        // undo that work.
        tc.commit();

        // Open the base table
        base_cc =
            tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        // Open the secondary index
        index_cc = 
            tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        // now insert enough rows to cause failure
        for (int i = 100; i > 0; i -= 2)
        {
            ((SQLLongint)r1[0]).setValue(2);
            ((SQLLongint)r1[1]).setValue(i);

            // Insert the row into the base table;remember its location.
            base_cc.insertAndFetchLocation(r1, base_rowloc1);

            // Insert the row into the secondary index.
            if (index_cc.insert(index_row1.getRow()) != 0)
            {
                throw T_Fail.testFailMsg("insert failed");
            }
        }

        tc.abort();

        // Now try simulated deadlocks
        // RESOLVE (Mikem) - test out aborts and errors during inserts.
        String[] deadlock_debug_strings = {
            "B2iRowLocking3_1_lockScanRow2",
            "B2iRowLocking3_2_lockScanRow2",
            "B2iRowLocking3_3_lockScanRow2",
            // "BTreeController_doIns2",
            "BTreeScan_positionAtStartPosition2",
            "BTreeScan_positionAtNextPage2",
            // "BTreeScan_reposition2",
            "BTreeScan_fetchNextGroup2"
        };

        for (int errs = 0; errs < deadlock_debug_strings.length; errs++)
        {
            try
            {
                REPORT("Doing deadlock tests: " + deadlock_debug_strings[errs]);

                // set the debug flag, which will cause a simulated lock wait
                // latch release path through the code.
                if (SanityManager.DEBUG)
                    SanityManager.DEBUG_SET(deadlock_debug_strings[errs]);

                // Just scan the rows and make sure you see them all, mostly just
                // a test to make sure no errors are thrown by the latch release
                // code paths.
                scan = tc.openScan(create_ret.index_conglomid, false,
                        0,
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE,
                        (FormatableBitSet) null,
                        null, ScanController.NA,
                        null,
                        null, ScanController.NA);

                int row_count = 0;
                while (scan.next())
                {
                    row_count++;
                }

                scan.close();

                throw T_Fail.testFailMsg("expected deadlock");
            }
            catch (StandardException e)
            {
View Full Code Here

                throw T_Fail.testFailMsg("insert failed");

            // now delete the row.
            base_cc.delete(row_loc);

            ScanController delete_scan =
                tc.openScan(index_conglomid, false,
                            TransactionController.OPENMODE_FORUPDATE,
                            TransactionController.MODE_RECORD,
                            TransactionController.ISOLATION_SERIALIZABLE,
                            (FormatableBitSet) null,
                            template.getRow(), ScanController.GE,
                            null,
                            template.getRow(), ScanController.GT);

            if (!delete_scan.next())
            {
                throw T_Fail.testFailMsg("delete could not find key");
            }
            else
            {
                delete_scan.delete();

                if (delete_scan.next())
                    throw T_Fail.testFailMsg("delete found more than one key");
            }

            delete_scan.close();
        }

        ret_val = t_desc_scan_test_cases(tc, index_conglomid, template);

View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.store.access.ScanController

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.