Search in sources :

Example 1 with PageContainer

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());
    }
}
Also used : PageReference(org.sirix.page.PageReference) PageContainer(org.sirix.cache.PageContainer) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) SirixIOException(org.sirix.exception.SirixIOException) RevisionRootPage(org.sirix.page.RevisionRootPage)

Example 2 with PageContainer

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;
}
Also used : PageContainer(org.sirix.cache.PageContainer) IndirectPage(org.sirix.page.IndirectPage)

Example 3 with PageContainer

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;
}
Also used : PageReference(org.sirix.page.PageReference) PageContainer(org.sirix.cache.PageContainer) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage)

Example 4 with 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);
}
Also used : PageContainer(org.sirix.cache.PageContainer) KeyValuePage(org.sirix.page.interfaces.KeyValuePage) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) CASPage(org.sirix.page.CASPage) Page(org.sirix.page.interfaces.Page) RevisionRootPage(org.sirix.page.RevisionRootPage) NamePage(org.sirix.page.NamePage) PathSummaryPage(org.sirix.page.PathSummaryPage) UberPage(org.sirix.page.UberPage) PathPage(org.sirix.page.PathPage) IndirectPage(org.sirix.page.IndirectPage)

Example 5 with PageContainer

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);
    }
}
Also used : PageContainer(org.sirix.cache.PageContainer) Record(org.sirix.node.interfaces.Record) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage)

Aggregations

PageContainer (org.sirix.cache.PageContainer)14 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)8 Record (org.sirix.node.interfaces.Record)5 SirixIOException (org.sirix.exception.SirixIOException)4 IndirectPage (org.sirix.page.IndirectPage)4 PageReference (org.sirix.page.PageReference)4 RevisionRootPage (org.sirix.page.RevisionRootPage)4 Page (org.sirix.page.interfaces.Page)4 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)3 ExecutionException (java.util.concurrent.ExecutionException)3 CASPage (org.sirix.page.CASPage)3 NamePage (org.sirix.page.NamePage)3 PathPage (org.sirix.page.PathPage)3 PathSummaryPage (org.sirix.page.PathSummaryPage)3 KeyValuePage (org.sirix.page.interfaces.KeyValuePage)3 SirixDeweyID (org.sirix.node.SirixDeweyID)2 NodeDelegate (org.sirix.node.delegates.NodeDelegate)2 UberPage (org.sirix.page.UberPage)2 IndexLogKey (org.sirix.cache.IndexLogKey)1 DeletedNode (org.sirix.node.DeletedNode)1