Search in sources :

Example 1 with Page

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

the class LeafControlRow method initEmptyBtree.

/**
 * Initialize conglomerate with one page, to be a 1 page btree.
 *
 * Given a conglomerate which already has one page allocated to it,
 * initialize the page to be a leaf-root page with no entries.  Allocate
 * the control row and store it on the page.
 *
 * @param open_btree The open btree to initialize (container is open).
 *
 * @exception StandardException Standard exception policy.
 */
public static void initEmptyBtree(OpenBTree open_btree) throws StandardException {
    Page page = open_btree.container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);
    // create a leaf control row for root page of a single page index //
    LeafControlRow control_row = new LeafControlRow(open_btree, page, null, true);
    byte insertFlag = Page.INSERT_INITIAL;
    insertFlag |= Page.INSERT_DEFAULT;
    RecordHandle rh = page.insertAtSlot(Page.FIRST_SLOT_NUMBER, control_row.getRow(), (FormatableBitSet) null, (LogicalUndo) null, insertFlag, AccessFactoryGlobals.BTREE_OVERFLOW_THRESHOLD);
    if (SanityManager.DEBUG) {
        RecordHandle rh2 = null;
        rh2 = page.fetchFromSlot((RecordHandle) null, Page.FIRST_SLOT_NUMBER, new DataValueDescriptor[0], (FetchDescriptor) null, true);
        SanityManager.ASSERT(rh.getId() == rh2.getId() && rh.getPageNumber() == rh2.getPageNumber());
    }
    if (SanityManager.DEBUG) {
        if (SanityManager.DEBUG_ON("enableBtreeConsistencyCheck")) {
            control_row.checkConsistency(open_btree, (ControlRow) null, true);
        }
    }
    page.unlatch();
    return;
}
Also used : RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle) FetchDescriptor(org.apache.derby.iapi.store.raw.FetchDescriptor) Page(org.apache.derby.iapi.store.raw.Page) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 2 with Page

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

use of org.apache.derby.iapi.store.raw.Page 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 4 with Page

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

the class HeapConglomerateFactory method readConglomerate.

/**
 * Return Conglomerate object for conglomerate with container_key.
 * <p>
 * Return the Conglomerate Object.  This is implementation specific.
 * Examples of what will be done is using the key 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.
 *
 * @param xact_mgr      transaction to perform the create in.
 * @param container_key The unique id of the existing conglomerate.
 *
 * @return An instance of the conglomerate.
 *
 * @exception  StandardException  Standard exception policy.
 */
public Conglomerate readConglomerate(TransactionManager xact_mgr, ContainerKey container_key) throws StandardException {
    ContainerHandle container = null;
    Page page = null;
    DataValueDescriptor[] control_row = new DataValueDescriptor[1];
    try {
        // open container to read the Heap object out of it's control row.
        container = xact_mgr.getRawStoreXact().openContainer(container_key, (LockingPolicy) null, 0);
        if (container == null) {
            throw StandardException.newException(SQLState.STORE_CONGLOMERATE_DOES_NOT_EXIST, container_key.getContainerId());
        }
        // row in slot 0 of heap page 1 which is just a single column with
        // the heap entry.
        control_row[0] = new Heap();
        page = container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);
        RecordHandle rh = page.fetchFromSlot((RecordHandle) null, 0, control_row, (FetchDescriptor) null, true);
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(rh != null);
            // for now the control row is always the first id assigned on
            // page 1.
            SanityManager.ASSERT(rh.getId() == 6);
        }
    } finally {
        if (page != null)
            page.unlatch();
        if (container != null)
            container.close();
    }
    return ((Conglomerate) control_row[0]);
}
Also used : RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle) Page(org.apache.derby.iapi.store.raw.Page) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) LockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Example 5 with Page

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

the class HeapController method load.

protected long load(TransactionManager xact_manager, Heap heap, boolean createConglom, RowLocationRetRowSource rowSource) throws StandardException {
    long num_rows_loaded = 0;
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(open_conglom == null, "load expects container handle to be closed on entry.");
    }
    // The individual rows that are inserted are not logged.  To use a
    // logged interface, use insert.  RESOLVE: do we want to allow client
    // to use the load interface even for logged insert?
    int mode = (ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_UNLOGGED);
    // page allocation.
    if (createConglom)
        mode |= ContainerHandle.MODE_CREATE_UNLOGGED;
    OpenConglomerate open_conglom = new OpenHeap();
    if (open_conglom.init((ContainerHandle) null, heap, heap.format_ids, heap.collation_ids, xact_manager, xact_manager.getRawStoreXact(), false, mode, TransactionController.MODE_TABLE, xact_manager.getRawStoreXact().newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true), (DynamicCompiledOpenConglomInfo) null) == null) {
        throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, heap.getId().getContainerId());
    }
    this.init(open_conglom);
    // For bulk loading, we always use only brand new page because the row
    // insertion itself is not logged.  We cannot pollute pages with
    // pre-existing data with unlogged rows because nobody is going to wipe
    // out these rows if the transaction rolls back.  We are counting on
    // the allocation page rollback to obliterate these rows if the
    // transaction fails, or, in the CREAT_UNLOGGED case, the whole
    // container to be removed.
    Page page = open_conglom.getContainer().addPage();
    boolean callbackWithRowLocation = rowSource.needsRowLocation();
    RecordHandle rh;
    HeapRowLocation rowlocation;
    if (callbackWithRowLocation || rowSource.needsRowLocationForDeferredCheckConstraints())
        rowlocation = new HeapRowLocation();
    else
        rowlocation = null;
    FormatableBitSet validColumns = rowSource.getValidColumns();
    try {
        // get the next row and its valid columns from the rowSource
        DataValueDescriptor[] row;
        while ((row = rowSource.getNextRowFromRowSource()) != null) {
            num_rows_loaded++;
            if (SanityManager.DEBUG) {
                // Make sure valid columns are in the list.  The RowUtil
                // call is too expensive to make in a released system for
                // every insert.
                int invalidColumn = RowUtil.columnOutOfRange(row, validColumns, heap.format_ids.length);
                if (invalidColumn >= 0) {
                    throw (StandardException.newException(SQLState.HEAP_TEMPLATE_MISMATCH, invalidColumn, heap.format_ids.length));
                }
            }
            // Insert it onto this page as long as it can fit more rows.
            if ((rh = page.insert(row, validColumns, Page.INSERT_DEFAULT, AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD)) == null) {
                // Insert faied, row did not fit.  Get a new page.
                page.unlatch();
                page = null;
                page = open_conglom.getContainer().addPage();
                // RESOLVE (mikem) - no long rows yet so the following code
                // will get an exception from the raw store for a row that
                // does not fit on a page.
                // 
                // Multi-thread considerations aside, the raw store will
                // guarantee that any size row will fit on an empty page.
                rh = page.insert(row, validColumns, Page.INSERT_OVERFLOW, AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);
            }
            // and go for the next row.
            if (callbackWithRowLocation) {
                rowlocation.setFrom(rh);
                rowSource.rowLocation(rowlocation);
            }
            if (rowSource.needsRowLocationForDeferredCheckConstraints()) {
                rowlocation.setFrom(rh);
                rowSource.offendingRowLocation(rowlocation, heap.getContainerid());
            }
        }
        page.unlatch();
        page = null;
        // it is unlogged.
        if (!heap.isTemporary())
            open_conglom.getContainer().flushContainer();
    } finally {
        // If an error happened here, don't bother flushing the
        // container since the changes should be rolled back anyhow.
        close();
    }
    return (num_rows_loaded);
}
Also used : RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle) DynamicCompiledOpenConglomInfo(org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo) Page(org.apache.derby.iapi.store.raw.Page) OpenConglomerate(org.apache.derby.impl.store.access.conglomerate.OpenConglomerate) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Aggregations

Page (org.apache.derby.iapi.store.raw.Page)28 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)11 ContainerHandle (org.apache.derby.iapi.store.raw.ContainerHandle)10 RecordHandle (org.apache.derby.iapi.store.raw.RecordHandle)9 FetchDescriptor (org.apache.derby.iapi.store.raw.FetchDescriptor)5 LockingPolicy (org.apache.derby.iapi.store.raw.LockingPolicy)4 ContainerKey (org.apache.derby.iapi.store.raw.ContainerKey)3 Transaction (org.apache.derby.iapi.store.raw.Transaction)2 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)2 OpenConglomerate (org.apache.derby.impl.store.access.conglomerate.OpenConglomerate)2 BasePage (org.apache.derby.impl.store.raw.data.BasePage)2 Properties (java.util.Properties)1 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)1 DynamicCompiledOpenConglomInfo (org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo)1 TransactionManager (org.apache.derby.iapi.store.access.conglomerate.TransactionManager)1 PageKey (org.apache.derby.iapi.store.raw.PageKey)1 PageTimeStamp (org.apache.derby.iapi.store.raw.PageTimeStamp)1 RawStoreFactory (org.apache.derby.iapi.store.raw.RawStoreFactory)1 StreamContainerHandle (org.apache.derby.iapi.store.raw.StreamContainerHandle)1 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)1