Search in sources :

Example 1 with OpenConglomerate

use of org.apache.derby.impl.store.access.conglomerate.OpenConglomerate 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 2 with OpenConglomerate

use of org.apache.derby.impl.store.access.conglomerate.OpenConglomerate 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 3 with OpenConglomerate

use of org.apache.derby.impl.store.access.conglomerate.OpenConglomerate 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 OpenConglomerate

use of org.apache.derby.impl.store.access.conglomerate.OpenConglomerate in project derby by apache.

the class Heap method openScan.

/**
 * Open a heap scan controller.
 * <p>
 *
 * @see Conglomerate#openScan
 *
 * @exception  StandardException  Standard exception policy.
 */
public ScanManager openScan(TransactionManager xact_manager, Transaction rawtran, boolean hold, int open_mode, int lock_level, LockingPolicy locking_policy, int isolation_level, FormatableBitSet scanColumnList, DataValueDescriptor[] startKeyValue, int startSearchOperator, Qualifier[][] qualifier, DataValueDescriptor[] stopKeyValue, int stopSearchOperator, StaticCompiledOpenConglomInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info) throws StandardException {
    if (SanityManager.DEBUG) {
        if ((open_mode & TransactionController.OPENMODE_LOCK_ROW_NOWAIT) != 0) {
            SanityManager.THROWASSERT("Bad open mode to Heap#openScan:" + Integer.toHexString(open_mode));
        }
    }
    // only make sense for ordered storage structures).
    if (!RowUtil.isRowEmpty(startKeyValue) || !RowUtil.isRowEmpty(stopKeyValue)) {
        throw StandardException.newException(SQLState.HEAP_UNIMPLEMENTED_FEATURE);
    }
    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, locking_policy, dynamic_info) == null) {
        throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, id.getContainerId());
    }
    HeapScan heapscan = new HeapScan();
    heapscan.init(open_conglom, scanColumnList, startKeyValue, startSearchOperator, qualifier, stopKeyValue, stopSearchOperator);
    return (heapscan);
}
Also used : OpenConglomerate(org.apache.derby.impl.store.access.conglomerate.OpenConglomerate) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Example 5 with OpenConglomerate

use of org.apache.derby.impl.store.access.conglomerate.OpenConglomerate 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

ContainerHandle (org.apache.derby.iapi.store.raw.ContainerHandle)7 OpenConglomerate (org.apache.derby.impl.store.access.conglomerate.OpenConglomerate)7 Page (org.apache.derby.iapi.store.raw.Page)2 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 RecordHandle (org.apache.derby.iapi.store.raw.RecordHandle)1 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)1