Search in sources :

Example 1 with TransactionManager

use of org.apache.derby.iapi.store.access.conglomerate.TransactionManager in project derby by apache.

the class Heap method purgeConglomerate.

public void purgeConglomerate(TransactionManager xact_manager, Transaction rawtran) throws StandardException {
    OpenConglomerate open_for_ddl_lock = null;
    HeapController heapcontroller = null;
    TransactionManager nested_xact = null;
    try {
        open_for_ddl_lock = new OpenHeap();
        if (open_for_ddl_lock.init((ContainerHandle) null, this, this.format_ids, this.collation_ids, xact_manager, rawtran, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, null, null) == null) {
            throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, id.getContainerId());
        }
        // perform all the "real" work in a non-readonly nested user
        // transaction, so that as work is completed on each page resources
        // can be released.  Must be careful as all locks obtained in nested
        // transaction will conflict with parent transaction - so this call
        // must be made only if parent transaction can have no conflicting
        // locks on the table, otherwise the purge will fail with a self
        // deadlock.
        nested_xact = (TransactionManager) xact_manager.startNestedUserTransaction(false, true);
        // now open the table in a nested user transaction so that each
        // page worth of work can be committed after it is done.
        OpenConglomerate open_conglom = new OpenHeap();
        if (open_conglom.init((ContainerHandle) null, this, this.format_ids, this.collation_ids, nested_xact, nested_xact.getRawStoreXact(), true, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, nested_xact.getRawStoreXact().newLockingPolicy(LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, true), null) == null) {
            throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, Long.toString(id.getContainerId()));
        }
        heapcontroller = new HeapController();
        heapcontroller.init(open_conglom);
        Page page = open_conglom.getContainer().getFirstPage();
        boolean purgingDone = false;
        while (page != null) {
            long pageno = page.getPageNumber();
            purgingDone = heapcontroller.purgeCommittedDeletes(page);
            if (purgingDone) {
                page = null;
                // commit xact to free resouurces ASAP, commit will
                // unlatch the page if it has not already been unlatched
                // by a remove.
                open_conglom.getXactMgr().commitNoSync(TransactionController.RELEASE_LOCKS);
                // the commit closes the underlying container, so let
                // the heapcontroller know this has happened.  Usually
                // the transaction takes care of this, but this controller
                // is internal, so the transaction does not know about it.
                heapcontroller.closeForEndTransaction(false);
                // the commit will close the underlying
                open_conglom.reopen();
            } else {
                page.unlatch();
                page = null;
            }
            page = open_conglom.getContainer().getNextPage(pageno);
        }
    } finally {
        if (open_for_ddl_lock != null)
            open_for_ddl_lock.close();
        if (heapcontroller != null)
            heapcontroller.close();
        if (nested_xact != null) {
            nested_xact.commitNoSync(TransactionController.RELEASE_LOCKS);
            nested_xact.destroy();
        }
    }
    return;
}
Also used : TransactionManager(org.apache.derby.iapi.store.access.conglomerate.TransactionManager) Page(org.apache.derby.iapi.store.raw.Page) OpenConglomerate(org.apache.derby.impl.store.access.conglomerate.OpenConglomerate) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Example 2 with TransactionManager

use of org.apache.derby.iapi.store.access.conglomerate.TransactionManager in project derby by apache.

the class HeapController method queueDeletePostCommitWork.

protected void queueDeletePostCommitWork(RowPosition pos) throws StandardException {
    TransactionManager xact_mgr = open_conglom.getXactMgr();
    xact_mgr.addPostCommitWork(new HeapPostCommit(xact_mgr.getAccessManager(), pos.current_page.getPageKey()));
}
Also used : TransactionManager(org.apache.derby.iapi.store.access.conglomerate.TransactionManager)

Example 3 with TransactionManager

use of org.apache.derby.iapi.store.access.conglomerate.TransactionManager in project derby by apache.

the class HeapPostCommit method performWork.

/**
 * perform the work described in the postcommit work.
 * <p>
 * In this implementation the only work that can be executed by this
 * post commit processor is this class itself.
 * <p>
 *
 * @return Returns Serviceable.DONE when work has completed, or
 *         returns Serviceable.REQUEUE if work needs to be requeued.
 *
 * @param contextMgr the context manager started by the post commit daemon
 *
 * @exception  StandardException  Standard exception policy.
 */
public int performWork(ContextManager contextMgr) throws StandardException {
    TransactionManager tc = (TransactionManager) this.access_factory.getAndNameTransaction(contextMgr, AccessFactoryGlobals.SYS_TRANS_NAME);
    TransactionManager internal_xact = tc.getInternalTransaction();
    // only requeue if work was not completed in this try.
    boolean requeue_work = false;
    HeapController heapcontroller;
    if (SanityManager.DEBUG) {
        if (SanityManager.DEBUG_ON("verbose_heap_post_commit"))
            SanityManager.DEBUG_PRINT("HeapPostCommit", "starting internal xact\n");
    }
    try {
        // This call will attempt to open the heap table locked with
        // table level IX mode, preparing to do record level locked space
        // reclamation.
        // 
        // The call will either succeed immediately, or throw an exception
        // which could mean the container does not exist or that the lock
        // could not be granted immediately.
        // Reversed the fix for 4255:
        // page reclaimation is done asynchronosly by rawstore daemon
        // not good to WAIT FOR LOCKS , as it can freeze the daemon
        // If we can not get the lock this reclamation request will be
        // requeued.
        // if does not exist will throw exception, which the code will
        // handle in the same way as it does heap.open failing if trying
        // to open a dropped container.
        // DERBY-6774, changed to use openByContainerKey which insures
        // that background thread will have a lock on the table before
        // accessing and possibly loading the conglomerate cache.  This
        // insure it waits for in process alter table calls, before
        // loading the conglomerate cache.
        heapcontroller = (HeapController) Heap.openByContainerKey(page_key.getContainerId(), internal_xact, internal_xact.getRawStoreXact(), false, ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_LOCK_NOWAIT, TransactionController.MODE_RECORD, internal_xact.getRawStoreXact().newLockingPolicy(LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, true), null, (DynamicCompiledOpenConglomInfo) null);
        // We got a table intent lock, all deleted rows we encounter can
        // be reclaimed, once an "X" row lock is obtained on them.
        // Process all the rows on the page while holding the latch.
        purgeCommittedDeletes(heapcontroller, this.page_key.getPageNumber());
    } catch (StandardException se) {
        // work is requeued.
        if (se.isLockTimeoutOrDeadlock()) {
            requeue_work = true;
        }
    // Do not close the controller because that will unlatch the
    // page.  Let the commit and destroy do release the latch and
    // close the controller.
    // heapcontroller.close();
    }
    // It is ok to not sync this post work.  If no subsequent log record
    // is sync'd to disk then it is ok that this transaction not make
    // it to the database.  If any subsequent transaction is sync'd to
    // the log file, then this transaction will be sync'd as part of that
    // work.
    internal_xact.commitNoSync(Transaction.RELEASE_LOCKS);
    internal_xact.destroy();
    if (SanityManager.DEBUG) {
        if (SanityManager.DEBUG_ON("verbose_heap_post_commit")) {
            if (requeue_work)
                SanityManager.DEBUG_PRINT("HeapPostCommit", "requeueing on page num = " + this.page_key.getPageNumber());
        }
    }
    return (requeue_work ? Serviceable.REQUEUE : Serviceable.DONE);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) TransactionManager(org.apache.derby.iapi.store.access.conglomerate.TransactionManager)

Example 4 with TransactionManager

use of org.apache.derby.iapi.store.access.conglomerate.TransactionManager in project derby by apache.

the class HeapScan method queueDeletePostCommitWork.

/**
 ************************************************************************
 * Protected concrete impl of abstract methods of
 *     GenericController class:
 **************************************************************************
 */
protected void queueDeletePostCommitWork(RowPosition pos) throws StandardException {
    TransactionManager xact_mgr = open_conglom.getXactMgr();
    xact_mgr.addPostCommitWork(new HeapPostCommit(xact_mgr.getAccessManager(), pos.current_page.getPageKey()));
}
Also used : TransactionManager(org.apache.derby.iapi.store.access.conglomerate.TransactionManager)

Example 5 with TransactionManager

use of org.apache.derby.iapi.store.access.conglomerate.TransactionManager in project derby by apache.

the class T_CreateConglomRet method t_014.

/**
 * Test getTableProperties() of BTreeController.
 * <p>
 *
 * @exception  StandardException  Standard exception policy.
 * @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");
    // create the base table
    DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
    T_SecondaryIndexRow index_row1 = new T_SecondaryIndexRow();
    long base_conglomid = tc.createConglomerate(// create a heap conglomerate
    "heap", // base table template row
    base_row, // column sort order - not required for heap
    null, // default collation
    null, // default properties
    null, TransactionController.IS_DEFAULT);
    // Open the base table
    ConglomerateController base_cc = tc.openConglomerate(base_conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    RowLocation base_rowloc1 = base_cc.newRowLocationTemplate();
    index_row1.init(base_row, base_rowloc1, 3);
    // create the secondary index
    Properties properties = createProperties(// no current properties list
    null, // don't allow duplicates
    false, // index on all base row cols + row location
    3, // non-unique index
    2, // maintain parent links
    true, // fake base conglom for now
    base_conglomid, // row loc in last column
    2);
    properties.put(Property.PAGE_SIZE_PARAMETER, "8192");
    properties.put(RawStoreFactory.PAGE_RESERVED_SPACE_PARAMETER, "99");
    properties.put(RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER, "42");
    TransactionManager tm = (TransactionManager) tc;
    // Create a index.
    long conglomid = tc.createConglomerate(// create a heap conglomerate
    "BTREE", // 1 column template.
    index_row1.getRow(), // column sort order - default
    null, // default collation
    null, // default properties
    properties, // not temporary
    TransactionController.IS_DEFAULT);
    // Open the conglomerate.
    ConglomerateController cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // verify that input properties were used.
    Properties ret_prop = new Properties();
    ret_prop.put(Property.PAGE_SIZE_PARAMETER, "");
    ret_prop.put(RawStoreFactory.PAGE_RESERVED_SPACE_PARAMETER, "");
    ret_prop.put(RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER, "");
    cc.getTableProperties(ret_prop);
    if (ret_prop.getProperty(Property.PAGE_SIZE_PARAMETER).compareTo("8192") != 0 || ret_prop.getProperty(RawStoreFactory.PAGE_RESERVED_SPACE_PARAMETER).compareTo("0") != 0 || ret_prop.getProperty(RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER).compareTo("1") != 0) {
        throw T_Fail.testFailMsg("(getTableProperties) Did not get expected table propertes." + "\nGot pageSize = " + ret_prop.getProperty(Property.PAGE_SIZE_PARAMETER) + "\nGot reserved = " + ret_prop.getProperty(RawStoreFactory.PAGE_RESERVED_SPACE_PARAMETER) + "\nGot minimum record size = " + ret_prop.getProperty(RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER));
    }
    tc.commit();
    REPORT("Ending t_014");
    return (true);
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) TransactionManager(org.apache.derby.iapi.store.access.conglomerate.TransactionManager) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) Properties(java.util.Properties) RowLocation(org.apache.derby.iapi.types.RowLocation)

Aggregations

TransactionManager (org.apache.derby.iapi.store.access.conglomerate.TransactionManager)9 StandardException (org.apache.derby.shared.common.error.StandardException)4 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)3 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)3 Properties (java.util.Properties)2 RowLocation (org.apache.derby.iapi.types.RowLocation)2 AccessFactory (org.apache.derby.iapi.store.access.AccessFactory)1 ScanController (org.apache.derby.iapi.store.access.ScanController)1 ContainerHandle (org.apache.derby.iapi.store.raw.ContainerHandle)1 Page (org.apache.derby.iapi.store.raw.Page)1 RawStoreFactory (org.apache.derby.iapi.store.raw.RawStoreFactory)1 OpenConglomerate (org.apache.derby.impl.store.access.conglomerate.OpenConglomerate)1