Search in sources :

Example 16 with ContainerHandle

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

the class BaseDataFileFactory method addContainer.

/**
 * Add a container with a specified page size to a segment.
 *		@exception StandardException Standard Derby error policy
 */
public long addContainer(RawTransaction t, long segmentId, long input_containerid, int mode, Properties tableProperties, int temporaryFlag) throws StandardException {
    if (SanityManager.DEBUG) {
        if ((mode & ContainerHandle.MODE_CREATE_UNLOGGED) != 0)
            SanityManager.ASSERT((mode & ContainerHandle.MODE_UNLOGGED) != 0, "cannot have CREATE_UNLOGGED set but UNLOGGED not set");
    }
    // If client has provided a containerid then use it, else use the
    // internally generated one from getNextId().
    long containerId = ((input_containerid != ContainerHandle.DEFAULT_ASSIGN_ID) ? input_containerid : getNextId());
    ContainerKey identity = new ContainerKey(segmentId, containerId);
    boolean tmpContainer = (segmentId == ContainerHandle.TEMPORARY_SEGMENT);
    ContainerHandle ch = null;
    LockingPolicy cl = null;
    if (!tmpContainer) {
        if (isReadOnly()) {
            throw StandardException.newException(SQLState.DATA_CONTAINER_READ_ONLY);
        }
        cl = t.newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true);
        if (SanityManager.DEBUG)
            SanityManager.ASSERT(cl != null);
        ch = t.openContainer(identity, cl, (ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY));
    }
    FileContainer container = (FileContainer) containerCache.create(identity, tableProperties);
    // create the first alloc page and the first user page,
    // if this fails for any reason the transaction
    // will roll back and the container will be dropped (removed)
    ContainerHandle containerHdl = null;
    Page firstPage = null;
    try {
        // make sure to open it with IS_KEPT too.
        if (tmpContainer && ((temporaryFlag & TransactionController.IS_KEPT) == TransactionController.IS_KEPT)) {
            mode |= ContainerHandle.MODE_TEMP_IS_KEPT;
        }
        // open no-locking as we already have the container locked
        containerHdl = t.openContainer(identity, null, (ContainerHandle.MODE_FORUPDATE | mode));
        // we just added it, containerHdl should not be null
        if (SanityManager.DEBUG)
            SanityManager.ASSERT(containerHdl != null);
        if (!tmpContainer) {
            // make it persistent (in concept if not in reality)
            RawContainerHandle rch = (RawContainerHandle) containerHdl;
            ContainerOperation lop = new ContainerOperation(rch, ContainerOperation.CREATE);
            // mark the container as pre-dirtied so that if a checkpoint
            // happens after the log record is sent to the log stream, the
            // cache cleaning will wait for this change.
            rch.preDirty(true);
            try {
                t.logAndDo(lop);
                // flush the log to reduce the window between where
                // the container is created & synced and the log record
                // for it makes it to disk. If we fail in this
                // window we will leave a stranded container file.
                flush(t.getLastLogInstant());
            } finally {
                // in case logAndDo fail, make sure the container is not
                // stuck in preDirty state.
                rch.preDirty(false);
            }
        }
        firstPage = containerHdl.addPage();
    } finally {
        if (firstPage != null) {
            firstPage.unlatch();
            firstPage = null;
        }
        containerCache.release(container);
        if (containerHdl != null) {
            containerHdl.close();
            containerHdl = null;
        }
        if (!tmpContainer) {
            // this should do nothing, since we requested isolation 3
            // but we can't assume that, so call the policy correctly.
            cl.unlockContainer(t, ch);
        }
    }
    return containerId;
}
Also used : Page(org.apache.derby.iapi.store.raw.Page) RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle) ContainerKey(org.apache.derby.iapi.store.raw.ContainerKey) LockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy) RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle) StreamContainerHandle(org.apache.derby.iapi.store.raw.StreamContainerHandle)

Example 17 with ContainerHandle

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

the class UpdateOperation method reclaimPrepareLocks.

/**
 ************************************************************************
 * Public Methods of RePreparable Interface:
 **************************************************************************
 */
/**
 * reclaim locks associated with the changes in this log record.
 * <p>
 * @param locking_policy  The locking policy to use to claim the locks.
 *
 * @exception  StandardException  Standard exception policy.
 */
public void reclaimPrepareLocks(Transaction t, LockingPolicy locking_policy) throws StandardException {
    if (SanityManager.DEBUG) {
        SanityManager.DEBUG_PRINT("", "UpdateOperation.reclaimPrepareLocks().");
        SanityManager.ASSERT(getRecordHandle() != null);
    }
    ContainerHandle ch = t.openContainer(getPageId().getContainerId(), locking_policy, (ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY | ContainerHandle.MODE_LOCK_NOWAIT));
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(ch != null);
    }
    if (ch != null)
        ch.close();
    // get the row lock on the updated row.
    boolean lock_granted = locking_policy.lockRecordForWrite(t, getRecordHandle(), // default is not for insert.
    false, // don't wait for the lock, it is bug if a
    false);
    // lock has to wait while reclaiming locks
    // during recovery.
    releaseResource(t);
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(lock_granted);
    }
}
Also used : ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Example 18 with ContainerHandle

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

the class LogicalPageOperation method reclaimPrepareLocks.

/**
 ************************************************************************
 * Public Methods of RePreparable Interface:
 **************************************************************************
 */
/**
 * reclaim locks associated with the changes in this log record.
 * <p>
 * @param locking_policy  The locking policy to use to claim the locks.
 *
 * @exception  StandardException  Standard exception policy.
 */
public void reclaimPrepareLocks(Transaction t, LockingPolicy locking_policy) throws StandardException {
    if (SanityManager.DEBUG) {
        SanityManager.DEBUG_PRINT("", "reclaimPrepareLocks().");
        SanityManager.ASSERT(getRecordHandle() != null);
    }
    ContainerHandle ch = t.openContainer(getPageId().getContainerId(), locking_policy, (ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY | ContainerHandle.MODE_LOCK_NOWAIT));
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(ch != null);
    }
    if (ch != null)
        ch.close();
    /*
        // get the intent lock on the container.
        boolean lock_granted = 
            locking_policy.lockContainer(
                t, 
                getContainer(), 
                false,          // don't wait for the lock, it is bug if a 
                                // lock has to wait while reclaiming locks 
                                // during recovery.
                true);          // lock for update.

        if (SanityManager.DEBUG)
        {
            SanityManager.ASSERT(lock_granted);
        }
        
        */
    // get the row lock on the c.
    boolean lock_granted = locking_policy.lockRecordForWrite(t, getRecordHandle(), // default is not for insert.
    false, // don't wait for the lock, it is bug if a
    false);
    // lock has to wait while reclaiming locks
    // during recovery.
    releaseResource(t);
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(lock_granted);
    }
}
Also used : RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Example 19 with ContainerHandle

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

the class Heap method open.

/**
 * Open a heap controller.
 * <p>
 *
 * @see Conglomerate#open
 *
 * @exception  StandardException  Standard exception policy.
 */
public ConglomerateController open(TransactionManager xact_manager, Transaction rawtran, boolean hold, int open_mode, int lock_level, LockingPolicy locking_policy, StaticCompiledOpenConglomInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info) 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, locking_policy, dynamic_info) == null) {
        throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, Long.toString(id.getContainerId()));
    }
    HeapController heapcontroller = new HeapController();
    heapcontroller.init(open_conglom);
    return (heapcontroller);
}
Also used : OpenConglomerate(org.apache.derby.impl.store.access.conglomerate.OpenConglomerate) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Example 20 with ContainerHandle

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

the class Heap method addColumn.

/*
	** Methods of Conglomerate
	*/
/**
 * Add a column to the heap conglomerate.
 * <p>
 * This routine update's the in-memory object version of the Heap
 * Conglomerate to have one more column of the type described by the
 * input template column.
 *
 * @param column_id        The column number to add this column at.
 * @param template_column  An instance of the column to be added to table.
 * @param collation_id     Collation id of the column added.
 *
 * @exception  StandardException  Standard exception policy.
 */
public void addColumn(TransactionManager xact_manager, int column_id, Storable template_column, int collation_id) throws StandardException {
    // need to open the container and update the row containing the
    // serialized format of the heap.
    ContainerHandle container = null;
    Page page = null;
    Transaction rawtran = xact_manager.getRawStoreXact();
    try {
        container = rawtran.openContainer(id, rawtran.newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true), ContainerHandle.MODE_FORUPDATE | (isTemporary() ? ContainerHandle.MODE_TEMP_IS_KEPT : 0));
        if (column_id != format_ids.length) {
            if (SanityManager.DEBUG)
                SanityManager.THROWASSERT("Expected (column_id == format_ids.length)" + "column_id = " + column_id + "format_ids.length = " + format_ids.length + "format_ids = " + format_ids);
            throw (StandardException.newException(SQLState.HEAP_TEMPLATE_MISMATCH, column_id, this.format_ids.length));
        }
        // create a new array, and copy old values to it.
        int[] old_format_ids = format_ids;
        format_ids = new int[old_format_ids.length + 1];
        System.arraycopy(old_format_ids, 0, format_ids, 0, old_format_ids.length);
        // add the new column
        format_ids[old_format_ids.length] = template_column.getTypeFormatId();
        // create a new collation array, and copy old values to it.
        int[] old_collation_ids = collation_ids;
        collation_ids = new int[old_collation_ids.length + 1];
        System.arraycopy(old_collation_ids, 0, collation_ids, 0, old_collation_ids.length);
        // add the new column's collation id.
        collation_ids[old_collation_ids.length] = collation_id;
        // row in slot 0 of heap page 1 which is just a single column with
        // the heap entry.
        DataValueDescriptor[] control_row = new DataValueDescriptor[1];
        control_row[0] = this;
        page = container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);
        page.updateAtSlot(Page.FIRST_SLOT_NUMBER, control_row, (FormatableBitSet) null);
        page.unlatch();
        page = null;
    } finally {
        if (container != null)
            container.close();
        if (page != null)
            page.unlatch();
    }
    return;
}
Also used : Transaction(org.apache.derby.iapi.store.raw.Transaction) Page(org.apache.derby.iapi.store.raw.Page) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) 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