Search in sources :

Example 11 with PageContainer

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

the class PageWriteTrxImpl method prepareEntryForModification.

@Override
public Record prepareEntryForModification(@Nonnegative final Long recordKey, final PageKind pageKind, final int index, final Optional<UnorderedKeyValuePage> keyValuePage) throws SirixIOException {
    mPageRtx.assertNotClosed();
    checkNotNull(recordKey);
    checkArgument(recordKey >= 0, "recordKey must be >= 0!");
    checkNotNull(pageKind);
    checkNotNull(keyValuePage);
    final long recordPageKey = mPageRtx.pageKey(recordKey);
    final PageContainer cont = prepareRecordPage(recordPageKey, index, pageKind);
    Record record = ((UnorderedKeyValuePage) cont.getModified()).getValue(recordKey);
    if (record == null) {
        final Record oldRecord = ((UnorderedKeyValuePage) cont.getComplete()).getValue(recordKey);
        if (oldRecord == null) {
            throw new SirixIOException("Cannot retrieve record from cache!");
        }
        record = oldRecord;
        ((UnorderedKeyValuePage) cont.getModified()).setEntry(record.getNodeKey(), record);
    }
    return record;
}
Also used : PageContainer(org.sirix.cache.PageContainer) Record(org.sirix.node.interfaces.Record) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) SirixIOException(org.sirix.exception.SirixIOException)

Example 12 with PageContainer

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

the class PageWriteTrxImpl method preparePreviousRevisionRootPage.

/**
 * Prepare the previous revision root page and retrieve the next {@link RevisionRootPage}.
 *
 * @param baseRevision base revision
 * @param representRevision the revision to represent
 * @return new {@link RevisionRootPage} instance
 * @throws SirixIOException if an I/O error occurs
 */
private RevisionRootPage preparePreviousRevisionRootPage(@Nonnegative final int baseRevision, @Nonnegative final int representRevision) throws SirixIOException {
    if (getUberPage().isBootstrap()) {
        final RevisionRootPage revisionRootPage = mPageRtx.loadRevRoot(baseRevision);
        // appendLogRecord(new PageContainer(revisionRootPage, revisionRootPage));
        return revisionRootPage;
    } else {
        // Prepare revision root nodePageReference.
        final RevisionRootPage revisionRootPage = new RevisionRootPage(mPageRtx.loadRevRoot(baseRevision), representRevision + 1);
        // Prepare indirect tree to hold reference to prepared revision root nodePageReference.
        final PageReference revisionRootPageReference = prepareLeafOfTree(getUberPage().getIndirectPageReference(), getUberPage().getRevisionNumber(), -1, PageKind.UBERPAGE);
        // Link the prepared revision root nodePageReference with the prepared indirect tree.
        appendLogRecord(revisionRootPageReference, new PageContainer(revisionRootPage, revisionRootPage));
        // Return prepared revision root nodePageReference.
        return revisionRootPage;
    }
}
Also used : PageReference(org.sirix.page.PageReference) PageContainer(org.sirix.cache.PageContainer) RevisionRootPage(org.sirix.page.RevisionRootPage)

Example 13 with PageContainer

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

the class PageWriteTrxImpl method createEntry.

@Override
public Record createEntry(final Long key, final Record record, final PageKind pageKind, final int index, final Optional<UnorderedKeyValuePage> keyValuePage) throws SirixIOException {
    mPageRtx.assertNotClosed();
    // Allocate record key and increment record count.
    long recordKey;
    switch(pageKind) {
        case RECORDPAGE:
            recordKey = mNewRoot.incrementAndGetMaxNodeKey();
            break;
        case PATHSUMMARYPAGE:
            final PathSummaryPage pathSummaryPage = ((PathSummaryPage) mNewRoot.getPathSummaryPageReference().getPage());
            recordKey = pathSummaryPage.incrementAndGetMaxNodeKey(index);
            break;
        case CASPAGE:
            final CASPage casPage = ((CASPage) mNewRoot.getCASPageReference().getPage());
            recordKey = casPage.incrementAndGetMaxNodeKey(index);
            break;
        case PATHPAGE:
            final PathPage pathPage = ((PathPage) mNewRoot.getPathPageReference().getPage());
            recordKey = pathPage.incrementAndGetMaxNodeKey(index);
            break;
        case NAMEPAGE:
            final NamePage namePage = ((NamePage) mNewRoot.getNamePageReference().getPage());
            recordKey = namePage.incrementAndGetMaxNodeKey(index);
            break;
        default:
            throw new IllegalStateException();
    }
    final long recordPageKey = mPageRtx.pageKey(recordKey);
    final PageContainer cont = prepareRecordPage(recordPageKey, index, pageKind);
    @SuppressWarnings("unchecked") final KeyValuePage<Long, Record> modified = (KeyValuePage<Long, Record>) cont.getModified();
    modified.setEntry(record.getNodeKey(), record);
    return record;
}
Also used : PageContainer(org.sirix.cache.PageContainer) PathSummaryPage(org.sirix.page.PathSummaryPage) CASPage(org.sirix.page.CASPage) NamePage(org.sirix.page.NamePage) PathPage(org.sirix.page.PathPage) KeyValuePage(org.sirix.page.interfaces.KeyValuePage) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) Record(org.sirix.node.interfaces.Record)

Example 14 with PageContainer

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

the class PageWriteTrxImpl method removeEntry.

@Override
public void removeEntry(final Long recordKey, @Nonnull final PageKind pageKind, final int index, final Optional<UnorderedKeyValuePage> keyValuePage) throws SirixIOException {
    mPageRtx.assertNotClosed();
    final long nodePageKey = mPageRtx.pageKey(recordKey);
    final PageContainer cont = prepareRecordPage(nodePageKey, index, pageKind);
    final Optional<Record> node = getRecord(recordKey, pageKind, index);
    if (node.isPresent()) {
        final Record nodeToDel = node.get();
        final Node delNode = new DeletedNode(new NodeDelegate(nodeToDel.getNodeKey(), -1, -1, -1, Optional.<SirixDeweyID>empty()));
        ((UnorderedKeyValuePage) cont.getModified()).setEntry(delNode.getNodeKey(), delNode);
        ((UnorderedKeyValuePage) cont.getComplete()).setEntry(delNode.getNodeKey(), delNode);
    } else {
        throw new IllegalStateException("Node not found!");
    }
}
Also used : PageContainer(org.sirix.cache.PageContainer) Node(org.sirix.node.interfaces.Node) DeletedNode(org.sirix.node.DeletedNode) Record(org.sirix.node.interfaces.Record) DeletedNode(org.sirix.node.DeletedNode) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) SirixDeweyID(org.sirix.node.SirixDeweyID) NodeDelegate(org.sirix.node.delegates.NodeDelegate)

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