Search in sources :

Example 21 with RawTransaction

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

the class PageBasicOperation method findpage.

/**
 * Find the page the operation applies to and latch it, this only
 *	    uses the segmentId, containerId, and pageId stored in this log
 *		record to find the page.
 *
 *		@return null if container is dropped and committed (possibly
 *		stubbified), else return the latched page
 *
 *		@exception StandardException Standard Derby policy.
 */
public final BasePage findpage(Transaction xact) throws StandardException {
    releaseResource(xact);
    RawTransaction rtran = (RawTransaction) xact;
    containerHdl = rtran.openDroppedContainer(pageId.getContainerId(), (LockingPolicy) null);
    if (containerHdl == null) {
        throw StandardException.newException(SQLState.DATA_CONTAINER_VANISHED, pageId.getContainerId());
    }
    foundHere = true;
    // it may be a container stub
    if (containerHdl.getContainerStatus() == RawContainerHandle.COMMITTED_DROP) {
        releaseResource(xact);
        return null;
    }
    StandardException getPageException = null;
    try {
        // get and latch page - we don't know the status of the page or what
        // kind of page we are looking for, get any type of page
        page = (BasePage) (containerHdl.getAnyPage(pageId.getPageNumber()));
    } catch (StandardException se) {
        getPageException = se;
    }
    // We do this if derby.storage.patchInitPageRecoverError is set.
    if (page == null && getPageException != null && pageVersion == 0)
        if (PropertyUtil.getSystemBoolean(RawStoreFactory.PATCH_INITPAGE_RECOVER_ERROR))
            page = getPageForRedoRecovery(xact);
    // give subclass a chance to create the page
    if (page == null && getPageException != null) {
        if (rtran.inRollForwardRecovery()) {
            if (SanityManager.DEBUG)
                if (SanityManager.DEBUG_ON("LoadTran"))
                    SanityManager.DEBUG_PRINT("Trace", "got null page " + pageId + " and getPageException, attempt last ditch effort");
            page = getPageForRedoRecovery(xact);
            if (SanityManager.DEBUG)
                if (SanityManager.DEBUG_ON("LoadTran"))
                    SanityManager.DEBUG_PRINT("Trace", " getPageForRedoRecovery, got page=" + (page != null));
        }
    }
    if (page == null) {
        if (getPageException != null) {
            // that is the original error
            throw getPageException;
        } else {
            throw StandardException.newException(SQLState.DATA_MISSING_PAGE, pageId);
        }
    }
    return page;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) LockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy)

Example 22 with RawTransaction

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

the class ContainerBasicOperation method findContainer.

/**
 *		Methods specific to this class
 */
/**
 *	  Open the container with this segmentId and containerId.
 *	  This method should only be called if the container has already been
 *	  created.
 *
 *	  @exception StandardException the container cannot be found or cannot be
 *	  opened.
 */
protected RawContainerHandle findContainer(Transaction tran) throws StandardException {
    releaseResource(tran);
    RawTransaction rtran = (RawTransaction) tran;
    containerHdl = rtran.openDroppedContainer(containerId, (LockingPolicy) null);
    // reused the container id that was dropped earlier.
    if (rtran.inRollForwardRecovery()) {
        if (containerHdl == null) {
            if (SanityManager.DEBUG) {
                if (SanityManager.DEBUG_ON("LoadTran")) {
                    SanityManager.DEBUG_PRINT("Trace", "cannot find container " + containerId + ", now attempt last ditch effort");
                }
            }
            containerHdl = findContainerForRedoRecovery(rtran);
            if (SanityManager.DEBUG) {
                if (SanityManager.DEBUG_ON("LoadTran")) {
                    SanityManager.DEBUG_PRINT("Trace", " findContainerForRedoRecovery, got container=" + (containerHdl != null));
                }
            }
        }
    }
    if (containerHdl == null) {
        throw StandardException.newException(SQLState.DATA_CONTAINER_VANISHED, containerId);
    }
    foundHere = true;
    return containerHdl;
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) LockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy)

Example 23 with RawTransaction

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

the class XactFactory method handlePreparedXacts.

/**
 *        Run through all prepared transactions known to this factory
 *        and restore their state such that they remain after recovery, and
 *        can be found and handled by a XA transaction manager.  This includes
 *        creating a context manager for each, pushing a xact context, and
 *        reclaiming update locks on all data changed by the transaction.
 *
 *        Expected to be called just after the redo and undo recovery loops,
 *        where the transaction table should be empty except for prepared
 *        xacts.
 *
 *		Used only in recovery.
 *
 *		@exception StandardException Derby Standard Error policy
 */
public void handlePreparedXacts(RawStoreFactory rsf) throws StandardException {
    if (SanityManager.DEBUG) {
        if (rawStoreFactory != null)
            SanityManager.ASSERT(rawStoreFactory == rsf, "raw store factory different");
    }
    int prepared_count = 0;
    if (ttab.hasPreparedRecoveredXact()) {
        while (true) {
            // allocate new context and associate new xact with it.
            ContextManager cm = contextFactory.newContextManager();
            contextFactory.setCurrentContextManager(cm);
            try {
                RawTransaction rawtran = startTransaction(rawStoreFactory, cm, AccessFactoryGlobals.USER_TRANS_NAME);
                if (ttab.getMostRecentPreparedRecoveredXact(rawtran)) {
                    // found a prepared xact.  The reprepare() call will
                    // accumulate locks, and change the transaction table entry
                    // to not be "in-recovery" so that it won't show up again.
                    rawtran.reprepare();
                    if (SanityManager.DEBUG)
                        prepared_count++;
                } else {
                    // get rid of last transaction allocated.
                    rawtran.destroy();
                    break;
                }
            } finally {
                contextFactory.resetCurrentContextManager(cm);
            }
        }
    }
    if (SanityManager.DEBUG) {
    // RESOLVE - need to only do this under a debug flag.
    // SanityManager.DEBUG_PRINT("",
    // "Recovery re-prepared " + prepared_count + " xa transactions.");
    }
}
Also used : ContextManager(org.apache.derby.iapi.services.context.ContextManager) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction)

Example 24 with RawTransaction

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

the class RemoveFile method remove.

/**
 *	  @see FileResource#remove
 *	  @exception StandardException Oops
 */
public void remove(String name, long currentGenerationId) throws StandardException {
    if (factory.isReadOnly())
        throw StandardException.newException(SQLState.FILE_READ_ONLY);
    ContextManager cm = FileContainer.getContextService().getCurrentContextManager();
    RawTransaction tran = factory.getRawStoreFactory().getXactFactory().findUserTransaction(factory.getRawStoreFactory(), cm, AccessFactoryGlobals.USER_TRANS_NAME);
    // Block the backup, If backup is already in progress wait
    // for the backup to finish. Jar files are unlogged but the
    // changes to the  references to the jar file in the catalogs
    // is logged. A consistent backup can not be made when jar file
    // is being removed.
    tran.blockBackup(true);
    tran.logAndDo(new RemoveFileOperation(name, currentGenerationId, true));
    Serviceable s = new RemoveFile(getAsFile(name, currentGenerationId));
    tran.addPostCommitWork(s);
}
Also used : Serviceable(org.apache.derby.iapi.services.daemon.Serviceable) ContextManager(org.apache.derby.iapi.services.context.ContextManager) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction)

Example 25 with RawTransaction

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

the class BasePage method insertNoOverflow.

protected RecordHandle insertNoOverflow(int slot, Object[] row, FormatableBitSet validColumns, LogicalUndo undo, byte insertFlag, int overflowThreshold) throws StandardException {
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(isLatched());
    }
    if (!owner.updateOK()) {
        throw StandardException.newException(SQLState.DATA_CONTAINER_READ_ONLY);
    }
    if (slot < FIRST_SLOT_NUMBER || slot > recordCount) {
        throw StandardException.newException(SQLState.DATA_SLOT_NOT_ON_PAGE);
    }
    if (!allowInsert())
        return null;
    RawTransaction t = owner.getTransaction();
    // logical operations not allowed in internal transactions.
    if (undo != null) {
        t.checkLogicalOperationOk();
    }
    int recordId;
    RecordHandle handle;
    do {
        // loop until we get a new record id we can get a lock on.
        // If we can't get the lock without waiting then assume the record
        // id is owned by another xact.  The current heap overflow
        // algorithm makes this likely, as it first try's to insert a row
        // telling raw store to fail if it doesn't fit on the page getting
        // a lock on an id that never makes it to disk.   The inserting
        // transaction will hold a lock on this "unused" record id until
        // it commits.  The page can leave the cache at this point, and
        // the inserting transaction has not dirtied the page (it failed
        // after getting the lock but before logging anything), another
        // inserting transaction will then get the same id as the
        // previous inserter - thus the loop on lock waits.
        // 
        // The lock we request indicates that this is a lock for insert,
        // which the locking policy may use to perform locking concurrency
        // optimizations.
        recordId = newRecordIdAndBump();
        handle = new RecordId(getPageId(), recordId, slot);
    } while (!owner.getLockingPolicy().lockRecordForWrite(t, handle, true, /* lock is for insert */
    false));
    owner.getActionSet().actionInsert(t, this, slot, recordId, row, validColumns, undo, insertFlag, 0, false, -1, (DynamicByteArrayOutputStream) null, -1, overflowThreshold);
    return handle;
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle)

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