//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustFlushDirtyPagesOnEvictingAllPages() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MustFlushDirtyPagesOnEvictingAllPages()
        {
            WriteInitialDataTo(file("a"));
            RecordingPageCacheTracer  tracer       = new RecordingPageCacheTracer();
            RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer(typeof(RecordingPageCursorTracer.Fault));
            ConfigurablePageCursorTracerSupplier <RecordingPageCursorTracer> cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier <RecordingPageCursorTracer>(cursorTracer);

            using (MuninnPageCache pageCache = createPageCache(fs, 4, BlockCacheFlush(tracer), cursorTracerSupplier), PagedFile pagedFile = map(pageCache, file("a"), 8))
            {
                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK | PF_NO_GROW))
                {
                    assertTrue(cursor.Next());
                    cursor.PutLong(0L);
                    assertTrue(cursor.Next());
                    cursor.PutLong(0L);
                    assertFalse(cursor.Next());
                }
                cursorTracer.ReportEvents();
                assertNotNull(cursorTracer.Observe(typeof(RecordingPageCursorTracer.Fault)));
                assertNotNull(cursorTracer.Observe(typeof(RecordingPageCursorTracer.Fault)));
                assertEquals(2, cursorTracer.Faults());
                assertEquals(2, tracer.Faults());

                long clockArm = pageCache.EvictPages(2, 0, tracer.BeginPageEvictions(2));
                assertThat(clockArm, @is(2L));
                assertNotNull(tracer.Observe(typeof(Evict)));
                assertNotNull(tracer.Observe(typeof(Evict)));

                ByteBuffer buf = ReadIntoBuffer("a");
                assertThat(buf.Long, @is(0L));
                assertThat(buf.Long, @is(0L));
            }
        }
Exemple #2
0
        public override void Get(long index, sbyte[] into)
        {
            long pageId = pageId(index);
            int  offset = offset(index);

            try
            {
                using (PageCursor cursor = PagedFile.io(pageId, PF_SHARED_READ_LOCK))
                {
                    cursor.Next();
                    do
                    {
                        for (int i = 0; i < into.Length; i++)
                        {
                            into[i] = cursor.GetByte(offset + i);
                        }
                    } while (cursor.ShouldRetry());
                    CheckBounds(cursor);
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
Exemple #3
0
        public override int Get3ByteInt(long index, int offset)
        {
            long pageId = pageId(index);

            offset += offset(index);
            try
            {
                using (PageCursor cursor = PagedFile.io(pageId, PF_SHARED_READ_LOCK))
                {
                    cursor.Next();
                    int result;
                    do
                    {
                        int lowWord  = cursor.GetShort(offset) & 0xFFFF;
                        int highByte = cursor.GetByte(offset + Short.BYTES) & 0xFF;
                        result = lowWord | (highByte << (sizeof(short) * 8));
                    } while (cursor.ShouldRetry());
                    CheckBounds(cursor);
                    return(result == 0xFFFFFF ? -1 : result);
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void pageModificationTracksHighestModifierTransactionId() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void PageModificationTracksHighestModifierTransactionId()
        {
            TestVersionContext     cursorContext          = new TestVersionContext(() => 0);
            VersionContextSupplier versionContextSupplier = new ConfiguredVersionContextSupplier(cursorContext);

            using (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL, Org.Neo4j.Io.pagecache.tracing.cursor.PageCursorTracerSupplier_Fields.Null, versionContextSupplier), PagedFile pagedFile = map(pageCache, file("a"), 8))
            {
                cursorContext.InitWrite(1);
                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK))
                {
                    assertTrue(cursor.Next());
                    cursor.PutLong(1);
                }
                cursorContext.InitWrite(12);
                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK))
                {
                    assertTrue(cursor.Next());
                    cursor.PutLong(2);
                }
                cursorContext.InitWrite(7);
                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK))
                {
                    assertTrue(cursor.Next());
                    cursor.PutLong(3);
                }

                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_READ_LOCK))
                {
                    assertTrue(cursor.Next());
                    MuninnPageCursor pageCursor = ( MuninnPageCursor )cursor;
                    assertEquals(12, pageCursor.PagedFile.getLastModifiedTxId(pageCursor.PinnedPageRef));
                    assertEquals(3, cursor.Long);
                }
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void doNotMarkContextAsDirtyWhenAnyEvictedPageHaveModificationTransactionLowerThenReader() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void DoNotMarkContextAsDirtyWhenAnyEvictedPageHaveModificationTransactionLowerThenReader()
        {
            TestVersionContext     cursorContext          = new TestVersionContext(() => 15);
            VersionContextSupplier versionContextSupplier = new ConfiguredVersionContextSupplier(cursorContext);

            using (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL, Org.Neo4j.Io.pagecache.tracing.cursor.PageCursorTracerSupplier_Fields.Null, versionContextSupplier), PagedFile pagedFile = map(pageCache, file("a"), 8))
            {
                cursorContext.InitWrite(3);
                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK))
                {
                    assertTrue(cursor.Next());
                    cursor.PutLong(3);
                }

                cursorContext.InitWrite(13);
                using (PageCursor cursor = pagedFile.Io(1, PF_SHARED_WRITE_LOCK))
                {
                    assertTrue(cursor.Next());
                    cursor.PutLong(4);
                }

                EvictAllPages(pageCache);

                cursorContext.InitRead();
                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_READ_LOCK))
                {
                    assertTrue(cursor.Next());
                    assertEquals(3, cursor.Long);
                    assertFalse(cursorContext.Dirty);
                }
            }
        }
Exemple #6
0
        public override long Get6ByteLong(long index, int offset)
        {
            long pageId = pageId(index);

            offset += offset(index);
            try
            {
                using (PageCursor cursor = PagedFile.io(pageId, PF_SHARED_READ_LOCK))
                {
                    cursor.Next();
                    long result;
                    do
                    {
                        long low4b  = cursor.GetInt(offset) & 0xFFFFFFFFL;
                        long high2b = cursor.GetShort(offset + Integer.BYTES) & 0xFFFF;
                        result = low4b | (high2b << (sizeof(int) * 8));
                    } while (cursor.ShouldRetry());
                    CheckBounds(cursor);
                    return(result == 0xFFFFFFFFFFFFL ? -1 : result);
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustUnblockPageFaultersWhenEvictionGetsException()
        internal virtual void MustUnblockPageFaultersWhenEvictionGetsException()
        {
            assertTimeout(ofMillis(SEMI_LONG_TIMEOUT_MILLIS), () =>
            {
                WriteInitialDataTo(file("a"));

                MutableBoolean throwException = new MutableBoolean(true);
                FileSystemAbstraction fs      = new DelegatingFileSystemAbstractionAnonymousInnerClass(this, this.fs, throwException);

                using (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL), PagedFile pagedFile = map(pageCache, file("a"), 8))
                {
                    // The basic idea is that this loop, which will encounter a lot of page faults, must not block forever even
                    // though the eviction thread is unable to flush any dirty pages because the file system throws
                    // exceptions on all writes.
                    try
                    {
                        using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK))
                        {
                            for (int i = 0; i < 1000; i++)
                            {
                                assertTrue(cursor.Next());
                            }
                            fail("Expected an exception at this point");
                        }
                    }
                    catch (IOException)
                    {
                        // Good.
                    }

                    throwException.setFalse();
                }
            });
Exemple #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Void call() throws Exception
        public override Void Call()
        {
            Random random         = new Random();
            int    recordsPerPage = _format.RecordsPerPage;
            int    recordSize     = _format.RecordSize;

            using (PageCursor cursor = _pagedFile.io(0, PF_SHARED_WRITE_LOCK))
            {
                while (!_condition.fulfilled())
                {
                    int recordId     = random.Next(_maxRecords);
                    int pageId       = recordId / recordsPerPage;
                    int recordOffset = (recordId % recordsPerPage) * recordSize;

                    _locks.@lock(recordId);
                    try
                    {
                        assertTrue(cursor.Next(pageId), "I must be able to access pages");
                        cursor.Offset = recordOffset;
                        long newValue = _format.incrementCounter(cursor, _threadId);
                        _countSum++;
                        assertFalse(cursor.ShouldRetry(), "Write lock, so never a need to retry");
                        assertThat("Record-local count must be less than or equal to thread-local count sum", newValue, lessThanOrEqualTo(_countSum));
                    }
                    finally
                    {
                        _locks.unlock(recordId);
                    }
                }
            }

            return(null);
        }
Exemple #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void perform() throws Exception
            public override void Perform()
            {
                PagedFile pagedFile = outerInstance.fileMap[File];

                if (pagedFile != null)
                {
                    // We use tryLock to avoid any deadlock scenarios.
                    if (outerInstance.recordLocks.TryLock(RecordId))
                    {
                        try
                        {
                            using (PageCursor cursor = pagedFile.Io(PageId, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
                            {
                                if (cursor.Next())
                                {
                                    cursor.Offset = PageOffset;
                                    outerInstance.recordFormat.Write(Record, cursor);
                                    PerformInnerAction();
                                }
                            }
                        }
                        finally
                        {
                            outerInstance.recordLocks.Unlock(RecordId);
                        }
                    }
                }
                else
                {
                    PerformInnerAction();
                }
            }
Exemple #10
0
        public override void Swap(long fromIndex, long toIndex)
        {
            long fromPageId = PageId(fromIndex);
            int  fromOffset = Offset(fromIndex);
            long toPageId   = PageId(toIndex);
            int  toOffset   = Offset(toIndex);

            try
            {
                using (PageCursor fromCursor = PagedFile.io(fromPageId, PF_SHARED_WRITE_LOCK), PageCursor toCursor = PagedFile.io(toPageId, PF_SHARED_WRITE_LOCK))
                {
                    fromCursor.Next();
                    toCursor.Next();
                    for (int i = 0; i < EntrySize; i++, fromOffset++, toOffset++)
                    {
                        sbyte intermediary = fromCursor.GetByte(fromOffset);
                        fromCursor.PutByte(fromOffset, toCursor.GetByte(toOffset));
                        toCursor.PutByte(toOffset, intermediary);
                    }
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
Exemple #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void profileAndReheatAfterRestart() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ProfileAndReheatAfterRestart()
        {
            using (PageCache pageCache = _pageCacheRule.getPageCache(_fs, _cfg), PagedFile pf = pageCache.Map(_file, pageCache.PageSize(), StandardOpenOption.CREATE))
            {
                PageCacheWarmer warmer = new PageCacheWarmer(_fs, pageCache, _scheduler, _testDirectory.databaseDir());
                warmer.Start();
                warmer.Stop();
                warmer.Start();
                using (PageCursor writer = pf.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
                {
                    assertTrue(writer.Next(1));
                    assertTrue(writer.Next(3));
                }
                warmer.Profile();
                assertNotSame(long?.empty(), warmer.Reheat());
            }
        }
Exemple #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void withCursor(java.io.File storeFile, boolean create, System.Action<org.neo4j.io.pagecache.PageCursor> cursorConsumer) throws java.io.IOException
        private void WithCursor(File storeFile, bool create, System.Action <PageCursor> cursorConsumer)
        {
            OpenOption[] openOptions = create ? new OpenOption[] { StandardOpenOption.WRITE, StandardOpenOption.CREATE } : new OpenOption[] { StandardOpenOption.WRITE };
            using (PageCache pageCache = PageCacheRule.getPageCache(GlobalFs.get()), PagedFile pagedFile = pageCache.Map(storeFile, pageCache.PageSize(), openOptions), PageCursor cursor = pagedFile.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
            {
                cursor.Next();
                cursorConsumer(cursor);
            }
        }
Exemple #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unused") @Test public void profileMustNotDeleteFilesCurrentlyExposedViaFileListing() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ProfileMustNotDeleteFilesCurrentlyExposedViaFileListing()
        {
            using (PageCache pageCache = _pageCacheRule.getPageCache(_fs, _cfg), PagedFile pf = pageCache.Map(_file, pageCache.PageSize(), StandardOpenOption.CREATE))
            {
                using (PageCursor writer = pf.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
                {
                    assertTrue(writer.Next(1));
                    assertTrue(writer.Next(3));
                }
                pf.FlushAndForce();
                PageCacheWarmer warmer = new PageCacheWarmer(_fs, pageCache, _scheduler, _testDirectory.databaseDir());
                warmer.Start();
                warmer.Profile();
                warmer.Profile();
                warmer.Profile();

                IList <StoreFileMetadata> fileListing = new List <StoreFileMetadata>();
                using (Resource firstListing = warmer.AddFilesTo(fileListing))
                {
                    warmer.Profile();
                    warmer.Profile();

                    // The files in the file listing cannot be deleted while the listing is in use.
                    assertThat(fileListing.Count, greaterThan(0));
                    AssertFilesExists(fileListing);
                    warmer.Profile();
                    using (Resource secondListing = warmer.AddFilesTo(new List <StoreFileMetadata>()))
                    {
                        warmer.Profile();
                        // This must hold even when there are file listings overlapping in time.
                        AssertFilesExists(fileListing);
                    }
                    warmer.Profile();
                    // And continue to hold after other overlapping listing finishes.
                    AssertFilesExists(fileListing);
                }
                // Once we are done with the file listing, profile should remove those files.
                warmer.Profile();
                warmer.Stop();
                AssertFilesNotExists(fileListing);
            }
        }
Exemple #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void initializeFile(org.neo4j.io.pagecache.PagedFile pagedFile, Page... pages) throws java.io.IOException
        private void InitializeFile(PagedFile pagedFile, params Page[] pages)
        {
            using (PageCursor cursor = pagedFile.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
            {
                foreach (Page page in pages)
                {
                    cursor.Next();
                    page.Write(pagedFile, cursor, _treeNode, _layout, _checkpointedTreeState, _unstableTreeState);
                }
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void markCursorContextDirtyWhenRepositionCursorOnItsCurrentPage() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MarkCursorContextDirtyWhenRepositionCursorOnItsCurrentPage()
        {
            TestVersionContext     cursorContext          = new TestVersionContext(() => 3);
            VersionContextSupplier versionContextSupplier = new ConfiguredVersionContextSupplier(cursorContext);

            using (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL, Org.Neo4j.Io.pagecache.tracing.cursor.PageCursorTracerSupplier_Fields.Null, versionContextSupplier), PagedFile pagedFile = map(pageCache, file("a"), 8))
            {
                cursorContext.InitRead();
                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK))
                {
                    assertTrue(cursor.Next(0));
                    assertFalse(cursorContext.Dirty);

                    MuninnPageCursor pageCursor = ( MuninnPageCursor )cursor;
                    pageCursor.PagedFile.setLastModifiedTxId((( MuninnPageCursor )cursor).PinnedPageRef, 17);

                    assertTrue(cursor.Next(0));
                    assertTrue(cursorContext.Dirty);
                }
            }
        }
Exemple #16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void verifyCounts() throws java.io.IOException
        public virtual void VerifyCounts()
        {
            long actualSum = 0;

            using (PageCursor cursor = _pagedFile.io(0, PF_SHARED_READ_LOCK))
            {
                while (cursor.Next())
                {
                    actualSum += _format.sumCountsForThread(cursor, _threadId);
                }
            }
            assertThat("Thread specific sum across all records", actualSum, @is(_countSum));
        }
Exemple #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustReheatProfiledPageCache() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustReheatProfiledPageCache()
        {
            using (PageCache pageCache = _pageCacheRule.getPageCache(_fs, _cfg), PagedFile pf = pageCache.Map(_file, pageCache.PageSize(), StandardOpenOption.CREATE))
            {
                using (PageCursor writer = pf.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
                {
                    assertTrue(writer.Next(1));
                    assertTrue(writer.Next(3));
                }
                pf.FlushAndForce();
                PageCacheWarmer warmer = new PageCacheWarmer(_fs, pageCache, _scheduler, _testDirectory.databaseDir());
                warmer.Start();
                warmer.Profile();
            }

            ClearTracerCounts();
            long initialFaults = _cacheTracer.faults();

            using (PageCache pageCache = _pageCacheRule.getPageCache(_fs, _cfg), PagedFile pf = pageCache.Map(_file, pageCache.PageSize()))
            {
                PageCacheWarmer warmer = new PageCacheWarmer(_fs, pageCache, _scheduler, _testDirectory.databaseDir());
                warmer.Start();
                warmer.Reheat();

                pageCache.ReportEvents();
                assertThat(_cacheTracer.faults(), @is(initialFaults + 2L));

                using (PageCursor reader = pf.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PF_SHARED_READ_LOCK))
                {
                    assertTrue(reader.Next(1));
                    assertTrue(reader.Next(3));
                }

                // No additional faults must have been reported.
                pageCache.ReportEvents();
                assertThat(_cacheTracer.faults(), @is(initialFaults + 2L));
            }
        }
Exemple #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyResults(RecordFormat format, org.neo4j.io.pagecache.PagedFile pagedFile, java.util.List<RecordStresser> recordStressers) throws java.io.IOException
        private void VerifyResults(RecordFormat format, PagedFile pagedFile, IList <RecordStresser> recordStressers)
        {
            foreach (RecordStresser stresser in recordStressers)
            {
                stresser.VerifyCounts();
            }
            using (PageCursor cursor = pagedFile.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PF_SHARED_READ_LOCK))
            {
                while (cursor.Next())
                {
                    format.VerifyCheckSums(cursor);
                }
            }
        }
Exemple #19
0
 private void ZapPage(long?pageId)
 {
     try
     {
         using (PageCursor cursor = _cursorSupplier.get())
         {
             cursor.Next(pageId.Value);
             cursor.ZapPage();
         }
     }
     catch (IOException)
     {
         throw new Exception("Could not go to page " + pageId);
     }
 }
Exemple #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void reheatingMustWorkOnLargeNumberOfPages() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReheatingMustWorkOnLargeNumberOfPages()
        {
            int maxPagesInMemory = 1_000;

            int[] pageIds = RandomSortedPageIds(maxPagesInMemory);

            string pageCacheMemory = (maxPagesInMemory * ByteUnit.kibiBytes(9)).ToString();

            using (PageCache pageCache = _pageCacheRule.getPageCache(_fs, _cfg.withMemory(pageCacheMemory)), PagedFile pf = pageCache.Map(_file, pageCache.PageSize(), StandardOpenOption.CREATE))
            {
                using (PageCursor writer = pf.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
                {
                    foreach (int pageId in pageIds)
                    {
                        assertTrue(writer.Next(pageId));
                    }
                }
                pf.FlushAndForce();
                PageCacheWarmer warmer = new PageCacheWarmer(_fs, pageCache, _scheduler, _testDirectory.databaseDir());
                warmer.Profile();
            }

            long initialFaults = _cacheTracer.faults();

            ClearTracerCounts();
            using (PageCache pageCache = _pageCacheRule.getPageCache(_fs, _cfg), PagedFile pf = pageCache.Map(_file, pageCache.PageSize()))
            {
                PageCacheWarmer warmer = new PageCacheWarmer(_fs, pageCache, _scheduler, _testDirectory.databaseDir());
                warmer.Start();
                warmer.Reheat();

                pageCache.ReportEvents();
                assertThat(_cacheTracer.faults(), @is(initialFaults + pageIds.Length));

                using (PageCursor reader = pf.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PF_SHARED_READ_LOCK))
                {
                    foreach (int pageId in pageIds)
                    {
                        assertTrue(reader.Next(pageId));
                    }
                }

                // No additional faults must have been reported.
                pageCache.ReportEvents();
                assertThat(_cacheTracer.faults(), @is(initialFaults + pageIds.Length));
            }
        }
Exemple #21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void perform() throws Exception
            public override void Perform()
            {
                PagedFile pagedFile = outerInstance.fileMap[File];

                if (pagedFile != null)
                {
                    using (PageCursor cursor = pagedFile.Io(PageId, Org.Neo4j.Io.pagecache.PagedFile_Fields.PF_SHARED_READ_LOCK))
                    {
                        if (cursor.Next())
                        {
                            cursor.Offset = PageOffset;
                            Record actualRecord = outerInstance.recordFormat.ReadRecord(cursor);
                            assertThat(ToString(), actualRecord, isOneOf(ExpectedRecord, outerInstance.recordFormat.ZeroRecord()));
                            PerformInnerAction();
                        }
                    }
                }
            }
Exemple #22
0
        public override void SetLong(long index, int offset, long value)
        {
            long pageId = pageId(index);

            offset += offset(index);
            try
            {
                using (PageCursor cursor = PagedFile.io(pageId, PF_SHARED_WRITE_LOCK | PF_NO_GROW))
                {
                    cursor.Next();
                    cursor.PutLong(offset, value);
                    CheckBounds(cursor);
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustFinishInitialisationOfIncompleteStoreHeader() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustFinishInitialisationOfIncompleteStoreHeader()
        {
            CreateStore();
            int headerSizeInRecords = _store.NumberOfReservedLowIds;
            int headerSizeInBytes   = headerSizeInRecords * _store.RecordSize;

            using (PageCursor cursor = _store.pagedFile.io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
            {
                assertTrue(cursor.Next());
                for (int i = 0; i < headerSizeInBytes; i++)
                {
                    cursor.PutByte(( sbyte )0);
                }
            }
            int pageSize = _store.pagedFile.pageSize();

            _store.close();
            _store.pageCache.map(_store.StorageFile, pageSize, StandardOpenOption.TRUNCATE_EXISTING).close();
            CreateStore();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void ableToEvictAllPageInAPageCache() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void AbleToEvictAllPageInAPageCache()
        {
            WriteInitialDataTo(file("a"));
            RecordingPageCacheTracer  tracer       = new RecordingPageCacheTracer();
            RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer();
            ConfigurablePageCursorTracerSupplier <RecordingPageCursorTracer> cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier <RecordingPageCursorTracer>(cursorTracer);

            using (MuninnPageCache pageCache = createPageCache(fs, 2, BlockCacheFlush(tracer), cursorTracerSupplier), PagedFile pagedFile = map(pageCache, file("a"), 8))
            {
                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_READ_LOCK))
                {
                    assertTrue(cursor.Next());
                }
                using (PageCursor cursor = pagedFile.Io(1, PF_SHARED_READ_LOCK))
                {
                    assertTrue(cursor.Next());
                }
                EvictAllPages(pageCache);
            }
        }
Exemple #25
0
        public override void Set3ByteInt(long index, int offset, int value)
        {
            long pageId = pageId(index);

            offset += offset(index);
            try
            {
                using (PageCursor cursor = PagedFile.io(pageId, PF_SHARED_WRITE_LOCK | PF_NO_GROW))
                {
                    cursor.Next();
                    cursor.PutShort(offset, ( short )value);
                    cursor.PutByte(offset + Short.BYTES, ( sbyte )(( int )(( uint )value >> (sizeof(short) * 8))));
                    CheckBounds(cursor);
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void closingTheCursorMustUnlockModifiedPage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ClosingTheCursorMustUnlockModifiedPage()
        {
            WriteInitialDataTo(file("a"));

            using (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL, Org.Neo4j.Io.pagecache.tracing.cursor.PageCursorTracerSupplier_Fields.Null), PagedFile pagedFile = map(pageCache, file("a"), 8))
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.Future<?> task = executor.submit(() ->
                Future <object> task = executor.submit(() =>
                {
                    try
                    {
                        using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK))
                        {
                            assertTrue(cursor.Next());
                            cursor.PutLong(41);
                        }
                    }
                    catch (IOException e)
                    {
                        throw new Exception(e);
                    }
                });
                task.get();

                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK))
                {
                    assertTrue(cursor.Next());
                    long value = cursor.Long;
                    cursor.Offset = 0;
                    cursor.PutLong(value + 1);
                }

                long clockArm = pageCache.EvictPages(1, 0, EvictionRunEvent.NULL);
                assertThat(clockArm, @is(1L));

                ByteBuffer buf = ReadIntoBuffer("a");
                assertThat(buf.Long, @is(42L));
                assertThat(buf.Long, @is(_y));
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void failStoreInitializationWhenHeaderRecordCantBeRead() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FailStoreInitializationWhenHeaderRecordCantBeRead()
        {
            File       storeFile  = _dir.file("a");
            File       idFile     = _dir.file("idFile");
            PageCache  pageCache  = mock(typeof(PageCache));
            PagedFile  pagedFile  = mock(typeof(PagedFile));
            PageCursor pageCursor = mock(typeof(PageCursor));

            when(pageCache.Map(eq(storeFile), anyInt(), any(typeof(OpenOption)))).thenReturn(pagedFile);
            when(pagedFile.Io(0L, Org.Neo4j.Io.pagecache.PagedFile_Fields.PF_SHARED_READ_LOCK)).thenReturn(pageCursor);
            when(pageCursor.Next()).thenReturn(false);

            RecordFormats recordFormats = Standard.LATEST_RECORD_FORMATS;

            ExpectedException.expect(typeof(StoreNotFoundException));
            ExpectedException.expectMessage("Fail to read header record of store file: " + storeFile.AbsolutePath);

            using (DynamicArrayStore dynamicArrayStore = new DynamicArrayStore(storeFile, idFile, _config, IdType.NODE_LABELS, _idGeneratorFactory, pageCache, NullLogProvider.Instance, Settings.INTEGER.apply(GraphDatabaseSettings.label_block_size.DefaultValue), recordFormats))
            {
                dynamicArrayStore.Initialise(false);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustEvictCleanPageWithoutFlushing() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MustEvictCleanPageWithoutFlushing()
        {
            WriteInitialDataTo(file("a"));
            RecordingPageCacheTracer  tracer       = new RecordingPageCacheTracer();
            RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer();
            ConfigurablePageCursorTracerSupplier <RecordingPageCursorTracer> cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier <RecordingPageCursorTracer>(cursorTracer);

            using (MuninnPageCache pageCache = createPageCache(fs, 2, BlockCacheFlush(tracer), cursorTracerSupplier), PagedFile pagedFile = map(pageCache, file("a"), 8))
            {
                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_READ_LOCK))
                {
                    assertTrue(cursor.Next());
                }
                cursorTracer.ReportEvents();
                assertNotNull(cursorTracer.Observe(typeof(RecordingPageCursorTracer.Fault)));
                assertEquals(1, cursorTracer.Faults());
                assertEquals(1, tracer.Faults());

                long clockArm = pageCache.EvictPages(1, 1, tracer.BeginPageEvictions(1));
                assertThat(clockArm, @is(1L));
                assertNotNull(tracer.Observe(typeof(Evict)));
            }
        }
Exemple #29
0
        public override void Set(long index, sbyte[] value)
        {
            Debug.Assert(value.Length == EntrySize);
            long pageId = pageId(index);
            int  offset = offset(index);

            try
            {
                using (PageCursor cursor = PagedFile.io(pageId, PF_SHARED_WRITE_LOCK | PF_NO_GROW))
                {
                    cursor.Next();
                    for (int i = 0; i < value.Length; i++)
                    {
                        cursor.PutByte(offset + i, value[i]);
                    }
                    CheckBounds(cursor);
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void pageModificationTrackingNoticeWriteFromAnotherThread() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void PageModificationTrackingNoticeWriteFromAnotherThread()
        {
            TestVersionContext     cursorContext          = new TestVersionContext(() => 0);
            VersionContextSupplier versionContextSupplier = new ConfiguredVersionContextSupplier(cursorContext);

            using (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL, Org.Neo4j.Io.pagecache.tracing.cursor.PageCursorTracerSupplier_Fields.Null, versionContextSupplier), PagedFile pagedFile = map(pageCache, file("a"), 8))
            {
                cursorContext.InitWrite(7);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.Future<?> future = executor.submit(() ->
                Future <object> future = executor.submit(() =>
                {
                    try
                    {
                        using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK))
                        {
                            assertTrue(cursor.Next());
                            cursor.PutLong(1);
                        }
                    }
                    catch (IOException e)
                    {
                        throw new Exception(e);
                    }
                });
                future.get();

                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_READ_LOCK))
                {
                    assertTrue(cursor.Next());
                    MuninnPageCursor pageCursor = ( MuninnPageCursor )cursor;
                    assertEquals(7, pageCursor.PagedFile.getLastModifiedTxId(pageCursor.PinnedPageRef));
                    assertEquals(1, cursor.Long);
                }
            }
        }