use of org.neo4j.kernel.api.direct.DirectStoreAccess 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.api.direct.DirectStoreAccess in project neo4j by neo4j.
the class FullCheck method execute.
void execute(final DirectStoreAccess directStoreAccess, final CheckDecorator decorator, final RecordAccess recordAccess, final InconsistencyReport report, CacheAccess cacheAccess, Monitor reportMonitor) throws ConsistencyCheckIncompleteException {
final ConsistencyReporter reporter = new ConsistencyReporter(recordAccess, report, reportMonitor);
StoreProcessor processEverything = new StoreProcessor(decorator, reporter, Stage.SEQUENTIAL_FORWARD, cacheAccess);
ProgressMonitorFactory.MultiPartBuilder progress = progressFactory.multipleParts("Full Consistency Check");
final StoreAccess nativeStores = directStoreAccess.nativeStores();
try (IndexAccessors indexes = new IndexAccessors(directStoreAccess.indexes(), nativeStores.getSchemaStore(), samplingConfig)) {
MultiPassStore.Factory multiPass = new MultiPassStore.Factory(decorator, recordAccess, cacheAccess, report, reportMonitor);
ConsistencyCheckTasks taskCreator = new ConsistencyCheckTasks(progress, processEverything, nativeStores, statistics, cacheAccess, directStoreAccess.labelScanStore(), indexes, multiPass, reporter, threads);
List<ConsistencyCheckerTask> tasks = taskCreator.createTasksForFullCheck(checkLabelScanStore, checkIndexes, checkGraph);
TaskExecutor.execute(tasks, decorator::prepare);
} catch (Exception e) {
throw new ConsistencyCheckIncompleteException(e);
}
}
use of org.neo4j.kernel.api.direct.DirectStoreAccess 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.api.direct.DirectStoreAccess in project neo4j by neo4j.
the class DetectAllRelationshipInconsistenciesIT method shouldDetectSabotagedRelationshipWhereEverItIs.
@Test
public void shouldDetectSabotagedRelationshipWhereEverItIs() throws Exception {
// GIVEN a database which lots of relationships
GraphDatabaseAPI db = getGraphDatabaseAPI();
Sabotage sabotage;
try {
Node[] nodes = new Node[1_000];
Relationship[] relationships = new Relationship[10_000];
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < nodes.length; i++) {
nodes[i] = db.createNode(label("Foo"));
}
for (int i = 0; i < 10_000; i++) {
relationships[i] = random.among(nodes).createRelationshipTo(random.among(nodes), MyRelTypes.TEST);
}
tx.success();
}
// WHEN sabotaging a random relationship
DependencyResolver resolver = db.getDependencyResolver();
PageCache pageCache = resolver.resolveDependency(PageCache.class);
StoreFactory storeFactory = newStoreFactory(pageCache);
try (NeoStores neoStores = storeFactory.openNeoStores(false, StoreType.RELATIONSHIP)) {
RelationshipStore relationshipStore = neoStores.getRelationshipStore();
Relationship sabotagedRelationships = random.among(relationships);
sabotage = sabotage(relationshipStore, sabotagedRelationships.getId());
}
} finally {
db.shutdown();
}
// THEN the checker should find it, where ever it is in the store
db = getGraphDatabaseAPI();
try {
DependencyResolver resolver = db.getDependencyResolver();
PageCache pageCache = resolver.resolveDependency(PageCache.class);
StoreFactory storeFactory = newStoreFactory(pageCache);
try (NeoStores neoStores = storeFactory.openAllNeoStores()) {
StoreAccess storeAccess = new StoreAccess(neoStores).initialize();
DirectStoreAccess directStoreAccess = new DirectStoreAccess(storeAccess, db.getDependencyResolver().resolveDependency(LabelScanStore.class), db.getDependencyResolver().resolveDependency(SchemaIndexProvider.class));
int threads = random.intBetween(2, 10);
FullCheck checker = new FullCheck(getTuningConfiguration(), ProgressMonitorFactory.NONE, Statistics.NONE, threads);
AssertableLogProvider logProvider = new AssertableLogProvider(true);
ConsistencySummaryStatistics summary = checker.execute(directStoreAccess, logProvider.getLog(FullCheck.class));
int relationshipInconsistencies = summary.getInconsistencyCountForRecordType(RecordType.RELATIONSHIP);
assertTrue("Couldn't detect sabotaged relationship " + sabotage, relationshipInconsistencies > 0);
logProvider.assertContainsLogCallContaining(sabotage.after.toString());
}
} finally {
db.shutdown();
}
}
use of org.neo4j.kernel.api.direct.DirectStoreAccess in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldNotReportIndexInconsistenciesIfIndexIsFailed.
@Test
public void shouldNotReportIndexInconsistenciesIfIndexIsFailed() throws Exception {
// this test fails all indexes, and then destroys a record and makes sure we only get a failure for
// the label scan store but not for any index
// given
DirectStoreAccess storeAccess = fixture.directStoreAccess();
// fail all indexes
Iterator<IndexRule> rules = new SchemaStorage(storeAccess.nativeStores().getSchemaStore()).indexesGetAll();
while (rules.hasNext()) {
IndexRule rule = rules.next();
IndexSamplingConfig samplingConfig = new IndexSamplingConfig(Config.empty());
IndexPopulator populator = storeAccess.indexes().getPopulator(rule.getId(), rule.getIndexDescriptor(), samplingConfig);
populator.markAsFailed("Oh noes! I was a shiny index and then I was failed");
populator.close(false);
}
for (Long indexedNodeId : indexedNodes) {
storeAccess.nativeStores().getNodeStore().updateRecord(notInUse(new NodeRecord(indexedNodeId, false, -1, -1)));
}
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.LABEL_SCAN_DOCUMENT, 1).verify(RecordType.COUNTS, 3).andThatsAllFolks();
}
Aggregations