Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void releaseId(long stableGeneration, long unstableGeneration, long id) throws java.io.IOException
        public override void ReleaseId(long stableGeneration, long unstableGeneration, long id)
        {
            using (PageCursor cursor = _pagedFile.io(_writePageId, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
            {
                PageCursorUtil.GoTo(cursor, "free-list write page", _writePageId);
                _freelistNode.write(cursor, unstableGeneration, id, _writePos);
                _writePos++;
            }

            if (_writePos >= _freelistNode.maxEntries())
            {
                // Current free-list write page is full, allocate a new one.
                long nextFreelistPage = AcquireNewId(stableGeneration, unstableGeneration, false);
                using (PageCursor cursor = _pagedFile.io(_writePageId, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
                {
                    PageCursorUtil.GoTo(cursor, "free-list write page", _writePageId);
                    FreelistNode.Initialize(cursor);
                    // Link previous --> new writer page
                    FreelistNode.SetNext(cursor, nextFreelistPage);
                }
                _writePageId = nextFreelistPage;
                _writePos    = 0;
                _monitor.acquiredFreelistPageId(nextFreelistPage);
            }
        }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void visitMeta(org.neo4j.io.pagecache.PageCursor cursor, GBPTreeVisitor visitor) throws java.io.IOException
        private static void VisitMeta(PageCursor cursor, GBPTreeVisitor visitor)
        {
            PageCursorUtil.GoTo(cursor, "meta page", IdSpace.META_PAGE_ID);
            Meta meta = Meta.Read(cursor, null);

            visitor.meta(meta);
        }
Exemple #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static TreeState readStatePage(org.neo4j.io.pagecache.PageCursor cursor, long pageIdA) throws java.io.IOException
        private static TreeState ReadStatePage(PageCursor cursor, long pageIdA)
        {
            PageCursorUtil.GoTo(cursor, "state page", pageIdA);
            TreeState state;

            do
            {
                state = TreeState.Read(cursor);
            } while (cursor.ShouldRetry());
            checkOutOfBounds(cursor);
            return(state);
        }
Exemple #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long acquireNewId(long stableGeneration, long unstableGeneration, boolean allowTakeLastFromPage) throws java.io.IOException
        private long AcquireNewId(long stableGeneration, long unstableGeneration, bool allowTakeLastFromPage)
        {
            // Acquire id from free-list or end of store file
            long acquiredId = AcquireNewIdFromFreelistOrEnd(stableGeneration, unstableGeneration, allowTakeLastFromPage);

            // Zap the page, i.e. set all bytes to zero
            using (PageCursor cursor = _pagedFile.io(acquiredId, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
            {
                PageCursorUtil.GoTo(cursor, "newly allocated free-list page", acquiredId);
                cursor.ZapPage();
                // don't initialize node here since this acquisition can be used both for tree nodes
                // as well as free-list nodes.
            }
            return(acquiredId);
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldFailOnInvalidValues()
        internal virtual void ShouldFailOnInvalidValues()
        {
            // GIVEN
            PageCursor cursor = ByteArrayPageCursor.wrap(10);

            // WHEN
            for (int i = 0; i < 1_000;)
            {
                long expected = _random.nextLong();
                if ((expected & ~_6B_MASK) != 0)
                {
                    // OK here we have an invalid value
                    cursor.Offset = 0;
                    assertThrows(typeof(System.ArgumentException), () => PageCursorUtil.put6BLong(cursor, expected));
                    i++;
                }
            }
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldPutAndGet6BLongs()
        internal virtual void ShouldPutAndGet6BLongs()
        {
            // GIVEN
            PageCursor cursor = ByteArrayPageCursor.wrap(10);

            // WHEN
            for (int i = 0; i < 1_000; i++)
            {
                long expected = _random.nextLong() & _6B_MASK;
                cursor.Offset = 0;
                PageCursorUtil.Put6BLong(cursor, expected);
                cursor.Offset = 0;
                long read = PageCursorUtil.Get6BLong(cursor);

                // THEN
                assertEquals(expected, read);
                assertTrue(read >= 0);
                assertEquals(0, read & ~_6B_MASK);
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
0
        /// <summary>
        /// Moves the provided {@code cursor} to the current root id and returning the generation where
        /// that root id was assigned.
        /// </summary>
        /// <param name="cursor"> <seealso cref="PageCursor"/> to place at the current root id. </param>
        /// <returns> the generation where the current root was assigned. </returns>
        /// <exception cref="IOException"> on <seealso cref="PageCursor"/> error. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: long goTo(org.neo4j.io.pagecache.PageCursor cursor) throws java.io.IOException
        internal virtual long GoTo(PageCursor cursor)
        {
            PageCursorUtil.GoTo(cursor, "root", _rootId);
            return(_rootGeneration);
        }
Exemple #9
0
        /// <summary>
        /// Initialize state pages because new pages are expected to be allocated directly after
        /// the existing highest allocated page. Otherwise there'd be a hole between meta and root pages
        /// until they would have been written, which isn't guaranteed to be handled correctly by the page cache.
        /// </summary>
        /// <param name="cursor"> <seealso cref="PageCursor"/> assumed to be opened with write capabilities. </param>
        /// <exception cref="IOException"> on <seealso cref="PageCursor"/> error. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void initializeStatePages(org.neo4j.io.pagecache.PageCursor cursor) throws java.io.IOException
        internal static void InitializeStatePages(PageCursor cursor)
        {
            PageCursorUtil.GoTo(cursor, "State page A", IdSpace.STATE_PAGE_A);
            PageCursorUtil.GoTo(cursor, "State page B", IdSpace.STATE_PAGE_B);
        }
Exemple #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void goTo(org.neo4j.io.pagecache.PageCursor cursor, String messageOnError, long nodeId) throws java.io.IOException
        internal static void GoTo(PageCursor cursor, string messageOnError, long nodeId)
        {
            PageCursorUtil.GoTo(cursor, messageOnError, GenerationSafePointerPair.Pointer(nodeId));
        }