Search in sources :

Example 16 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class PageReadTrxImpl method getPage.

/**
 * Set the page if it is not set already.
 *
 * @param reference page reference
 * @throws SirixIOException if an I/O error occurs
 */
private Page getPage(final PageReference reference, final PageKind pageKind) throws SirixIOException {
    try {
        Page page = reference.getPage();
        if (page == null) {
            page = mPageCache.get(reference);
            reference.setPage(page);
        }
        return page;
    } catch (final ExecutionException | UncheckedExecutionException e) {
        throw new SirixIOException(e.getCause());
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) 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) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) SirixIOException(org.sirix.exception.SirixIOException)

Example 17 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class PageReadTrxImpl method getPageReferenceForPage.

/**
 * Find reference pointing to leaf page of an indirect tree.
 *
 * @param startReference start reference pointing to the indirect tree
 * @param recordPageKey key to look up in the indirect tree
 * @return reference denoted by key pointing to the leaf page
 *
 * @throws SirixIOException if an I/O error occurs
 */
@Nullable
@Override
public final PageReference getPageReferenceForPage(final PageReference startReference, @Nonnegative final long recordPageKey, final int index, final PageKind pageKind) throws SirixIOException {
    assertNotClosed();
    // Initial state pointing to the indirect page of level 0.
    PageReference reference = checkNotNull(startReference);
    checkArgument(recordPageKey >= 0, "key must be >= 0!");
    checkNotNull(pageKind);
    int offset = 0;
    long levelKey = recordPageKey;
    final int[] inpLevelPageCountExp = mUberPage.getPageCountExp(pageKind);
    // Iterate through all levels.
    for (int level = 0, height = inpLevelPageCountExp.length; level < height; level++) {
        final Page derefPage = dereferenceIndirectPageReference(reference);
        if (derefPage == null) {
            reference = null;
            break;
        } else {
            offset = (int) (levelKey >> inpLevelPageCountExp[level]);
            levelKey -= offset << inpLevelPageCountExp[level];
            try {
                // assert offset >= 0 && offset < mUberPage.getPageReferenceCount(pageKind);
                reference = derefPage.getReference(offset);
            } catch (final IndexOutOfBoundsException e) {
                throw new SirixIOException("Node key isn't supported, it's too big!");
            }
        }
    }
    // Return reference to leaf of indirect tree.
    return reference;
}
Also used : PageReference(org.sirix.page.PageReference) 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) SirixIOException(org.sirix.exception.SirixIOException) Nullable(javax.annotation.Nullable)

Example 18 with SirixIOException

use of org.sirix.exception.SirixIOException 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 19 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class PageReadTrxImpl method clone.

@SuppressWarnings("unchecked")
<E extends Page> E clone(final E toClone) throws SirixIOException {
    try {
        final ByteArrayDataOutput output = ByteStreams.newDataOutput();
        PagePersistenter.serializePage(output, toClone, SerializationType.TRANSACTION_INTENT_LOG);
        final ByteArrayDataInput input = ByteStreams.newDataInput(output.toByteArray());
        return (E) PagePersistenter.deserializePage(input, this, SerializationType.TRANSACTION_INTENT_LOG);
    } catch (final IOException e) {
        throw new SirixIOException(e);
    }
}
Also used : ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) SirixIOException(org.sirix.exception.SirixIOException) IOException(java.io.IOException) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) SirixIOException(org.sirix.exception.SirixIOException)

Example 20 with SirixIOException

use of org.sirix.exception.SirixIOException 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)

Aggregations

SirixIOException (org.sirix.exception.SirixIOException)42 IOException (java.io.IOException)14 DatabaseException (com.sleepycat.je.DatabaseException)9 DatabaseEntry (com.sleepycat.je.DatabaseEntry)7 UberPage (org.sirix.page.UberPage)6 OperationStatus (com.sleepycat.je.OperationStatus)5 Path (java.nio.file.Path)5 QNm (org.brackit.xquery.atomic.QNm)5 PageReference (org.sirix.page.PageReference)5 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)5 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)4 ExecutionException (java.util.concurrent.ExecutionException)4 Str (org.brackit.xquery.atomic.Str)4 Page (org.sirix.page.interfaces.Page)4 UncheckedIOException (java.io.UncheckedIOException)3 HashSet (java.util.HashSet)3 QueryException (org.brackit.xquery.QueryException)3 Item (org.brackit.xquery.xdm.Item)3 Iter (org.brackit.xquery.xdm.Iter)3 IndexController (org.sirix.access.IndexController)3