use of org.neo4j.kernel.impl.store.RelationshipStore in project neo4j by neo4j.
the class ConsistencyCheckServiceIntegrationTest method prepareDbWithDeletedRelationshipPartOfTheChain.
private void prepareDbWithDeletedRelationshipPartOfTheChain() {
GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(testDirectory.graphDbDir()).setConfig(GraphDatabaseSettings.record_format, getRecordFormatName()).newGraphDatabase();
try {
RelationshipType relationshipType = RelationshipType.withName("testRelationshipType");
try (Transaction tx = db.beginTx()) {
Node node1 = set(db.createNode());
Node node2 = set(db.createNode(), property("key", "value"));
node1.createRelationshipTo(node2, relationshipType);
node1.createRelationshipTo(node2, relationshipType);
node1.createRelationshipTo(node2, relationshipType);
node1.createRelationshipTo(node2, relationshipType);
node1.createRelationshipTo(node2, relationshipType);
node1.createRelationshipTo(node2, relationshipType);
tx.success();
}
RecordStorageEngine recordStorageEngine = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class);
NeoStores neoStores = recordStorageEngine.testAccessNeoStores();
RelationshipStore relationshipStore = neoStores.getRelationshipStore();
RelationshipRecord relationshipRecord = new RelationshipRecord(-1);
RelationshipRecord record = relationshipStore.getRecord(4, relationshipRecord, RecordLoad.FORCE);
record.setInUse(false);
relationshipStore.updateRecord(relationshipRecord);
} finally {
db.shutdown();
}
}
use of org.neo4j.kernel.impl.store.RelationshipStore 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.impl.store.RelationshipStore in project neo4j by neo4j.
the class StoreMigrator method legacyRelationshipsAsInput.
private InputIterable<InputRelationship> legacyRelationshipsAsInput(NeoStores legacyStore, boolean requiresPropertyMigration, RecordCursors cursors) {
RelationshipStore store = legacyStore.getRelationshipStore();
final BiConsumer<InputRelationship, RelationshipRecord> propertyDecorator = propertyDecorator(requiresPropertyMigration, cursors);
return new StoreScanAsInputIterable<InputRelationship, RelationshipRecord>(store) {
@Override
protected InputRelationship inputEntityOf(RelationshipRecord record) {
InputRelationship result = new InputRelationship("legacy store", record.getId(), record.getId() * RelationshipRecordFormat.RECORD_SIZE, InputEntity.NO_PROPERTIES, record.getNextProp(), record.getFirstNode(), record.getSecondNode(), null, record.getType());
propertyDecorator.accept(result, record);
return result;
}
};
}
use of org.neo4j.kernel.impl.store.RelationshipStore in project neo4j by neo4j.
the class ParallelBatchImporter method doImport.
@Override
public void doImport(Input input) throws IOException {
log.info("Import starting");
// Things that we need to close later. The reason they're not in the try-with-resource statement
// is that we need to close, and set to null, at specific points preferably. So use good ol' finally block.
NodeRelationshipCache nodeRelationshipCache = null;
NodeLabelsCache nodeLabelsCache = null;
long startTime = currentTimeMillis();
CountingStoreUpdateMonitor storeUpdateMonitor = new CountingStoreUpdateMonitor();
try (BatchingNeoStores neoStore = getBatchingNeoStores();
CountsAccessor.Updater countsUpdater = neoStore.getCountsStore().reset(neoStore.getLastCommittedTransactionId());
InputCache inputCache = new InputCache(fileSystem, storeDir, recordFormats, config)) {
Collector badCollector = input.badCollector();
// Some temporary caches and indexes in the import
IoMonitor writeMonitor = new IoMonitor(neoStore.getIoTracer());
IdMapper idMapper = input.idMapper();
IdGenerator idGenerator = input.idGenerator();
nodeRelationshipCache = new NodeRelationshipCache(AUTO, config.denseNodeThreshold());
StatsProvider memoryUsageStats = new MemoryUsageStatsProvider(nodeRelationshipCache, idMapper);
InputIterable<InputNode> nodes = input.nodes();
InputIterable<InputRelationship> relationships = input.relationships();
InputIterable<InputNode> cachedNodes = cachedForSure(nodes, inputCache.nodes(MAIN, true));
InputIterable<InputRelationship> cachedRelationships = cachedForSure(relationships, inputCache.relationships(MAIN, true));
RelationshipStore relationshipStore = neoStore.getRelationshipStore();
// Stage 1 -- nodes, properties, labels
NodeStage nodeStage = new NodeStage(config, writeMonitor, nodes, idMapper, idGenerator, neoStore, inputCache, neoStore.getLabelScanStore(), storeUpdateMonitor, nodeRelationshipCache, memoryUsageStats);
executeStage(nodeStage);
if (idMapper.needsPreparation()) {
executeStage(new IdMapperPreparationStage(config, idMapper, cachedNodes, badCollector, memoryUsageStats));
PrimitiveLongIterator duplicateNodeIds = badCollector.leftOverDuplicateNodesIds();
if (duplicateNodeIds.hasNext()) {
executeStage(new DeleteDuplicateNodesStage(config, duplicateNodeIds, neoStore));
}
}
// Stage 2 -- calculate dense node threshold
CalculateDenseNodesStage calculateDenseNodesStage = new CalculateDenseNodesStage(withBatchSize(config, config.batchSize() * 10), relationships, nodeRelationshipCache, idMapper, badCollector, inputCache, neoStore);
executeStage(calculateDenseNodesStage);
importRelationships(nodeRelationshipCache, storeUpdateMonitor, neoStore, writeMonitor, idMapper, cachedRelationships, inputCache, calculateDenseNodesStage.getRelationshipTypes(Long.MAX_VALUE), calculateDenseNodesStage.getRelationshipTypes(100));
// Release this potentially really big piece of cached data
long peakMemoryUsage = totalMemoryUsageOf(idMapper, nodeRelationshipCache);
long highNodeId = nodeRelationshipCache.getHighNodeId();
idMapper.close();
idMapper = null;
nodeRelationshipCache.close();
nodeRelationshipCache = null;
new RelationshipGroupDefragmenter(config, executionMonitor).run(max(max(peakMemoryUsage, highNodeId * 4), mebiBytes(1)), neoStore, highNodeId);
// Stage 6 -- count nodes per label and labels per node
nodeLabelsCache = new NodeLabelsCache(AUTO, neoStore.getLabelRepository().getHighId());
memoryUsageStats = new MemoryUsageStatsProvider(nodeLabelsCache);
executeStage(new NodeCountsStage(config, nodeLabelsCache, neoStore.getNodeStore(), neoStore.getLabelRepository().getHighId(), countsUpdater, memoryUsageStats));
// Stage 7 -- count label-[type]->label
executeStage(new RelationshipCountsStage(config, nodeLabelsCache, relationshipStore, neoStore.getLabelRepository().getHighId(), neoStore.getRelationshipTypeRepository().getHighId(), countsUpdater, AUTO));
// We're done, do some final logging about it
long totalTimeMillis = currentTimeMillis() - startTime;
executionMonitor.done(totalTimeMillis, format("%n") + storeUpdateMonitor.toString() + format("%n") + "Peak memory usage: " + bytes(peakMemoryUsage));
log.info("Import completed, took " + Format.duration(totalTimeMillis) + ". " + storeUpdateMonitor);
} catch (Throwable t) {
log.error("Error during import", t);
throw Exceptions.launderedException(IOException.class, t);
} finally {
if (nodeRelationshipCache != null) {
nodeRelationshipCache.close();
}
if (nodeLabelsCache != null) {
nodeLabelsCache.close();
}
}
}
use of org.neo4j.kernel.impl.store.RelationshipStore in project neo4j by neo4j.
the class StoreIteratorRelationshipCursorTest method getRelationshipStore.
private RelationshipStore getRelationshipStore(RelationshipRecord relationshipRecord, RecordCursor recordCursor) {
RelationshipStore relationshipStore = mock(RelationshipStore.class);
when(recordCursor.acquire(anyLong(), any())).thenReturn(recordCursor);
when(relationshipStore.newRecord()).thenReturn(relationshipRecord);
when(relationshipStore.newRecordCursor(relationshipRecord)).thenReturn(recordCursor);
return relationshipStore;
}
Aggregations