Search in sources :

Example 1 with CursorException

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

the class ConsistencyCheckerTest method shouldThrowDescriptiveExceptionOnBrokenGSPP.

@Test
public void shouldThrowDescriptiveExceptionOnBrokenGSPP() throws Exception {
    // GIVEN
    int pageSize = 256;
    PageCursor cursor = new PageAwareByteArrayCursor(pageSize);
    Layout<MutableLong, MutableLong> layout = new SimpleLongLayout();
    TreeNode<MutableLong, MutableLong> treeNode = new TreeNode<>(pageSize, layout);
    long stableGeneration = MIN_GENERATION;
    long crashGeneration = stableGeneration + 1;
    long unstableGeneration = stableGeneration + 2;
    String pointerFieldName = "abc";
    long pointer = 123;
    cursor.next(0);
    treeNode.initializeInternal(cursor, stableGeneration, crashGeneration);
    treeNode.setSuccessor(cursor, pointer, stableGeneration, crashGeneration);
    // WHEN
    try {
        assertNoCrashOrBrokenPointerInGSPP(cursor, stableGeneration, unstableGeneration, pointerFieldName, TreeNode.BYTE_POS_SUCCESSOR, treeNode);
        cursor.checkAndClearCursorException();
        fail("Should have failed");
    } catch (CursorException e) {
        // THEN
        assertThat(e.getMessage(), containsString(pointerFieldName));
        assertThat(e.getMessage(), containsString(pointerFieldName));
        assertThat(e.getMessage(), containsString("state=CRASH"));
        assertThat(e.getMessage(), containsString("state=EMPTY"));
        assertThat(e.getMessage(), containsString(String.valueOf(pointer)));
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) CursorException(org.neo4j.io.pagecache.CursorException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PageCursor(org.neo4j.io.pagecache.PageCursor) Test(org.junit.Test)

Example 2 with CursorException

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

the class GBPTree method readMeta.

private void readMeta(File indexFile, Layout<KEY, VALUE> layout, PagedFile pagedFile) throws IOException {
    // Read meta
    int formatVersion;
    long layoutIdentifier;
    int majorVersion;
    int minorVersion;
    try (PageCursor metaCursor = openMetaPageCursor(pagedFile, PagedFile.PF_SHARED_READ_LOCK)) {
        do {
            formatVersion = metaCursor.getInt();
            pageSize = metaCursor.getInt();
            layoutIdentifier = metaCursor.getLong();
            majorVersion = metaCursor.getInt();
            minorVersion = metaCursor.getInt();
            layout.readMetaData(metaCursor);
        } while (metaCursor.shouldRetry());
        checkOutOfBounds(metaCursor);
        metaCursor.checkAndClearCursorException();
    } catch (CursorException e) {
        throw new MetadataMismatchException(format("Tried to open %s, but caught an error while reading meta data. " + "File is expected to be corrupt, try to rebuild.", indexFile), e);
    }
    if (formatVersion != FORMAT_VERSION) {
        throw new MetadataMismatchException("Tried to open %s with a different format version than " + "what it was created with. Created with:%d, opened with %d", indexFile, formatVersion, FORMAT_VERSION);
    }
    if (layoutIdentifier != layout.identifier()) {
        throw new MetadataMismatchException("Tried to open " + indexFile + " using different layout identifier " + "than what it was created with. Created with:" + layoutIdentifier + ", opened with " + layout.identifier());
    }
    if (majorVersion != layout.majorVersion() || minorVersion != layout.minorVersion()) {
        throw new MetadataMismatchException("Tried to open " + indexFile + " using different layout version " + "than what it was created with. Created with:" + majorVersion + "." + minorVersion + ", opened with " + layout.majorVersion() + "." + layout.minorVersion());
    }
}
Also used : CursorException(org.neo4j.io.pagecache.CursorException) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 3 with CursorException

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

the class CompositePageCursorTest method checkAndClearCursorErrorMustThrowIfSecondCursorHasError.

@Test
public void checkAndClearCursorErrorMustThrowIfSecondCursorHasError() throws Exception {
    PageCursor cursor = CompositePageCursor.compose(first, PAGE_SIZE, second, PAGE_SIZE);
    second.setCursorException("boo");
    try {
        cursor.checkAndClearCursorException();
        fail("composite cursor checkAndClearCursorError should have thrown");
    } catch (CursorException e) {
        assertThat(e.getMessage(), is("boo"));
    }
}
Also used : CursorException(org.neo4j.io.pagecache.CursorException) PageCursor(org.neo4j.io.pagecache.PageCursor) StubPageCursor(org.neo4j.io.pagecache.StubPageCursor) Test(org.junit.Test)

Example 4 with CursorException

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

the class CompositePageCursorTest method setCursorErrorMustApplyToCursorAtCurrentOffset.

@Test
public void setCursorErrorMustApplyToCursorAtCurrentOffset() throws Exception {
    PageCursor cursor = CompositePageCursor.compose(first, PAGE_SIZE, second, PAGE_SIZE);
    String firstMsg = "first boo";
    String secondMsg = "second boo";
    cursor.setCursorException(firstMsg);
    assertFalse(cursor.checkAndClearBoundsFlag());
    try {
        first.checkAndClearCursorException();
        fail("first checkAndClearCursorError should have thrown");
    } catch (CursorException e) {
        assertThat(e.getMessage(), is(firstMsg));
    }
    cursor.setOffset(PAGE_SIZE);
    cursor.setCursorException(secondMsg);
    assertFalse(cursor.checkAndClearBoundsFlag());
    try {
        second.checkAndClearCursorException();
        fail("second checkAndClearCursorError should have thrown");
    } catch (CursorException e) {
        assertThat(e.getMessage(), is(secondMsg));
    }
}
Also used : CursorException(org.neo4j.io.pagecache.CursorException) PageCursor(org.neo4j.io.pagecache.PageCursor) StubPageCursor(org.neo4j.io.pagecache.StubPageCursor) Test(org.junit.Test)

Example 5 with CursorException

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

the class CompositePageCursorTest method checkAndClearCursorErrorWillOnlyCheckFirstCursorIfBothHaveErrorsSet.

@Test
public void checkAndClearCursorErrorWillOnlyCheckFirstCursorIfBothHaveErrorsSet() throws Exception {
    PageCursor cursor = CompositePageCursor.compose(first, PAGE_SIZE, second, PAGE_SIZE);
    first.setCursorException("first boo");
    second.setCursorException("second boo");
    try {
        cursor.checkAndClearCursorException();
        fail("composite cursor checkAndClearCursorError should have thrown");
    } catch (CursorException e) {
        assertThat(e.getMessage(), is("first boo"));
    }
    try {
        second.checkAndClearCursorException();
        fail("second cursor checkAndClearCursorError should have thrown");
    } catch (CursorException e) {
        assertThat(e.getMessage(), is("second boo"));
    }
}
Also used : CursorException(org.neo4j.io.pagecache.CursorException) PageCursor(org.neo4j.io.pagecache.PageCursor) StubPageCursor(org.neo4j.io.pagecache.StubPageCursor) Test(org.junit.Test)

Aggregations

CursorException (org.neo4j.io.pagecache.CursorException)6 PageCursor (org.neo4j.io.pagecache.PageCursor)6 Test (org.junit.Test)5 StubPageCursor (org.neo4j.io.pagecache.StubPageCursor)4 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1