Exemplo n.º 1
0
        public static PageCorruption <KEY, VALUE> SwapKeyOrderInternal <KEY, VALUE>(int firstKeyPos, int secondKeyPos, int keyCount)
        {
            return((cursor, layout, node, treeState) =>
            {
                // Remove key from higher position and insert into lower position
                int lowerKeyPos = firstKeyPos < secondKeyPos ? firstKeyPos : secondKeyPos;
                int higherKeyPos = firstKeyPos == lowerKeyPos ? secondKeyPos : firstKeyPos;

                // Record key and right child on higher position together with generation of child pointer
                KEY key = layout.newKey();
                node.keyAt(cursor, key, higherKeyPos, TreeNode.Type.Internal);
                GenerationKeeper childPointerGeneration = new GenerationKeeper();
                long rightChild = node.childAt(cursor, higherKeyPos + 1, treeState.stableGeneration(), treeState.unstableGeneration(), childPointerGeneration);

                // Remove key and right child, may need to defragment node to make sure we have room for insert later
                node.removeKeyAndRightChildAt(cursor, higherKeyPos, keyCount);
                node.defragmentLeaf(cursor);

                // Insert key and right child in lower position
                node.insertKeyAndRightChildAt(cursor, key, rightChild, lowerKeyPos, keyCount - 1, treeState.stableGeneration(), treeState.unstableGeneration());

                // Overwrite the newly inserted child to reset the generation
                int childOffset = node.childOffset(lowerKeyPos + 1);
                OverwriteGSPP(cursor, childOffset, childPointerGeneration.Generation, rightChild);
            });
        }
Exemplo n.º 2
0
 public static PageCorruption <KEY, VALUE> SetChild <KEY, VALUE>(int childPos, long childPointer)
 {
     return((cursor, layout, node, treeState) =>
     {
         GenerationKeeper childGeneration = new GenerationKeeper();
         node.childAt(cursor, childPos, treeState.stableGeneration(), treeState.unstableGeneration(), childGeneration);
         OverwriteGSPP(cursor, GBPTreePointerType.child(childPos).offset(node), childGeneration.Generation, childPointer);
     });
 }
Exemplo n.º 3
0
        public static PageCorruption <KEY, VALUE> SwapChildOrder <KEY, VALUE>(int firstChildPos, int secondChildPos, int keyCount)
        {
            return((cursor, layout, node, treeState) =>
            {
                // Read first and second child together with generation
                GenerationKeeper firstChildGeneration = new GenerationKeeper();
                long firstChild = node.childAt(cursor, firstChildPos, treeState.stableGeneration(), treeState.unstableGeneration(), firstChildGeneration);
                GenerationKeeper secondChildGeneration = new GenerationKeeper();
                long secondChild = node.childAt(cursor, secondChildPos, treeState.stableGeneration(), treeState.unstableGeneration(), secondChildGeneration);

                // Overwrite respective child with the other
                OverwriteGSPP(cursor, GBPTreePointerType.child(firstChildPos).offset(node), secondChildGeneration.Generation, secondChild);
                OverwriteGSPP(cursor, GBPTreePointerType.child(secondChildPos).offset(node), firstChildGeneration.Generation, firstChild);
            });
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRead()
        public virtual void ShouldRead()
        {
            // GIVEN
            _cursor.Offset = SLOT_A_OFFSET;
            long preStatePointerA = StateA.materialize(_cursor, POINTER_A);

            _cursor.Offset = _slotBOffset;
            long preStatePointerB = StateB.materialize(_cursor, POINTER_B);

            // WHEN
            _cursor.Offset = GSPP_OFFSET;
            GenerationKeeper generationKeeper = new GenerationKeeper();
            long             result           = GenerationSafePointerPair.Read(_cursor, STABLE_GENERATION, UNSTABLE_GENERATION, generationKeeper);

            // THEN
            ExpectedReadOutcome.verifyRead(_cursor, result, StateA, StateB, preStatePointerA, preStatePointerB, generationKeeper.Generation);
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void visitFreelist(IdProvider_IdProviderVisitor visitor) throws java.io.IOException
        public override void VisitFreelist(IdProvider_IdProviderVisitor visitor)
        {
            if (_readPageId == FreelistNode.NoPageId)
            {
                return;
            }

            using (PageCursor cursor = _pagedFile.io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PF_SHARED_READ_LOCK))
            {
                GenerationKeeper generation = new GenerationKeeper();
                long             prevPage;
                long             pageId = _readPageId;
                int pos = _readPos;
                do
                {
                    PageCursorUtil.GoTo(cursor, "free-list", pageId);
                    visitor.BeginFreelistPage(pageId);
                    int targetPos = pageId == _writePageId ? _writePos : _freelistNode.maxEntries();
                    while (pos < targetPos)
                    {
                        // Read next un-acquired id
                        long unacquiredId;
                        do
                        {
                            unacquiredId = _freelistNode.read(cursor, long.MaxValue, pos, generation);
                        } while (cursor.ShouldRetry());
                        visitor.FreelistEntry(unacquiredId, generation.Generation, pos);
                        pos++;
                    }
                    visitor.EndFreelistPage(pageId);

                    prevPage = pageId;
                    pos      = 0;
                    do
                    {
                        pageId = FreelistNode.Next(cursor);
                    } while (cursor.ShouldRetry());
                } while (prevPage != _writePageId);
            }
        }