use of org.sirix.exception.SirixIOException in project sirix by sirixdb.
the class PageReadTrxImpl method getPage.
/**
* Set the page if it is not set already.
*
* @param reference page reference
* @throws SirixIOException if an I/O error occurs
*/
private Page getPage(final PageReference reference, final PageKind pageKind) throws SirixIOException {
try {
Page page = reference.getPage();
if (page == null) {
page = mPageCache.get(reference);
reference.setPage(page);
}
return page;
} catch (final ExecutionException | UncheckedExecutionException e) {
throw new SirixIOException(e.getCause());
}
}
use of org.sirix.exception.SirixIOException in project sirix by sirixdb.
the class PageReadTrxImpl method getPageReferenceForPage.
/**
* Find reference pointing to leaf page of an indirect tree.
*
* @param startReference start reference pointing to the indirect tree
* @param recordPageKey key to look up in the indirect tree
* @return reference denoted by key pointing to the leaf page
*
* @throws SirixIOException if an I/O error occurs
*/
@Nullable
@Override
public final PageReference getPageReferenceForPage(final PageReference startReference, @Nonnegative final long recordPageKey, final int index, final PageKind pageKind) throws SirixIOException {
assertNotClosed();
// Initial state pointing to the indirect page of level 0.
PageReference reference = checkNotNull(startReference);
checkArgument(recordPageKey >= 0, "key must be >= 0!");
checkNotNull(pageKind);
int offset = 0;
long levelKey = recordPageKey;
final int[] inpLevelPageCountExp = mUberPage.getPageCountExp(pageKind);
// Iterate through all levels.
for (int level = 0, height = inpLevelPageCountExp.length; level < height; level++) {
final Page derefPage = dereferenceIndirectPageReference(reference);
if (derefPage == null) {
reference = null;
break;
} else {
offset = (int) (levelKey >> inpLevelPageCountExp[level]);
levelKey -= offset << inpLevelPageCountExp[level];
try {
// assert offset >= 0 && offset < mUberPage.getPageReferenceCount(pageKind);
reference = derefPage.getReference(offset);
} catch (final IndexOutOfBoundsException e) {
throw new SirixIOException("Node key isn't supported, it's too big!");
}
}
}
// Return reference to leaf of indirect tree.
return reference;
}
use of org.sirix.exception.SirixIOException 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.exception.SirixIOException in project sirix by sirixdb.
the class PageReadTrxImpl method clone.
@SuppressWarnings("unchecked")
<E extends Page> E clone(final E toClone) throws SirixIOException {
try {
final ByteArrayDataOutput output = ByteStreams.newDataOutput();
PagePersistenter.serializePage(output, toClone, SerializationType.TRANSACTION_INTENT_LOG);
final ByteArrayDataInput input = ByteStreams.newDataInput(output.toByteArray());
return (E) PagePersistenter.deserializePage(input, this, SerializationType.TRANSACTION_INTENT_LOG);
} catch (final IOException e) {
throw new SirixIOException(e);
}
}
use of org.sirix.exception.SirixIOException 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;
}
Aggregations