Example #1
0
 internal FreeListIdProvider(PagedFile pagedFile, int pageSize, long lastId, Monitor monitor)
 {
     this._pagedFile    = pagedFile;
     this._monitor      = monitor;
     this._freelistNode = new FreelistNode(pageSize);
     this._lastId       = lastId;
 }
Example #2
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);
            }
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldInitializeTreeNode()
        internal virtual void ShouldInitializeTreeNode()
        {
            // GIVEN
            FreelistNode.Initialize(_cursor);

            // WHEN
            sbyte nodeType = TreeNode.NodeType(_cursor);

            // THEN
            assertEquals(TreeNode.NODE_TYPE_FREE_LIST_NODE, nodeType);
        }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSetAndGetNext()
        internal virtual void ShouldSetAndGetNext()
        {
            // GIVEN
            long nextId = 12345;

            // WHEN
            FreelistNode.SetNext(_cursor, nextId);
            long readNextId = FreelistNode.Next(_cursor);

            // THEN
            assertEquals(nextId, readNextId);
        }
Example #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void initializeAfterCreation() throws java.io.IOException
        internal virtual void InitializeAfterCreation()
        {
            // Allocate a new free-list page id and set both write/read free-list page id to it.
            _writePageId = NextLastId();
            _readPageId  = _writePageId;

            using (PageCursor cursor = _pagedFile.io(_writePageId, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
            {
                goTo(cursor, "free-list", _writePageId);
                FreelistNode.Initialize(cursor);
                checkOutOfBounds(cursor);
            }
        }
Example #6
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());
        }
Example #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNodeOverwriteNodeType()
        internal virtual void ShouldNodeOverwriteNodeType()
        {
            // GIVEN
            FreelistNode.Initialize(_cursor);
            sbyte nodeType = TreeNode.NodeType(_cursor);

            assertEquals(TreeNode.NODE_TYPE_FREE_LIST_NODE, nodeType);

            // WHEN
            long someId = 1234;

            FreelistNode.SetNext(_cursor, someId);

            // THEN
            nodeType = TreeNode.NodeType(_cursor);
            assertEquals(TreeNode.NODE_TYPE_FREE_LIST_NODE, nodeType);
        }
Example #8
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);
            }
        }