use of org.sirix.page.PageReference 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());
}
}
use of org.sirix.page.PageReference in project sirix by sirixdb.
the class PageWriteTrxImpl method prepareRecordPage.
/**
* Prepare record page.
*
* @param recordPageKey the key of the record page
* @param pageKind the kind of page (used to determine the right subtree)
* @return {@link PageContainer} instance
* @throws SirixIOException if an I/O error occurs
*/
private PageContainer prepareRecordPage(@Nonnegative final long recordPageKey, final int index, final PageKind pageKind) throws SirixIOException {
assert recordPageKey >= 0;
assert pageKind != null;
// Get the reference to the unordered key/value page storing the records.
final PageReference reference = prepareLeafOfTree(mPageRtx.getPageReference(mNewRoot, pageKind, index), recordPageKey, index, pageKind);
PageContainer pageContainer = mLog.get(reference);
if (pageContainer.equals(PageContainer.emptyInstance())) {
if (reference.getKey() == Constants.NULL_ID_LONG) {
final UnorderedKeyValuePage completePage = new UnorderedKeyValuePage(recordPageKey, pageKind, Constants.NULL_ID_LONG, mPageRtx);
final UnorderedKeyValuePage modifyPage = mPageRtx.clone(completePage);
pageContainer = new PageContainer(completePage, modifyPage);
} else {
pageContainer = dereferenceRecordPageForModification(reference);
}
assert pageContainer != null;
switch(pageKind) {
case RECORDPAGE:
case PATHSUMMARYPAGE:
case PATHPAGE:
case CASPAGE:
case NAMEPAGE:
appendLogRecord(reference, pageContainer);
break;
default:
throw new IllegalStateException("Page kind not known!");
}
}
return pageContainer;
}
use of org.sirix.page.PageReference 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;
}
use of org.sirix.page.PageReference in project sirix by sirixdb.
the class PageDelegate method createNewReference.
private PageReference createNewReference(final BitSet offsetBitmap, int offset) {
final int index = index(offsetBitmap, offset);
final PageReference reference = new PageReference();
mReferences.add(index, reference);
// final PageReference[] newArray = new PageReference[mReferences.length + 1];
// System.arraycopy(mReferences, 0, newArray, 0, index);
// newArray[index] = new PageReference();
// System.arraycopy(mReferences, index, newArray, index + 1, mReferences.length - index);
mBitmap.set(offset, true);
// mReferences = newArray;
return reference;
}
use of org.sirix.page.PageReference in project sirix by sirixdb.
the class PageDelegate method toString.
@Override
public String toString() {
final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this);
for (final PageReference ref : mReferences) {
helper.add("reference", ref);
}
helper.add("bitmap", dumpBitmap(mBitmap));
return helper.toString();
}
Aggregations