use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageUtils method createTree.
/**
* Create the initial tree structure.
*
* @param reference reference from revision root
* @param pageKind the page kind
*/
public static void createTree(@Nonnull PageReference reference, final PageKind pageKind, final int index, final PageReadTrx pageReadTrx, final TransactionIntentLog log) {
Page page = null;
// Level page count exponent from the configuration.
final int[] levelPageCountExp = pageReadTrx.getUberPage().getPageCountExp(pageKind);
// Remaining levels.
for (int i = 0, l = levelPageCountExp.length; i < l; i++) {
page = new IndirectPage();
log.put(reference, new PageContainer(page, page));
reference = page.getReference(0);
}
// Create new record page.
final UnorderedKeyValuePage ndp = new UnorderedKeyValuePage(Fixed.ROOT_PAGE_KEY.getStandardProperty(), pageKind, Constants.NULL_ID_LONG, pageReadTrx);
// Create a {@link DocumentRootNode}.
final Optional<SirixDeweyID> id = pageReadTrx.getResourceManager().getResourceConfig().mDeweyIDsStored ? Optional.of(SirixDeweyID.newRootID()) : Optional.empty();
final NodeDelegate nodeDel = new NodeDelegate(Fixed.DOCUMENT_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), 0, id);
final StructNodeDelegate strucDel = new StructNodeDelegate(nodeDel, Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), 0, 0);
ndp.setEntry(0L, new DocumentRootNode(nodeDel, strucDel));
log.put(reference, new PageContainer(ndp, ndp));
}
use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class UberPage method createRevisionTree.
/**
* Create revision tree.
*
* @param pageReadTrx {@link PageReadTrx} instance
* @param revisionRoot {@link RevisionRootPage} instance
*/
public void createRevisionTree(final TransactionIntentLog log) {
// Initialize revision tree to guarantee that there is a revision root page.
Page page = null;
PageReference reference = getIndirectPageReference();
// Remaining levels.
for (int i = 0, l = Constants.UBPINP_LEVEL_PAGE_COUNT_EXPONENT.length; i < l; i++) {
page = new IndirectPage();
log.put(reference, new PageContainer(page, page));
reference = page.getReference(0);
}
mRootPage = new RevisionRootPage();
final Page namePage = mRootPage.getNamePageReference().getPage();
log.put(mRootPage.getNamePageReference(), new PageContainer(namePage, namePage));
final Page casPage = mRootPage.getCASPageReference().getPage();
log.put(mRootPage.getCASPageReference(), new PageContainer(casPage, casPage));
final Page pathPage = mRootPage.getPathPageReference().getPage();
log.put(mRootPage.getPathPageReference(), new PageContainer(pathPage, pathPage));
final Page pathSummaryPage = mRootPage.getPathSummaryPageReference().getPage();
log.put(mRootPage.getPathSummaryPageReference(), new PageContainer(pathSummaryPage, pathSummaryPage));
log.put(reference, new PageContainer(mRootPage, mRootPage));
}
use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageReadTrxImpl method dereferenceIndirectPageReference.
/**
* Dereference indirect page reference.
*
* @param reference reference to dereference
* @return dereferenced page
*
* @throws SirixIOException if something odd happens within the creation process
* @throws NullPointerException if {@code reference} is {@code null}
*/
@Override
public IndirectPage dereferenceIndirectPageReference(final PageReference reference) {
try {
IndirectPage 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 : (IndirectPage) cont.getComplete();
}
if (page == null) {
// Then try to get the in-memory reference.
page = (IndirectPage) reference.getPage();
}
if (page == null && (reference.getKey() != Constants.NULL_ID_LONG || reference.getLogKey() != Constants.NULL_ID_INT || reference.getPersistentLogKey() != Constants.NULL_ID_LONG)) {
// Then try to get it from the page cache which might read it from the persistent storage
// on a cache miss.
page = (IndirectPage) mPageCache.get(reference);
}
return page;
} catch (final ExecutionException | UncheckedExecutionException e) {
throw new SirixIOException(e.getCause());
}
}
use of org.sirix.cache.PageContainer 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);
}
use of org.sirix.cache.PageContainer in project sirix by sirixdb.
the class PageReadTrxImpl method getRecordPageContainer.
@Override
public <K extends Comparable<? super K>, V extends Record, T extends KeyValuePage<K, V>> PageContainer getRecordPageContainer(@Nonnegative final Long recordPageKey, final int index, final PageKind pageKind) throws SirixIOException {
assertNotClosed();
checkArgument(recordPageKey >= 0, "recordPageKey must not be negative!");
final Optional<PageReference> pageReferenceToRecordPage = getLeafPageReference(checkNotNull(recordPageKey), index, checkNotNull(pageKind));
if (!pageReferenceToRecordPage.isPresent()) {
return PageContainer.emptyInstance();
}
// Try to get from resource buffer manager.
final PageContainer recordPageContainerFromBuffer = mResourceBufferManager.getRecordPageCache().get(pageReferenceToRecordPage.get());
if (recordPageContainerFromBuffer != null) {
return recordPageContainerFromBuffer;
}
// Load list of page "fragments" from persistent storage.
final List<T> pages = getSnapshotPages(pageReferenceToRecordPage.get());
if (pages.isEmpty()) {
return PageContainer.emptyInstance();
}
final int mileStoneRevision = mResourceConfig.mRevisionsToRestore;
final Versioning revisioning = mResourceConfig.mRevisionKind;
final Page completePage = revisioning.combineRecordPages(pages, mileStoneRevision, this);
final PageContainer recordPageContainer = new PageContainer(completePage, clone(completePage));
if (mTrxIntentLog == null)
mResourceBufferManager.getRecordPageCache().put(pageReferenceToRecordPage.get(), recordPageContainer);
return recordPageContainer;
}
Aggregations