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;
}
}
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());
}
}
}
}
Aggregations