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));
}
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;
}
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());
}
}
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;
}
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;
}
Aggregations