Search in sources :

Example 81 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class CrashGenerationCleanerTest method initializeFile.

private void initializeFile(PagedFile pagedFile, Page... pages) throws IOException {
    try (PageCursor cursor = pagedFile.io(0, PagedFile.PF_SHARED_WRITE_LOCK)) {
        for (Page page : pages) {
            cursor.next();
            page.write(cursor, corruptableTreeNode, stableGeneration, unstableGeneration, crashGeneration);
        }
    }
}
Also used : PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 82 with PageCursor

use of org.neo4j.io.pagecache.PageCursor 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);
    }
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 83 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class PageAwareByteArrayCursor method openLinkedCursor.

@Override
public PageCursor openLinkedCursor(long pageId) {
    PageCursor toReturn = new PageAwareByteArrayCursor(pages, pageSize, pageId);
    if (linkedCursor != null) {
        linkedCursor.close();
    }
    linkedCursor = toReturn;
    return toReturn;
}
Also used : PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 84 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class PageCursorUtilTest method shouldFailOnInvalidValues.

@Test
public void shouldFailOnInvalidValues() throws Exception {
    // GIVEN
    PageCursor cursor = ByteArrayPageCursor.wrap(10);
    // WHEN
    for (int i = 0; i < 1_000; ) {
        long expected = random.nextLong();
        if ((expected & ~_6B_MASK) != 0) {
            // OK here we have an invalid value
            cursor.setOffset(0);
            try {
                PageCursorUtil.put6BLong(cursor, expected);
                fail("Should have failed");
            } catch (IllegalArgumentException e) {
            // THEN good
            }
            i++;
        }
    }
}
Also used : PageCursor(org.neo4j.io.pagecache.PageCursor) Test(org.junit.Test)

Example 85 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class FreeListIdProvider method releaseId.

@Override
public void releaseId(long stableGeneration, long unstableGeneration, long id) throws IOException {
    try (PageCursor cursor = pagedFile.io(writePageId, PagedFile.PF_SHARED_WRITE_LOCK)) {
        PageCursorUtil.goTo(cursor, "free-list write page", writePageId);
        freelistNode.write(cursor, unstableGeneration, id, writePos);
        writePos++;
    }
    if (writePos >= freelistNode.maxEntries()) {
        // Current free-list write page is full, allocate a new one.
        long nextFreelistPage = acquireNewId(stableGeneration, unstableGeneration, false);
        try (PageCursor cursor = pagedFile.io(writePageId, PagedFile.PF_SHARED_WRITE_LOCK)) {
            PageCursorUtil.goTo(cursor, "free-list write page", writePageId);
            FreelistNode.initialize(cursor);
            // Link previous --> new writer page
            FreelistNode.setNext(cursor, nextFreelistPage);
        }
        writePageId = nextFreelistPage;
        writePos = 0;
        monitor.acquiredFreelistPageId(nextFreelistPage);
    }
}
Also used : PageCursor(org.neo4j.io.pagecache.PageCursor)

Aggregations

PageCursor (org.neo4j.io.pagecache.PageCursor)184 Test (org.junit.Test)124 StubPageCursor (org.neo4j.io.pagecache.StubPageCursor)106 PagedFile (org.neo4j.io.pagecache.PagedFile)19 IOException (java.io.IOException)12 File (java.io.File)8 CursorException (org.neo4j.io.pagecache.CursorException)6 PageCacheTest (org.neo4j.io.pagecache.PageCacheTest)6 CompositePageCursor (org.neo4j.io.pagecache.impl.CompositePageCursor)6 DelegatingPageCursor (org.neo4j.io.pagecache.impl.DelegatingPageCursor)6 ByteBuffer (java.nio.ByteBuffer)5 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)5 StoreChannel (org.neo4j.io.fs.StoreChannel)4 DelegatingPagedFile (org.neo4j.io.pagecache.DelegatingPagedFile)4 ConfigurablePageCursorTracerSupplier (org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier)4 RecordingPageCacheTracer (org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer)4 Evict (org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict)4 RecordingPageCursorTracer (org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer)4 Fault (org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3