Search in sources :

Example 1 with ReadAheadChannel

use of org.neo4j.kernel.impl.transaction.log.ReadAheadChannel in project neo4j by neo4j.

the class StateRecoveryManager method readLastEntryFrom.

private STATE readLastEntryFrom(File file) throws IOException {
    try (ReadableClosableChannel channel = new ReadAheadChannel<>(fileSystem.open(file, "r"))) {
        STATE result = null;
        STATE lastRead;
        try {
            while ((lastRead = marshal.unmarshal(channel)) != null) {
                result = lastRead;
            }
        } catch (EndOfStreamException e) {
        // ignore; just use previous complete entry
        }
        return result;
    }
}
Also used : ReadableClosableChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosableChannel) EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) ReadAheadChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadChannel)

Example 2 with ReadAheadChannel

use of org.neo4j.kernel.impl.transaction.log.ReadAheadChannel in project neo4j by neo4j.

the class InMemoryCountsStoreCountsSnapshotSerializerIntegrationTest method largeWorkloadOnPhysicalLogTest.

@Test
public void largeWorkloadOnPhysicalLogTest() throws IOException {
    //GIVEN
    try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction()) {
        File tempFile = new File(testDir.directory(), "temp");
        StoreChannel rawChannel = fs.create(tempFile);
        Map<CountsKey, long[]> map = CountsStoreMapGenerator.simpleCountStoreMap(100000);
        CountsSnapshot countsSnapshot = new CountsSnapshot(1, map);
        CountsSnapshot recovered;
        //WHEN
        try (FlushableChannel tempChannel = new PhysicalFlushableChannel(rawChannel)) {
            serialize(tempChannel, countsSnapshot);
        }
        // close() here is necessary to flush the temp buffer into the channel so we can read it next
        // The try-with-resources closes the channel, need to reopen
        rawChannel = fs.open(tempFile, "r");
        try (ReadAheadChannel<StoreChannel> readAheadChannel = new ReadAheadChannel<>(rawChannel)) {
            recovered = deserialize(readAheadChannel);
            //THEN
            Assert.assertEquals(countsSnapshot.getTxId(), recovered.getTxId());
            for (Map.Entry<CountsKey, long[]> pair : countsSnapshot.getMap().entrySet()) {
                long[] value = recovered.getMap().get(pair.getKey());
                Assert.assertNotNull(value);
                Assert.assertArrayEquals(value, pair.getValue());
            }
            for (Map.Entry<CountsKey, long[]> pair : recovered.getMap().entrySet()) {
                long[] value = countsSnapshot.getMap().get(pair.getKey());
                Assert.assertNotNull(value);
                Assert.assertArrayEquals(value, pair.getValue());
            }
        }
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) PhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) FlushableChannel(org.neo4j.kernel.impl.transaction.log.FlushableChannel) PhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel) File(java.io.File) Map(java.util.Map) ReadAheadChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadChannel) Test(org.junit.Test)

Aggregations

ReadAheadChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadChannel)2 File (java.io.File)1 Map (java.util.Map)1 Test (org.junit.Test)1 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1 CountsKey (org.neo4j.kernel.impl.store.counts.keys.CountsKey)1 FlushableChannel (org.neo4j.kernel.impl.transaction.log.FlushableChannel)1 PhysicalFlushableChannel (org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel)1 ReadableClosableChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosableChannel)1