Search in sources :

Example 1 with RecordHandle

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

the class ControlRow method compareRowsOnSiblings.

protected boolean compareRowsOnSiblings(OpenBTree btree, ControlRow left_sib, ControlRow right_sib) throws StandardException {
    if (SanityManager.DEBUG) {
        boolean is_consistent = true;
        // Check that left last row is < right page's first row.
        if (left_sib.page.recordCount() > 1 && right_sib.page.recordCount() > 1) {
            DataValueDescriptor[] left_lastrow = getRowTemplate(btree);
            DataValueDescriptor[] right_firstrow = getRowTemplate(btree);
            RecordHandle left_lastrow_handle = left_sib.page.fetchFromSlot((RecordHandle) null, left_sib.page.recordCount() - 1, left_lastrow, (FetchDescriptor) null, true);
            RecordHandle right_firstrow_handle = right_sib.page.fetchFromSlot((RecordHandle) null, 1, right_firstrow, (FetchDescriptor) null, true);
            int r = compareIndexRowToKey(left_lastrow, right_firstrow, btree.getConglomerate().nUniqueColumns, 0, btree.getConglomerate().ascDescInfo);
            if (r >= 0) {
                SanityManager.THROWASSERT("last row on left page " + left_sib.page.getPageNumber() + " > than first row on right page " + right_sib.page.getPageNumber() + "\n" + "left last row = " + RowUtil.toString(left_lastrow) + "right first row = " + RowUtil.toString(right_firstrow) + left_sib + " last > first of " + right_sib);
                is_consistent = false;
            }
        }
        return (is_consistent);
    } else {
        return (true);
    }
}
Also used : RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 2 with RecordHandle

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

the class ControlRow method checkRowOrder.

/**
 ** Check that all rows on the page are in order.  This
 ** means that each key is &gt; than the previous key.
 *
 *    @exception StandardException Standard exception policy.
 */
protected boolean checkRowOrder(OpenBTree btree, ControlRow parent) throws StandardException {
    if (SanityManager.DEBUG) {
        RecordHandle lesser_handle = null;
        RecordHandle greater_handle = null;
        DataValueDescriptor[] lesser = getRowTemplate(btree);
        DataValueDescriptor[] greater = getRowTemplate(btree);
        boolean is_consistent = true;
        int numslots = page.recordCount();
        for (int i = ControlRow.CR_SLOT + 1; (i + 1) < numslots; i++) {
            lesser_handle = page.fetchFromSlot((RecordHandle) null, i, lesser, (FetchDescriptor) null, true);
            greater_handle = page.fetchFromSlot((RecordHandle) null, i + 1, greater, (FetchDescriptor) null, true);
            SanityManager.ASSERT(btree.getConglomerate().nUniqueColumns <= btree.getConglomerate().nKeyFields);
            int compare_result = compareIndexRowToKey(lesser, greater, btree.getConglomerate().nUniqueColumns, 0, btree.getConglomerate().ascDescInfo);
            // >= 0 means that lesser >= greater
            if (compare_result >= 0) {
                SanityManager.THROWASSERT("Bad order of rows found in conglomerate: " + btree + "\n." + "compare result = " + compare_result + ".  " + "nKeyFields = " + btree.getConglomerate().nKeyFields + ".\n" + this + " rows " + (i) + " and " + (i + 1) + " out of order.\n" + "row[" + i + "] + " + RowUtil.toString(lesser) + "\n" + "row[" + (i + 1) + "] + " + RowUtil.toString(greater) + "\ndump of page = " + debugPage(btree) + "\ndump of parent page = " + ((parent != null) ? parent.debugPage(btree) : "null parent") + "\rawstore dump = " + this.page);
                is_consistent = false;
            }
        }
        return (is_consistent);
    } else {
        return (true);
    }
}
Also used : RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle) FetchDescriptor(org.apache.derby.iapi.store.raw.FetchDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 3 with RecordHandle

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

the class LeafControlRow method initEmptyBtree.

/**
 * Initialize conglomerate with one page, to be a 1 page btree.
 *
 * Given a conglomerate which already has one page allocated to it,
 * initialize the page to be a leaf-root page with no entries.  Allocate
 * the control row and store it on the page.
 *
 * @param open_btree The open btree to initialize (container is open).
 *
 * @exception StandardException Standard exception policy.
 */
public static void initEmptyBtree(OpenBTree open_btree) throws StandardException {
    Page page = open_btree.container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);
    // create a leaf control row for root page of a single page index //
    LeafControlRow control_row = new LeafControlRow(open_btree, page, null, true);
    byte insertFlag = Page.INSERT_INITIAL;
    insertFlag |= Page.INSERT_DEFAULT;
    RecordHandle rh = page.insertAtSlot(Page.FIRST_SLOT_NUMBER, control_row.getRow(), (FormatableBitSet) null, (LogicalUndo) null, insertFlag, AccessFactoryGlobals.BTREE_OVERFLOW_THRESHOLD);
    if (SanityManager.DEBUG) {
        RecordHandle rh2 = null;
        rh2 = page.fetchFromSlot((RecordHandle) null, Page.FIRST_SLOT_NUMBER, new DataValueDescriptor[0], (FetchDescriptor) null, true);
        SanityManager.ASSERT(rh.getId() == rh2.getId() && rh.getPageNumber() == rh2.getPageNumber());
    }
    if (SanityManager.DEBUG) {
        if (SanityManager.DEBUG_ON("enableBtreeConsistencyCheck")) {
            control_row.checkConsistency(open_btree, (ControlRow) null, true);
        }
    }
    page.unlatch();
    return;
}
Also used : RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle) FetchDescriptor(org.apache.derby.iapi.store.raw.FetchDescriptor) Page(org.apache.derby.iapi.store.raw.Page) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 4 with RecordHandle

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

the class BasePage method updateAtSlot.

/**
 * @see Page#updateAtSlot
 *		@exception StandardException	Standard Derby error policy
 *		@exception StandardException	StandardException.newException(SQLState.UPDATE_DELETED_RECORD
 *		if the record is already deleted
 *		@exception StandardException	StandardException.newException(SQLState.CONTAINER_READ_ONLY
 *		if the container is read only
 */
public final RecordHandle updateAtSlot(int slot, Object[] row, FormatableBitSet validColumns) throws StandardException {
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(isLatched());
    }
    if (!owner.updateOK()) {
        throw StandardException.newException(SQLState.DATA_CONTAINER_READ_ONLY);
    }
    if (isDeletedAtSlot(slot)) {
        throw StandardException.newException(SQLState.DATA_UPDATE_DELETED_RECORD);
    }
    RecordHandle handle = getRecordHandleAtSlot(slot);
    RawTransaction t = owner.getTransaction();
    doUpdateAtSlot(t, slot, handle.getId(), row, validColumns);
    return handle;
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle)

Example 5 with RecordHandle

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

the class BasePage method updateFieldAtSlot.

/**
 * @see Page#updateFieldAtSlot
 *		@exception StandardException	Standard Derby error policy
 *		@exception StandardException	StandardException.newException(SQLState.UPDATE_DELETED_RECORD
 *		if the record is already deleted
 *		@exception StandardException	StandardException.newException(SQLState.CONTAINER_READ_ONLY
 *		if the container is read only
 */
public RecordHandle updateFieldAtSlot(int slot, int fieldId, Object newValue, LogicalUndo undo) throws StandardException {
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(isLatched());
        SanityManager.ASSERT(newValue != null);
    }
    if (!owner.updateOK()) {
        throw StandardException.newException(SQLState.DATA_CONTAINER_READ_ONLY);
    }
    if (isDeletedAtSlot(slot)) {
        throw StandardException.newException(SQLState.DATA_UPDATE_DELETED_RECORD);
    }
    RawTransaction t = owner.getTransaction();
    RecordHandle handle = getRecordHandleAtSlot(slot);
    owner.getActionSet().actionUpdateField(t, this, slot, handle.getId(), fieldId, newValue, undo);
    return handle;
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) 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