Search in sources :

Example 1 with InvalidIdGeneratorException

use of org.neo4j.kernel.impl.store.InvalidIdGeneratorException in project neo4j by neo4j.

the class IdGeneratorImplTest method shouldForceStickyMark.

@Test
public void shouldForceStickyMark() throws Exception {
    // GIVEN
    try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction()) {
        File dir = new File("target/test-data/" + getClass().getName());
        fs.mkdirs(dir);
        File file = new File(dir, "ids");
        fs.deleteFile(file);
        IdGeneratorImpl.createGenerator(fs, file, 0, false);
        // WHEN opening the id generator, where the jvm crashes right after
        executeSubProcess(getClass(), 1, MINUTES, file.getAbsolutePath());
        // THEN
        try {
            IdGeneratorImpl.readHighId(fs, file);
            fail("Should have thrown, saying something with sticky generator");
        } catch (InvalidIdGeneratorException e) {
        // THEN Good
        }
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) InvalidIdGeneratorException(org.neo4j.kernel.impl.store.InvalidIdGeneratorException) File(java.io.File) Test(org.junit.Test)

Example 2 with InvalidIdGeneratorException

use of org.neo4j.kernel.impl.store.InvalidIdGeneratorException in project neo4j by neo4j.

the class IdGeneratorImpl method readHighIdFromHeader.

private static ByteBuffer readHighIdFromHeader(StoreChannel channel, File fileName) throws IOException {
    ByteBuffer buffer = ByteBuffer.allocate(HEADER_SIZE);
    int read = channel.read(buffer);
    if (read != HEADER_SIZE) {
        throw new InvalidIdGeneratorException("Unable to read header, bytes read: " + read);
    }
    buffer.flip();
    byte storageStatus = buffer.get();
    if (storageStatus != CLEAN_GENERATOR) {
        throw new InvalidIdGeneratorException("Sticky generator[ " + fileName + "] delete this id file and build a new one");
    }
    return buffer;
}
Also used : InvalidIdGeneratorException(org.neo4j.kernel.impl.store.InvalidIdGeneratorException) ByteBuffer(java.nio.ByteBuffer)

Example 3 with InvalidIdGeneratorException

use of org.neo4j.kernel.impl.store.InvalidIdGeneratorException in project neo4j by neo4j.

the class IdGeneratorImpl method readHeader.

private ByteBuffer readHeader() throws IOException {
    try {
        ByteBuffer buffer = readHighIdFromHeader(fileChannel, file);
        this.highId.set(buffer.getLong());
        return buffer;
    } catch (InvalidIdGeneratorException e) {
        fileChannel.close();
        throw e;
    }
}
Also used : InvalidIdGeneratorException(org.neo4j.kernel.impl.store.InvalidIdGeneratorException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

InvalidIdGeneratorException (org.neo4j.kernel.impl.store.InvalidIdGeneratorException)3 ByteBuffer (java.nio.ByteBuffer)2 File (java.io.File)1 Test (org.junit.Test)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1