Search in sources :

Example 51 with StoreChannel

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

the class FailureStorage method readFailure.

private String readFailure(File failureFile) throws IOException {
    try (StoreChannel channel = fs.open(failureFile, "r")) {
        byte[] data = new byte[(int) channel.size()];
        int readData = channel.read(ByteBuffer.wrap(data));
        return readData <= 0 ? "" : UTF8.decode(withoutZeros(data));
    }
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel)

Example 52 with StoreChannel

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

the class FailureStorage method reserveForIndex.

/**
     * Create/reserve an empty failure file for the given indexId.
     *
     * This will overwrite any pre-existing failure file.
     *
     * @throws IOException if the failure file could not be created
     */
public synchronized void reserveForIndex() throws IOException {
    fs.mkdirs(folderLayout.getIndexFolder());
    File failureFile = failureFile();
    try (StoreChannel channel = fs.create(failureFile)) {
        channel.write(ByteBuffer.wrap(new byte[MAX_FAILURE_SIZE]));
        channel.force(true);
    }
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File)

Example 53 with StoreChannel

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

the class FileSenderTest method sendLargeFile.

@Test
public void sendLargeFile() throws Exception {
    // given
    int dataSize = MAX_SIZE + (MAX_SIZE / 2);
    byte[] bytes = new byte[dataSize];
    random.nextBytes(bytes);
    File smallFile = testDirectory.file("smallFile");
    try (StoreChannel storeChannel = fs.create(smallFile)) {
        storeChannel.write(ByteBuffer.wrap(bytes));
    }
    FileSender fileSender = new FileSender(fs.open(smallFile, "r"));
    // when + then
    assertFalse(fileSender.isEndOfInput());
    assertEquals(FileChunk.create(copyOfRange(bytes, 0, MAX_SIZE), false), fileSender.readChunk(allocator));
    assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE, bytes.length), true), fileSender.readChunk(allocator));
    assertNull(fileSender.readChunk(allocator));
    assertTrue(fileSender.isEndOfInput());
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File) Test(org.junit.Test)

Example 54 with StoreChannel

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

the class FileSenderTest method sendLargeFileWithSizeMultipleOfTheChunkSize.

@Test
public void sendLargeFileWithSizeMultipleOfTheChunkSize() throws Exception {
    // given
    byte[] bytes = new byte[MAX_SIZE * 3];
    random.nextBytes(bytes);
    File smallFile = testDirectory.file("smallFile");
    try (StoreChannel storeChannel = fs.create(smallFile)) {
        storeChannel.write(ByteBuffer.wrap(bytes));
    }
    FileSender fileSender = new FileSender(fs.open(smallFile, "r"));
    // when + then
    assertFalse(fileSender.isEndOfInput());
    assertEquals(FileChunk.create(copyOfRange(bytes, 0, MAX_SIZE), false), fileSender.readChunk(allocator));
    assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE, MAX_SIZE * 2), false), fileSender.readChunk(allocator));
    assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE * 2, bytes.length), true), fileSender.readChunk(allocator));
    assertNull(fileSender.readChunk(allocator));
    assertTrue(fileSender.isEndOfInput());
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File) Test(org.junit.Test)

Example 55 with StoreChannel

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

the class FileSenderTest method sendLargeFileWithUnreliableReadBufferSize.

@Test
public void sendLargeFileWithUnreliableReadBufferSize() throws Exception {
    // given
    byte[] bytes = new byte[MAX_SIZE * 3];
    random.nextBytes(bytes);
    File smallFile = testDirectory.file("smallFile");
    try (StoreChannel storeChannel = fs.create(smallFile)) {
        storeChannel.write(ByteBuffer.wrap(bytes));
    }
    Adversary adversary = new RandomAdversary(0.9, 0.0, 0.0);
    AdversarialFileSystemAbstraction afs = new AdversarialFileSystemAbstraction(adversary, fs);
    FileSender fileSender = new FileSender(afs.open(smallFile, "r"));
    // when + then
    assertFalse(fileSender.isEndOfInput());
    assertEquals(FileChunk.create(copyOfRange(bytes, 0, MAX_SIZE), false), fileSender.readChunk(allocator));
    assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE, MAX_SIZE * 2), false), fileSender.readChunk(allocator));
    assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE * 2, bytes.length), true), fileSender.readChunk(allocator));
    assertNull(fileSender.readChunk(allocator));
    assertTrue(fileSender.isEndOfInput());
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) RandomAdversary(org.neo4j.adversaries.RandomAdversary) Adversary(org.neo4j.adversaries.Adversary) RandomAdversary(org.neo4j.adversaries.RandomAdversary) Test(org.junit.Test)

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