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);
}
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;
}
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;
}
}
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;
}
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);
}
Aggregations