Search in sources :

Example 1 with IdGeneratorImpl

use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.

the class ReplicatedIdGeneratorFactory method openGenerator.

private IdGenerator openGenerator(File fileName, int grabSize, IdType idType, long highId, long maxId, boolean aggressiveReuse) {
    SwitchableRaftIdGenerator previous = generators.remove(idType);
    if (previous != null) {
        previous.close();
    }
    IdGenerator initialIdGenerator = new IdGeneratorImpl(fs, fileName, grabSize, maxId, aggressiveReuse, highId);
    SwitchableRaftIdGenerator switchableIdGenerator = new SwitchableRaftIdGenerator(initialIdGenerator, idType, idRangeAcquirer, logProvider);
    if (replicatedMode) {
        switchableIdGenerator.switchToRaft();
    }
    generators.put(idType, switchableIdGenerator);
    return switchableIdGenerator;
}
Also used : IdGeneratorImpl(org.neo4j.kernel.impl.store.id.IdGeneratorImpl) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator)

Example 2 with IdGeneratorImpl

use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.

the class IdGeneratorTest method grabSizeCannotBeZero.

@Test(expected = IllegalArgumentException.class)
public void grabSizeCannotBeZero() throws Exception {
    IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
    new IdGeneratorImpl(fs, idGeneratorFile(), 0, 100, false, 0).close();
}
Also used : IdGeneratorImpl(org.neo4j.kernel.impl.store.id.IdGeneratorImpl) Test(org.junit.Test)

Example 3 with IdGeneratorImpl

use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.

the class IdGeneratorTest method testClose.

@Test
public void testClose() {
    try {
        IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
        IdGenerator idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), 2, 1000, false, 0);
        closeIdGenerator(idGenerator);
        try {
            idGenerator.nextId();
            fail("nextId after close should throw exception");
        } catch (IllegalStateException e) {
        // good
        }
        try {
            idGenerator.freeId(0);
            fail("freeId after close should throw exception");
        } catch (IllegalStateException e) {
        // good
        }
        idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), 2, 1000, false, 0);
        assertEquals(0L, idGenerator.nextId());
        assertEquals(1L, idGenerator.nextId());
        assertEquals(2L, idGenerator.nextId());
        closeIdGenerator(idGenerator);
        try {
            idGenerator.nextId();
            fail("nextId after close should throw exception");
        } catch (IllegalStateException e) {
        // good
        }
        try {
            idGenerator.freeId(0);
            fail("freeId after close should throw exception");
        } catch (IllegalStateException e) {
        // good
        }
    } finally {
        File file = idGeneratorFile();
        if (file.exists()) {
            assertTrue(file.delete());
        }
    }
}
Also used : IdGeneratorImpl(org.neo4j.kernel.impl.store.id.IdGeneratorImpl) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) File(java.io.File) Test(org.junit.Test)

Example 4 with IdGeneratorImpl

use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.

the class IdGeneratorTest method makeSureMagicMinusOneIsSkipped.

private void makeSureMagicMinusOneIsSkipped(RecordFormat format) {
    deleteIdGeneratorFile();
    IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
    IdGenerator idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), 1, format.getMaxId(), false, 0);
    long id = (long) Math.pow(2, 32) - 3;
    idGenerator.setHighId(id);
    assertEquals(id, idGenerator.nextId());
    assertEquals(id + 1, idGenerator.nextId());
    // Here we make sure that id+2 (integer -1) is skipped
    assertEquals(id + 3, idGenerator.nextId());
    assertEquals(id + 4, idGenerator.nextId());
    assertEquals(id + 5, idGenerator.nextId());
    closeIdGenerator(idGenerator);
}
Also used : IdGeneratorImpl(org.neo4j.kernel.impl.store.id.IdGeneratorImpl) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator)

Example 5 with IdGeneratorImpl

use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.

the class IdGeneratorTest method delete.

@Test
public void delete() throws Exception {
    IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
    IdGeneratorImpl idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), 10, 1000, false, 0);
    long id = idGenerator.nextId();
    idGenerator.nextId();
    idGenerator.freeId(id);
    idGenerator.close();
    idGenerator.delete();
    assertFalse(idGeneratorFile().exists());
    IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
    idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), 10, 1000, false, 0);
    assertEquals(id, idGenerator.nextId());
    idGenerator.close();
}
Also used : IdGeneratorImpl(org.neo4j.kernel.impl.store.id.IdGeneratorImpl) Test(org.junit.Test)

Aggregations

IdGeneratorImpl (org.neo4j.kernel.impl.store.id.IdGeneratorImpl)18 Test (org.junit.Test)15 IdGenerator (org.neo4j.kernel.impl.store.id.IdGenerator)14 File (java.io.File)10 StoreChannel (org.neo4j.io.fs.StoreChannel)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 NodeRecordFormat (org.neo4j.kernel.impl.store.format.standard.NodeRecordFormat)1 PropertyKeyTokenRecordFormat (org.neo4j.kernel.impl.store.format.standard.PropertyKeyTokenRecordFormat)1 StoreFile (org.neo4j.kernel.impl.storemigration.StoreFile)1