Search in sources :

Example 1 with PageReadTrx

use of org.sirix.api.PageReadTrx in project sirix by sirixdb.

the class XdmResourceManager method openPathSummary.

@Override
public synchronized PathSummaryReader openPathSummary(@Nonnegative final int revision) {
    assertAccess(revision);
    final PageReadTrx pageReadTrx = beginPageReadTrx(revision);
    return PathSummaryReader.getInstance(pageReadTrx, this);
}
Also used : PageReadTrx(org.sirix.api.PageReadTrx)

Example 2 with PageReadTrx

use of org.sirix.api.PageReadTrx in project sirix by sirixdb.

the class XdmResourceManager method beginPageReadTrx.

@Override
public synchronized PageReadTrx beginPageReadTrx(@Nonnegative final int revision) {
    assertAccess(revision);
    final long currentPageTrxID = mPageTrxIDCounter.incrementAndGet();
    final PageReadTrx pageReadTrx = new PageReadTrxImpl(currentPageTrxID, this, mLastCommittedUberPage.get(), revision, mFac.createReader(), null, null, mBufferManager);
    // Remember page transaction for debugging and safe close.
    if (mPageTrxMap.put(currentPageTrxID, pageReadTrx) != null) {
        throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
    }
    return pageReadTrx;
}
Also used : SirixThreadedException(org.sirix.exception.SirixThreadedException) PageReadTrx(org.sirix.api.PageReadTrx)

Example 3 with PageReadTrx

use of org.sirix.api.PageReadTrx in project sirix by sirixdb.

the class XdmResourceManager method close.

@Override
public synchronized void close() {
    if (!mClosed) {
        // Close all open node transactions.
        for (XdmNodeReadTrx rtx : mNodeReaderMap.values()) {
            if (rtx instanceof XdmNodeWriteTrx) {
                ((XdmNodeWriteTrx) rtx).rollback();
            }
            rtx.close();
            rtx = null;
        }
        // Close all open node page transactions.
        for (PageReadTrx rtx : mNodePageTrxMap.values()) {
            rtx.close();
            rtx = null;
        }
        // Close all open page transactions.
        for (PageReadTrx rtx : mPageTrxMap.values()) {
            rtx.close();
            rtx = null;
        }
        // Immediately release all ressources.
        mLastCommittedUberPage = null;
        mNodeReaderMap.clear();
        mPageTrxMap.clear();
        mNodePageTrxMap.clear();
        mResourceStore.closeResource(mResourceConfig.getResource());
        mFac.close();
        mClosed = true;
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) PageReadTrx(org.sirix.api.PageReadTrx)

Example 4 with PageReadTrx

use of org.sirix.api.PageReadTrx in project sirix by sirixdb.

the class XdmResourceManager method beginNodeReadTrx.

@Override
public synchronized XdmNodeReadTrx beginNodeReadTrx(@Nonnegative final int revisionKey) {
    assertAccess(revisionKey);
    // Make sure not to exceed available number of read transactions.
    try {
        if (!mReadSemaphore.tryAcquire(20, TimeUnit.SECONDS)) {
            throw new SirixUsageException("No read transactions available, please close at least one read transaction at first!");
        }
    } catch (final InterruptedException e) {
        throw new SirixThreadedException(e);
    }
    final PageReadTrx pageReadTrx = beginPageReadTrx(revisionKey);
    final Node documentNode = getDocumentNode(pageReadTrx);
    // Create new reader.
    final XdmNodeReadTrx reader = new XdmNodeReadTrxImpl(this, mNodeTrxIDCounter.incrementAndGet(), pageReadTrx, documentNode);
    // Remember reader for debugging and safe close.
    if (mNodeReaderMap.put(reader.getId(), reader) != null) {
        throw new SirixUsageException("ID generation is bogus because of duplicate ID.");
    }
    return reader;
}
Also used : SirixThreadedException(org.sirix.exception.SirixThreadedException) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Node(org.sirix.node.interfaces.Node) SirixUsageException(org.sirix.exception.SirixUsageException) PageReadTrx(org.sirix.api.PageReadTrx)

Example 5 with PageReadTrx

use of org.sirix.api.PageReadTrx in project sirix by sirixdb.

the class XdmResourceManager method binarySearch.

private int binarySearch(final long timestamp) {
    int low = 0;
    int high = getMostRecentRevisionNumber();
    while (low <= high) {
        final int mid = (low + high) >>> 1;
        try (final PageReadTrx trx = beginPageReadTrx(mid)) {
            final long midVal = trx.getActualRevisionRootPage().getRevisionTimestamp();
            final int cmp = Instant.ofEpochMilli(midVal).compareTo(Instant.ofEpochMilli(timestamp));
            if (cmp < 0)
                low = mid + 1;
            else if (cmp > 0)
                high = mid - 1;
            else
                // key found
                return mid;
        }
    }
    // key not found
    return -(low + 1);
}
Also used : PageReadTrx(org.sirix.api.PageReadTrx)

Aggregations

PageReadTrx (org.sirix.api.PageReadTrx)5 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)2 SirixThreadedException (org.sirix.exception.SirixThreadedException)2 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)1 SirixUsageException (org.sirix.exception.SirixUsageException)1 Node (org.sirix.node.interfaces.Node)1