protected NodeInfo getNextDataNode(NodePosition nodePos) {
if (finished) {
return null;
}
int id = btree.getBtreeId();
final PageBufferManager buffer = btree.getBuffer();
final BTreeSpec btreeSpec = btree.getBTreeSpec();
dupNextCountForTest = dupNextCountForNextNode;
dupNextCountForNextNode = 0;
int curPageNo = nodePos.getPageNo();
PageNumber dupPageNumber = new PageNumber(curPageNo);
try {
DataPage dupDataPage = new DataPage(id, dupPageNumber, btreeSpec, buffer);
NodeInfo node = new NodeInfo();
node.nodePosition = nodePos;
while (true) {
int ret = getNode(dupDataPage, node);
if ((ret & DUP_FINISHED) == DUP_FINISHED) {
finished = true;
if ((ret & DUP_NEXT) == DUP_NEXT) {
break;
}
}
if ((ret & DUP_DATA) == DUP_DATA) {
return node;
} else if ((ret & DUP_NEXT) == DUP_NEXT) {
node.nodePosition = node.nodeNextPosition;
if (node.nodeNextPosition.getPageNo() != curPageNo) {
curPageNo = node.nodeNextPosition.getPageNo();
buffer.releasePage(id, dupPageNumber, false);
dupPageNumber = new PageNumber(curPageNo);
dupDataPage = new DataPage(id, dupPageNumber, btreeSpec, buffer);
}
} else {
logger.error("Failed to get next dup node.");
break;
}
}
} catch (ChaiDBException e) {
logger.error(e);
} finally {
buffer.releasePage(id, dupPageNumber, false);
}
return null;
}