/// <summary> /// Reads the tree state pair, one from each of {@code pageIdA} and {@code pageIdB}, deciding their validity /// and returning them as a <seealso cref="Pair"/>. /// do-shouldRetry is managed inside this method because data is read from two pages. /// </summary> /// <param name="cursor"> <seealso cref="PageCursor"/> to use when reading. This cursor will be moved to the two pages /// one after the other, to read their states. </param> /// <param name="pageIdA"> page id containing the first state. </param> /// <param name="pageIdB"> page id containing the second state. </param> /// <returns> <seealso cref="Pair"/> of both tree states. </returns> /// <exception cref="IOException"> on <seealso cref="PageCursor"/> reading error. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: static org.apache.commons.lang3.tuple.Pair<TreeState,TreeState> readStatePages(org.neo4j.io.pagecache.PageCursor cursor, long pageIdA, long pageIdB) throws java.io.IOException internal static Pair <TreeState, TreeState> ReadStatePages(PageCursor cursor, long pageIdA, long pageIdB) { TreeState stateA = ReadStatePage(cursor, pageIdA); TreeState stateB = ReadStatePage(cursor, pageIdB); return(Pair.of(stateA, stateB)); }
/// <summary> /// Let the passed in {@code cursor} point to the root or sub-tree (internal node) of what to visit. /// </summary> /// <param name="cursor"> <seealso cref="PageCursor"/> placed at root of tree or sub-tree. </param> /// <param name="writeCursor"> Currently active <seealso cref="PageCursor write cursor"/> in tree. </param> /// <param name="visitor"> <seealso cref="GBPTreeVisitor"/> that should visit the tree. </param> /// <exception cref="IOException"> on page cache access error. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: void visitTree(org.neo4j.io.pagecache.PageCursor cursor, org.neo4j.io.pagecache.PageCursor writeCursor, GBPTreeVisitor<KEY,VALUE> visitor) throws java.io.IOException internal virtual void VisitTree(PageCursor cursor, PageCursor writeCursor, GBPTreeVisitor <KEY, VALUE> visitor) { // TreeState long currentPage = cursor.CurrentPageId; Pair <TreeState, TreeState> statePair = TreeStatePair.ReadStatePages(cursor, IdSpace.STATE_PAGE_A, IdSpace.STATE_PAGE_B); visitor.TreeState(statePair); TreeNode.GoTo(cursor, "back to tree node from reading state", currentPage); AssertOnTreeNode(Select(cursor, writeCursor)); // Traverse the tree int level = 0; do { // One level at the time visitor.BeginLevel(level); long leftmostSibling = cursor.CurrentPageId; // Go right through all siblings VisitLevel(cursor, writeCursor, visitor); visitor.EndLevel(level); level++; // Then go back to the left-most node on this level TreeNode.GoTo(cursor, "back", leftmostSibling); } while (GoToLeftmostChild(cursor, writeCursor)); // And continue down to next level if this level was an internal level }
public override void TreeState(Pair <TreeState, TreeState> statePair) { if (_printState) { @out.println("StateA: " + statePair.Left); @out.println("StateB: " + statePair.Right); } }
private static Optional <TreeState> SelectNewestValidStateOptionally(Pair <TreeState, TreeState> states) { TreeState stateA = states.Left; TreeState stateB = states.Right; if (stateA.Valid != stateB.Valid) { // return only valid return(stateA.Valid ? stateA : stateB); } else if (stateA.Valid && stateB.Valid) { // return newest // compare unstable generations of A/B, if equal, compare clean flag (clean is newer than dirty) // and include sanity check for stable generations such that there cannot be a state S compared // to other state O where // S.unstableGeneration > O.unstableGeneration AND S.stableGeneration < O.stableGeneration if (stateA.StableGeneration() == stateB.StableGeneration() && stateA.UnstableGeneration() == stateB.UnstableGeneration() && stateA.Clean != stateB.Clean) { return(stateA.Clean ? stateA : stateB); } else if (stateA.StableGeneration() >= stateB.StableGeneration() && stateA.UnstableGeneration() > stateB.UnstableGeneration()) { return(stateA); } else if (stateA.StableGeneration() <= stateB.StableGeneration() && stateA.UnstableGeneration() < stateB.UnstableGeneration()) { return(stateB); } } // return null communicating that this combination didn't result in any valid "newest" state return(null); }
internal abstract void verify(org.apache.commons.lang3.tuple.Pair <TreeState, TreeState> states, SelectionUseCase selection);
internal abstract TreeState select(org.apache.commons.lang3.tuple.Pair <TreeState, TreeState> states);
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: static void visitTreeState(org.neo4j.io.pagecache.PageCursor cursor, GBPTreeVisitor visitor) throws java.io.IOException internal static void VisitTreeState(PageCursor cursor, GBPTreeVisitor visitor) { Pair <TreeState, TreeState> statePair = TreeStatePair.ReadStatePages(cursor, IdSpace.STATE_PAGE_A, IdSpace.STATE_PAGE_B); visitor.treeState(statePair); }
/// <param name="states"> the two states to compare. </param> /// <returns> newest (w/ regards to <seealso cref="TreeState.stableGeneration()"/>) <seealso cref="TreeState.isValid() valid"/> /// <seealso cref="TreeState"/> of the two. </returns> /// <exception cref="IllegalStateException"> if none were valid. </exception> internal static TreeState SelectNewestValidState(Pair <TreeState, TreeState> states) { return(SelectNewestValidStateOptionally(states).orElseThrow(() => new TreeInconsistencyException("Unexpected combination of state.%n STATE_A[%s]%n STATE_B[%s]", states.Left, states.Right))); }
/// <param name="states"> the two states to compare. </param> /// <returns> oldest (w/ regards to <seealso cref="TreeState.stableGeneration()"/>) <seealso cref="TreeState.isValid() invalid"/> /// <seealso cref="TreeState"/> of the two. If both are invalid then the <seealso cref="Pair.getLeft() first one"/> is returned. </returns> internal static TreeState SelectOldestOrInvalid(Pair <TreeState, TreeState> states) { TreeState newestValidState = SelectNewestValidStateOptionally(states).orElse(states.Right); return(newestValidState == states.Left ? states.Right : states.Left); }
public override void TreeState(Pair <TreeState, TreeState> statePair) { }