Search in sources :

Example 21 with PagedFile

use of org.neo4j.io.pagecache.PagedFile in project neo4j by neo4j.

the class SwitchToSlaveCopyThenBranchTest method newSwitchToSlaveSpy.

private SwitchToSlaveCopyThenBranch newSwitchToSlaveSpy() throws Exception {
    PageCache pageCacheMock = mock(PageCache.class);
    PagedFile pagedFileMock = mock(PagedFile.class);
    when(pagedFileMock.getLastPageId()).thenReturn(1L);
    when(pageCacheMock.map(any(File.class), anyInt())).thenReturn(pagedFileMock);
    StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
    Stream mockStream = mock(Stream.class);
    when(mockStream.filter(any(Predicate.class))).thenReturn(mock(Stream.class));
    when(pageCacheMock.streamFilesRecursive(any(File.class))).thenReturn(mockStream);
    return newSwitchToSlaveSpy(pageCacheMock, storeCopyClient);
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) StoreCopyClient(org.neo4j.com.storecopy.StoreCopyClient) Stream(java.util.stream.Stream) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Predicate(java.util.function.Predicate)

Example 22 with PagedFile

use of org.neo4j.io.pagecache.PagedFile in project neo4j by neo4j.

the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingFirstPage.

@Test
public void mustFlushDirtyPagesOnEvictingFirstPage() throws Exception {
    writeInitialDataTo(file("a"));
    RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
    RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer();
    ConfigurablePageCursorTracerSupplier cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier(cursorTracer);
    MuninnPageCache pageCache = createPageCache(fs, 2, 8, blockCacheFlush(tracer), cursorTracerSupplier);
    PagedFile pagedFile = pageCache.map(file("a"), 8);
    try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK)) {
        assertTrue(cursor.next());
        cursor.putLong(0L);
    }
    cursorTracer.reportEvents();
    assertNotNull(cursorTracer.observe(Fault.class));
    assertEquals(1, cursorTracer.faults());
    assertEquals(1, tracer.faults());
    int clockArm = pageCache.evictPages(1, 0, tracer.beginPageEvictions(1));
    assertThat(clockArm, is(1));
    assertNotNull(tracer.observe(Evict.class));
    ByteBuffer buf = ByteBuffer.allocate(16);
    StoreChannel channel = fs.open(file("a"), "r");
    channel.read(buf);
    buf.flip();
    assertThat(buf.getLong(), is(0L));
    assertThat(buf.getLong(), is(y));
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.graphdb.mockfs.DelegatingStoreChannel) RecordingPageCacheTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer) Fault(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault) Evict(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict) RecordingPageCursorTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer) ByteBuffer(java.nio.ByteBuffer) ConfigurablePageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.Test)

Example 23 with PagedFile

use of org.neo4j.io.pagecache.PagedFile in project neo4j by neo4j.

the class MuninnPageCacheTest method mustEvictCleanPageWithoutFlushing.

@Test
public void mustEvictCleanPageWithoutFlushing() throws Exception {
    writeInitialDataTo(file("a"));
    RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
    RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer();
    ConfigurablePageCursorTracerSupplier cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier(cursorTracer);
    MuninnPageCache pageCache = createPageCache(fs, 2, 8, blockCacheFlush(tracer), cursorTracerSupplier);
    PagedFile pagedFile = pageCache.map(file("a"), 8);
    try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK)) {
        assertTrue(cursor.next());
    }
    cursorTracer.reportEvents();
    assertNotNull(cursorTracer.observe(Fault.class));
    assertEquals(1, cursorTracer.faults());
    assertEquals(1, tracer.faults());
    int clockArm = pageCache.evictPages(1, 0, tracer.beginPageEvictions(1));
    assertThat(clockArm, is(1));
    assertNotNull(tracer.observe(Evict.class));
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) RecordingPageCacheTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer) Fault(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault) Evict(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict) RecordingPageCursorTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer) ConfigurablePageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.Test)

Example 24 with PagedFile

use of org.neo4j.io.pagecache.PagedFile in project neo4j by neo4j.

the class MuninnPageCacheTest method mustThrowIfMappingFileWouldOverflowReferenceCount.

@Test(timeout = SEMI_LONG_TIMEOUT_MILLIS)
public void mustThrowIfMappingFileWouldOverflowReferenceCount() throws Exception {
    File file = file("a");
    writeInitialDataTo(file);
    MuninnPageCache pageCache = createPageCache(fs, 30, pageCachePageSize, PageCacheTracer.NULL, DefaultPageCursorTracerSupplier.NULL);
    PagedFile pf = null;
    int i = 0;
    try {
        expectedException.expect(IllegalStateException.class);
        for (; i < Integer.MAX_VALUE; i++) {
            pf = pageCache.map(file, filePageSize);
        }
    } finally {
        for (int j = 0; j < i; j++) {
            try {
                pf.close();
            } catch (Exception e) {
                //noinspection ThrowFromFinallyBlock
                throw new AssertionError("Did not expect pf.close() to throw", e);
            }
        }
    }
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) IOException(java.io.IOException) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.Test)

Example 25 with PagedFile

use of org.neo4j.io.pagecache.PagedFile in project neo4j by neo4j.

the class RandomPageCacheTestHarness method runIteration.

@SuppressWarnings("unchecked")
private void runIteration(long timeout, TimeUnit unit) throws Exception {
    assert filePageSize % recordFormat.getRecordSize() == 0 : "File page size must be a multiple of the record size";
    if (!fixedRandomSeed) {
        randomSeed = ThreadLocalRandom.current().nextLong();
    }
    FileSystemAbstraction fs = this.fs;
    File[] files = buildFileNames();
    RandomAdversary adversary = new RandomAdversary(mischiefRate, failureRate, errorRate);
    adversary.setProbabilityFactor(0.0);
    if (useAdversarialIO) {
        adversary.setSeed(randomSeed);
        fs = new AdversarialFileSystemAbstraction(adversary, fs);
    }
    PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory();
    swapperFactory.setFileSystemAbstraction(fs);
    MuninnPageCache cache = new MuninnPageCache(swapperFactory, cachePageCount, cachePageSize, tracer, cursorTracerSupplier);
    cache.setPrintExceptionsOnClose(false);
    Map<File, PagedFile> fileMap = new HashMap<>(files.length);
    for (int i = 0; i < Math.min(files.length, initialMappedFiles); i++) {
        File file = files[i];
        fileMap.put(file, cache.map(file, filePageSize));
    }
    plan = plan(cache, files, fileMap);
    Callable<Void> planRunner = new PlanRunner(plan);
    Future<Void>[] futures = new Future[concurrencyLevel];
    ExecutorService executor = Executors.newFixedThreadPool(concurrencyLevel);
    for (int i = 0; i < concurrencyLevel; i++) {
        futures[i] = executor.submit(planRunner);
    }
    if (preparation != null) {
        preparation.run(cache, this.fs, plan.getFilesTouched());
    }
    adversary.setProbabilityFactor(1.0);
    plan.start();
    long deadlineMillis = System.currentTimeMillis() + unit.toMillis(timeout);
    long now;
    try {
        for (Future<Void> future : futures) {
            now = System.currentTimeMillis();
            if (deadlineMillis < now) {
                throw new TimeoutException();
            }
            future.get(deadlineMillis - now, TimeUnit.MILLISECONDS);
        }
        adversary.setProbabilityFactor(0.0);
        runVerificationPhase(cache);
    } finally {
        adversary.setProbabilityFactor(0.0);
        for (Future<Void> future : futures) {
            future.cancel(true);
        }
        executor.shutdown();
        now = System.currentTimeMillis();
        executor.awaitTermination(deadlineMillis - now, TimeUnit.MILLISECONDS);
        plan.close();
        cache.close();
        if (this.fs instanceof EphemeralFileSystemAbstraction) {
            this.fs.close();
            this.fs = new EphemeralFileSystemAbstraction();
        } else {
            for (File file : files) {
                file.delete();
            }
        }
    }
}
Also used : PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) PagedFile(org.neo4j.io.pagecache.PagedFile) HashMap(java.util.HashMap) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) RandomAdversary(org.neo4j.adversaries.RandomAdversary) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache) ExecutorService(java.util.concurrent.ExecutorService) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) Future(java.util.concurrent.Future) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

PagedFile (org.neo4j.io.pagecache.PagedFile)39 File (java.io.File)23 PageCursor (org.neo4j.io.pagecache.PageCursor)20 Test (org.junit.Test)16 IOException (java.io.IOException)13 PageCache (org.neo4j.io.pagecache.PageCache)10 ByteBuffer (java.nio.ByteBuffer)8 PageCacheTest (org.neo4j.io.pagecache.PageCacheTest)7 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)5 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)5 StoreChannel (org.neo4j.io.fs.StoreChannel)5 NoSuchFileException (java.nio.file.NoSuchFileException)4 DelegatingPagedFile (org.neo4j.io.pagecache.DelegatingPagedFile)3 DelegatingPageCursor (org.neo4j.io.pagecache.impl.DelegatingPageCursor)3 ConfigurablePageCursorTracerSupplier (org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier)3 RecordingPageCacheTracer (org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer)3 Evict (org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict)3 RecordingPageCursorTracer (org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer)3 Fault (org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault)3 TransactionId (org.neo4j.kernel.impl.store.TransactionId)3