use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.
the class IndexedIdGeneratorRecoverabilityTest method resetUsabilityOnRestart.
@Test
void resetUsabilityOnRestart() throws IOException {
// Create the freelist
try (IdGenerator freelist = instantiateFreelist()) {
freelist.checkpoint(NULL);
}
final long id1;
final long id2;
try (IdGenerator freelist = instantiateFreelist()) {
id1 = freelist.nextId(NULL);
id2 = freelist.nextId(NULL);
markUsed(freelist, id1, id2);
markDeleted(freelist, id1, id2);
freelist.checkpoint(NULL);
}
try (IdGenerator freelist = instantiateFreelist()) {
freelist.start(NO_FREE_IDS, NULL);
final ImmutableLongSet reused = LongSets.immutable.of(freelist.nextId(NULL), freelist.nextId(NULL));
assertEquals(LongSets.immutable.of(id1, id2), reused, "IDs are not reused");
}
}
use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.
the class IndexedIdGeneratorRecoverabilityTest method doNotPersistHighIdBetweenCleanRestartsWithoutCheckpoint.
@Test
void doNotPersistHighIdBetweenCleanRestartsWithoutCheckpoint() {
try (IdGenerator freelist = instantiateFreelist()) {
freelist.nextId(NULL);
assertEquals(1, freelist.getHighId());
freelist.nextId(NULL);
assertEquals(2, freelist.getHighId());
}
try (IdGenerator freelist = instantiateFreelist()) {
assertEquals(0, freelist.getHighId());
}
}
use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.
the class RecoveryIT method idGeneratorIsDirty.
private boolean idGeneratorIsDirty(Path path, IdType idType) throws IOException {
DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), "my db");
try (IdGenerator idGenerator = idGeneratorFactory.open(pageCache, path, idType, () -> 0L, /*will not be used*/
10_000, readOnly(), Config.defaults(), NULL, Sets.immutable.empty())) {
MutableBoolean dirtyOnStartup = new MutableBoolean();
InvocationHandler invocationHandler = (proxy, method, args) -> {
if (method.getName().equals("dirtyOnStartup")) {
dirtyOnStartup.setTrue();
}
return null;
};
ReporterFactory reporterFactory = new ReporterFactory(invocationHandler);
idGenerator.consistencyCheck(reporterFactory, NULL);
return dirtyOnStartup.booleanValue();
}
}
use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.
the class RecoveryIT method shouldForceRecoveryEvenThoughNotSeeminglyRequired.
@Test
void shouldForceRecoveryEvenThoughNotSeeminglyRequired() throws Exception {
// given
GraphDatabaseAPI db = createDatabase();
generateSomeData(db);
DatabaseLayout layout = db.databaseLayout();
managementService.shutdown();
assertFalse(isRecoveryRequired(layout));
// Make an ID generator, say for the node store, dirty
DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), "my db");
try (IdGenerator idGenerator = idGeneratorFactory.open(pageCache, layout.idNodeStore(), IdType.NODE, () -> 0L, /*will not be used*/
10_000, writable(), Config.defaults(), NULL, Sets.immutable.empty())) {
// Merely opening a marker will make the backing GBPTree dirty
idGenerator.marker(NULL).close();
}
assertFalse(isRecoveryRequired(layout));
assertTrue(idGeneratorIsDirty(layout.idNodeStore(), IdType.NODE));
// when
MutableBoolean recoveryRunEvenThoughNoCommitsAfterLastCheckpoint = new MutableBoolean();
RecoveryStartInformationProvider.Monitor monitor = new RecoveryStartInformationProvider.Monitor() {
@Override
public void noCommitsAfterLastCheckPoint(LogPosition logPosition) {
recoveryRunEvenThoughNoCommitsAfterLastCheckpoint.setTrue();
}
};
Monitors monitors = new Monitors();
monitors.addMonitorListener(monitor);
Recovery.performRecovery(fileSystem, pageCache, EMPTY, Config.defaults(), layout, defaultStorageEngine(), true, nullLogProvider(), monitors, Iterables.cast(Services.loadAll(ExtensionFactory.class)), Optional.empty(), null, INSTANCE, Clock.systemUTC());
// then
assertFalse(idGeneratorIsDirty(layout.idNodeStore(), IdType.NODE));
assertTrue(recoveryRunEvenThoughNoCommitsAfterLastCheckpoint.booleanValue());
}
use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.
the class BigStoreIT method setHighId.
private void setHighId(IdType type, long highId) {
IdGeneratorFactory idGeneratorFactory = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(IdGeneratorFactory.class);
IdGenerator idGenerator = idGeneratorFactory.get(type);
idGenerator.setHighId(highId);
idGenerator.markHighestWrittenAtHighId();
}
Aggregations