Search in sources :

Example 6 with PageContainer

use of org.sirix.cache.PageContainer in project sirix by sirixdb.

the class PageUtils method createTree.

/**
 * Create the initial tree structure.
 *
 * @param reference reference from revision root
 * @param pageKind the page kind
 */
public static void createTree(@Nonnull PageReference reference, final PageKind pageKind, final int index, final PageReadTrx pageReadTrx, final TransactionIntentLog log) {
    Page page = null;
    // Level page count exponent from the configuration.
    final int[] levelPageCountExp = pageReadTrx.getUberPage().getPageCountExp(pageKind);
    // Remaining levels.
    for (int i = 0, l = levelPageCountExp.length; i < l; i++) {
        page = new IndirectPage();
        log.put(reference, new PageContainer(page, page));
        reference = page.getReference(0);
    }
    // Create new record page.
    final UnorderedKeyValuePage ndp = new UnorderedKeyValuePage(Fixed.ROOT_PAGE_KEY.getStandardProperty(), pageKind, Constants.NULL_ID_LONG, pageReadTrx);
    // Create a {@link DocumentRootNode}.
    final Optional<SirixDeweyID> id = pageReadTrx.getResourceManager().getResourceConfig().mDeweyIDsStored ? Optional.of(SirixDeweyID.newRootID()) : Optional.empty();
    final NodeDelegate nodeDel = new NodeDelegate(Fixed.DOCUMENT_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), 0, id);
    final StructNodeDelegate strucDel = new StructNodeDelegate(nodeDel, Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), 0, 0);
    ndp.setEntry(0L, new DocumentRootNode(nodeDel, strucDel));
    log.put(reference, new PageContainer(ndp, ndp));
}
Also used : PageContainer(org.sirix.cache.PageContainer) DocumentRootNode(org.sirix.node.DocumentRootNode) StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) Page(org.sirix.page.interfaces.Page) SirixDeweyID(org.sirix.node.SirixDeweyID) NodeDelegate(org.sirix.node.delegates.NodeDelegate) StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate)

Example 7 with PageContainer

use of org.sirix.cache.PageContainer in project sirix by sirixdb.

the class UberPage method createRevisionTree.

/**
 * Create revision tree.
 *
 * @param pageReadTrx {@link PageReadTrx} instance
 * @param revisionRoot {@link RevisionRootPage} instance
 */
public void createRevisionTree(final TransactionIntentLog log) {
    // Initialize revision tree to guarantee that there is a revision root page.
    Page page = null;
    PageReference reference = getIndirectPageReference();
    // Remaining levels.
    for (int i = 0, l = Constants.UBPINP_LEVEL_PAGE_COUNT_EXPONENT.length; i < l; i++) {
        page = new IndirectPage();
        log.put(reference, new PageContainer(page, page));
        reference = page.getReference(0);
    }
    mRootPage = new RevisionRootPage();
    final Page namePage = mRootPage.getNamePageReference().getPage();
    log.put(mRootPage.getNamePageReference(), new PageContainer(namePage, namePage));
    final Page casPage = mRootPage.getCASPageReference().getPage();
    log.put(mRootPage.getCASPageReference(), new PageContainer(casPage, casPage));
    final Page pathPage = mRootPage.getPathPageReference().getPage();
    log.put(mRootPage.getPathPageReference(), new PageContainer(pathPage, pathPage));
    final Page pathSummaryPage = mRootPage.getPathSummaryPageReference().getPage();
    log.put(mRootPage.getPathSummaryPageReference(), new PageContainer(pathSummaryPage, pathSummaryPage));
    log.put(reference, new PageContainer(mRootPage, mRootPage));
}
Also used : PageContainer(org.sirix.cache.PageContainer) Page(org.sirix.page.interfaces.Page)

Example 8 with PageContainer

use of org.sirix.cache.PageContainer in project sirix by sirixdb.

the class PageReadTrxImpl method dereferenceIndirectPageReference.

/**
 * Dereference indirect page reference.
 *
 * @param reference reference to dereference
 * @return dereferenced page
 *
 * @throws SirixIOException if something odd happens within the creation process
 * @throws NullPointerException if {@code reference} is {@code null}
 */
@Override
public IndirectPage dereferenceIndirectPageReference(final PageReference reference) {
    try {
        IndirectPage 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 : (IndirectPage) cont.getComplete();
        }
        if (page == null) {
            // Then try to get the in-memory reference.
            page = (IndirectPage) reference.getPage();
        }
        if (page == null && (reference.getKey() != Constants.NULL_ID_LONG || reference.getLogKey() != Constants.NULL_ID_INT || reference.getPersistentLogKey() != Constants.NULL_ID_LONG)) {
            // Then try to get it from the page cache which might read it from the persistent storage
            // on a cache miss.
            page = (IndirectPage) mPageCache.get(reference);
        }
        return page;
    } catch (final ExecutionException | UncheckedExecutionException e) {
        throw new SirixIOException(e.getCause());
    }
}
Also used : 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) IndirectPage(org.sirix.page.IndirectPage)

Example 9 with PageContainer

use of org.sirix.cache.PageContainer in project sirix by sirixdb.

the class PageReadTrxImpl method getRecord.

@Override
public Optional<Record> getRecord(final long nodeKey, final PageKind pageKind, @Nonnegative final int index) {
    checkNotNull(pageKind);
    assertNotClosed();
    if (nodeKey == Fixed.NULL_NODE_KEY.getStandardProperty()) {
        return Optional.empty();
    }
    final long recordPageKey = pageKey(nodeKey);
    final PageContainer cont;
    try {
        switch(pageKind) {
            case RECORDPAGE:
            case PATHSUMMARYPAGE:
            case PATHPAGE:
            case CASPAGE:
            case NAMEPAGE:
                cont = mNodeCache.get(new IndexLogKey(pageKind, recordPageKey, index));
                break;
            default:
                throw new IllegalStateException();
        }
    } catch (final ExecutionException | UncheckedExecutionException e) {
        throw new SirixIOException(e.getCause());
    }
    if (PageContainer.emptyInstance().equals(cont)) {
        return Optional.empty();
    }
    final Record retVal = ((UnorderedKeyValuePage) cont.getComplete()).getValue(nodeKey);
    return checkItemIfDeleted(retVal);
}
Also used : PageContainer(org.sirix.cache.PageContainer) IndexLogKey(org.sirix.cache.IndexLogKey) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Record(org.sirix.node.interfaces.Record) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) SirixIOException(org.sirix.exception.SirixIOException)

Example 10 with PageContainer

use of org.sirix.cache.PageContainer in project sirix by sirixdb.

the class PageReadTrxImpl method getRecordPageContainer.

@Override
public <K extends Comparable<? super K>, V extends Record, T extends KeyValuePage<K, V>> PageContainer getRecordPageContainer(@Nonnegative final Long recordPageKey, final int index, final PageKind pageKind) throws SirixIOException {
    assertNotClosed();
    checkArgument(recordPageKey >= 0, "recordPageKey must not be negative!");
    final Optional<PageReference> pageReferenceToRecordPage = getLeafPageReference(checkNotNull(recordPageKey), index, checkNotNull(pageKind));
    if (!pageReferenceToRecordPage.isPresent()) {
        return PageContainer.emptyInstance();
    }
    // Try to get from resource buffer manager.
    final PageContainer recordPageContainerFromBuffer = mResourceBufferManager.getRecordPageCache().get(pageReferenceToRecordPage.get());
    if (recordPageContainerFromBuffer != null) {
        return recordPageContainerFromBuffer;
    }
    // Load list of page "fragments" from persistent storage.
    final List<T> pages = getSnapshotPages(pageReferenceToRecordPage.get());
    if (pages.isEmpty()) {
        return PageContainer.emptyInstance();
    }
    final int mileStoneRevision = mResourceConfig.mRevisionsToRestore;
    final Versioning revisioning = mResourceConfig.mRevisionKind;
    final Page completePage = revisioning.combineRecordPages(pages, mileStoneRevision, this);
    final PageContainer recordPageContainer = new PageContainer(completePage, clone(completePage));
    if (mTrxIntentLog == null)
        mResourceBufferManager.getRecordPageCache().put(pageReferenceToRecordPage.get(), recordPageContainer);
    return recordPageContainer;
}
Also used : PageReference(org.sirix.page.PageReference) PageContainer(org.sirix.cache.PageContainer) Versioning(org.sirix.settings.Versioning) 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)

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