LOG.warn("Failed to acquire read lock on " + db.getFile().getName());
//TODO : throw exception here ? -pb
return null;
}
db.setOwnerObject(broker);
StoredNode nextNode = null;
if (gotoNextPosition()) {
long backLink = 0;
do {
final DOMFile.DOMFilePageHeader pageHeader = page.getPageHeader();
//Next value larger than length of the current page?
if (offset >= pageHeader.getDataLength()) {
//Load next page in chain
long nextPageNum = pageHeader.getNextDataPage();
if (nextPageNum == Page.NO_PAGE) {
SanityCheck.TRACE("bad link to next " + page.page.getPageInfo() +
"; previous: " + pageHeader.getPreviousDataPage() +
"; offset = " + offset + "; lastTupleID = " + lastTupleID);
System.out.println(db.debugPageContents(page));
//TODO : throw exception here ? -pb
return null;
}
pageNum = nextPageNum;
page = db.getDOMPage(nextPageNum);
db.addToBuffer(page);
offset = 0;
}
//Extract the tuple ID
lastTupleID = ByteConversion.byteToShort(page.data, offset);
offset += DOMFile.LENGTH_TID;
//Check if this is just a link to a relocated node
if(ItemId.isLink(lastTupleID)) {
//Skip this
offset += DOMFile.LENGTH_FORWARD_LOCATION;
//Continue the iteration
continue;
}
//Read data length
short vlen = ByteConversion.byteToShort(page.data, offset);
offset += DOMFile.LENGTH_DATA_LENGTH;
if (vlen < 0) {
LOG.error("Got negative length" + vlen + " at offset " + offset + "!!!");
LOG.debug(db.debugPageContents(page));
//TODO : throw an exception right now ?
}
if(ItemId.isRelocated(lastTupleID)) {
//Found a relocated node. Read the original address
backLink = ByteConversion.byteToLong(page.data, offset);
offset += DOMFile.LENGTH_ORIGINAL_LOCATION;
}
//Overflow page? Load the overflow value
if (vlen == DOMFile.OVERFLOW) {
vlen = DOMFile.LENGTH_OVERFLOW_LOCATION;
final long overflow = ByteConversion.byteToLong(page.data, offset);
offset += DOMFile.LENGTH_OVERFLOW_LOCATION;
try {
final byte[] overflowValue = db.getOverflowValue(overflow);
nextNode = StoredNode.deserialize(overflowValue, 0, overflowValue.length,
doc, useNodePool);
} catch(final Exception e) {
LOG.warn("Exception while loading overflow value: " + e.getMessage() +
"; originating page: " + page.page.getPageInfo());
//TODO : rethrow exception ? -pb
}
//Normal node
} else {
try {
nextNode = StoredNode.deserialize(page.data, offset, vlen, doc, useNodePool);
offset += vlen;
} catch(final Exception e) {
LOG.error("Error while deserializing node: " + e.getMessage(), e);
LOG.error("Reading from offset: " + offset + "; len = " + vlen);
LOG.debug(db.debugPageContents(page));
System.out.println(db.debugPageContents(page));
throw new RuntimeException(e);
}
}
if (nextNode == null) {
LOG.error("illegal node on page " + page.getPageNum() +
"; tid = " + ItemId.getId(lastTupleID) +
"; next = " + page.getPageHeader().getNextDataPage() +
"; prev = " + page.getPageHeader().getPreviousDataPage() +
"; offset = " + (offset - vlen) +
"; len = " + page.getPageHeader().getDataLength());
System.out.println(db.debugPageContents(page));
//TODO : throw an exception here ? -pb
return null;
}
if (ItemId.isRelocated(lastTupleID)) {
nextNode.setInternalAddress(backLink);
} else {
nextNode.setInternalAddress(StorageAddress.createPointer((int) pageNum,
ItemId.getId(lastTupleID)));
}
nextNode.setOwnerDocument(doc);
} while (nextNode == null);
}
return nextNode;
} catch (final BTreeException e) {
LOG.error(e.getMessage(), e);