use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.
the class AllocPage method readAllocPageHeader.
private void readAllocPageHeader() throws IOException {
ArrayInputStream lrdi = rawDataIn;
lrdi.setPosition(ALLOC_PAGE_HEADER_OFFSET);
nextAllocPageNumber = lrdi.readLong();
nextAllocPageOffset = lrdi.readLong();
reserved1 = lrdi.readLong();
reserved2 = lrdi.readLong();
reserved3 = lrdi.readLong();
reserved4 = lrdi.readLong();
}
use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.
the class AllocPage method readExtent.
private AllocExtent readExtent(int offset) throws IOException, ClassNotFoundException {
ArrayInputStream lrdi = rawDataIn;
rawDataIn.setPosition(offset);
AllocExtent newExtent = new AllocExtent();
newExtent.readExternal(lrdi);
// in 1.3 or later, make sure the upgrade from before 1.3 is legal.
if (SanityManager.DEBUG) {
int max_range = AllocExtent.MAX_RANGE(getMaxFreeSpace());
long extent_start = newExtent.getFirstPagenum();
long extent_end = newExtent.getExtentEnd();
if ((extent_start + max_range - 1) < extent_end) {
SanityManager.THROWASSERT("extent range exceed what extent's space can handle ");
}
}
return newExtent;
}
use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.
the class StoredPage method restoreLongRecordFromSlot.
private StoredRecordHeader restoreLongRecordFromSlot(Object[] row, FetchDescriptor fetchDesc, RecordHandle recordToLock, StoredRecordHeader parent_recordHeader) throws StandardException {
int slot = findRecordById(parent_recordHeader.getOverflowId(), Page.FIRST_SLOT_NUMBER);
StoredRecordHeader recordHeader = getHeaderAtSlot(slot);
try {
int offset_to_row_data = getRecordOffset(slot) + recordHeader.size();
if (SanityManager.DEBUG) {
if (getRecordOffset(slot) < (PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE)) {
SanityManager.THROWASSERT("Incorrect offset. offset = " + getRecordOffset(slot) + ", offset should be < " + "(PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE) = " + (PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE) + ", current slot = " + slot + ", total slotsInUse = " + slotsInUse);
}
}
// position the array reading stream at beginning of row data
// just past the record header.
ArrayInputStream lrdi = rawDataIn;
lrdi.setPosition(offset_to_row_data);
if (fetchDesc != null) {
if (fetchDesc.getQualifierList() != null) {
fetchDesc.reset();
}
readRecordFromArray(row, (fetchDesc.getValidColumns() == null) ? row.length - 1 : fetchDesc.getMaxFetchColumnId(), fetchDesc.getValidColumnsArray(), fetchDesc.getMaterializedColumns(), lrdi, recordHeader, recordToLock);
} else {
readRecordFromArray(row, row.length - 1, (int[]) null, (int[]) null, lrdi, recordHeader, recordToLock);
}
return (recordHeader.hasOverflow() ? recordHeader : null);
} catch (IOException ioe) {
if (SanityManager.DEBUG) {
if (pageData == null) {
SanityManager.DEBUG_PRINT("DEBUG_TRACE", "caught an IOException in restoreRecordFromSlot " + (PageKey) getIdentity() + " slot " + slot + ", pageData is null");
} else {
SanityManager.DEBUG_PRINT("DEBUG_TRACE", "caught an IOException in reestoreRecordFromSlot, " + (PageKey) getIdentity() + " slot " + slot + ", pageData.length = " + pageData.length + " pageSize = " + getPageSize());
SanityManager.DEBUG_PRINT("DEBUG_TRACE", "Hex dump of pageData \n " + "--------------------------------------------------\n" + pagedataToHexDump(pageData) + "--------------------------------------------------\n");
SanityManager.DEBUG_PRINT("DEBUG_TRACE", "Attempt to dump page " + this.toString());
}
}
// i/o methods on the byte array have thrown an IOException
throw dataFactory.markCorrupt(StandardException.newException(SQLState.DATA_CORRUPT_PAGE, ioe, getPageId()));
}
}
use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.
the class StoredPage method getFieldOffset.
/*
**
*/
/**
* Get the offset of the field header of the given field for
* the record in the given slot.
*
* Field number is the absolute number for the complete record, not just this portion.
* E.g. if this is a record portion that starts at field 3 and has 6 fields
* then the second field on this *page* has field number 4.
*/
private int getFieldOffset(int slot, int fieldNumber) throws IOException {
// RESOLVE - overflow, needs to be changed
int offset = getRecordOffset(slot);
StoredRecordHeader recordHeader = getHeaderAtSlot(slot);
// get the number of fields
int startField = recordHeader.getFirstField();
if (SanityManager.DEBUG) {
int numberFields = recordHeader.getNumberFields();
if ((fieldNumber < startField) || (fieldNumber >= (startField + numberFields)))
SanityManager.THROWASSERT("fieldNumber: " + fieldNumber + " start field: " + startField + " number of fields " + numberFields);
}
ArrayInputStream lrdi = rawDataIn;
// skip the record header
lrdi.setPosition(offset + recordHeader.size());
// skip any earlier fields ...
for (int i = startField; i < fieldNumber; i++) {
skipField(lrdi);
}
return rawDataIn.getPosition();
}
use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.
the class StoredPage method purgeColumnChains.
/**
* purge long columns chains which eminate from this page.
* <p>
* Purge all the long column chains emanating from the record on this slot
* of this page. The headRowHandle is the record handle of the head row
* piece of this row - if this page is the head row, then headRowHandle is
* the record handle at the slot. Otherwise, headRowHandle points to a
* row on a different page, i.e., the head page.
* <p>
*
* @param t The raw transaction doing the purging.
* @param slot The slot of the row to purge.
* @param headRowHandle The RecordHandle of the head row.
*
* @exception StandardException Standard exception policy.
*/
private void purgeColumnChains(RawTransaction t, int slot, RecordHandle headRowHandle) throws StandardException {
try {
StoredRecordHeader recordHeader = getHeaderAtSlot(slot);
int numberFields = recordHeader.getNumberFields();
// these reads are always against the page array
ArrayInputStream lrdi = rawDataIn;
// position the stream to just after record header.
int offset = getRecordOffset(slot) + recordHeader.size();
lrdi.setPosition(offset);
for (int i = 0; i < numberFields; i++) {
int fieldStatus = StoredFieldHeader.readStatus(lrdi);
int fieldLength = StoredFieldHeader.readFieldDataLength(lrdi, fieldStatus, slotFieldSize);
if (!StoredFieldHeader.isOverflow(fieldStatus)) {
// skip this field, it is not an long column
if (fieldLength != 0)
lrdi.setPosition(lrdi.getPosition() + fieldLength);
continue;
} else {
// Got an overflow field. The column value is the
// <pageId, recordId> pair where the next column piece is
// residing
long overflowPageId = CompressedNumber.readLong((InputStream) lrdi);
int overflowRecordId = CompressedNumber.readInt((InputStream) lrdi);
purgeOneColumnChain(overflowPageId, overflowRecordId);
}
}
} catch (IOException ioe) {
throw dataFactory.markCorrupt(StandardException.newException(SQLState.DATA_CORRUPT_PAGE, ioe, getPageId()));
}
}
Aggregations