Search in sources :

Example 26 with RawTransaction

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

the class BasePage method setExclusive.

/**
 *		Get an exclusive latch on the page.
 *		<BR>
 *		MT - thread safe
 *		@exception StandardException Standard Derby policy.
 */
void setExclusive(BaseContainerHandle requester) throws StandardException {
    RawTransaction t = requester.getTransaction();
    // object for every latch; iii) other unknown reasons :-)
    synchronized (this) {
        // page
        if ((owner != null) && (t == owner.getTransaction())) {
            if (t.inAbort()) {
                // 
                nestedLatch++;
                return;
            }
            // severity;
            throw StandardException.newException(SQLState.DATA_DOUBLE_LATCH_INTERNAL_ERROR, identity);
        }
        while (owner != null) {
            try {
                // Expect notify from releaseExclusive().
                wait();
            } catch (InterruptedException ie) {
                InterruptStatus.setInterrupted();
            }
        }
        preLatch(requester);
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(isLatched(), "page not latched");
        }
        while (inClean) {
            try {
                // Expect notify from clean() routine.
                wait();
            } catch (InterruptedException ie) {
                InterruptStatus.setInterrupted();
            }
        }
        // no clean taking place, so safe to move to full LATCHED state.
        preLatch = false;
    }
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction)

Example 27 with RawTransaction

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

the class BasePage method copyInto.

/**
 *		Copy num_rows from srcPage, src_slot into this page starting at dest_slot.
 *		This is destination page of the the copy half of copy and Purge.
 *
 *		@see Page#copyAndPurge
 */
private void copyInto(BasePage srcPage, int src_slot, int num_rows, int dest_slot) throws StandardException {
    if ((dest_slot < 0) || dest_slot > recordCount) {
        throw StandardException.newException(SQLState.DATA_SLOT_NOT_ON_PAGE);
    }
    RawTransaction t = owner.getTransaction();
    // get num_rows row locks, need to predict what those recordIds will be
    int[] recordIds = new int[num_rows];
    // RESOLVE - MT problem ?
    PageKey pageId = getPageId();
    for (int i = 0; i < num_rows; i++) {
        if (i == 0)
            recordIds[i] = newRecordId();
        else
            recordIds[i] = newRecordId(recordIds[i - 1]);
        RecordHandle handle = new RecordId(pageId, recordIds[i], i);
        owner.getLockingPolicy().lockRecordForWrite(t, handle, false, true);
    }
    // RESOLVE: need try block here to invalidate self and crash the system
    owner.getActionSet().actionCopyRows(t, this, srcPage, dest_slot, num_rows, src_slot, recordIds);
}
Also used : PageKey(org.apache.derby.iapi.store.raw.PageKey) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle)

Example 28 with RawTransaction

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

the class BasePage method purgeAtSlot.

/**
 *		Purge one or more rows on a non-overflow page.
 *
 *		@see Page#purgeAtSlot
 *		@exception StandardException Standard exception policy.
 */
public void purgeAtSlot(int slot, int numpurges, boolean needDataLogged) throws StandardException {
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(isLatched());
        if (isOverflowPage())
            SanityManager.THROWASSERT("purge committed deletes on an overflow page.  Page = " + this);
    }
    if (numpurges <= 0)
        return;
    if (!owner.updateOK()) {
        throw StandardException.newException(SQLState.DATA_CONTAINER_READ_ONLY);
    }
    if ((slot < 0) || ((slot + numpurges) > recordCount)) {
        throw StandardException.newException(SQLState.DATA_SLOT_NOT_ON_PAGE);
    }
    RawTransaction t = owner.getTransaction();
    // lock the records to be purged
    int[] recordIds = new int[numpurges];
    // RESOLVE: MT problem ?
    PageKey pageId = getPageId();
    for (int i = 0; i < numpurges; i++) {
        recordIds[i] = getHeaderAtSlot(slot + i).getId();
        // get row lock on head row piece
        RecordHandle handle = getRecordHandleAtSlot(slot);
        owner.getLockingPolicy().lockRecordForWrite(t, handle, false, true);
        if (owner.isTemporaryContainer() || entireRecordOnPage(slot + i))
            continue;
        // row[slot+i] has overflow rows and/or long columns, reclaim
        // them in a loop.
        RecordHandle headRowHandle = getHeaderAtSlot(slot + i).getHandle(pageId, slot + i);
        purgeRowPieces(t, slot + i, headRowHandle, needDataLogged);
    }
    owner.getActionSet().actionPurge(t, this, slot, numpurges, recordIds, needDataLogged);
}
Also used : PageKey(org.apache.derby.iapi.store.raw.PageKey) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle)

Example 29 with RawTransaction

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

the class T_RawStoreFactory method P054.

/**
 *		Test internal transaction
 *
 *		@exception T_Fail Unexpected behaviour from the API
 *		@exception StandardException Unexpected exception from the implementation
 */
protected void P054() throws StandardException, T_Fail {
    if (!testRollback)
        return;
    ContextManager previousCM = contextService.getCurrentContextManager();
    ContextManager cm1 = contextService.newContextManager();
    contextService.setCurrentContextManager(cm1);
    Transaction tuser = t_util.t_startTransaction();
    Transaction tinternal = null;
    try {
        long cid1 = t_util.t_addContainer(tuser, 0);
        ContainerHandle c1 = t_util.t_openContainer(tuser, 0, cid1, true);
        Page p1 = t_util.t_addPage(c1);
        t_util.t_commit(tuser);
        // insert a row using user transaction
        T_RawStoreRow row = new T_RawStoreRow(REC_001);
        c1 = t_util.t_openContainer(tuser, 0, cid1, true);
        p1 = t_util.t_getLastPage(c1);
        RecordHandle r1 = t_util.t_insert(p1, row);
        REPORT("starting internal transaction");
        tinternal = t_util.t_startInternalTransaction();
        long cid2 = t_util.t_addContainer(tinternal, 0);
        ContainerHandle c2 = t_util.t_openContainer(tinternal, 0, cid2, true);
        Page p2 = t_util.t_addPage(c2);
        RecordHandle r2 = t_util.t_insert(p2, row);
        // commit internal transaction
        tinternal.commit();
        // this will close the container and release
        tinternal.abort();
        // the page
        tinternal.close();
        tinternal = null;
        REPORT("commit internal transaction");
        // abort user transaction
        t_util.t_abort(tuser);
        REPORT("rollback user transaction");
        c1 = t_util.t_openContainer(tuser, 0, cid1, true);
        p1 = t_util.t_getPage(c1, r1.getPageNumber());
        if (p1.recordExists(r1, false))
            throw T_Fail.testFailMsg("user transaction failed to rollback");
        c2 = t_util.t_openContainer(tuser, 0, cid2, true);
        // this should be unaffected by the
        t_util.t_checkFetch(c2, r2, REC_001);
        // user transaction rollback
        p2 = t_util.t_getLastPage(c2);
        T_RawStoreRow row2 = new T_RawStoreRow(REC_002);
        if (!p2.spaceForInsert()) {
            REPORT("P054 not run, page cannot accomodate 2 rows");
            return;
        }
        RecordHandle r21 = t_util.t_insert(p2, row2);
        // throw an exception, make sure everything is aborted.
        tinternal = t_util.t_startInternalTransaction();
        long cid3 = t_util.t_addContainer(tinternal, 0);
        ContainerHandle c3 = t_util.t_openContainer(tinternal, 0, cid3, true);
        Page p3 = t_util.t_addPage(c3);
        RecordHandle r3 = t_util.t_insert(p3, row);
        try {
            // this will throw a data statement exception
            t_util.t_insertAtSlot(p3, 100, row);
        } catch (StandardException se) {
            REPORT("cleanup on error");
            // Assume database is not active. DERBY-4856 thread dump
            cm1.cleanupOnError(se, false);
            REPORT("done cleanup on error");
        }
        tinternal = null;
        // tuser = t_util.t_startTransaction();
        c2 = t_util.t_openContainer(tuser, 0, cid2, true);
        t_util.t_checkFetch(c2, r2, REC_001);
        p2 = t_util.t_getPage(c2, r21.getPageNumber());
        if (p2.recordExists(r21, false))
            throw T_Fail.testFailMsg("expect user transaction to rollback");
        // this should fail
        ContainerKey id3 = new ContainerKey(0, cid3);
        c3 = tuser.openContainer(id3, ContainerHandle.MODE_READONLY);
        if (c3 != null)
            throw T_Fail.testFailMsg("expect internal transaction to rollback");
        LockingPolicy nolock = tuser.newLockingPolicy(LockingPolicy.MODE_NONE, 0, false);
        RawContainerHandle stub = ((RawTransaction) tuser).openDroppedContainer(id3, nolock);
        if (stub == null)
            throw T_Fail.testFailMsg("expect container to be dropped");
        if (stub.getContainerStatus() != RawContainerHandle.COMMITTED_DROP)
            throw T_Fail.testFailMsg("expect container to be committed dropped");
        // this should fail
        p3 = stub.getPage(r3.getPageNumber());
        if (p3 != null)
            throw T_Fail.testFailMsg("should not getpage with committed dropped container");
        PASS("P054");
        // cleanup
        t_util.t_dropContainer(tuser, 0, cid2);
        // cleanup
        t_util.t_dropContainer(tuser, 0, cid1);
        if (tinternal != null) {
            t_util.t_abort(tinternal);
            tinternal.close();
        }
        if (tuser != null) {
            t_util.t_commit(tuser);
            tuser.close();
        }
    } finally {
        contextService.resetCurrentContextManager(cm1);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) ContextManager(org.apache.derby.iapi.services.context.ContextManager) 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 30 with RawTransaction

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

the class T_Recovery method S301.

/*
	 * incomplete transactions with create container
	 */
protected void S301() throws T_Fail, StandardException {
    T_TWC ctx = t_util.t_startTransactionWithContext();
    Transaction t = ctx.tran;
    Page page = null;
    ctx.switchTransactionContext();
    try {
        long cid1 = t_util.t_addContainer(t, 0);
        ContainerHandle c1 = t_util.t_openContainer(t, 0, cid1, true);
        page = t_util.t_addPage(c1);
        T_RawStoreRow row1 = new T_RawStoreRow(REC_001);
        RecordHandle r1 = t_util.t_insert(page, row1);
        t.abort();
        ContainerKey id1 = new ContainerKey(0, cid1);
        c1 = t.openContainer(id1, ContainerHandle.MODE_READONLY);
        if (c1 != null)
            throw T_Fail.testFailMsg("expect container to be dropped");
        LockingPolicy nolock = t.newLockingPolicy(LockingPolicy.MODE_NONE, 0, false);
        RawContainerHandle stub = ((RawTransaction) t).openDroppedContainer(new ContainerKey(0, cid1), 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");
        long cid2 = t_util.t_addContainer(t, 0);
        ContainerHandle c2 = t_util.t_openContainer(t, 0, cid2, true);
        page = t_util.t_addPage(c2);
        T_RawStoreRow row2 = new T_RawStoreRow(REC_002);
        RecordHandle r2 = t_util.t_insert(page, row2);
        REPORT("setup S301: cid1 " + cid1 + " cid2 " + cid2);
        register(key(301, 1), cid1);
        register(key(301, 2), cid2);
    } finally {
        if (page != null && page.isLatched())
            page.unlatch();
        ctx.resetContext();
    }
// let recovery rollback incomplete transaction
}
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)

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