use of org.neo4j.kernel.impl.spi.SimpleKernelContext in project neo4j by neo4j.
the class GraphStoreFixture method directStoreAccess.
public DirectStoreAccess directStoreAccess() {
if (directStoreAccess == null) {
fileSystem = new DefaultFileSystemAbstraction();
PageCache pageCache = getPageCache(fileSystem);
LogProvider logProvider = NullLogProvider.getInstance();
StoreFactory storeFactory = new StoreFactory(directory, pageCache, fileSystem, logProvider);
neoStore = storeFactory.openAllNeoStores();
StoreAccess nativeStores;
if (keepStatistics) {
AccessStatistics accessStatistics = new AccessStatistics();
statistics = new VerboseStatistics(accessStatistics, new DefaultCounts(defaultConsistencyCheckThreadsNumber()), NullLog.getInstance());
nativeStores = new AccessStatsKeepingStoreAccess(neoStore, accessStatistics);
} else {
statistics = Statistics.NONE;
nativeStores = new StoreAccess(neoStore);
}
nativeStores.initialize();
Config config = Config.empty();
OperationalMode operationalMode = OperationalMode.single;
IndexStoreView indexStoreView = new NeoStoreIndexStoreView(LockService.NO_LOCK_SERVICE, nativeStores.getRawNeoStores());
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependencies(Config.defaults(), fileSystem, new SimpleLogService(logProvider, logProvider), indexStoreView, pageCache);
KernelContext kernelContext = new SimpleKernelContext(directory, UNKNOWN, dependencies);
LabelScanStore labelScanStore = startLabelScanStore(config, dependencies, kernelContext);
directStoreAccess = new DirectStoreAccess(nativeStores, labelScanStore, createIndexes(fileSystem, config, operationalMode));
}
return directStoreAccess;
}
use of org.neo4j.kernel.impl.spi.SimpleKernelContext 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.impl.spi.SimpleKernelContext 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.impl.spi.SimpleKernelContext in project neo4j by neo4j.
the class CsvOutputTest method setup.
@Before
public void setup() {
File storeDir = directory.directory();
kernelContext = new SimpleKernelContext(storeDir, DatabaseInfo.UNKNOWN, new Dependencies());
}
use of org.neo4j.kernel.impl.spi.SimpleKernelContext in project neo4j by neo4j.
the class BackupServiceIT method shouldContainTransactionsThatHappenDuringBackupProcess.
@Test
public void shouldContainTransactionsThatHappenDuringBackupProcess() throws Throwable {
// given
defaultBackupPortHostParams();
Config defaultConfig = dbRule.getConfigCopy();
dbRule.setConfig(OnlineBackupSettings.online_backup_enabled, "false");
Config withOnlineBackupDisabled = dbRule.getConfigCopy();
final Barrier.Control barrier = new Barrier.Control();
final GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
// create some data
createAndIndexNode(db, 1);
final DependencyResolver resolver = db.getDependencyResolver();
long expectedLastTxId = resolver.resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
// This monitor is added server-side...
monitors.addMonitorListener(new StoreSnoopingMonitor(barrier));
Dependencies dependencies = new Dependencies(resolver);
dependencies.satisfyDependencies(defaultConfig, monitors, NullLogProvider.getInstance());
OnlineBackupKernelExtension backup = (OnlineBackupKernelExtension) new OnlineBackupExtensionFactory().newInstance(new SimpleKernelContext(storeDir, DatabaseInfo.UNKNOWN, dependencies), DependenciesProxy.dependencies(dependencies, OnlineBackupExtensionFactory.Dependencies.class));
backup.start();
// when
BackupService backupService = backupService();
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
barrier.awaitUninterruptibly();
createAndIndexNode(db, 1);
resolver.resolveDependency(StorageEngine.class).flushAndForce(limiter);
barrier.release();
});
BackupService.BackupOutcome backupOutcome = backupService.doFullBackup(BACKUP_HOST, backupPort, backupDir.getAbsoluteFile(), ConsistencyCheck.FULL, withOnlineBackupDisabled, BackupClient.BIG_READ_TIMEOUT, false);
backup.stop();
executor.shutdown();
executor.awaitTermination(30, TimeUnit.SECONDS);
// then
checkPreviousCommittedTxIdFromLog(0, expectedLastTxId);
File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
long txIdFromOrigin = MetaDataStore.getRecord(resolver.resolveDependency(PageCache.class), neoStore, Position.LAST_TRANSACTION_ID);
checkLastCommittedTxIdInLogAndNeoStore(expectedLastTxId + 1, txIdFromOrigin);
assertEquals(DbRepresentation.of(db), getBackupDbRepresentation());
assertTrue(backupOutcome.isConsistent());
}
Aggregations