private Sabotage sabotage( RelationshipStore store, long id ) { RelationshipRecord before = store.getRecord( id, store.newRecord(), RecordLoad.NORMAL ); RelationshipRecord after = before.clone(); long otherReference; if ( !after.isFirstInFirstChain() ) { after.setFirstPrevRel( otherReference = after.getFirstPrevRel() + 1 ); } else { after.setFirstNextRel( otherReference = after.getFirstNextRel() + 1 ); } store.prepareForCommit( after ); store.updateRecord( after ); RelationshipRecord other = store.getRecord( otherReference, store.newRecord(), RecordLoad.FORCE ); return new Sabotage( before, after, other ); } }
private RecordProxy<RelationshipRecord,Void> getRelationshipRecord( long id ) { if ( id < 0 || id >= relationshipStore.getHighId() ) { throw new NotFoundException( "id=" + id ); } return recordAccess.getRelRecords().getOrLoad( id, null ); }
private int count( long reference ) { if ( reference == NO_ID ) { return 0; } if ( edgePage == null ) { edgePage = relationshipStore.openPageCursorForReading( reference ); } relationshipStore.getRecordByCursor( reference, edge, RecordLoad.FORCE, edgePage ); if ( edge.getFirstNode() == getOwningNode() ) { return (int) edge.getFirstPrevRel(); } else { return (int) edge.getSecondPrevRel(); } }
private void unUseRecord( long recordId ) { RelationshipStore relationshipStore = neoStores.getRelationshipStore(); RelationshipRecord relationshipRecord = relationshipStore.getRecord( recordId, new RelationshipRecord( -1 ), RecordLoad.FORCE ); relationshipRecord.setInUse( false ); relationshipStore.updateRecord( relationshipRecord ); }
@Test public void shouldDeleteIdGeneratorsWhenOpeningExistingStore() throws IOException { // given long expectedHighId; try ( BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache( storage.fileSystem(), storage.pageCache(), PageCacheTracer.NULL, storage.directory().absolutePath(), LATEST_RECORD_FORMATS, DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults() ) ) { stores.createNew(); RelationshipStore relationshipStore = stores.getRelationshipStore(); RelationshipRecord record = relationshipStore.newRecord(); long no = NULL_REFERENCE.longValue(); record.initialize( true, no, 1, 2, 0, no, no, no, no, true, true ); record.setId( relationshipStore.nextId() ); expectedHighId = relationshipStore.getHighId(); relationshipStore.updateRecord( record ); // fiddle with the highId relationshipStore.setHighId( record.getId() + 999 ); } // when try ( BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache( storage.fileSystem(), storage.pageCache(), PageCacheTracer.NULL, storage.directory().absolutePath(), LATEST_RECORD_FORMATS, DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults() ) ) { stores.pruneAndOpenExistingStore( Predicates.alwaysTrue(), Predicates.alwaysTrue() ); // then assertEquals( expectedHighId, stores.getRelationshipStore().getHighId() ); } }
RelationshipRecord record = stores.getRelationshipStore().newRecord(); record = stores.getRelationshipStore().getRecord( relId, record, RecordLoad.NORMAL ); long propId = record.getNextProp(); record.setNextProp( AbstractBaseRecord.NO_ID ); stores.getRelationshipStore().updateRecord( record ); PropertyRecord propRecord = stores.getPropertyStore().getRecord( propId, stores.getPropertyStore().newRecord(), RecordLoad.NORMAL ); propRecord.setInUse( false );
private void update( RelationshipRecord record ) { resolveNeoStores().getRelationshipStore().updateRecord( record ); }
relationshipRecord.setFirstPrevRel( Record.NO_NEXT_RELATIONSHIP.intValue() ); relationshipRecord.setSecondPrevRel( Record.NO_NEXT_RELATIONSHIP.intValue() ); relationshipStore.prepareForCommit( relationshipRecord, prepareIdSequence.apply( relationshipRecord.getId() ) ); relationshipStore.updateRecord( relationshipRecord ); relationshipCount++; typeCounts.increment( relationshipRecord.getType() );
public NodeDegreeCountStage( Configuration config, RelationshipStore store, NodeRelationshipCache cache, StatsProvider memoryUsageStatsProvider ) { super( NAME, null, config, RECYCLE_BATCHES ); add( new BatchFeedStep( control(), config, forwards( 0, store.getHighId(), config ), store.getRecordSize() ) ); add( new ReadRecordsStep<>( control(), config, false, store ) ); add( new CalculateDenseNodesStep( control(), config, cache, memoryUsageStatsProvider ) ); } }
@Test public void shouldApplyRelationshipCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final RelationshipRecord before = new RelationshipRecord( 12 ); final RelationshipRecord record = new RelationshipRecord( 12, 3, 4, 5 ); record.setInUse( true ); final Command command = new Command.RelationshipCommand( before, record ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( relationshipStore, times( 1 ) ).setHighestPossibleIdInUse( record.getId() ); verify( relationshipStore, times( 1 ) ).updateRecord( record ); }
protected RelationshipImporter( BatchingNeoStores stores, IdMapper idMapper, DataStatistics typeDistribution, Monitor monitor, Collector badCollector, boolean validateRelationshipData, boolean doubleRecordUnits ) { super( stores, monitor ); this.doubleRecordUnits = doubleRecordUnits; this.relationshipTypeTokenRepository = stores.getRelationshipTypeRepository(); this.idMapper = idMapper; this.badCollector = badCollector; this.validateRelationshipData = validateRelationshipData; this.relationshipStore = stores.getRelationshipStore(); this.relationshipRecord = relationshipStore.newRecord(); this.relationshipIds = new BatchingIdGetter( relationshipStore ); this.typeCounts = typeDistribution.newClient(); this.prepareIdSequence = PrepareIdSequence.of( doubleRecordUnits ).apply( stores.getRelationshipStore() ); relationshipRecord.setInUse( true ); }
@Override public long createRelationship( long node1, long node2, RelationshipType type, Map<String, Object> properties ) { long id = relationshipStore.nextId(); int typeId = getOrCreateRelationshipTypeId( type.name() ); relationshipCreator.relationshipCreate( id, typeId, node1, node2, recordAccess, noopLockClient ); if ( properties != null && !properties.isEmpty() ) { RelationshipRecord record = recordAccess.getRelRecords().getOrLoad( id, null ).forChangingData(); record.setNextProp( propertyCreator.createPropertyChain( record, propertiesIterator( properties ), recordAccess.getPropertyRecords() ) ); } flushStrategy.flush(); return id; }
@Test public void shouldSetCorrectHighIdWhenApplyingExternalTransactions() throws Exception { // WHEN recovering a transaction that creates some data long nodeId = neoStores.getNodeStore().nextId(); long relationshipId = neoStores.getRelationshipStore().nextId(); int type = 1; applyExternalTransaction( 1, new NodeCommand( new NodeRecord( nodeId ), inUse( created( new NodeRecord( nodeId ) ) ) ), new RelationshipCommand( null, inUse( created( with( new RelationshipRecord( relationshipId ), nodeId, nodeId, type ) ) ) ) ); // and when, later on, recovering a transaction deleting some of those applyExternalTransaction( 2, new NodeCommand( inUse( created( new NodeRecord( nodeId ) ) ), new NodeRecord( nodeId ) ), new RelationshipCommand( null, new RelationshipRecord( relationshipId ) ) ); // THEN that should be possible and the high ids should be correct, i.e. highest applied + 1 assertEquals( nodeId + 1, neoStores.getNodeStore().getHighId() ); assertEquals( relationshipId + 1, neoStores.getRelationshipStore().getHighId() ); }
PageCursor relationshipPage( long reference ) { return relationshipStore.openPageCursorForReading( reference ); }
@Override public long relationshipsGetCount() { return relationshipStore.getNumberOfIdsInUse(); }
@Test public void shouldScanAllInUseRelationships() { // given RelationshipStore relationshipStore = neoStores.getRelationshipStore(); int count = 100; relationshipStore.setHighId( count ); Set<Long> expected = new HashSet<>(); for ( long id = 0; id < count; id++ ) { boolean inUse = random.nextBoolean(); createRelationshipRecord( id, 1, relationshipStore, inUse ); if ( inUse ) { expected.add( id ); } } // when assertSeesRelationships( expected, ANY_RELATIONSHIP_TYPE ); }
void updateCorrespondingIdGenerators( NeoStores neoStores ) { neoStores.getNodeStore().setHighestPossibleIdInUse( nodeId ); neoStores.getRelationshipStore().setHighestPossibleIdInUse( relId ); neoStores.getRelationshipGroupStore().setHighestPossibleIdInUse( relGroupId ); } }
private void prepareForCommit() { for ( Command.NodeCommand command : nodeCommands ) { neoStores.getNodeStore().prepareForCommit( command.getAfter() ); } for ( Command.RelationshipCommand command : relationshipCommands ) { neoStores.getRelationshipStore().prepareForCommit( command.getAfter() ); } for ( Command.RelationshipGroupCommand command : relationshipGroupCommands ) { neoStores.getRelationshipGroupStore().prepareForCommit( command.getAfter() ); } }
private void createRelationshipRecord( long id, int type, RelationshipStore relationshipStore, boolean used ) { relationshipStore.updateRecord( new RelationshipRecord( id ).initialize( used, -1, 1, 2, type, -1, -1, -1, -1, true, true ) ); }