Search in sources :

Example 66 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingLastPage.

@Test
public void mustFlushDirtyPagesOnEvictingLastPage() 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(1, 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(x));
    assertThat(buf.getLong(), is(0L));
}
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 67 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class IndexConfigStore method write.

private void write(File file) {
    StoreChannel channel = null;
    try {
        channel = fileSystem.open(file, "rw");
        channel.write(ByteBuffer.wrap(MAGICK));
        IoPrimitiveUtils.writeInt(channel, buffer(4), VERSION);
        writeMap(channel, nodeConfig);
        writeMap(channel, relConfig);
        channel.force(false);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        close(channel);
    }
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) IOException(java.io.IOException)

Example 68 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class IndexProviderStore method create.

private void create(File file, FileSystemAbstraction fileSystem, long indexVersion) throws IOException {
    if (fileSystem.fileExists(file) && fileSystem.getFileSize(file) > 0) {
        throw new IllegalArgumentException(file + " already exist");
    }
    StoreChannel fileChannel = null;
    try {
        fileChannel = fileSystem.open(file, "rw");
        write(fileChannel, System.currentTimeMillis(), random.nextLong(), 0, 1, indexVersion);
    } finally {
        if (fileChannel != null) {
            fileChannel.close();
        }
    }
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel)

Example 69 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class LegacyStoreVersionCheck method hasVersion.

public Result hasVersion(File storeFile, String expectedVersion, boolean optional) {
    StoreChannel fileChannel = null;
    String storeFilename = storeFile.getName();
    byte[] expectedVersionBytes = UTF8.encode(expectedVersion);
    try {
        if (!fs.fileExists(storeFile)) {
            if (optional) {
                return new Result(Outcome.ok, null, storeFilename);
            }
            return new Result(Outcome.missingStoreFile, null, storeFilename);
        }
        fileChannel = fs.open(storeFile, "r");
        if (fileChannel.size() < expectedVersionBytes.length) {
            return new Result(Outcome.storeVersionNotFound, null, storeFilename);
        }
        String actualVersion = readVersion(fileChannel, expectedVersionBytes.length);
        if (!expectedVersion.equals(actualVersion)) {
            return new Result(Outcome.unexpectedStoreVersion, actualVersion, storeFilename);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (fileChannel != null) {
            try {
                fileChannel.close();
            } catch (IOException e) {
            // Ignore exception on close
            }
        }
    }
    return new Result(Outcome.ok, null, storeFilename);
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) IOException(java.io.IOException) Result(org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result)

Example 70 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class LegacyLogEntryWriter method openWritableChannel.

public LogVersionedStoreChannel openWritableChannel(File file) throws IOException {
    final StoreChannel storeChannel = fs.open(file, "rw");
    final long version = getLegacyLogVersion(file.getName());
    return new PhysicalLogVersionedStoreChannel(storeChannel, version, CURRENT_LOG_VERSION);
}
Also used : LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)

Aggregations

StoreChannel (org.neo4j.io.fs.StoreChannel)113 Test (org.junit.Test)71 File (java.io.File)65 ByteBuffer (java.nio.ByteBuffer)48 IOException (java.io.IOException)20 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)17 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)15 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)13 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)11 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)10 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)7 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)7 LogHeaderReader.readLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader)7 InputStream (java.io.InputStream)6 PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)6 PageSwapperTest (org.neo4j.io.pagecache.PageSwapperTest)6 HashSet (java.util.HashSet)5 AdversarialPagedFile (org.neo4j.adversaries.pagecache.AdversarialPagedFile)5 PageSwapper (org.neo4j.io.pagecache.PageSwapper)5 PagedFile (org.neo4j.io.pagecache.PagedFile)5