Search in sources :

Example 21 with ArrayInputStream

use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.

the class ArrayInputStreamTest method testSkipNegative.

/**
 * Test that skip() returns 0 when the argument is negative (DERBY-3739).
 */
public void testSkipNegative() throws IOException {
    ArrayInputStream ais = new ArrayInputStream(new byte[1000]);
    assertEquals(0, ais.skip(-1));
}
Also used : ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream)

Example 22 with ArrayInputStream

use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.

the class StoredPage method getNextColumnPiece.

/**
 *        @return a recordHandle pointing to the next piece of the column chain.
 *        This page must be an overflow page that is in a column chain.  If this
 *        is the last piece of the overflow colum, return null.
 *
 *        @param slot the slot number where the current piece of overflow column
 *        is at.
 *        @exception StandardException Derby Standard Error Policy
 */
/**
 * Return the next recordHandle in a long column chain.
 * <p>
 * Return a recordHandle pointing to the next piece of the column chain.
 * This page must be an overflow page that is in a column chain.  If this
 * is the last piece of the overflow colum, return null.
 * <p>
 *
 * @return The next record handle in a long column chain.
 *
 * @param slot   The slot of the current long column piece.
 *
 * @exception  StandardException  Standard exception policy.
 */
private RecordHandle getNextColumnPiece(int slot) throws StandardException {
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(isLatched());
        SanityManager.ASSERT(isOverflowPage(), "not expected to call getNextColumnPiece on non-overflow page");
        if (recordCount() != 1) {
            SanityManager.THROWASSERT("getNextColumnPiece called on a page with " + recordCount() + " rows");
        }
    }
    try {
        StoredRecordHeader recordHeader = getHeaderAtSlot(slot);
        int numberFields = recordHeader.getNumberFields();
        if (SanityManager.DEBUG) {
            if ((numberFields > 2) || (numberFields < 1)) {
                SanityManager.THROWASSERT("longColumn record header must have 1 or 2 fields." + " numberFields = " + numberFields);
            }
        }
        if (// End of column chain.
        numberFields != 2)
            return null;
        // these reads are always against the page array
        ArrayInputStream lrdi = rawDataIn;
        // The 2nd field is the pointer to the next page in column chain.
        int offset = getRecordOffset(slot) + recordHeader.size();
        lrdi.setPosition(offset);
        // skip the first field
        skipField(lrdi);
        // the 2nd field should be <pageId, recordId> pair, return the
        // pageId part and skip over the length.
        int fieldStatus = StoredFieldHeader.readStatus(lrdi);
        int fieldLength = StoredFieldHeader.readFieldDataLength(lrdi, fieldStatus, slotFieldSize);
        long ovflowPage = CompressedNumber.readLong((InputStream) lrdi);
        int ovflowRid = CompressedNumber.readInt((InputStream) lrdi);
        if (SanityManager.DEBUG) {
            if (!StoredFieldHeader.isOverflow(fieldStatus)) {
                // In version 1.5, the first field is overflow and the
                // second is not. In version 2.0 onwards, the first field
                // is not overflow and the second is overflow (the overflow
                // bit goes with the overflow pointer).  Check first field
                // to make sure its overflow bit is set on.
                // Offset still points to the first column.
                lrdi.setPosition(offset);
                fieldStatus = StoredFieldHeader.readStatus(lrdi);
                SanityManager.ASSERT(StoredFieldHeader.isOverflow(fieldStatus));
            }
        }
        return owner.makeRecordHandle(ovflowPage, ovflowRid);
    } catch (IOException ioe) {
        throw dataFactory.markCorrupt(StandardException.newException(SQLState.DATA_CORRUPT_PAGE, ioe, getPageId()));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream) IOException(java.io.IOException)

Example 23 with ArrayInputStream

use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.

the class StoredPage method initialize.

/**
 * Initialize the StoredPage.
 * <p>
 * Initialize the object, ie. perform work normally perfomed in constructor.
 * Called by setIdentity() and createIdentity() - the Cacheable interfaces
 * which are used to move a page in/out of cache.
 */
protected void initialize() {
    super.initialize();
    if (rawDataIn == null) {
        rawDataIn = new ArrayInputStream();
        checksum = new CRC32();
    }
    if (pageData != null)
        rawDataIn.setData(pageData);
}
Also used : CRC32(java.util.zip.CRC32) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream)

Example 24 with ArrayInputStream

use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.

the class StoredPage method entireRecordOnPage.

/**
 ************************************************************************
 * Record based routines.
 **************************************************************************
 */
/**
 * Is entire record on the page?
 * <p>
 *
 * @return true if the entire record at slot is on this page,
 *         i.e, no overflow row or long columns.
 *
 * @param slot   Check record at this slot.
 *
 * @exception  StandardException  Standard exception policy.
 */
public boolean entireRecordOnPage(int slot) throws StandardException {
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(isLatched());
    }
    StoredRecordHeader recordHeader = getHeaderAtSlot(slot);
    if (recordHeader.hasOverflow())
        return false;
    try {
        int offset = getRecordOffset(slot);
        if (SanityManager.DEBUG) {
            if (offset < (PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE)) {
                SanityManager.THROWASSERT("Incorrect offset.  offset = " + offset + ", offset should be < " + "(PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE) = " + (PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE) + ", current slot = " + slot + ", total slotsInUse = " + slotsInUse);
            }
            if (recordHeader.getFirstField() != 0) {
                SanityManager.THROWASSERT("Head row piece should start at field 0 but is not," + ", current slot = " + slot + ", total slotsInUse = " + slotsInUse + "page = " + this);
            }
        }
        int numberFields = recordHeader.getNumberFields();
        // these reads are always against the page array
        ArrayInputStream lrdi = rawDataIn;
        // position after the record header, at 1st column.
        lrdi.setPosition(offset + recordHeader.size());
        for (int i = 0; i < numberFields; i++) {
            int fieldStatus = StoredFieldHeader.readStatus(lrdi);
            if (StoredFieldHeader.isOverflow(fieldStatus))
                return false;
            int fieldLength = StoredFieldHeader.readFieldDataLength(lrdi, fieldStatus, slotFieldSize);
            if (fieldLength != 0)
                lrdi.setPosition(lrdi.getPosition() + fieldLength);
        }
    } catch (IOException ioe) {
        throw dataFactory.markCorrupt(StandardException.newException(SQLState.DATA_CORRUPT_PAGE, ioe, getPageId()));
    }
    // we have examined all the fields on this page and none overflows
    return true;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream) IOException(java.io.IOException)

Example 25 with ArrayInputStream

use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.

the class StoredPage method getReservedCount.

/**
 * Return reserved length of row on this page.
 * <p>
 * Return the reserved length of this record.
 * This length is stored as the third "field" of the slot table entry.
 *
 * @return The reserved length of the row on this page.
 *
 * @param slot   the slot of the row to look up the length of.
 */
public int getReservedCount(int slot) throws IOException {
    if (SanityManager.DEBUG) {
        if (getRecordOffset(slot) <= 0) {
            SanityManager.DEBUG_PRINT("DEBUG_TRACE", "getReservedCount failed with getRecordOffset(" + slot + ") = " + getRecordOffset(slot) + " must be greater than 0." + "page dump = \n" + toUncheckedString());
            SanityManager.THROWASSERT("bad record offset found in getReservedCount");
        }
    }
    // these reads are always against the page array
    ArrayInputStream lrdi = rawDataIn;
    lrdi.setPosition(slotTableOffsetToFirstReservedSpaceField - (slot * slotEntrySize));
    return ((slotFieldSize == SMALL_SLOT_SIZE) ? lrdi.readUnsignedShort() : lrdi.readInt());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream)

Aggregations

ArrayInputStream (org.apache.derby.iapi.services.io.ArrayInputStream)28 ByteArrayInputStream (java.io.ByteArrayInputStream)16 IOException (java.io.IOException)11 StandardException (org.apache.derby.shared.common.error.StandardException)4 PageKey (org.apache.derby.iapi.store.raw.PageKey)3 LogRecord (org.apache.derby.impl.store.raw.log.LogRecord)3 EOFException (java.io.EOFException)2 InputStream (java.io.InputStream)2 ErrorObjectInput (org.apache.derby.iapi.services.io.ErrorObjectInput)2 FormatIdInputStream (org.apache.derby.iapi.services.io.FormatIdInputStream)2 StreamStorable (org.apache.derby.iapi.services.io.StreamStorable)2 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)2 LogCounter (org.apache.derby.impl.store.raw.log.LogCounter)2 StreamLogScan (org.apache.derby.impl.store.raw.log.StreamLogScan)2 CRC32 (java.util.zip.CRC32)1 Compensation (org.apache.derby.iapi.store.raw.Compensation)1 Loggable (org.apache.derby.iapi.store.raw.Loggable)1 RePreparable (org.apache.derby.iapi.store.raw.RePreparable)1 Undoable (org.apache.derby.iapi.store.raw.Undoable)1 LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)1