use of org.neo4j.io.pagecache.PagedFile in project neo4j by neo4j.
the class GBPTreeTest method setFormatVersion.
private void setFormatVersion(int pageSize, int formatVersion) throws IOException {
try (PagedFile pagedFile = pageCache.map(indexFile, pageSize);
PageCursor cursor = pagedFile.io(IdSpace.META_PAGE_ID, PagedFile.PF_SHARED_WRITE_LOCK)) {
assertTrue(cursor.next());
cursor.putInt(formatVersion);
}
}
use of org.neo4j.io.pagecache.PagedFile in project neo4j by neo4j.
the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingAllPages.
@Test
public void mustFlushDirtyPagesOnEvictingAllPages() throws Exception {
writeInitialDataTo(file("a"));
RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer(Fault.class);
ConfigurablePageCursorTracerSupplier cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier(cursorTracer);
MuninnPageCache pageCache = createPageCache(fs, 4, 8, blockCacheFlush(tracer), cursorTracerSupplier);
PagedFile pagedFile = pageCache.map(file("a"), 8);
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK | PF_NO_GROW)) {
assertTrue(cursor.next());
cursor.putLong(0L);
assertTrue(cursor.next());
cursor.putLong(0L);
assertFalse(cursor.next());
}
cursorTracer.reportEvents();
assertNotNull(cursorTracer.observe(Fault.class));
assertNotNull(cursorTracer.observe(Fault.class));
assertEquals(2, cursorTracer.faults());
assertEquals(2, tracer.faults());
int clockArm = pageCache.evictPages(2, 0, tracer.beginPageEvictions(2));
assertThat(clockArm, is(2));
assertNotNull(tracer.observe(Evict.class));
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(0L));
assertThat(buf.getLong(), is(0L));
}
use of org.neo4j.io.pagecache.PagedFile in project neo4j by neo4j.
the class MuninnPageCacheTest method closingTheCursorMustUnlockModifiedPage.
@Test
public void closingTheCursorMustUnlockModifiedPage() throws Exception {
writeInitialDataTo(file("a"));
final MuninnPageCache pageCache = createPageCache(fs, 2, 8, PageCacheTracer.NULL, DefaultPageCursorTracerSupplier.INSTANCE);
final PagedFile pagedFile = pageCache.map(file("a"), 8);
Future<?> task = executor.submit(() -> {
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK)) {
assertTrue(cursor.next());
cursor.putLong(41);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
task.get();
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK)) {
assertTrue(cursor.next());
long value = cursor.getLong();
cursor.setOffset(0);
cursor.putLong(value + 1);
}
int clockArm = pageCache.evictPages(1, 0, EvictionRunEvent.NULL);
assertThat(clockArm, is(1));
ByteBuffer buf = ByteBuffer.allocate(16);
StoreChannel channel = fs.open(file("a"), "r");
channel.read(buf);
buf.flip();
assertThat(buf.getLong(), is(42L));
assertThat(buf.getLong(), is(y));
}
use of org.neo4j.io.pagecache.PagedFile in project neo4j by neo4j.
the class MuninnPageCacheTest method mustUnblockPageFaultersWhenEvictionGetsException.
@Test(timeout = SEMI_LONG_TIMEOUT_MILLIS)
public void mustUnblockPageFaultersWhenEvictionGetsException() throws Exception {
writeInitialDataTo(file("a"));
FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(this.fs) {
@Override
public StoreChannel open(File fileName, String mode) throws IOException {
return new DelegatingStoreChannel(super.open(fileName, mode)) {
@Override
public void writeAll(ByteBuffer src, long position) throws IOException {
throw new IOException("uh-oh...");
}
};
}
};
MuninnPageCache pageCache = createPageCache(fs, 2, 8, PageCacheTracer.NULL, DefaultPageCursorTracerSupplier.INSTANCE);
final PagedFile pagedFile = pageCache.map(file("a"), 8);
// all writes.
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK)) {
for (int i = 0; i < 1000; i++) {
assertTrue(cursor.next());
}
fail("Expected an exception at this point");
} catch (IOException ignore) {
// Good.
}
}
use of org.neo4j.io.pagecache.PagedFile in project neo4j by neo4j.
the class CommonAbstractStore method checkAndLoadStorage.
/**
* This method is called by constructors. Checks the header record and loads the store.
* <p>
* Note: This method will map the file with the page cache. The store file must not
* be accessed directly until it has been unmapped - the store file must only be
* accessed through the page cache.
* @param createIfNotExists If true, creates and initialises the store file if it does not exist already. If false,
* this method will instead throw an exception in that situation.
*/
protected void checkAndLoadStorage(boolean createIfNotExists) {
int pageSize = pageCache.pageSize();
int filePageSize;
try (PagedFile pagedFile = pageCache.map(storageFileName, pageSize, ANY_PAGE_SIZE)) {
extractHeaderRecord(pagedFile);
filePageSize = pageCache.pageSize() - pageCache.pageSize() % getRecordSize();
} catch (NoSuchFileException | StoreNotFoundException e) {
if (createIfNotExists) {
try {
createStore(pageSize);
return;
} catch (IOException e1) {
e.addSuppressed(e1);
}
}
if (e instanceof StoreNotFoundException) {
throw (StoreNotFoundException) e;
}
throw new StoreNotFoundException("Store file not found: " + storageFileName, e);
} catch (IOException e) {
throw new UnderlyingStorageException("Unable to open store file: " + storageFileName, e);
}
loadStorage(filePageSize);
}
Aggregations