Search in sources :

Example 6 with Record

use of org.sirix.node.interfaces.Record in project sirix by sirixdb.

the class UnorderedKeyValuePage method getValue.

@Override
public Record getValue(final Long key) {
    assert key != null : "key must not be null!";
    Record record = mRecords.get(key);
    if (record == null) {
        byte[] data = null;
        try {
            final PageReference reference = mReferences.get(key);
            if (reference != null && reference.getKey() != Constants.NULL_ID_LONG) {
                data = ((OverflowPage) mPageReadTrx.getReader().read(reference, mPageReadTrx)).getData();
            } else {
                return null;
            }
        } catch (final SirixIOException e) {
            return null;
        }
        final InputStream in = new ByteArrayInputStream(data);
        try {
            record = mPersistenter.deserialize(new DataInputStream(in), key, Optional.empty(), null);
        } catch (final IOException e) {
            return null;
        }
        mRecords.put(key, record);
    }
    return record;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Record(org.sirix.node.interfaces.Record) SirixIOException(org.sirix.exception.SirixIOException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) SirixIOException(org.sirix.exception.SirixIOException)

Example 7 with Record

use of org.sirix.node.interfaces.Record in project sirix by sirixdb.

the class XdmResourceManager method beginNodeWriteTrx.

@Override
public synchronized XdmNodeWriteTrx beginNodeWriteTrx(@Nonnegative final int maxNodeCount, @Nonnull final TimeUnit timeUnit, @Nonnegative final int maxTime) {
    // Checks.
    assertAccess(mLastCommittedUberPage.get().getRevision());
    if (maxNodeCount < 0 || maxTime < 0) {
        throw new SirixUsageException("maxNodeCount may not be < 0!");
    }
    checkNotNull(timeUnit);
    // Make sure not to exceed available number of write transactions.
    try {
        if (!mWriteSemaphore.tryAcquire(20, TimeUnit.SECONDS)) {
            throw new SirixUsageException("No write transaction available, please close the write transaction first.");
        }
    } catch (final InterruptedException e) {
        throw new SirixThreadedException(e);
    }
    // Create new page write transaction (shares the same ID with the node write trx).
    final long currentTrxID = mNodeTrxIDCounter.incrementAndGet();
    final int lastRev = mLastCommittedUberPage.get().getRevisionNumber();
    final PageWriteTrx<Long, Record, UnorderedKeyValuePage> pageWtx = createPageWriteTransaction(currentTrxID, lastRev, lastRev, Abort.NO);
    final Node documentNode = getDocumentNode(pageWtx);
    // Create new node write transaction.
    final XdmNodeWriteTrx wtx = new XdmNodeWriterTrxImpl(currentTrxID, this, pageWtx, maxNodeCount, timeUnit, maxTime, documentNode);
    // Remember node transaction for debugging and safe close.
    if (mNodeReaderMap.put(currentTrxID, wtx) != null || mNodePageTrxMap.put(currentTrxID, pageWtx) != null) {
        throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
    }
    return wtx;
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) SirixThreadedException(org.sirix.exception.SirixThreadedException) Node(org.sirix.node.interfaces.Node) AtomicLong(java.util.concurrent.atomic.AtomicLong) Record(org.sirix.node.interfaces.Record) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) SirixUsageException(org.sirix.exception.SirixUsageException)

Example 8 with Record

use of org.sirix.node.interfaces.Record 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 9 with Record

use of org.sirix.node.interfaces.Record 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 10 with Record

use of org.sirix.node.interfaces.Record 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)

Aggregations

Record (org.sirix.node.interfaces.Record)11 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)8 PageContainer (org.sirix.cache.PageContainer)5 SirixIOException (org.sirix.exception.SirixIOException)3 Node (org.sirix.node.interfaces.Node)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 SirixThreadedException (org.sirix.exception.SirixThreadedException)2 SirixUsageException (org.sirix.exception.SirixUsageException)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutput (java.io.DataOutput)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Entry (java.util.Map.Entry)1 ExecutionException (java.util.concurrent.ExecutionException)1 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)1 IndexLogKey (org.sirix.cache.IndexLogKey)1