Search in sources :

Example 66 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_CreateConglomRet method t_005.

/**
 * Test Branch splits - number of rows necessary to cause splits is raw
 * store implementation dependant (currently 5 rows per page in in-memory
 * implementation).
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_005(TransactionController tc) throws StandardException, T_Fail {
    boolean ret_val = true;
    REPORT("Starting t_005");
    T_CreateConglomRet create_ret = new T_CreateConglomRet();
    createCongloms(tc, 2, false, false, 0, create_ret);
    // Open the base conglomerate.
    ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Open the index conglomerate.
    ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a row.
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
    RowLocation rowloc = base_cc.newRowLocationTemplate();
    DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
    index_row.init(base_row, rowloc, 3);
    // insert them in reverse order just to make sure btree is sorting them
    for (int i = 200; i >= 0; i -= 4) {
        ((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");
    }
    for (int i = 199; i >= 0; i -= 4) {
        ((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();
    // Close the conglomerate.
    index_cc.close();
    tc.commit();
    // Search for each of the keys and delete them one at a time.
    DataValueDescriptor[] delete_key = TemplateRow.newU8Row(2);
    for (int i = 200; i >= 0; i -= 4) {
        ((SQLLongint) delete_key[0]).setValue(1);
        ((SQLLongint) delete_key[1]).setValue(i);
        if (!t_delete(tc, create_ret.index_conglomid, delete_key, false)) {
            ret_val = false;
        }
    }
    for (int i = 199; i >= 0; i -= 4) {
        ((SQLLongint) delete_key[0]).setValue(1);
        ((SQLLongint) delete_key[1]).setValue(i);
        if (!t_delete(tc, create_ret.index_conglomid, delete_key, false)) {
            ret_val = false;
        }
    }
    tc.commit();
    // Open the base conglomerate.
    base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Open the conglomerate.
    index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // flush and empty cache to make sure rereading stuff works.
    RawStoreFactory rawstore = (RawStoreFactory) findServiceModule(this.store_module, RawStoreFactory.MODULE);
    rawstore.idle();
    for (int i = 200; i >= 0; 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");
    }
    for (int i = 200; i >= 0; i -= 3) {
        ((SQLLongint) delete_key[0]).setValue(1);
        ((SQLLongint) delete_key[1]).setValue(i);
        if (!t_delete(tc, create_ret.index_conglomid, delete_key, false)) {
            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");
    return (ret_val);
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint) RawStoreFactory(org.apache.derby.iapi.store.raw.RawStoreFactory)

Example 67 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_CreateConglomRet method t_020.

/**
 * Test read uncommitted cases on scan.
 * <p>
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_020(TransactionController tc) throws StandardException, T_Fail {
    ScanController scan = null;
    REPORT("Starting t_020");
    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);
    // objects used to insert rows into base and index tables.
    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);
    // insert one row into the table/index
    // 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);
    // insert one row that does not cause failure.
    ((SQLLongint) r1[0]).setValue(2);
    ((SQLLongint) r1[1]).setValue(10000);
    // 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");
    // Commit the create of the tables so that the following aborts don't
    // undo that work.
    tc.commit();
    // TEST 1 - position a read uncommitted scan on a row which is
    // purged by a split trying to get space on the page, and then see
    // what happens when the scan trys to continue.  This can only happen
    // currently if the same transaction deletes the row and while having
    // the scan open also does inserts onto the same page.  Otherwise the
    // btree scan will maintain a "page scan locks" which will prevent
    // the row from being purged out from underneath it.
    tc.commit();
    REPORT("Ending t_020");
    return true;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 68 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_CreateConglomRet method t_011.

/**
 * Test Special cases of split.
 * <p>
 * Testing: restartSplitFor() call in LeafControlRow().
 *
 * The first case is where we split
 * down the tree and reach the leaf, pick a split point, and then find
 * that there is not enough room to insert row into parent branch page.
 *
 * The second case is the same as the first except the calling code is
 * trying to split a branch page and the parent branch page doesn't have
 * room for the row.
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_011(TransactionController tc) throws StandardException, T_Fail {
    boolean ret_val = true;
    REPORT("Starting t_011");
    T_CreateConglomRet create_ret = new T_CreateConglomRet();
    createCongloms(tc, 2, false, true, 0, create_ret);
    // Open the base conglomerate.
    ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Open the index conglomerate.
    ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a row.
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
    RowLocation rowloc = base_cc.newRowLocationTemplate();
    DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
    base_row[0] = new SQLChar("aaaaaaaaaa");
    index_row.init(base_row, rowloc, 3);
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("a", 1000));
    ((SQLLongint) base_row[1]).setValue(1);
    base_cc.insertAndFetchLocation(base_row, rowloc);
    // CAUSE LEAF splitFor to loop:
    // pick numbers so that split will happen in middle of page.  Do this
    // by first inserting last row in table and then insert smaller rows,
    // then insert rows before it until the table is just ready to split
    // the root, and finally insert some shorter rows in such a way as
    // they cause a split but the split point is chosen with one of the
    // larger rows as the descriminator causing 1st splitfor pass to fail
    // and loop back and do a splitFor the larger row.
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("m", 1000));
    {
        ((SQLLongint) base_row[1]).setValue(0);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    // insert enough rows to make a 2 level btree where if another row
    // with a 1000 byte string would cause a root split.
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("a", 1000));
    for (int i = 0; i < 5; i++) {
        ((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");
    }
    // insert a shorter leaf row, such that it will fit in the root, but
    // make the split point pick a longer row descriminator which won't
    // fit in the root page.
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("z", 500));
    for (int i = 10; i > 8; i--) {
        ((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();
    // Close the conglomerate.
    index_cc.close();
    tc.dropConglomerate(create_ret.index_conglomid);
    tc.dropConglomerate(create_ret.base_conglomid);
    tc.abort();
    REPORT("Ending t_011");
    return (ret_val);
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 69 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_CreateConglomRet method t_008.

/**
 * Test multiple scans in a single table/with splits
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_008(TransactionController tc) throws StandardException, T_Fail {
    boolean ret_val = true;
    REPORT("Starting t_008");
    T_CreateConglomRet create_ret = new T_CreateConglomRet();
    createCongloms(tc, 2, false, false, 0, create_ret);
    // Open the base conglomerate.
    ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Open the index conglomerate.
    ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a base row template.
    DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
    RowLocation base_rowloc = base_cc.newRowLocationTemplate();
    T_SecondaryIndexRow index_row_from_base_row = new T_SecondaryIndexRow();
    index_row_from_base_row.init(base_row, base_rowloc, 3);
    ((SQLLongint) base_row[0]).setValue(1);
    // Create a row.
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
    index_row.init(TemplateRow.newU8Row(2), base_cc.newRowLocationTemplate(), 3);
    // test: make sure scan position is right after inserts before scan
    // no split case.  In this case the slot position of the current
    // position should change, but the code will keep a record handle
    // and not need to reposition by key.
    // before keys: 1000, 3000
    // last key gotten froms scan : 0
    // insert keys:1-900
    // next key from scan should be: 5
    // insert 1000
    ((SQLLongint) base_row[1]).setValue(1000);
    base_cc.insertAndFetchLocation(base_row, base_rowloc);
    if (index_cc.insert(index_row_from_base_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 == 1000);
    // 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");
        }
        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);
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 70 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_CreateConglomRet method t_perf.

/**
 * Test simple btree insert performance
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_perf(TransactionController tc) throws StandardException, T_Fail {
    boolean ret_val = true;
    REPORT("Starting t_005");
    T_CreateConglomRet create_ret = new T_CreateConglomRet();
    createCongloms(tc, 2, false, false, 0, create_ret);
    // Open the base conglomerate.
    ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Open the index conglomerate.
    ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a row.
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
    RowLocation rowloc = base_cc.newRowLocationTemplate();
    DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
    index_row.init(base_row, rowloc, 3);
    ((SQLLongint) base_row[0]).setValue(1);
    ((SQLLongint) base_row[1]).setValue(1);
    base_cc.insertAndFetchLocation(base_row, rowloc);
    long startms = System.currentTimeMillis();
    // insert them in reverse order just to make sure btree is sorting them
    for (int i = 0; i < 2000; i++) {
        ((SQLLongint) base_row[1]).setValue(i);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    // ((B2IController)index_cc).printTree();
    tc.commit();
    long endms = System.currentTimeMillis();
    long elapsedms = endms - startms;
    System.out.println("  Elapsed (ms)      " + elapsedms);
    System.out.println("  inserts/second " + (1000 * 1000 / elapsedms));
    // Close the conglomerate.
    index_cc.close();
    REPORT("Ending t_011");
    return (ret_val);
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Aggregations

RowLocation (org.apache.derby.iapi.types.RowLocation)89 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)54 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)40 SQLLongint (org.apache.derby.iapi.types.SQLLongint)35 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)32 ScanController (org.apache.derby.iapi.store.access.ScanController)29 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)27 Properties (java.util.Properties)16 SQLInteger (org.apache.derby.iapi.types.SQLInteger)13 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)12 StandardException (org.apache.derby.shared.common.error.StandardException)11 SQLChar (org.apache.derby.iapi.types.SQLChar)10 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)7 TransactionController (org.apache.derby.iapi.store.access.TransactionController)7 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)6 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)4 ColumnOrdering (org.apache.derby.iapi.store.access.ColumnOrdering)4 UUID (org.apache.derby.catalog.UUID)3 ContextManager (org.apache.derby.iapi.services.context.ContextManager)3 StreamStorable (org.apache.derby.iapi.services.io.StreamStorable)3