Search in sources :

Example 6 with IdGenerator

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

the class HaIdGeneratorFactoryTest method shouldDeleteIdGeneratorsAsPartOfOpenAfterSwitchingToSlave.

@Test
public void shouldDeleteIdGeneratorsAsPartOfOpenAfterSwitchingToSlave() throws Exception {
    // GIVEN we're in master mode. We do that to allow HaIdGeneratorFactory to open id generators at all
    fac.switchToSlave();
    File idFile = new File("my.id");
    // ... opening an id generator as master
    fac.create(idFile, 10, true);
    // WHEN
    IdGenerator idGenerator = fac.open(idFile, 10, IdType.NODE, 10, Standard.LATEST_RECORD_FORMATS.node().getMaxId());
    // THEN
    assertFalse("Id file should've been deleted by now", fs.fileExists(idFile));
}
Also used : IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) File(java.io.File) Test(org.junit.Test)

Example 7 with IdGenerator

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

the class HaIdGeneratorFactoryTest method switchToSlave.

private IdGenerator switchToSlave() {
    fac.switchToSlave();
    IdGenerator gen = fac.open(new File("someFile"), 10, IdType.NODE, 1, Standard.LATEST_RECORD_FORMATS.node().getMaxId());
    masterDelegate.setDelegate(master);
    return gen;
}
Also used : IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) File(java.io.File)

Example 8 with IdGenerator

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

the class HaIdGeneratorFactoryTest method shouldUseDefraggedIfPresent.

@Test
public void shouldUseDefraggedIfPresent() throws Exception {
    // GIVEN
    long[] defragIds = { 42, 27172828, 314159 };
    IdAllocation firstResult = new IdAllocation(new IdRange(defragIds, 0, 0), 0, defragIds.length);
    Response<IdAllocation> response = response(firstResult);
    when(master.allocateIds(any(RequestContext.class), any(IdType.class))).thenReturn(response);
    // WHEN
    IdGenerator gen = switchToSlave();
    // THEN
    for (long defragId : defragIds) {
        assertEquals(defragId, gen.nextId());
    }
}
Also used : RequestContext(org.neo4j.com.RequestContext) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) IdRange(org.neo4j.kernel.impl.store.id.IdRange) IdType(org.neo4j.kernel.impl.store.id.IdType) Test(org.junit.Test)

Example 9 with IdGenerator

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

the class CoreBootstrapper method getHighId.

private long getHighId(File coreDir, DefaultIdGeneratorFactory factory, IdType idType, String store) {
    IdGenerator idGenerator = factory.open(new File(coreDir, idFile(store)), idType, -1, Long.MAX_VALUE);
    long highId = idGenerator.getHighId();
    idGenerator.close();
    return highId;
}
Also used : IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) File(java.io.File)

Example 10 with IdGenerator

use of org.neo4j.kernel.impl.store.id.IdGenerator 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)

Aggregations

IdGenerator (org.neo4j.kernel.impl.store.id.IdGenerator)31 Test (org.junit.Test)24 File (java.io.File)15 IdGeneratorImpl (org.neo4j.kernel.impl.store.id.IdGeneratorImpl)14 IdType (org.neo4j.kernel.impl.store.id.IdType)8 RequestContext (org.neo4j.com.RequestContext)6 IdRange (org.neo4j.kernel.impl.store.id.IdRange)5 IdGeneratorFactory (org.neo4j.kernel.impl.store.id.IdGeneratorFactory)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EphemeralIdGenerator (org.neo4j.test.impl.EphemeralIdGenerator)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Function (java.util.function.Function)1 Collectors.toSet (java.util.stream.Collectors.toSet)1