Search in sources :

Example 1 with IndirectPage

use of org.sirix.page.IndirectPage 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 2 with IndirectPage

use of org.sirix.page.IndirectPage 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 3 with IndirectPage

use of org.sirix.page.IndirectPage in project sirix by sirixdb.

the class PageWriteTrxImpl method prepareLeafOfTree.

/**
 * Prepare the leaf of a tree, namely the reference to a {@link UnorderedKeyValuePage}.
 *
 * @param startReference start reference
 * @param key page key to lookup
 * @param index the index number or {@code -1} if a regular record page should be prepared
 * @return {@link PageReference} instance pointing to the right {@link UnorderedKeyValuePage} with
 *         the {@code pKey}
 * @throws SirixIOException if an I/O error occured
 */
private PageReference prepareLeafOfTree(final PageReference startReference, @Nonnegative final long key, final int index, final PageKind pageKind) throws SirixIOException {
    // Initial state pointing to the indirect nodePageReference of level 0.
    PageReference reference = startReference;
    int offset = 0;
    long levelKey = key;
    final int[] inpLevelPageCountExp = mPageRtx.getUberPage().getPageCountExp(pageKind);
    // Iterate through all levels.
    for (int level = 0, height = inpLevelPageCountExp.length; level < height; level++) {
        offset = (int) (levelKey >> inpLevelPageCountExp[level]);
        levelKey -= offset << inpLevelPageCountExp[level];
        final IndirectPage page = prepareIndirectPage(reference);
        reference = page.getReference(offset);
    }
    // Return reference to leaf of indirect tree.
    return reference;
}
Also used : PageReference(org.sirix.page.PageReference) IndirectPage(org.sirix.page.IndirectPage)

Aggregations

IndirectPage (org.sirix.page.IndirectPage)3 PageContainer (org.sirix.cache.PageContainer)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 ExecutionException (java.util.concurrent.ExecutionException)1 SirixIOException (org.sirix.exception.SirixIOException)1 PageReference (org.sirix.page.PageReference)1