use of org.neo4j.io.pagecache.impl.FileIsNotMappedException in project neo4j by neo4j.
the class PageCacheTest method pagedFileIoMustThrowIfFileIsUnmapped.
@Test
void pagedFileIoMustThrowIfFileIsUnmapped() {
assertTimeoutPreemptively(ofMillis(SHORT_TIMEOUT_MILLIS), () -> {
configureStandardPageCache();
PagedFile pagedFile = map(file("a"), filePageSize);
closeThisPagedFile(pagedFile);
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, NULL)) {
FileIsNotMappedException exception = assertThrows(FileIsNotMappedException.class, cursor::next);
StringWriter out = new StringWriter();
exception.printStackTrace(new PrintWriter(out));
assertThat(out.toString()).contains("closeThisPagedFile");
}
});
}
use of org.neo4j.io.pagecache.impl.FileIsNotMappedException in project neo4j by neo4j.
the class GBPTreeTest method closeShouldLockOutWriter.
@Test
void closeShouldLockOutWriter() throws ExecutionException, InterruptedException, IOException {
// GIVEN
AtomicBoolean enabled = new AtomicBoolean();
Barrier.Control barrier = new Barrier.Control();
try (PageCache pageCacheWithBarrier = pageCacheWithBarrierInClose(enabled, barrier)) {
GBPTree<MutableLong, MutableLong> index = index(pageCacheWithBarrier).build();
long key = 10;
try (Writer<MutableLong, MutableLong> writer = index.writer(NULL)) {
writer.put(new MutableLong(key), new MutableLong(key));
}
// WHEN
enabled.set(true);
Future<?> close = executor.submit(throwing(index::close));
barrier.awaitUninterruptibly();
// now we're in the smack middle of a close/checkpoint
AtomicReference<Exception> writerError = new AtomicReference<>();
Future<?> write = executor.submit(() -> {
try {
index.writer(NULL).close();
} catch (Exception e) {
writerError.set(e);
}
});
shouldWait(write);
barrier.release();
// THEN
write.get();
close.get();
assertTrue(writerError.get() instanceof FileIsNotMappedException, "Writer should not be able to acquired after close");
}
}
use of org.neo4j.io.pagecache.impl.FileIsNotMappedException in project neo4j by neo4j.
the class PageCacheTest method writeLockedPageCursorNextMustThrowIfFileIsUnmapped.
@Test
void writeLockedPageCursorNextMustThrowIfFileIsUnmapped() {
assertTimeoutPreemptively(ofMillis(SHORT_TIMEOUT_MILLIS), () -> {
configureStandardPageCache();
PagedFile pagedFile = map(file("a"), filePageSize);
PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, NULL);
closeThisPagedFile(pagedFile);
FileIsNotMappedException exception = assertThrows(FileIsNotMappedException.class, cursor::next);
StringWriter out = new StringWriter();
exception.printStackTrace(new PrintWriter(out));
assertThat(out.toString()).contains("closeThisPagedFile");
});
}
use of org.neo4j.io.pagecache.impl.FileIsNotMappedException in project neo4j by neo4j.
the class MuninnPagedFile method fileIsNotMappedException.
private FileIsNotMappedException fileIsNotMappedException() {
FileIsNotMappedException exception = new FileIsNotMappedException(path());
Exception closedBy = closeStackTrace;
if (closedBy != null) {
exception.addSuppressed(closedBy);
}
return exception;
}
use of org.neo4j.io.pagecache.impl.FileIsNotMappedException in project neo4j by neo4j.
the class NativeIndexReader method createSampler.
@Override
public IndexSampler createSampler() {
// For a unique index there's an optimization, knowing that all values in it are unique, to simply count
// the number of indexed values and create a sample for that count. The GBPTree doesn't have an O(1)
// count mechanism, it will have to manually count the indexed values in it to get it.
// For that reason this implementation opts for keeping complexity down by just using the existing
// non-unique sampler which scans the index and counts (potentially duplicates, of which there will
// be none in a unique index).
FullScanNonUniqueIndexSampler<KEY, VALUE> sampler = new FullScanNonUniqueIndexSampler<>(tree, layout);
return tracer -> {
try {
return sampler.sample(tracer);
} catch (UncheckedIOException e) {
if (getRootCause(e) instanceof FileIsNotMappedException) {
IndexNotFoundKernelException exception = new IndexNotFoundKernelException("Index dropped while sampling.");
exception.addSuppressed(e);
throw exception;
}
throw e;
}
};
}
Aggregations