use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageReadTrxImpl method loadRevRoot.
/**
* Get revision root page belonging to revision key.
*
* @param revisionKey key of revision to find revision root page for
* @return revision root page of this revision key
*
* @throws SirixIOException if something odd happens within the creation process
*/
@Override
public RevisionRootPage loadRevRoot(@Nonnegative final int revisionKey) throws SirixIOException {
checkArgument(revisionKey >= 0 && revisionKey <= mResourceManager.getMostRecentRevisionNumber(), "%s must be >= 0 and <= last stored revision (%s)!", revisionKey, mResourceManager.getMostRecentRevisionNumber());
// The indirect page reference either fails horribly or returns a non null instance.
final PageReference reference = getPageReferenceForPage(mUberPage.getIndirectPageReference(), revisionKey, -1, PageKind.UBERPAGE);
try {
RevisionRootPage page = null;
if (mTrxIntentLog != null) {
// Try to get it from the transaction log if it's present.
final PageContainer cont = mTrxIntentLog.get(reference);
page = cont == null ? null : (RevisionRootPage) cont.getComplete();
}
if (page == null) {
assert reference.getKey() != Constants.NULL_ID_LONG || reference.getLogKey() != Constants.NULL_ID_INT || reference.getPersistentLogKey() != Constants.NULL_ID_LONG;
page = (RevisionRootPage) mPageCache.get(reference);
}
return page;
} catch (final ExecutionException | UncheckedExecutionException e) {
throw new SirixIOException(e.getCause());
}
}
use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageWriteTrxImpl method prepareIndirectPage.
/**
* Prepare indirect page, that is getting the referenced indirect page or a new page.
*
* @param reference {@link PageReference} to get the indirect page from or to create a new one
* @return {@link IndirectPage} reference
* @throws SirixIOException if an I/O error occurs
*/
private IndirectPage prepareIndirectPage(final PageReference reference) throws SirixIOException {
final PageContainer cont = mLog.get(reference);
IndirectPage page = cont == null ? null : (IndirectPage) cont.getComplete();
if (page == null) {
if (reference.getKey() == Constants.NULL_ID_LONG) {
page = new IndirectPage();
} else {
final IndirectPage indirectPage = mPageRtx.dereferenceIndirectPageReference(reference);
page = new IndirectPage(indirectPage);
}
appendLogRecord(reference, new PageContainer(page, page));
}
return page;
}
use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageWriteTrxImpl method prepareRecordPage.
/**
* Prepare record page.
*
* @param recordPageKey the key of the record page
* @param pageKind the kind of page (used to determine the right subtree)
* @return {@link PageContainer} instance
* @throws SirixIOException if an I/O error occurs
*/
private PageContainer prepareRecordPage(@Nonnegative final long recordPageKey, final int index, final PageKind pageKind) throws SirixIOException {
assert recordPageKey >= 0;
assert pageKind != null;
// Get the reference to the unordered key/value page storing the records.
final PageReference reference = prepareLeafOfTree(mPageRtx.getPageReference(mNewRoot, pageKind, index), recordPageKey, index, pageKind);
PageContainer pageContainer = mLog.get(reference);
if (pageContainer.equals(PageContainer.emptyInstance())) {
if (reference.getKey() == Constants.NULL_ID_LONG) {
final UnorderedKeyValuePage completePage = new UnorderedKeyValuePage(recordPageKey, pageKind, Constants.NULL_ID_LONG, mPageRtx);
final UnorderedKeyValuePage modifyPage = mPageRtx.clone(completePage);
pageContainer = new PageContainer(completePage, modifyPage);
} else {
pageContainer = dereferenceRecordPageForModification(reference);
}
assert pageContainer != null;
switch(pageKind) {
case RECORDPAGE:
case PATHSUMMARYPAGE:
case PATHPAGE:
case CASPAGE:
case NAMEPAGE:
appendLogRecord(reference, pageContainer);
break;
default:
throw new IllegalStateException("Page kind not known!");
}
}
return pageContainer;
}
use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageWriteTrxImpl method commit.
@Override
public void commit(@Nullable final PageReference reference) {
if (reference == null)
return;
final PageContainer container = mLog.get(reference);
Page page = null;
if (container != null) {
page = container.getModified();
}
if (page == null) {
return;
}
reference.setPage(page);
// Recursively commit indirectly referenced pages and then write self.
page.commit(this);
mPageWriter.write(reference);
// Remove page reference.
reference.setPage(null);
}
use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageWriteTrxImpl method getRecord.
@Override
public Optional<Record> getRecord(@Nonnegative final long recordKey, final PageKind pageKind, @Nonnegative final int index) throws SirixIOException {
mPageRtx.assertNotClosed();
checkArgument(recordKey >= Fixed.NULL_NODE_KEY.getStandardProperty());
checkNotNull(pageKind);
// Calculate page.
final long recordPageKey = mPageRtx.pageKey(recordKey);
final PageContainer pageCont = prepareRecordPage(recordPageKey, index, pageKind);
if (pageCont.equals(PageContainer.emptyInstance())) {
return mPageRtx.getRecord(recordKey, pageKind, index);
} else {
Record node = ((UnorderedKeyValuePage) pageCont.getModified()).getValue(recordKey);
if (node == null) {
node = ((UnorderedKeyValuePage) pageCont.getComplete()).getValue(recordKey);
}
return mPageRtx.checkItemIfDeleted(node);
}
}
Aggregations