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