use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class IdGeneratorMigrator method migrateIdFiles.
private void migrateIdFiles(DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, RecordFormats oldFormat, RecordFormats newFormat, ProgressReporter progress, CursorContext cursorContext) throws IOException {
// The store .id files needs to be migrated. At this point some of them have been sort-of-migrated, i.e. merely ported
// to the new format, but just got the highId and nothing else. Regardless we want to do a proper migration here,
// which not only means creating an empty id file w/ only highId. No, it also means scanning the stores and properly
// updating its freelist so that from this point no ids will be lost, ever.
// For every store type: if store is in migrationLayout use that, else use the one from the dbLayout because it will
// be of the current format already. Then scan it and create the .id file in the migration layout.
List<StoreType> storesInDbDirectory = new ArrayList<>();
List<StoreType> storesInMigrationDirectory = new ArrayList<>();
for (StoreType storeType : StoreType.values()) {
// See if it exists in migration directory, otherwise it must be in the db directory
List<StoreType> list = fileSystem.fileExists(migrationLayout.file(storeType.getDatabaseFile())) ? storesInMigrationDirectory : storesInDbDirectory;
list.add(storeType);
}
progress.start(storesInDbDirectory.size() + storesInMigrationDirectory.size());
// Rebuild the .id files from the legacy stores that haven't been upgraded, i.e. if they remained unchanged
// Make them end up in upgrade/<store>.id so that they won't overwrite the origin .id file before the upgrade is completed
IdGeneratorFactory rebuiltIdGeneratorsFromOldStore = new DefaultIdGeneratorFactory(fileSystem, immediate(), directoryLayout.getDatabaseName()) {
@Override
public IdGenerator open(PageCache pageCache, Path filename, IdType idType, LongSupplier highIdScanner, long maxId, DatabaseReadOnlyChecker readOnlyChecker, Config config, CursorContext cursorContext, ImmutableSet<OpenOption> openOptions) throws IOException {
Path redirectedFilename = migrationLayout.databaseDirectory().resolve(filename.getFileName().toString());
return super.open(pageCache, redirectedFilename, idType, highIdScanner, maxId, readOnlyChecker, config, cursorContext, openOptions);
}
@Override
public IdGenerator create(PageCache pageCache, Path fileName, IdType idType, long highId, boolean throwIfFileExists, long maxId, DatabaseReadOnlyChecker readOnlyChecker, Config config, CursorContext cursorContext, ImmutableSet<OpenOption> openOptions) {
throw new IllegalStateException("The store file should exist and therefore all calls should be to open, not create");
}
};
startAndTriggerRebuild(directoryLayout, oldFormat, rebuiltIdGeneratorsFromOldStore, storesInDbDirectory, progress, cursorContext);
// Build the ones from the migration directory, those stores that have been migrated
// Before doing this we will have to create empty stores for those that are missing, otherwise some of the stores
// that we need to open will complain because some of their "sub-stores" doesn't exist. They will be empty, it's fine...
// and we will not read from them at all. They will just sit there and allow their parent store to be opened.
// We'll remove them after we have built the id files
IdGeneratorFactory rebuiltIdGeneratorsFromNewStore = new DefaultIdGeneratorFactory(fileSystem, immediate(), migrationLayout.getDatabaseName());
Set<Path> placeHolderStoreFiles = createEmptyPlaceHolderStoreFiles(migrationLayout, newFormat);
startAndTriggerRebuild(migrationLayout, newFormat, rebuiltIdGeneratorsFromNewStore, storesInMigrationDirectory, progress, cursorContext);
for (Path emptyPlaceHolderStoreFile : placeHolderStoreFiles) {
fileSystem.deleteFile(emptyPlaceHolderStoreFile);
}
}
use of org.neo4j.internal.id.DefaultIdGeneratorFactory 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.DefaultIdGeneratorFactory 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.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class TransactionRecordStateTest method createStores.
private NeoStores createStores(Config config, RecordFormats formats) {
idGeneratorFactory = new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName());
var storeFactory = new StoreFactory(databaseLayout, config, idGeneratorFactory, pageCache, fs, formats, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable(), immutable.empty());
return storeFactory.openAllNeoStores(true);
}
use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class SchemaStorageTest method before.
@BeforeEach
void before() {
var storeFactory = new StoreFactory(databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, fs, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable());
neoStores = storeFactory.openNeoStores(true, StoreType.SCHEMA, StoreType.PROPERTY_KEY_TOKEN, StoreType.LABEL_TOKEN, StoreType.RELATIONSHIP_TYPE_TOKEN);
storage = new SchemaStorage(neoStores.getSchemaStore(), StoreTokens.readOnlyTokenHolders(neoStores, NULL), () -> KernelVersion.LATEST);
}
Aggregations