use of org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy in project neo4j by neo4j.
the class GraphStoreFixture method startLabelScanStore.
private LabelScanStore startLabelScanStore(Config config, Dependencies dependencies, KernelContext kernelContext) {
// Load correct LSS from kernel extensions
LifeSupport life = new LifeSupport();
KernelExtensions extensions = life.add(new KernelExtensions(kernelContext, (Iterable) load(KernelExtensionFactory.class), dependencies, ignore()));
life.start();
LabelScanStore labelScanStore = extensions.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config)).getLabelScanStore();
life.shutdown();
// Start the selected LSS
try {
labelScanStore.init();
labelScanStore.start();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return labelScanStore;
}
use of org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy in project neo4j by neo4j.
the class ConsistencyCheckService method runFullConsistencyCheck.
public Result runFullConsistencyCheck(final File storeDir, Config config, ProgressMonitorFactory progressFactory, final LogProvider logProvider, final FileSystemAbstraction fileSystem, final PageCache pageCache, final boolean verbose, File reportDir, CheckConsistencyConfig checkConsistencyConfig) throws ConsistencyCheckIncompleteException {
Log log = logProvider.getLog(getClass());
config = config.with(stringMap(GraphDatabaseSettings.read_only.name(), TRUE, GraphDatabaseSettings.label_index.name(), LabelIndex.AUTO.name()));
StoreFactory factory = new StoreFactory(storeDir, config, new DefaultIdGeneratorFactory(fileSystem), pageCache, fileSystem, logProvider);
ConsistencySummaryStatistics summary;
final File reportFile = chooseReportPath(reportDir);
Log reportLog = new ConsistencyReportLog(Suppliers.lazySingleton(() -> {
try {
return new PrintWriter(createOrOpenAsOuputStream(fileSystem, reportFile, true));
} catch (IOException e) {
throw new RuntimeException(e);
}
}));
// Bootstrap kernel extensions
LifeSupport life = new LifeSupport();
try (NeoStores neoStores = factory.openAllNeoStores()) {
IndexStoreView indexStoreView = new NeoStoreIndexStoreView(LockService.NO_LOCK_SERVICE, neoStores);
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependencies(config, fileSystem, new SimpleLogService(logProvider, logProvider), indexStoreView, pageCache);
KernelContext kernelContext = new SimpleKernelContext(storeDir, UNKNOWN, dependencies);
KernelExtensions extensions = life.add(new KernelExtensions(kernelContext, (Iterable) load(KernelExtensionFactory.class), dependencies, ignore()));
life.start();
LabelScanStore labelScanStore = life.add(extensions.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config)).getLabelScanStore());
SchemaIndexProvider indexes = life.add(extensions.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance()));
int numberOfThreads = defaultConsistencyCheckThreadsNumber();
Statistics statistics;
StoreAccess storeAccess;
AccessStatistics stats = new AccessStatistics();
if (verbose) {
statistics = new VerboseStatistics(stats, new DefaultCounts(numberOfThreads), log);
storeAccess = new AccessStatsKeepingStoreAccess(neoStores, stats);
} else {
statistics = Statistics.NONE;
storeAccess = new StoreAccess(neoStores);
}
storeAccess.initialize();
DirectStoreAccess stores = new DirectStoreAccess(storeAccess, labelScanStore, indexes);
FullCheck check = new FullCheck(progressFactory, statistics, numberOfThreads, checkConsistencyConfig);
summary = check.execute(stores, new DuplicatingLog(log, reportLog));
} finally {
life.shutdown();
}
if (!summary.isConsistent()) {
log.warn("See '%s' for a detailed consistency report.", reportFile.getPath());
return Result.failure(reportFile);
}
return Result.success(reportFile);
}
use of org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy in project neo4j by neo4j.
the class StoreMigration method run.
public void run(final FileSystemAbstraction fs, final File storeDirectory, Config config, LogProvider userLogProvider) throws IOException {
StoreLogService logService = StoreLogService.withUserLogProvider(userLogProvider).inLogsDirectory(fs, storeDirectory);
VisibleMigrationProgressMonitor progressMonitor = new VisibleMigrationProgressMonitor(logService.getUserLog(StoreMigration.class));
LifeSupport life = new LifeSupport();
life.add(logService);
// Add participants from kernel extensions...
LegacyIndexProvider legacyIndexProvider = new LegacyIndexProvider();
Log log = userLogProvider.getLog(StoreMigration.class);
try (PageCache pageCache = createPageCache(fs, config)) {
Dependencies deps = new Dependencies();
deps.satisfyDependencies(fs, config, legacyIndexProvider, pageCache, logService);
KernelContext kernelContext = new SimpleKernelContext(storeDirectory, DatabaseInfo.UNKNOWN, deps);
KernelExtensions kernelExtensions = life.add(new KernelExtensions(kernelContext, GraphDatabaseDependencies.newDependencies().kernelExtensions(), deps, ignore()));
// Add the kernel store migrator
life.start();
SchemaIndexProvider schemaIndexProvider = kernelExtensions.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
LabelScanStoreProvider labelScanStoreProvider = kernelExtensions.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config));
long startTime = System.currentTimeMillis();
DatabaseMigrator migrator = new DatabaseMigrator(progressMonitor, fs, config, logService, schemaIndexProvider, labelScanStoreProvider, legacyIndexProvider.getIndexProviders(), pageCache, RecordFormatSelector.selectForConfig(config, userLogProvider));
migrator.migrate(storeDirectory);
long duration = System.currentTimeMillis() - startTime;
log.info(format("Migration completed in %d s%n", duration / 1000));
} catch (Exception e) {
throw new StoreUpgrader.UnableToUpgradeException("Failure during upgrade", e);
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy in project neo4j by neo4j.
the class NeoStoreDataSource method start.
@Override
public void start() throws IOException {
dependencies = new Dependencies();
life = new LifeSupport();
schemaIndexProvider = dependencyResolver.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
labelScanStoreProvider = dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config));
dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new DeleteStoresFromOtherLabelScanStoreProviders(labelScanStoreProvider));
IndexConfigStore indexConfigStore = new IndexConfigStore(storeDir, fs);
dependencies.satisfyDependency(lockService);
dependencies.satisfyDependency(indexConfigStore);
life.add(indexConfigStore);
// Monitor listeners
LoggingLogFileMonitor loggingLogMonitor = new LoggingLogFileMonitor(msgLog);
monitors.addMonitorListener(loggingLogMonitor);
life.add(new Delegate(Lifecycles.multiple(indexProviders.values())));
// Upgrade the store before we begin
RecordFormats formats = selectStoreFormats(config, storeDir, fs, pageCache, logService);
upgradeStore(formats);
// Build all modules and their services
StorageEngine storageEngine = null;
try {
UpdateableSchemaState updateableSchemaState = new KernelSchemaStateStore(logProvider);
SynchronizedArrayIdOrderingQueue legacyIndexTransactionOrdering = new SynchronizedArrayIdOrderingQueue(20);
storageEngine = buildStorageEngine(propertyKeyTokenHolder, labelTokens, relationshipTypeTokens, legacyIndexProviderLookup, indexConfigStore, updateableSchemaState::clear, legacyIndexTransactionOrdering);
LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>(storageEngine.commandReaderFactory());
TransactionIdStore transactionIdStore = dependencies.resolveDependency(TransactionIdStore.class);
LogVersionRepository logVersionRepository = dependencies.resolveDependency(LogVersionRepository.class);
NeoStoreTransactionLogModule transactionLogModule = buildTransactionLogs(storeDir, config, logProvider, scheduler, fs, storageEngine, logEntryReader, legacyIndexTransactionOrdering, transactionIdStore, logVersionRepository);
transactionLogModule.satisfyDependencies(dependencies);
buildRecovery(fs, transactionIdStore, logVersionRepository, monitors.newMonitor(Recovery.Monitor.class), monitors.newMonitor(PositionToRecoverFrom.Monitor.class), transactionLogModule.logFiles(), startupStatistics, storageEngine, logEntryReader, transactionLogModule.logicalTransactionStore());
// At the time of writing this comes from the storage engine (IndexStoreView)
PropertyAccessor propertyAccessor = dependencies.resolveDependency(PropertyAccessor.class);
final NeoStoreKernelModule kernelModule = buildKernel(transactionLogModule.transactionAppender(), dependencies.resolveDependency(IndexingService.class), storageEngine.storeReadLayer(), updateableSchemaState, dependencies.resolveDependency(LabelScanStore.class), storageEngine, indexConfigStore, transactionIdStore, availabilityGuard, clock, propertyAccessor);
kernelModule.satisfyDependencies(dependencies);
// Do these assignments last so that we can ensure no cyclical dependencies exist
this.storageEngine = storageEngine;
this.transactionLogModule = transactionLogModule;
this.kernelModule = kernelModule;
dependencies.satisfyDependency(this);
dependencies.satisfyDependency(updateableSchemaState);
dependencies.satisfyDependency(storageEngine.storeReadLayer());
dependencies.satisfyDependency(logEntryReader);
dependencies.satisfyDependency(storageEngine);
} catch (Throwable e) {
// Something unexpected happened during startup
msgLog.warn("Exception occurred while setting up store modules. Attempting to close things down.", e);
try {
// Close the neostore, so that locks are released properly
if (storageEngine != null) {
storageEngine.forceClose();
}
} catch (Exception closeException) {
msgLog.error("Couldn't close neostore after startup failure", closeException);
}
throw Exceptions.launderedException(e);
}
// NOTE: please make sure this is performed after having added everything to the life, in fact we would like
// to perform the checkpointing as first step when the life is shutdown.
life.add(lifecycleToTriggerCheckPointOnShutdown());
try {
life.start();
} catch (Throwable e) {
// Something unexpected happened during startup
msgLog.warn("Exception occurred while starting the datasource. Attempting to close things down.", e);
try {
life.shutdown();
// Close the neostore, so that locks are released properly
storageEngine.forceClose();
} catch (Exception closeException) {
msgLog.error("Couldn't close neostore after startup failure", closeException);
}
throw Exceptions.launderedException(e);
}
/*
* At this point recovery has completed and the datasource is ready for use. Whatever panic might have
* happened before has been healed. So we can safely set the kernel health to ok.
* This right now has any real effect only in the case of internal restarts (for example, after a store copy
* in the case of HA). Standalone instances will have to be restarted by the user, as is proper for all
* kernel panics.
*/
databaseHealth.healed();
}
Aggregations