Search in sources :

Example 36 with RecordHandle

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

the class HeapController method lockRow.

/**
 * Lock the given record id/page num pair.
 * <p>
 * Should only be called by access, to lock "special" locks formed from
 * the Recordhandle.* reserved constants for page specific locks.
 * <p>
 * This call can be made on a ConglomerateController that was opened
 * for locking only.
 * <p>
 * RESOLVE (mikem) - move this call to ConglomerateManager so it is
 * obvious that non-access clients should not call this.
 *
 * @return true if lock was granted, only can be false if wait was false.
 *
 * @param page_num          Page number of row to lock.
 * @param record_id         Record id of row on page_num to lock.
 * @param lock_operation    Desc of what to lock for, ie. update, insert ...
 * @param wait              Should the lock call wait to be granted?
 *
 * @exception  StandardException  Standard exception policy.
 */
public boolean lockRow(long page_num, int record_id, int lock_operation, boolean wait, int lock_duration) throws StandardException {
    boolean ret_val;
    RecordHandle rh = open_conglom.getContainer().makeRecordHandle(page_num, record_id);
    return (lockRow(rh, lock_operation, wait, lock_duration));
}
Also used : RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle)

Example 37 with RecordHandle

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

the class HeapController method unlockRowAfterRead.

/**
 * UnLock the given row location.
 * <p>
 * Should only be called by access.
 * <p>
 * This call can be made on a ConglomerateController that was opened
 * for locking only.
 * <p>
 * RESOLVE (mikem) - move this call to ConglomerateManager so it is
 * obvious that non-access clients should not call this.
 *
 * @param loc       The "RowLocation" which describes the row to unlock.
 * @param forUpdate Row was previously Locked the record for read or update.
 *
 * @exception  StandardException  Standard exception policy.
 */
public void unlockRowAfterRead(RowLocation loc, boolean forUpdate, boolean row_qualified) throws StandardException {
    RecordHandle rh = ((HeapRowLocation) loc).getRecordHandle(open_conglom.getContainer());
    open_conglom.getContainer().getLockingPolicy().unlockRecordAfterRead(open_conglom.getRawTran(), open_conglom.getContainer(), rh, open_conglom.isForUpdate(), row_qualified);
}
Also used : RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle)

Example 38 with RecordHandle

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

the class HeapController method purgeCommittedDeletes.

/**
 ************************************************************************
 * Private/Protected methods of This class:
 **************************************************************************
 */
/**
 * Check and purge committed deleted rows on a page.
 * <p>
 *
 * @return true, if no purging has been done on page, and thus latch
 *         can be released before end transaction.  Otherwise the latch
 *         on the page can not be released before commit.
 *
 * @param page   A non-null, latched page must be passed in.  If all
 *               rows on page are purged, then page will be removed and
 *               latch released.
 *
 * @exception  StandardException  Standard exception policy.
 */
protected final boolean purgeCommittedDeletes(Page page) throws StandardException {
    boolean purgingDone = false;
    // The number records that can be reclaimed is:
    // total recs - recs_not_deleted
    int num_possible_commit_delete = page.recordCount() - page.nonDeletedRecordCount();
    if (num_possible_commit_delete > 0) {
        // have already looked at).
        for (int slot_no = page.recordCount() - 1; slot_no >= 0; slot_no--) {
            boolean row_is_committed_delete = page.isDeletedAtSlot(slot_no);
            if (row_is_committed_delete) {
                // At this point we only know that the row is
                // deleted, not whether it is committed.
                // see if we can purge the row, by getting an
                // exclusive lock on the row.  If it is marked
                // deleted and we can get this lock, then it
                // must be a committed delete and we can purge
                // it.
                RecordHandle rh = page.fetchFromSlot((RecordHandle) null, slot_no, RowUtil.EMPTY_ROW, RowUtil.EMPTY_ROW_FETCH_DESCRIPTOR, true);
                row_is_committed_delete = this.lockRowAtSlotNoWaitExclusive(rh);
                if (row_is_committed_delete) {
                    purgingDone = true;
                    page.purgeAtSlot(slot_no, 1, false);
                }
            }
        }
    }
    if (page.recordCount() == 0) {
        // Deallocate the current page with 0 rows on it.
        this.removePage(page);
        // removePage guarantees to unlatch the page even if an
        // exception is thrown. The page is protected against reuse
        // because removePage locks it with a dealloc lock, so it
        // is OK to release the latch even after a purgeAtSlot is
        // called.
        // @see ContainerHandle#removePage
        purgingDone = true;
    }
    return (purgingDone);
}
Also used : RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle)

Aggregations

RecordHandle (org.apache.derby.iapi.store.raw.RecordHandle)38 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)10 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)10 Page (org.apache.derby.iapi.store.raw.Page)9 PageKey (org.apache.derby.iapi.store.raw.PageKey)6 IOException (java.io.IOException)4 DynamicByteArrayOutputStream (org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream)4 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)4 ContainerHandle (org.apache.derby.iapi.store.raw.ContainerHandle)4 FetchDescriptor (org.apache.derby.iapi.store.raw.FetchDescriptor)4 StandardException (org.apache.derby.shared.common.error.StandardException)3 LogicalUndo (org.apache.derby.iapi.store.access.conglomerate.LogicalUndo)2 LockingPolicy (org.apache.derby.iapi.store.raw.LockingPolicy)2 SQLLongint (org.apache.derby.iapi.types.SQLLongint)2 ByteArray (org.apache.derby.iapi.util.ByteArray)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 EOFException (java.io.EOFException)1 InputStream (java.io.InputStream)1 ArrayInputStream (org.apache.derby.iapi.services.io.ArrayInputStream)1