Search in sources :

Example 1 with ContainerHandle

use of org.apache.derby.iapi.store.raw.ContainerHandle in project derby by apache.

the class B2IFactory method readConglomerate.

/**
 * Return Conglomerate object for conglomerate with conglomid.
 * <p>
 * Return the Conglomerate Object.  This is implementation specific.
 * Examples of what will be done is using the id to find the file where
 * the conglomerate is located, and then executing implementation specific
 * code to instantiate an object from reading a "special" row from a
 * known location in the file.  In the btree case the btree conglomerate
 * is stored as a column in the control row on the root page.
 * <p>
 * This operation is costly so it is likely an implementation using this
 * will cache the conglomerate row in memory so that subsequent accesses
 * need not perform this operation.
 * <p>
 * The btree object returned by this routine may be installed in a cache
 * so the object must not change.
 *
 * @return An instance of the conglomerate.
 *
 * @exception  StandardException  Standard exception policy.
 */
public Conglomerate readConglomerate(TransactionManager xact_manager, ContainerKey container_key) throws StandardException {
    Conglomerate btree = null;
    ContainerHandle container = null;
    ControlRow root = null;
    try {
        // open readonly, with no locks.  Dirty read is ok as it is the
        // responsibility of client code to make sure this data is not
        // changing while being read.  The only changes that currently
        // happen to this data is creation and deletion - no updates
        // ever happen to btree conglomerates.
        container = (xact_manager.getRawStoreXact()).openContainer(container_key, (LockingPolicy) null, ContainerHandle.MODE_READONLY);
        if (container == null) {
            throw StandardException.newException(SQLState.STORE_CONGLOMERATE_DOES_NOT_EXIST, container_key.getContainerId());
        }
        // The conglomerate is located in the control row on the root page.
        root = ControlRow.get(container, BTree.ROOTPAGEID);
        if (SanityManager.DEBUG)
            SanityManager.ASSERT(root.getPage().isLatched());
        // read the Conglomerate from it's entry in the control row.
        btree = (Conglomerate) root.getConglom(B2I.FORMAT_NUMBER);
        if (SanityManager.DEBUG)
            SanityManager.ASSERT(btree instanceof B2I);
    } finally {
        if (root != null)
            root.release();
        if (container != null)
            container.close();
    }
    return (btree);
}
Also used : ControlRow(org.apache.derby.impl.store.access.btree.ControlRow) Conglomerate(org.apache.derby.iapi.store.access.conglomerate.Conglomerate) LockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Example 2 with ContainerHandle

use of org.apache.derby.iapi.store.raw.ContainerHandle in project derby by apache.

the class D_HeapController method diag.

/**
 * Default implementation of diagnostic on the object.
 * <p>
 * This routine returns a string with whatever diagnostic information
 * you would like to provide about this object.
 * <p>
 * This routine should be overriden by a real implementation of the
 * diagnostic information you would like to provide.
 * <p>
 *
 * @return A string with diagnostic information about the object.
 *
 * @exception StandardException  Standard Derby exception policy
 */
public String diag() throws StandardException {
    long pageid;
    ContainerHandle container = ((HeapController) this.diag_object).getOpenConglom().getContainer();
    TableStats stat = new TableStats();
    // ask page to provide diag info:
    Properties prop = new Properties();
    prop.put(Page.DIAG_PAGE_SIZE, "");
    prop.put(Page.DIAG_BYTES_FREE, "");
    prop.put(Page.DIAG_BYTES_RESERVED, "");
    prop.put(Page.DIAG_RESERVED_SPACE, "");
    prop.put(Page.DIAG_MINIMUM_REC_SIZE, "");
    prop.put(Page.DIAG_NUMOVERFLOWED, "");
    prop.put(Page.DIAG_ROWSIZE, "");
    prop.put(Page.DIAG_MINROWSIZE, "");
    prop.put(Page.DIAG_MAXROWSIZE, "");
    // scan all pages in the heap gathering summary stats in stat
    Page page = container.getFirstPage();
    while (page != null) {
        D_HeapController.diag_page(page, prop, stat);
        pageid = page.getPageNumber();
        page.unlatch();
        page = container.getNextPage(pageid);
    }
    return (D_HeapController.diag_tabulate(prop, stat));
}
Also used : Page(org.apache.derby.iapi.store.raw.Page) Properties(java.util.Properties) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Example 3 with ContainerHandle

use of org.apache.derby.iapi.store.raw.ContainerHandle in project derby by apache.

the class Heap method compressConglomerate.

public void compressConglomerate(TransactionManager xact_manager, Transaction rawtran) throws StandardException {
    OpenConglomerate open_conglom = null;
    HeapController heapcontroller = null;
    try {
        open_conglom = new OpenHeap();
        if (open_conglom.init((ContainerHandle) null, this, this.format_ids, this.collation_ids, xact_manager, rawtran, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, rawtran.newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_REPEATABLE_READ, true), null) == null) {
            throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, id.getContainerId());
        }
        heapcontroller = new HeapController();
        heapcontroller.init(open_conglom);
        open_conglom.getContainer().compressContainer();
    } finally {
        if (open_conglom != null)
            open_conglom.close();
    }
    return;
}
Also used : OpenConglomerate(org.apache.derby.impl.store.access.conglomerate.OpenConglomerate) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Example 4 with ContainerHandle

use of org.apache.derby.iapi.store.raw.ContainerHandle in project derby by apache.

the class Heap method defragmentConglomerate.

/**
 * Open a heap compress scan.
 * <p>
 *
 * @see Conglomerate#defragmentConglomerate
 *
 * @exception  StandardException  Standard exception policy.
 */
public ScanManager defragmentConglomerate(TransactionManager xact_manager, Transaction rawtran, boolean hold, int open_mode, int lock_level, LockingPolicy locking_policy, int isolation_level) throws StandardException {
    OpenConglomerate open_conglom = new OpenHeap();
    if (open_conglom.init((ContainerHandle) null, this, this.format_ids, this.collation_ids, xact_manager, rawtran, hold, open_mode, lock_level, rawtran.newLockingPolicy(LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, true), null) == null) {
        throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, id.getContainerId());
    }
    HeapCompressScan heap_compress_scan = new HeapCompressScan();
    heap_compress_scan.init(open_conglom, null, null, 0, null, null, 0);
    return (heap_compress_scan);
}
Also used : OpenConglomerate(org.apache.derby.impl.store.access.conglomerate.OpenConglomerate) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Example 5 with ContainerHandle

use of org.apache.derby.iapi.store.raw.ContainerHandle 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)

Aggregations

ContainerHandle (org.apache.derby.iapi.store.raw.ContainerHandle)22 Page (org.apache.derby.iapi.store.raw.Page)10 OpenConglomerate (org.apache.derby.impl.store.access.conglomerate.OpenConglomerate)7 LockingPolicy (org.apache.derby.iapi.store.raw.LockingPolicy)6 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)5 ContainerKey (org.apache.derby.iapi.store.raw.ContainerKey)4 RecordHandle (org.apache.derby.iapi.store.raw.RecordHandle)4 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)4 Properties (java.util.Properties)2 StreamContainerHandle (org.apache.derby.iapi.store.raw.StreamContainerHandle)2 Transaction (org.apache.derby.iapi.store.raw.Transaction)2 ControlRow (org.apache.derby.impl.store.access.btree.ControlRow)2 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)1 DynamicCompiledOpenConglomInfo (org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo)1 Conglomerate (org.apache.derby.iapi.store.access.conglomerate.Conglomerate)1 TransactionManager (org.apache.derby.iapi.store.access.conglomerate.TransactionManager)1 PageKey (org.apache.derby.iapi.store.raw.PageKey)1 RawStoreFactory (org.apache.derby.iapi.store.raw.RawStoreFactory)1 OpenBTree (org.apache.derby.impl.store.access.btree.OpenBTree)1 SearchParameters (org.apache.derby.impl.store.access.btree.SearchParameters)1