Search in sources :

Example 6 with PageReference

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

use of org.sirix.page.PageReference 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 8 with PageReference

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

the class PageWriteTrxImpl method commit.

@Override
public UberPage commit() {
    mPageRtx.assertNotClosed();
    mPageRtx.mResourceManager.getCommitLock().lock();
    final Path commitFile = mPageRtx.mResourceManager.commitFile();
    commitFile.toFile().deleteOnExit();
    // Issues with windows that it's not created in the first time?
    while (!Files.exists(commitFile)) {
        try {
            Files.createFile(commitFile);
        } catch (final IOException e) {
            throw new SirixIOException(e);
        }
    }
    // Forcefully flush write-ahead transaction logs to persistent storage.
    if (mPageRtx.mResourceManager.getResourceManagerConfig().dumpLogs()) {
        mLog.toSecondCache();
    }
    final PageReference uberPageReference = new PageReference();
    final UberPage uberPage = getUberPage();
    uberPageReference.setPage(uberPage);
    final int revision = uberPage.getRevisionNumber();
    // Recursively write indirectly referenced pages.
    uberPage.commit(this);
    uberPageReference.setPage(uberPage);
    mPageWriter.writeUberPageReference(uberPageReference);
    uberPageReference.setPage(null);
    final Path indexes = mPageRtx.mResourceConfig.mPath.resolve(ResourceConfiguration.ResourcePaths.INDEXES.getFile() + String.valueOf(revision) + ".xml");
    if (!Files.exists(indexes)) {
        try {
            Files.createFile(indexes);
        } catch (final IOException e) {
            throw new SirixIOException(e);
        }
    }
    try (final OutputStream out = new FileOutputStream(indexes.toFile())) {
        mIndexController.serialize(out);
    } catch (final IOException e) {
        throw new SirixIOException("Index definitions couldn't be serialized!", e);
    }
    mLog.clear();
    mLog.close();
    mLog = createTrxIntentLog(mPageRtx.mResourceManager);
    try {
        Files.delete(commitFile);
    } catch (final IOException e) {
        throw new SirixIOException("Commit file couldn't be deleted!");
    }
    final UberPage commitedUberPage = (UberPage) mPageWriter.read(mPageWriter.readUberPageReference(), mPageRtx);
    mPageRtx.mResourceManager.getCommitLock().unlock();
    return commitedUberPage;
}
Also used : Path(java.nio.file.Path) PageReference(org.sirix.page.PageReference) UberPage(org.sirix.page.UberPage) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) SirixIOException(org.sirix.exception.SirixIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) SirixIOException(org.sirix.exception.SirixIOException)

Example 9 with PageReference

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

the class PageDelegate method createNewReference.

private PageReference createNewReference(final BitSet offsetBitmap, int offset) {
    final int index = index(offsetBitmap, offset);
    final PageReference reference = new PageReference();
    mReferences.add(index, reference);
    // final PageReference[] newArray = new PageReference[mReferences.length + 1];
    // System.arraycopy(mReferences, 0, newArray, 0, index);
    // newArray[index] = new PageReference();
    // System.arraycopy(mReferences, index, newArray, index + 1, mReferences.length - index);
    mBitmap.set(offset, true);
    // mReferences = newArray;
    return reference;
}
Also used : PageReference(org.sirix.page.PageReference)

Example 10 with PageReference

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

the class PageDelegate method toString.

@Override
public String toString() {
    final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this);
    for (final PageReference ref : mReferences) {
        helper.add("reference", ref);
    }
    helper.add("bitmap", dumpBitmap(mBitmap));
    return helper.toString();
}
Also used : PageReference(org.sirix.page.PageReference) MoreObjects(com.google.common.base.MoreObjects)

Aggregations

PageReference (org.sirix.page.PageReference)15 UberPage (org.sirix.page.UberPage)8 SirixIOException (org.sirix.exception.SirixIOException)5 PageContainer (org.sirix.cache.PageContainer)4 RevisionRootPage (org.sirix.page.RevisionRootPage)4 IndirectPage (org.sirix.page.IndirectPage)3 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)3 IOException (java.io.IOException)2 CASPage (org.sirix.page.CASPage)2 NamePage (org.sirix.page.NamePage)2 PathPage (org.sirix.page.PathPage)2 PathSummaryPage (org.sirix.page.PathSummaryPage)2 KeyValuePage (org.sirix.page.interfaces.KeyValuePage)2 Page (org.sirix.page.interfaces.Page)2 MoreObjects (com.google.common.base.MoreObjects)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1 DatabaseException (com.sleepycat.je.DatabaseException)1 OperationStatus (com.sleepycat.je.OperationStatus)1 FileOutputStream (java.io.FileOutputStream)1