use of org.sirix.page.UnorderedKeyValuePage 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.UnorderedKeyValuePage in project sirix by sirixdb.
the class PageWriteTrxImpl method getRecord.
@Override
public Optional<Record> getRecord(@Nonnegative final long recordKey, final PageKind pageKind, @Nonnegative final int index) throws SirixIOException {
mPageRtx.assertNotClosed();
checkArgument(recordKey >= Fixed.NULL_NODE_KEY.getStandardProperty());
checkNotNull(pageKind);
// Calculate page.
final long recordPageKey = mPageRtx.pageKey(recordKey);
final PageContainer pageCont = prepareRecordPage(recordPageKey, index, pageKind);
if (pageCont.equals(PageContainer.emptyInstance())) {
return mPageRtx.getRecord(recordKey, pageKind, index);
} else {
Record node = ((UnorderedKeyValuePage) pageCont.getModified()).getValue(recordKey);
if (node == null) {
node = ((UnorderedKeyValuePage) pageCont.getComplete()).getValue(recordKey);
}
return mPageRtx.checkItemIfDeleted(node);
}
}
use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.
the class XdmResourceManager method beginPageWriteTrx.
@Override
public synchronized PageWriteTrx<Long, Record, UnorderedKeyValuePage> beginPageWriteTrx(@Nonnegative final int revision) throws SirixException {
assertAccess(revision);
// Make sure not to exceed available number of write transactions.
try {
if (!mWriteSemaphore.tryAcquire(20, TimeUnit.SECONDS)) {
throw new SirixUsageException("No write transaction available, please close the write transaction first.");
}
} catch (final InterruptedException e) {
throw new SirixThreadedException(e);
}
final long currentPageTrxID = mPageTrxIDCounter.incrementAndGet();
final int lastRev = mLastCommittedUberPage.get().getRevisionNumber();
final PageWriteTrx<Long, Record, UnorderedKeyValuePage> pageWtx = createPageWriteTransaction(currentPageTrxID, lastRev, lastRev, Abort.NO);
// Remember page transaction for debugging and safe close.
if (mPageTrxMap.put(currentPageTrxID, pageWtx) != null) {
throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
}
return pageWtx;
}
use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.
the class LRUCacheTest method test.
@Test
public void test() {
for (int i = 1; i < CacheTestHelper.PAGES.length; i++) {
final PageContainer cont = cache.get((long) i);
final UnorderedKeyValuePage current = (UnorderedKeyValuePage) cont.getComplete();
assertEquals(CacheTestHelper.PAGES[i][0], current);
}
final PageContainer page = cache.get(0L);
assertNull(page);
}
use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.
the class PathSummaryWriter method processFoundPathNode.
/**
* Process a found path node.
*
* @param oldPathNodeKey key of old path node
* @param newPathNodeKey key of new path node
* @param oldNodeKey key of old node
* @param uriKey key of URI
* @param prefixKey key of prefix
* @param localNameKey key of local name
* @param remove determines if a {@link PathNode} must be removed or not
* @param type type of operation
* @throws SirixException if Sirix fails to do so
*/
private void processFoundPathNode(@Nonnegative final long oldPathNodeKey, @Nonnegative final long newPathNodeKey, @Nonnegative final long oldNodeKey, final int uriKey, final int prefixKey, final int localNameKey, final Remove remove, final OPType type) throws SirixException {
final PathSummaryReader cloned = PathSummaryReader.getInstance(mPageWriteTrx, mNodeRtx.getResourceManager());
boolean moved = cloned.moveTo(oldPathNodeKey).hasMoved();
assert moved;
// Set new reference count of the root.
if (type != OPType.MOVEDSAMELEVEL) {
final PathNode currNode = (PathNode) mPageWriteTrx.prepareEntryForModification(mPathSummaryReader.getNodeKey(), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
currNode.setReferenceCount(currNode.getReferences() + cloned.getReferences());
currNode.setLocalNameKey(localNameKey);
currNode.setPrefixKey(prefixKey);
currNode.setURIKey(uriKey);
}
// For all old path nodes: Merge paths and adapt reference counts.
mPathSummaryReader.moveToFirstChild();
final int oldLevel = cloned.getLevel();
for (final Axis oldDescendants = new DescendantAxis(cloned); oldDescendants.hasNext(); ) {
oldDescendants.next();
// Search for new path entry.
final Axis axis = new FilterAxis(new LevelOrderAxis.Builder(mPathSummaryReader).filterLevel(cloned.getLevel() - oldLevel).includeSelf().build(), new NameFilter(mPathSummaryReader, Utils.buildName(cloned.getName())), new PathKindFilter(mPathSummaryReader, cloned.getPathKind()), new PathLevelFilter(mPathSummaryReader, cloned.getLevel()));
if (axis.hasNext()) {
axis.next();
// Set new reference count.
if (type != OPType.MOVEDSAMELEVEL) {
final PathNode currNode = (PathNode) mPageWriteTrx.prepareEntryForModification(mPathSummaryReader.getNodeKey(), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
currNode.setReferenceCount(currNode.getReferences() + cloned.getReferences());
}
} else {
// Insert new node.
insertPathAsFirstChild(cloned.getName(), cloned.getPathKind(), mPathSummaryReader.getLevel() + 1);
// Set new reference count.
final PathNode currNode = (PathNode) mPageWriteTrx.prepareEntryForModification(mPathSummaryReader.getNodeKey(), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
currNode.setReferenceCount(cloned.getReferences());
}
mPathSummaryReader.moveTo(newPathNodeKey);
}
// Set new path nodes of the changed nodes, that is set their PCR
// references.
mPathSummaryReader.moveTo(newPathNodeKey);
mNodeRtx.moveTo(oldNodeKey);
boolean first = true;
for (final Axis axis = new DescendantAxis(mNodeRtx, IncludeSelf.YES); axis.hasNext(); ) {
axis.next();
if (first && type == OPType.SETNAME) {
first = false;
} else if (mNodeRtx.getNode() instanceof ImmutableNameNode) {
cloned.moveTo(((NameNode) mNodeRtx.getCurrentNode()).getPathNodeKey());
resetPath(newPathNodeKey, cloned.getLevel());
if (mNodeRtx.getNode().getKind() == Kind.ELEMENT) {
final ElementNode element = (ElementNode) mNodeRtx.getCurrentNode();
for (int i = 0, nspCount = element.getNamespaceCount(); i < nspCount; i++) {
mNodeRtx.moveToNamespace(i);
cloned.moveTo(((NameNode) mNodeRtx.getCurrentNode()).getPathNodeKey());
resetPath(newPathNodeKey, cloned.getLevel());
mNodeRtx.moveToParent();
}
for (int i = 0, attCount = element.getAttributeCount(); i < attCount; i++) {
mNodeRtx.moveToAttribute(i);
cloned.moveTo(((NameNode) mNodeRtx.getCurrentNode()).getPathNodeKey());
resetPath(newPathNodeKey, cloned.getLevel());
mNodeRtx.moveToParent();
}
}
}
}
// Then: Remove old nodes.
if (remove == Remove.YES) {
mPathSummaryReader.moveTo(oldPathNodeKey);
removePathSummaryNode(remove);
}
}
Aggregations