use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class DeleteDuplicateNodesStepTest 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.openAllNeoStores(true);
}
use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class Recovery method performRecovery.
/**
* Performs recovery of database described by provided layout.
*
* @param fs database filesystem
* @param pageCache page cache used to perform database recovery.
* @param tracers underlying operation tracers
* @param config custom configuration
* @param databaseLayout database to recover layout.
* @param storageEngineFactory {@link StorageEngineFactory} for the storage to recover.
* @param logProvider log provider
* @param globalMonitors global server monitors
* @param extensionFactories extension factories for extensions that should participate in recovery
* @param providedLogFiles log files from database
* @param forceRunRecovery to force recovery to run even if the usual checks indicates that it's not required.
* In specific cases, like after store copy there's always a need for doing a recovery or at least to start the db, checkpoint and shut down,
* even if the normal "is recovery required" checks says that recovery isn't required.
* @throws IOException on any unexpected I/O exception encountered during recovery.
*/
public static void performRecovery(FileSystemAbstraction fs, PageCache pageCache, DatabaseTracers tracers, Config config, DatabaseLayout databaseLayout, StorageEngineFactory storageEngineFactory, boolean forceRunRecovery, LogProvider logProvider, Monitors globalMonitors, Iterable<ExtensionFactory<?>> extensionFactories, Optional<LogFiles> providedLogFiles, RecoveryStartupChecker startupChecker, MemoryTracker memoryTracker, Clock clock) throws IOException {
Log recoveryLog = logProvider.getLog(Recovery.class);
if (!forceRunRecovery && !isRecoveryRequired(fs, pageCache, databaseLayout, storageEngineFactory, config, providedLogFiles, memoryTracker)) {
return;
}
checkAllFilesPresence(databaseLayout, fs, pageCache, storageEngineFactory);
LifeSupport recoveryLife = new LifeSupport();
Monitors monitors = new Monitors(globalMonitors, logProvider);
DatabasePageCache databasePageCache = new DatabasePageCache(pageCache, IOController.DISABLED);
SimpleLogService logService = new SimpleLogService(logProvider);
VersionAwareLogEntryReader logEntryReader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
DatabaseReadOnlyChecker readOnlyChecker = writable();
DatabaseSchemaState schemaState = new DatabaseSchemaState(logProvider);
JobScheduler scheduler = JobSchedulerFactory.createInitialisedScheduler();
VersionContextSupplier versionContextSupplier = EmptyVersionContextSupplier.EMPTY;
DatabaseHealth databaseHealth = new DatabaseHealth(PanicEventGenerator.NO_OP, recoveryLog);
TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TYPE_PROPERTY_KEY), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TYPE_LABEL), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TYPE_RELATIONSHIP_TYPE));
RecoveryCleanupWorkCollector recoveryCleanupCollector = new GroupingRecoveryCleanupWorkCollector(scheduler, INDEX_CLEANUP, INDEX_CLEANUP_WORK, databaseLayout.getDatabaseName());
DatabaseExtensions extensions = instantiateRecoveryExtensions(databaseLayout, fs, config, logService, databasePageCache, scheduler, DbmsInfo.TOOL, monitors, tokenHolders, recoveryCleanupCollector, readOnlyChecker, extensionFactories, tracers.getPageCacheTracer());
DefaultIndexProviderMap indexProviderMap = new DefaultIndexProviderMap(extensions, config);
StorageEngine storageEngine = storageEngineFactory.instantiate(fs, databaseLayout, config, databasePageCache, tokenHolders, schemaState, getConstraintSemantics(), indexProviderMap, NO_LOCK_SERVICE, new DefaultIdGeneratorFactory(fs, recoveryCleanupCollector, databaseLayout.getDatabaseName()), new DefaultIdController(), databaseHealth, logService.getInternalLogProvider(), recoveryCleanupCollector, tracers.getPageCacheTracer(), true, readOnlyChecker, memoryTracker);
// Schema indexes
FullScanStoreView fullScanStoreView = new FullScanStoreView(NO_LOCK_SERVICE, storageEngine::newReader, config, scheduler);
IndexStoreViewFactory indexStoreViewFactory = new IndexStoreViewFactory(config, storageEngine::newReader, NO_LOCKS, fullScanStoreView, NO_LOCK_SERVICE, logProvider);
IndexStatisticsStore indexStatisticsStore = new IndexStatisticsStore(databasePageCache, databaseLayout, recoveryCleanupCollector, readOnlyChecker, tracers.getPageCacheTracer());
IndexingService indexingService = Database.buildIndexingService(storageEngine, schemaState, indexStoreViewFactory, indexStatisticsStore, config, scheduler, indexProviderMap, tokenHolders, logProvider, logProvider, monitors.newMonitor(IndexingService.Monitor.class), tracers.getPageCacheTracer(), memoryTracker, databaseLayout.getDatabaseName(), readOnlyChecker);
MetadataProvider metadataProvider = storageEngine.metadataProvider();
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependencies(databaseLayout, config, databasePageCache, fs, logProvider, tokenHolders, schemaState, getConstraintSemantics(), NO_LOCK_SERVICE, databaseHealth, new DefaultIdGeneratorFactory(fs, recoveryCleanupCollector, databaseLayout.getDatabaseName()), new DefaultIdController(), readOnlyChecker, versionContextSupplier, logService, metadataProvider);
LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fs).withLogEntryReader(logEntryReader).withConfig(config).withDependencies(dependencies).withMemoryTracker(memoryTracker).build();
boolean failOnCorruptedLogFiles = config.get(GraphDatabaseInternalSettings.fail_on_corrupted_log_files);
validateStoreId(logFiles, storageEngine.getStoreId(), config);
TransactionMetadataCache metadataCache = new TransactionMetadataCache();
PhysicalLogicalTransactionStore transactionStore = new PhysicalLogicalTransactionStore(logFiles, metadataCache, logEntryReader, monitors, failOnCorruptedLogFiles);
BatchingTransactionAppender transactionAppender = new BatchingTransactionAppender(logFiles, LogRotation.NO_ROTATION, metadataCache, metadataProvider, databaseHealth);
LifeSupport schemaLife = new LifeSupport();
schemaLife.add(storageEngine.schemaAndTokensLifecycle());
schemaLife.add(indexingService);
var doParallelRecovery = config.get(GraphDatabaseInternalSettings.do_parallel_recovery);
TransactionLogsRecovery transactionLogsRecovery = transactionLogRecovery(fs, metadataProvider, monitors.newMonitor(RecoveryMonitor.class), monitors.newMonitor(RecoveryStartInformationProvider.Monitor.class), logFiles, storageEngine, transactionStore, metadataProvider, schemaLife, databaseLayout, failOnCorruptedLogFiles, recoveryLog, startupChecker, tracers.getPageCacheTracer(), memoryTracker, doParallelRecovery);
CheckPointerImpl.ForceOperation forceOperation = new DefaultForceOperation(indexingService, storageEngine);
var checkpointAppender = logFiles.getCheckpointFile().getCheckpointAppender();
CheckPointerImpl checkPointer = new CheckPointerImpl(metadataProvider, RecoveryThreshold.INSTANCE, forceOperation, LogPruning.NO_PRUNING, checkpointAppender, databaseHealth, logProvider, tracers, IOController.DISABLED, new StoreCopyCheckPointMutex(), versionContextSupplier, clock);
recoveryLife.add(scheduler);
recoveryLife.add(recoveryCleanupCollector);
recoveryLife.add(extensions);
recoveryLife.add(indexProviderMap);
recoveryLife.add(storageEngine);
recoveryLife.add(new MissingTransactionLogsCheck(databaseLayout, config, fs, logFiles, recoveryLog));
recoveryLife.add(logFiles);
recoveryLife.add(transactionLogsRecovery);
recoveryLife.add(transactionAppender);
recoveryLife.add(checkPointer);
try {
recoveryLife.start();
if (databaseHealth.isHealthy()) {
checkPointer.forceCheckPoint(new SimpleTriggerInfo("Recovery completed."));
}
} finally {
recoveryLife.shutdown();
}
}
use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class NodeCommandTest method before.
@BeforeEach
void before() {
StoreFactory storeFactory = new StoreFactory(databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, fs, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable());
neoStores = storeFactory.openAllNeoStores(true);
nodeStore = neoStores.getNodeStore();
}
use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class HighIdTransactionApplierTest 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.openAllNeoStores(true);
}
use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class IdGeneratorMigratorTest method shouldFindAndStoreDeletedIds.
@Test
void shouldFindAndStoreDeletedIds() throws IOException {
// given
DatabaseLayout db = DatabaseLayout.ofFlat(directory.directory("from"));
DatabaseLayout upgrade = DatabaseLayout.ofFlat(directory.directory("to"));
long nodeStoreStartId;
long stringStoreStartId;
long relationshipStoreStartId;
try (NeoStores neoStores = new StoreFactory(db, defaults(), new DefaultIdGeneratorFactory(fs, immediate(), DEFAULT_DATABASE_NAME), pageCache, fs, StandardV3_4.RECORD_FORMATS, nullLogProvider(), PageCacheTracer.NULL, writable(), immutable.empty()).openAllNeoStores(true)) {
// Let nodes have every fourth a deleted record
createSomeRecordsAndSomeHoles(neoStores.getNodeStore(), 500, 1, 3);
createSomeRecordsAndSomeHoles(neoStores.getPropertyStore().getStringStore(), 100, 1, 2);
nodeStoreStartId = neoStores.getNodeStore().getNumberOfReservedLowIds();
stringStoreStartId = neoStores.getPropertyStore().getStringStore().getNumberOfReservedLowIds();
}
// Pretend that the relationship store was copied so that relationship id file should be migrated from there
try (NeoStores neoStores = new StoreFactory(upgrade, defaults(), new DefaultIdGeneratorFactory(fs, immediate(), DEFAULT_DATABASE_NAME), pageCache, fs, Standard.LATEST_RECORD_FORMATS, nullLogProvider(), PageCacheTracer.NULL, writable(), immutable.empty()).openAllNeoStores(true)) {
// Let relationships have every fourth a created record
createSomeRecordsAndSomeHoles(neoStores.getRelationshipStore(), 600, 3, 1);
relationshipStoreStartId = neoStores.getRelationshipStore().getNumberOfReservedLowIds();
}
fs.deleteFile(upgrade.nodeStore());
fs.deleteFile(upgrade.idNodeStore());
fs.deleteFile(upgrade.propertyStringStore());
fs.deleteFile(upgrade.idPropertyStringStore());
fs.deleteFile(db.relationshipStore());
fs.deleteFile(upgrade.idRelationshipStore());
// when
IdGeneratorMigrator migrator = new IdGeneratorMigrator(fs, pageCache, defaults(), PageCacheTracer.NULL);
migrator.migrate(db, upgrade, ProgressReporter.SILENT, StandardV3_4.STORE_VERSION, Standard.LATEST_STORE_VERSION, IndexImporterFactory.EMPTY);
migrator.moveMigratedFiles(upgrade, db, StandardV3_4.STORE_VERSION, Standard.LATEST_STORE_VERSION);
// then
assertIdGeneratorContainsIds(db.idNodeStore(), IdType.NODE, 500, 1, 3, nodeStoreStartId);
assertIdGeneratorContainsIds(db.idPropertyStringStore(), IdType.STRING_BLOCK, 100, 1, 2, stringStoreStartId);
assertIdGeneratorContainsIds(db.idRelationshipStore(), IdType.RELATIONSHIP, 600, 3, 1, relationshipStoreStartId);
}
Aggregations