use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageWriteTrxImpl method prepareEntryForModification.
@Override
public Record prepareEntryForModification(@Nonnegative final Long recordKey, final PageKind pageKind, final int index, final Optional<UnorderedKeyValuePage> keyValuePage) throws SirixIOException {
mPageRtx.assertNotClosed();
checkNotNull(recordKey);
checkArgument(recordKey >= 0, "recordKey must be >= 0!");
checkNotNull(pageKind);
checkNotNull(keyValuePage);
final long recordPageKey = mPageRtx.pageKey(recordKey);
final PageContainer cont = prepareRecordPage(recordPageKey, index, pageKind);
Record record = ((UnorderedKeyValuePage) cont.getModified()).getValue(recordKey);
if (record == null) {
final Record oldRecord = ((UnorderedKeyValuePage) cont.getComplete()).getValue(recordKey);
if (oldRecord == null) {
throw new SirixIOException("Cannot retrieve record from cache!");
}
record = oldRecord;
((UnorderedKeyValuePage) cont.getModified()).setEntry(record.getNodeKey(), record);
}
return record;
}
use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageWriteTrxImpl method preparePreviousRevisionRootPage.
/**
* Prepare the previous revision root page and retrieve the next {@link RevisionRootPage}.
*
* @param baseRevision base revision
* @param representRevision the revision to represent
* @return new {@link RevisionRootPage} instance
* @throws SirixIOException if an I/O error occurs
*/
private RevisionRootPage preparePreviousRevisionRootPage(@Nonnegative final int baseRevision, @Nonnegative final int representRevision) throws SirixIOException {
if (getUberPage().isBootstrap()) {
final RevisionRootPage revisionRootPage = mPageRtx.loadRevRoot(baseRevision);
// appendLogRecord(new PageContainer(revisionRootPage, revisionRootPage));
return revisionRootPage;
} else {
// Prepare revision root nodePageReference.
final RevisionRootPage revisionRootPage = new RevisionRootPage(mPageRtx.loadRevRoot(baseRevision), representRevision + 1);
// Prepare indirect tree to hold reference to prepared revision root nodePageReference.
final PageReference revisionRootPageReference = prepareLeafOfTree(getUberPage().getIndirectPageReference(), getUberPage().getRevisionNumber(), -1, PageKind.UBERPAGE);
// Link the prepared revision root nodePageReference with the prepared indirect tree.
appendLogRecord(revisionRootPageReference, new PageContainer(revisionRootPage, revisionRootPage));
// Return prepared revision root nodePageReference.
return revisionRootPage;
}
}
use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageWriteTrxImpl method createEntry.
@Override
public Record createEntry(final Long key, final Record record, final PageKind pageKind, final int index, final Optional<UnorderedKeyValuePage> keyValuePage) throws SirixIOException {
mPageRtx.assertNotClosed();
// Allocate record key and increment record count.
long recordKey;
switch(pageKind) {
case RECORDPAGE:
recordKey = mNewRoot.incrementAndGetMaxNodeKey();
break;
case PATHSUMMARYPAGE:
final PathSummaryPage pathSummaryPage = ((PathSummaryPage) mNewRoot.getPathSummaryPageReference().getPage());
recordKey = pathSummaryPage.incrementAndGetMaxNodeKey(index);
break;
case CASPAGE:
final CASPage casPage = ((CASPage) mNewRoot.getCASPageReference().getPage());
recordKey = casPage.incrementAndGetMaxNodeKey(index);
break;
case PATHPAGE:
final PathPage pathPage = ((PathPage) mNewRoot.getPathPageReference().getPage());
recordKey = pathPage.incrementAndGetMaxNodeKey(index);
break;
case NAMEPAGE:
final NamePage namePage = ((NamePage) mNewRoot.getNamePageReference().getPage());
recordKey = namePage.incrementAndGetMaxNodeKey(index);
break;
default:
throw new IllegalStateException();
}
final long recordPageKey = mPageRtx.pageKey(recordKey);
final PageContainer cont = prepareRecordPage(recordPageKey, index, pageKind);
@SuppressWarnings("unchecked") final KeyValuePage<Long, Record> modified = (KeyValuePage<Long, Record>) cont.getModified();
modified.setEntry(record.getNodeKey(), record);
return record;
}
use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageWriteTrxImpl method removeEntry.
@Override
public void removeEntry(final Long recordKey, @Nonnull final PageKind pageKind, final int index, final Optional<UnorderedKeyValuePage> keyValuePage) throws SirixIOException {
mPageRtx.assertNotClosed();
final long nodePageKey = mPageRtx.pageKey(recordKey);
final PageContainer cont = prepareRecordPage(nodePageKey, index, pageKind);
final Optional<Record> node = getRecord(recordKey, pageKind, index);
if (node.isPresent()) {
final Record nodeToDel = node.get();
final Node delNode = new DeletedNode(new NodeDelegate(nodeToDel.getNodeKey(), -1, -1, -1, Optional.<SirixDeweyID>empty()));
((UnorderedKeyValuePage) cont.getModified()).setEntry(delNode.getNodeKey(), delNode);
((UnorderedKeyValuePage) cont.getComplete()).setEntry(delNode.getNodeKey(), delNode);
} else {
throw new IllegalStateException("Node not found!");
}
}
Aggregations