Search in sources :

Example 11 with RawTransaction

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

the class BaseContainer method letGo.

/**
 *		Discontinue use of this container. Note that the unlockContainer
 *		call made from this method may not release any locks. The container
 *		lock may be held until the end of the transaction.
 */
protected void letGo(BaseContainerHandle handle) {
    RawTransaction t = handle.getTransaction();
    handle.getLockingPolicy().unlockContainer(t, handle);
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction)

Example 12 with RawTransaction

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

the class BaseContainer method getDeallocLock.

/**
 *		Get the special dealloc lock on the page - the lock is gotten by the
 *		transaction that owns the container handle
 *
 *		@exception StandardException Standard Derby error policy
 */
protected boolean getDeallocLock(BaseContainerHandle handle, RecordHandle deallocLock, boolean wait, boolean zeroDuration) throws StandardException {
    // get deallocate lock on page so that the GC won't attempt to
    // free and re-allocate it until the transaction commits
    RawTransaction tran = handle.getTransaction();
    LockingPolicy lp = tran.newLockingPolicy(LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, // striterOK
    true);
    PageKey pkey = new PageKey(identity, deallocLock.getPageNumber());
    if (lp != null) {
        if (zeroDuration)
            return lp.zeroDurationLockRecordForWrite(tran, deallocLock, false, wait);
        else
            return lp.lockRecordForWrite(tran, deallocLock, false, wait);
    } else {
        throw StandardException.newException(SQLState.DATA_CANNOT_GET_DEALLOC_LOCK, pkey);
    }
}
Also used : PageKey(org.apache.derby.iapi.store.raw.PageKey) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) LockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy)

Example 13 with RawTransaction

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

the class BaseContainer method addPage.

/**
 *		Add a page to this container.
 *
 *		<BR> MT - thread aware -
 *
 *		The add page operation involves 2 transactions, one is the user
 *		transaction (the transaction which owns the passed in handle), the
 *		other one is a NestedTopTransaction created by this BaseContainer.
 *
 *		The nestedTopTransaction is used by the underlying container to change
 *		high contention structures, such as link list anchor or bit map pages.
 *		The nestedTopTransaction commits or aborts before this routine returns.
 *
 *		The user transaction is used to latch the newly created page.
 *
 *		@exception StandardException Standard Derby error policy
 */
public Page addPage(BaseContainerHandle handle, boolean isOverflow) throws StandardException {
    RawTransaction ntt = handle.getTransaction().startNestedTopTransaction();
    int mode = handle.getMode();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT((mode & ContainerHandle.MODE_FORUPDATE) == ContainerHandle.MODE_FORUPDATE, "addPage handle not for update");
    }
    // crashed.
    if ((mode & ContainerHandle.MODE_CREATE_UNLOGGED) == 0 && (mode & ContainerHandle.MODE_UNLOGGED) == ContainerHandle.MODE_UNLOGGED)
        mode &= ~ContainerHandle.MODE_UNLOGGED;
    // make a handle which is tied to the ntt, not to the user transaction this
    // handle is tied to.  The container is already locked by the user transaction,
    // open it nolock
    BaseContainerHandle allocHandle = (BaseContainerHandle) ntt.openContainer(identity, (LockingPolicy) null, mode);
    if (allocHandle == null) {
        throw StandardException.newException(SQLState.DATA_ALLOC_NTT_CANT_OPEN, getSegmentId(), getContainerId());
    }
    // Latch this container, the commit will release the latch
    CompatibilitySpace cs = ntt.getCompatibilitySpace();
    ntt.getLockFactory().lockObject(cs, ntt, this, null, C_LockFactory.WAIT_FOREVER);
    BasePage newPage = null;
    try {
        newPage = newPage(handle, ntt, allocHandle, isOverflow);
    } finally {
        if (newPage != null) {
            // it is ok to commit without syncing, as it is ok if this
            // transaction never makes it to the db, if no subsequent
            // log record makes it to the log.  If any subsequent log
            // record is sync'd then this transaction will be sync'd
            // as well.
            ntt.commitNoSync(Transaction.RELEASE_LOCKS);
        } else {
            ntt.abort();
        }
        ntt.close();
    }
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(newPage.isLatched());
    }
    if (!this.identity.equals(newPage.getPageId().getContainerId())) {
        if (SanityManager.DEBUG) {
            SanityManager.THROWASSERT("BaseContainer.addPage(), just got a new page from a different container" + "\n this.identity = " + this.identity + "\n newPage.getPageId().getContainerId() = " + newPage.getPageId().getContainerId() + "\n handle is: " + handle + "\n allocHandle is: " + allocHandle + "\n this container is: " + this);
        }
        throw StandardException.newException(SQLState.DATA_DIFFERENT_CONTAINER, this.identity, newPage.getPageId().getContainerId());
    }
    return newPage;
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) CompatibilitySpace(org.apache.derby.iapi.services.locks.CompatibilitySpace) LockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy)

Example 14 with RawTransaction

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

the class T_Recovery method R301.

/*
	 * test recovery of 301
	 */
protected void R301() throws T_Fail, StandardException {
    long cid1 = find(key(301, 1));
    if (cid1 < 0) {
        REPORT("R301 not run");
        return;
    }
    long cid2 = find(key(301, 2));
    Transaction t = t_util.t_startTransaction();
    try {
        LockingPolicy nolock = t.newLockingPolicy(LockingPolicy.MODE_NONE, 0, false);
        ContainerKey id1 = new ContainerKey(0, cid1);
        ContainerHandle c = t.openContainer(id1, ContainerHandle.MODE_READONLY);
        if (c != null)
            throw T_Fail.testFailMsg("expect container to be dropped");
        RawContainerHandle stub = ((RawTransaction) t).openDroppedContainer(id1, nolock);
        /*Not true always after fix for p4#25641(fix for bug:4580)
			  Checkpoint calls cleans up the stubs that not necessary
			  for recovery.
			  if (stub == null)
			  throw T_Fail.testFailMsg("drop container should still be there");
			*/
        if (stub != null)
            if (stub.getContainerStatus() != RawContainerHandle.COMMITTED_DROP)
                throw T_Fail.testFailMsg("expect container to be committed dropped");
        ContainerKey id2 = new ContainerKey(0, cid2);
        c = t.openContainer(id2, ContainerHandle.MODE_READONLY);
        if (c != null)
            throw T_Fail.testFailMsg("expect container to be dropped");
        stub = ((RawTransaction) t).openDroppedContainer(id2, nolock);
        /*Not true always after fix for p4#25641(fix for bug:4580)
			  Checkpoint calls cleans up the stubs that not necessary
			  for recovery.
			  if (stub == null)
			  throw T_Fail.testFailMsg("drop container should still be there");
			*/
        if (stub != null)
            if (stub.getContainerStatus() != RawContainerHandle.COMMITTED_DROP)
                throw T_Fail.testFailMsg("expect container to be committed dropped");
    } finally {
        t_util.t_commit(t);
        t.close();
    }
    PASS("R301 : cid1 " + cid1 + " cid2 " + cid2);
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle) RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle)

Example 15 with RawTransaction

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

the class StoredPage method purgeOverflowAtSlot.

/**
 * Purge one row on an overflow page.
 * <p>
 * HeadRowHandle is the recordHandle pointing to the head row piece.
 * <p>
 *
 * @param slot              slot number of row to purge.
 * @param headRowHandle     recordHandle of the head row piece.
 * @param needDataLogged    when true data is logged for purges otherwise just headers.
 *
 * @exception  StandardException  Standard exception policy.
 */
protected void purgeOverflowAtSlot(int slot, RecordHandle headRowHandle, boolean needDataLogged) throws StandardException {
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(isLatched());
        SanityManager.ASSERT(isOverflowPage());
    }
    if ((slot < 0) || (slot >= slotsInUse)) {
        throw StandardException.newException(SQLState.DATA_SLOT_NOT_ON_PAGE);
    }
    // TODO (mikem) - should a global scratch variable be used?
    // this is an overflow page purge, no need to lock the head row (it
    // has already been locked, hopefully).  No need to check for long rows
    // (they have already been deleted, hopefully).
    RawTransaction t = owner.getTransaction();
    int[] recordId = new int[1];
    recordId[0] = getHeaderAtSlot(slot).getId();
    owner.getActionSet().actionPurge(t, this, slot, 1, recordId, needDataLogged);
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction)

Aggregations

RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)40 RecordHandle (org.apache.derby.iapi.store.raw.RecordHandle)10 LockingPolicy (org.apache.derby.iapi.store.raw.LockingPolicy)6 PageKey (org.apache.derby.iapi.store.raw.PageKey)6 StandardException (org.apache.derby.shared.common.error.StandardException)6 ContextManager (org.apache.derby.iapi.services.context.ContextManager)5 StorageFile (org.apache.derby.io.StorageFile)5 IOException (java.io.IOException)4 DynamicByteArrayOutputStream (org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream)3 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)3 Serviceable (org.apache.derby.iapi.services.daemon.Serviceable)2 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)2 CompatibilitySpace (org.apache.derby.iapi.services.locks.CompatibilitySpace)2 LogicalUndo (org.apache.derby.iapi.store.access.conglomerate.LogicalUndo)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Properties (java.util.Properties)1