Search in sources :

Example 1 with FileIsNotMappedException

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");
        }
    });
}
Also used : FileIsNotMappedException(org.neo4j.io.pagecache.impl.FileIsNotMappedException) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 2 with FileIsNotMappedException

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");
    }
}
Also used : FileIsNotMappedException(org.neo4j.io.pagecache.impl.FileIsNotMappedException) Barrier(org.neo4j.test.Barrier) AtomicReference(java.util.concurrent.atomic.AtomicReference) NoSuchFileException(java.nio.file.NoSuchFileException) TimeoutException(java.util.concurrent.TimeoutException) FileIsNotMappedException(org.neo4j.io.pagecache.impl.FileIsNotMappedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MutableLong(org.apache.commons.lang3.mutable.MutableLong) PageCache(org.neo4j.io.pagecache.PageCache) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) Test(org.junit.jupiter.api.Test)

Example 3 with FileIsNotMappedException

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");
    });
}
Also used : FileIsNotMappedException(org.neo4j.io.pagecache.impl.FileIsNotMappedException) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 4 with FileIsNotMappedException

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;
}
Also used : FileIsNotMappedException(org.neo4j.io.pagecache.impl.FileIsNotMappedException) ClosedChannelException(java.nio.channels.ClosedChannelException) FileIsNotMappedException(org.neo4j.io.pagecache.impl.FileIsNotMappedException) IOException(java.io.IOException)

Example 5 with FileIsNotMappedException

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;
        }
    };
}
Also used : IndexOrder(org.neo4j.internal.schema.IndexOrder) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) Seeker(org.neo4j.index.internal.gbptree.Seeker) CursorContext(org.neo4j.io.pagecache.context.CursorContext) FileIsNotMappedException(org.neo4j.io.pagecache.impl.FileIsNotMappedException) ExceptionUtils.getRootCause(org.apache.commons.lang3.exception.ExceptionUtils.getRootCause) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) IOException(java.io.IOException) Value(org.neo4j.values.storable.Value) UncheckedIOException(java.io.UncheckedIOException) GBPTree(org.neo4j.index.internal.gbptree.GBPTree) IndexProgressor(org.neo4j.kernel.api.index.IndexProgressor) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) QueryContext(org.neo4j.internal.kernel.api.QueryContext) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) NEUTRAL(org.neo4j.kernel.impl.index.schema.NativeIndexKey.Inclusion.NEUTRAL) FileIsNotMappedException(org.neo4j.io.pagecache.impl.FileIsNotMappedException) UncheckedIOException(java.io.UncheckedIOException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)

Aggregations

FileIsNotMappedException (org.neo4j.io.pagecache.impl.FileIsNotMappedException)5 IOException (java.io.IOException)3 Test (org.junit.jupiter.api.Test)3 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 UncheckedIOException (java.io.UncheckedIOException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ExceptionUtils.getRootCause (org.apache.commons.lang3.exception.ExceptionUtils.getRootCause)1 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 GBPTree (org.neo4j.index.internal.gbptree.GBPTree)1 Seeker (org.neo4j.index.internal.gbptree.Seeker)1 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)1 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)1 QueryContext (org.neo4j.internal.kernel.api.QueryContext)1