Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long acquireNewIdFromFreelistOrEnd(long stableGeneration, long unstableGeneration, boolean allowTakeLastFromPage) throws java.io.IOException
        private long AcquireNewIdFromFreelistOrEnd(long stableGeneration, long unstableGeneration, bool allowTakeLastFromPage)
        {
            if ((_readPageId != _writePageId || _readPos < _writePos) && (allowTakeLastFromPage || _readPos < _freelistNode.maxEntries() - 1))
            {
                // It looks like reader isn't even caught up to the writer page-wise,
                // or the read pos is < write pos so check if we can grab the next id (generation could still mismatch).
                using (PageCursor cursor = _pagedFile.io(_readPageId, Org.Neo4j.Io.pagecache.PagedFile_Fields.PF_SHARED_READ_LOCK))
                {
                    if (!cursor.Next())
                    {
                        throw new IOException("Couldn't go to free-list read page " + _readPageId);
                    }

                    long resultPageId;
                    do
                    {
                        resultPageId = _freelistNode.read(cursor, stableGeneration, _readPos);
                    } while (cursor.ShouldRetry());

                    if (resultPageId != FreelistNode.NoPageId)
                    {
                        // FreelistNode compares generation and so this means that we have an available
                        // id in the free list which we can acquire from a stable generation. Increment readPos
                        _readPos++;
                        if (_readPos >= _freelistNode.maxEntries())
                        {
                            // The current reader page is exhausted, go to the next free-list page.
                            _readPos = 0;
                            do
                            {
                                _readPageId = FreelistNode.Next(cursor);
                            } while (cursor.ShouldRetry());

                            // Put the exhausted free-list page id itself on the free-list
                            long exhaustedFreelistPageId = cursor.CurrentPageId;
                            ReleaseId(stableGeneration, unstableGeneration, exhaustedFreelistPageId);
                            _monitor.releasedFreelistPageId(exhaustedFreelistPageId);
                        }
                        return(resultPageId);
                    }
                }
            }

            // Fall-back to acquiring at the end of the file
            return(NextLastId());
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReadAndWriteFreeListEntries()
        internal virtual void ShouldReadAndWriteFreeListEntries()
        {
            // GIVEN
            long generationA = 34;
            long pointerA    = 56;
            long generationB = 78;
            long pointerB    = 90;

            // WHEN
            _freelist.write(_cursor, generationA, pointerA, 0);
            _freelist.write(_cursor, generationB, pointerB, 1);
            long readPointerA = _freelist.read(_cursor, generationA + 1, 0);
            long readPointerB = _freelist.read(_cursor, generationB + 1, 1);

            // THEN
            assertEquals(pointerA, readPointerA);
            assertEquals(pointerB, readPointerB);
        }