use of org.neo4j.kernel.impl.store.id.IdGenerator in project neo4j by neo4j.
the class LabelsAcceptanceTest method beansAPIWithNoMoreLabelIds.
@SuppressWarnings("deprecation")
private GraphDatabaseService beansAPIWithNoMoreLabelIds() {
final EphemeralIdGenerator.Factory idFactory = new EphemeralIdGenerator.Factory() {
private IdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();
@Override
public IdGenerator open(File fileName, int grabSize, IdType idType, long highId, long maxId) {
if (idType == IdType.LABEL_TOKEN) {
IdGenerator generator = generators.get(idType);
if (generator == null) {
IdTypeConfiguration idTypeConfiguration = idTypeConfigurationProvider.getIdTypeConfiguration(idType);
generator = new EphemeralIdGenerator(idType, idTypeConfiguration) {
@Override
public long nextId() {
// Same exception as the one thrown by IdGeneratorImpl
throw new UnderlyingStorageException("Id capacity exceeded");
}
};
generators.put(idType, generator);
}
return generator;
}
return super.open(fileName, grabSize, idType, Long.MAX_VALUE, Long.MAX_VALUE);
}
};
TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory() {
@Override
protected GraphDatabaseBuilder.DatabaseCreator createImpermanentDatabaseCreator(final File storeDir, final TestGraphDatabaseFactoryState state) {
return new GraphDatabaseBuilder.DatabaseCreator() {
@Override
public GraphDatabaseService newDatabase(Map<String, String> config) {
return newDatabase(Config.embeddedDefaults(config));
}
@Override
public GraphDatabaseService newDatabase(@Nonnull Config config) {
return new ImpermanentGraphDatabase(storeDir, config, GraphDatabaseDependencies.newDependencies(state.databaseDependencies())) {
@Override
protected void create(File storeDir, Config config, GraphDatabaseFacadeFactory.Dependencies dependencies) {
Function<PlatformModule, EditionModule> factory = (platformModule) -> new CommunityEditionModule(platformModule) {
@Override
protected IdGeneratorFactory createIdGeneratorFactory(FileSystemAbstraction fs, IdTypeConfigurationProvider idTypeConfigurationProvider) {
return idFactory;
}
};
new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, factory) {
@Override
protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
return new ImpermanentPlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade);
}
}.initFacade(storeDir, config, dependencies, this);
}
};
}
};
}
};
return dbFactory.newImpermanentDatabase();
}
use of org.neo4j.kernel.impl.store.id.IdGenerator in project neo4j by neo4j.
the class TestJumpingIdGenerator method testOffsettedFileChannel.
@Test
public void testOffsettedFileChannel() throws Exception {
try (JumpingFileSystemAbstraction offsettedFileSystem = new JumpingFileSystemAbstraction(10)) {
File fileName = new File("target/var/neostore.nodestore.db");
offsettedFileSystem.deleteFile(fileName);
offsettedFileSystem.mkdirs(fileName.getParentFile());
IdGenerator idGenerator = new JumpingIdGeneratorFactory(10).get(IdType.NODE);
try (JumpingFileChannel channel = (JumpingFileChannel) offsettedFileSystem.open(fileName, "rw")) {
for (int i = 0; i < 16; i++) {
writeSomethingLikeNodeRecord(channel, idGenerator.nextId(), i);
}
}
try (JumpingFileChannel 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()));
}
}
}
}
use of org.neo4j.kernel.impl.store.id.IdGenerator in project neo4j by neo4j.
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(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());
}
}
use of org.neo4j.kernel.impl.store.id.IdGenerator in project neo4j by neo4j.
the class HaIdGeneratorFactoryTest method slaveShouldNeverAllowReducingHighId.
@Test
public void slaveShouldNeverAllowReducingHighId() throws Exception {
// GIVEN
final int highIdFromAllocation = 123;
IdAllocation firstResult = new IdAllocation(new IdRange(new long[] {}, 42, highIdFromAllocation), highIdFromAllocation, 0);
Response<IdAllocation> response = response(firstResult);
when(master.allocateIds(any(RequestContext.class), any(IdType.class))).thenReturn(response);
// WHEN
IdGenerator gen = switchToSlave();
final int highIdFromUpdatedRecord = highIdFromAllocation + 1;
// Assume this is from a received transaction
gen.setHighId(highIdFromUpdatedRecord);
// that will ask the master for an IdRange
gen.nextId();
// THEN
assertEquals(highIdFromUpdatedRecord, gen.getHighId());
}
use of org.neo4j.kernel.impl.store.id.IdGenerator in project neo4j by neo4j.
the class HaIdGeneratorFactoryTest method shouldDeleteIdGeneratorsAsPartOfSwitchingToSlave.
@Test
public void shouldDeleteIdGeneratorsAsPartOfSwitchingToSlave() throws Exception {
// GIVEN we're in master mode. We do that to allow HaIdGeneratorFactory to open id generators at all
fac.switchToMaster();
File idFile = new File("my.id");
// ... opening an id generator as master
fac.create(idFile, 10, true);
IdGenerator idGenerator = fac.open(idFile, 10, IdType.NODE, 10, Standard.LATEST_RECORD_FORMATS.node().getMaxId());
assertTrue(fs.fileExists(idFile));
idGenerator.close();
// WHEN switching to slave
fac.switchToSlave();
// THEN the .id file underneath should be deleted
assertFalse("Id file should've been deleted by now", fs.fileExists(idFile));
}
Aggregations