Search in sources :

Example 1 with IdGenerator

use of org.neo4j.kernel.impl.nioneo.store.IdGenerator in project graphdb by neo4j-attic.

the class JumpingIdGeneratorFactory method get.

public IdGenerator get(IdType idType) {
    if (idType == IdType.NODE || idType == IdType.RELATIONSHIP || idType == IdType.PROPERTY || idType == IdType.STRING_BLOCK || idType == IdType.ARRAY_BLOCK) {
        IdGenerator generator = generators.get(idType);
        if (generator == null) {
            generator = new JumpingIdGenerator();
            generators.put(idType, generator);
        }
        return generator;
    }
    return forTheRest;
}
Also used : IdGenerator(org.neo4j.kernel.impl.nioneo.store.IdGenerator)

Example 2 with IdGenerator

use of org.neo4j.kernel.impl.nioneo.store.IdGenerator in project graphdb by neo4j-attic.

the class TestJumpingIdGenerator method testOffsettedFileChannel.

@Test
public void testOffsettedFileChannel() throws Exception {
    String fileName = "target/var/neostore.nodestore.db";
    deleteFileOrDirectory(fileName);
    FileSystemAbstraction offsettedFileSystem = new JumpingFileSystemAbstraction(10);
    IdGenerator idGenerator = new JumpingIdGeneratorFactory(10).get(IdType.NODE);
    JumpingFileChannel channel = (JumpingFileChannel) offsettedFileSystem.open(fileName, "rw");
    for (int i = 0; i < 16; i++) {
        writeSomethingLikeNodeRecord(channel, idGenerator.nextId(), i);
    }
    channel.close();
    channel = (JumpingFileChannel) offsettedFileSystem.open(fileName, "rw");
    idGenerator = new JumpingIdGeneratorFactory(10).get(IdType.NODE);
    for (int i = 0; i < 16; i++) {
        assertEquals(i, readSomethingLikeNodeRecord(channel, idGenerator.nextId()));
    }
    channel.close();
}
Also used : FileSystemAbstraction(org.neo4j.kernel.impl.nioneo.store.FileSystemAbstraction) JumpingFileChannel(org.neo4j.kernel.impl.core.JumpingFileSystemAbstraction.JumpingFileChannel) IdGenerator(org.neo4j.kernel.impl.nioneo.store.IdGenerator) Test(org.junit.Test)

Example 3 with IdGenerator

use of org.neo4j.kernel.impl.nioneo.store.IdGenerator in project graphdb by neo4j-attic.

the class TestJumpingIdGenerator method testIt.

@Test
public void testIt() throws Exception {
    int sizePerJump = 1000;
    IdGeneratorFactory factory = new JumpingIdGeneratorFactory(sizePerJump);
    IdGenerator generator = factory.get(IdType.NODE);
    for (int i = 0; i < sizePerJump / 2; i++) {
        assertEquals((long) i, generator.nextId());
    }
    for (int i = 0; i < sizePerJump - 1; i++) {
        long expected = 0x100000000L - sizePerJump / 2 + i;
        if (expected >= 0xFFFFFFFFL) {
            expected++;
        }
        assertEquals(expected, generator.nextId());
    }
    for (int i = 0; i < sizePerJump; i++) {
        assertEquals(0x200000000L - sizePerJump / 2 + i, generator.nextId());
    }
    for (int i = 0; i < sizePerJump; i++) {
        assertEquals(0x300000000L - sizePerJump / 2 + i, generator.nextId());
    }
}
Also used : IdGeneratorFactory(org.neo4j.kernel.IdGeneratorFactory) IdGenerator(org.neo4j.kernel.impl.nioneo.store.IdGenerator) Test(org.junit.Test)

Example 4 with IdGenerator

use of org.neo4j.kernel.impl.nioneo.store.IdGenerator in project graphdb by neo4j-attic.

the class MasterImpl method allocateIds.

public Response<IdAllocation> allocateIds(IdType idType) {
    IdGenerator generator = graphDbConfig.getIdGeneratorFactory().get(idType);
    IdAllocation result = new IdAllocation(generator.nextIdBatch(ID_GRAB_SIZE), generator.getHighId(), generator.getDefragCount());
    return MasterUtil.packResponseWithoutTransactionStream(graphDb, SlaveContext.EMPTY, result);
}
Also used : IdGenerator(org.neo4j.kernel.impl.nioneo.store.IdGenerator)

Aggregations

IdGenerator (org.neo4j.kernel.impl.nioneo.store.IdGenerator)4 Test (org.junit.Test)2 IdGeneratorFactory (org.neo4j.kernel.IdGeneratorFactory)1 JumpingFileChannel (org.neo4j.kernel.impl.core.JumpingFileSystemAbstraction.JumpingFileChannel)1 FileSystemAbstraction (org.neo4j.kernel.impl.nioneo.store.FileSystemAbstraction)1